@matheusbsbs / matheus-bagliano / commits / c56c48dd07
Fork 0

grep: ignore --recurse-submodules if --no-index is given

Since grep learned to recurse into submodules in 0281e487fd (grep: optionally recurse into submodules, 2016-12-16), using --recurse-submodules along with --no-index makes Git die(). This is unfortunate because if submodule.recurse is set in a user's ~/.gitconfig, invoking `git grep --no-index` either inside or outside a Git repository results in fatal: option not supported with --recurse-submodules Let's allow using these options together, so that setting submodule.recurse globally does not prevent using `git grep --no-index`. Using `--recurse-submodules` should not have any effect if `--no-index` is used inside a repository, as Git will recurse into the checked out submodule directories just like into regular directories. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Jan 30, 2020 at 13:37 UTC c56c48dd0750dc7759f5e9a33cd4a01d6162b06e
3 files changed +17 -4
Documentation/git-grep.txt
+2 -1
@@ -96,7 +96,8 @@ OPTIONS
96 Recursively search in each submodule that has been initialized and
97 checked out in the repository. When used in combination with the
98 <tree> option the prefix of all submodule output will be the name of
99 - the parent project's <tree> object.
99 + the parent project's <tree> object. This option has no effect
100 + if `--no-index` is given.
101
102 -a::
103 --text::
builtin/grep.c
+5 -2
@@ -958,6 +958,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
958 /* die the same way as if we did it at the beginning */
959 setup_git_directory();
960 }
961 + /* Ignore --recurse-submodules if --no-index is given or implied */
962 + if (!use_index)
963 + recurse_submodules = 0;
964
965 /*
966 * skip a -- separator; we know it cannot be
@@ -1115,8 +1118,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1118 }
1119 }
1120
1118 - if (recurse_submodules && (!use_index || untracked))
1119 - die(_("option not supported with --recurse-submodules"));
1121 + if (recurse_submodules && untracked)
1122 + die(_("--untracked not supported with --recurse-submodules"));
1123
1124 if (!show_in_pager && !opt.status_only)
1125 setup_pager();
t/t7814-grep-recurse-submodules.sh
+10 -1
@@ -345,7 +345,16 @@ test_incompatible_with_recurse_submodules ()
345 }
346
347 test_incompatible_with_recurse_submodules --untracked
348 -test_incompatible_with_recurse_submodules --no-index
348 +
349 +test_expect_success 'grep --recurse-submodules --no-index ignores --recurse-submodules' '
350 + git grep --recurse-submodules --no-index -e "^(.|.)[\d]" >actual &&
351 + cat >expect <<-\EOF &&
352 + a:(1|2)d(3|4)
353 + submodule/a:(1|2)d(3|4)
354 + submodule/sub/a:(1|2)d(3|4)
355 + EOF
356 + test_cmp expect actual
357 +'
358
359 test_expect_success 'grep --recurse-submodules should pass the pattern type along' '
360 # Fixed