builtin/grep.c: respect 'submodule.recurse' option

In builtin/grep.c we parse the config before evaluating the command line options. This makes the task of teaching grep to respect the new config option 'submodule.recurse' very easy by just parsing that option. As an alternative I had implemented a similar structure to treat submodules as the fetch/push command have, including * aligning the meaning of the 'recurse_submodules' to possible submodule values RECURSE_SUBMODULES_* as defined in submodule.h. * having a callback to parse the value and * reacting to the RECURSE_SUBMODULES_DEFAULT state that was the initial state. However all this is not needed for a true boolean value, so let's keep it simple. However this adds another place where "submodule.recurse" is parsed. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 31, 2017 at 17:30 UTC 9071c078af637573a3068c6920dd4ceff6a5a69f
2 files changed +21
builtin/grep.c
+3
@@ -302,6 +302,9 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
302 #endif
303 }
304
305 + if (!strcmp(var, "submodule.recurse"))
306 + recurse_submodules = git_config_bool(var, value);
307 +
308 return st;
309 }
310
t/t7814-grep-recurse-submodules.sh
+18
@@ -33,6 +33,24 @@ test_expect_success 'grep correctly finds patterns in a submodule' '
33 test_cmp expect actual
34 '
35
36 +test_expect_success 'grep finds patterns in a submodule via config' '
37 + test_config submodule.recurse true &&
38 + # expect from previous test
39 + git grep -e "(3|4)" >actual &&
40 + test_cmp expect actual
41 +'
42 +
43 +test_expect_success 'grep --no-recurse-submodules overrides config' '
44 + test_config submodule.recurse true &&
45 + cat >expect <<-\EOF &&
46 + a:(1|2)d(3|4)
47 + b/b:(3|4)
48 + EOF
49 +
50 + git grep -e "(3|4)" --no-recurse-submodules >actual &&
51 + test_cmp expect actual
52 +'
53 +
54 test_expect_success 'grep and basic pathspecs' '
55 cat >expect <<-\EOF &&
56 submodule/a:(1|2)d(3|4)