Skip to content

Commit 6634266

Browse files
committed
grep: ignore --recurse-submodules if --no-index is given
Since grep learned to recurse into submodules in 0281e48 (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. Signed-off-by: Philippe Blain <[email protected]>
1 parent bc7a3d4 commit 6634266

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Documentation/git-grep.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ OPTIONS
9696
Recursively search in each submodule that has been initialized and
9797
checked out in the repository. When used in combination with the
9898
<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.
100101

101102
-a::
102103
--text::

builtin/grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11151115
}
11161116
}
11171117

1118-
if (recurse_submodules && (!use_index || untracked))
1119-
die(_("option not supported with --recurse-submodules"));
1118+
if (recurse_submodules && untracked)
1119+
die(_("--untracked not supported with --recurse-submodules"));
11201120

11211121
if (!show_in_pager && !opt.status_only)
11221122
setup_pager();

t/t7814-grep-recurse-submodules.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,16 @@ test_incompatible_with_recurse_submodules ()
345345
}
346346

347347
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+
'
349358

350359
test_expect_success 'grep --recurse-submodules should pass the pattern type along' '
351360
# Fixed

0 commit comments

Comments
 (0)