]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/grep.c: respect 'submodule.recurse' option
authorStefan Beller <sbeller@google.com>
Thu, 1 Jun 2017 00:30:48 +0000 (17:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Jun 2017 01:36:36 +0000 (10:36 +0900)
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>
builtin/grep.c
t/t7814-grep-recurse-submodules.sh

index b1095362fbf9a4726367b96e0f34d38faf27d9bd..454e26382006f3ed872fa8150f37f595706010b6 100644 (file)
@@ -302,6 +302,9 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
 #endif
        }
 
+       if (!strcmp(var, "submodule.recurse"))
+               recurse_submodules = git_config_bool(var, value);
+
        return st;
 }
 
index 3a58197f472f38c320de33fa82896c0a77d125ae..7184113b9b2b381a6e7e0def8a8c1ba06771f8a6 100755 (executable)
@@ -33,6 +33,24 @@ test_expect_success 'grep correctly finds patterns in a submodule' '
        test_cmp expect actual
 '
 
+test_expect_success 'grep finds patterns in a submodule via config' '
+       test_config submodule.recurse true &&
+       # expect from previous test
+       git grep -e "(3|4)" >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'grep --no-recurse-submodules overrides config' '
+       test_config submodule.recurse true &&
+       cat >expect <<-\EOF &&
+       a:(1|2)d(3|4)
+       b/b:(3|4)
+       EOF
+
+       git grep -e "(3|4)" --no-recurse-submodules >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'grep and basic pathspecs' '
        cat >expect <<-\EOF &&
        submodule/a:(1|2)d(3|4)