Skip to content

Commit 6fc8bf7

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. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Philippe Blain <[email protected]>
1 parent bc7a3d4 commit 6fc8bf7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
958958
/* die the same way as if we did it at the beginning */
959959
setup_git_directory();
960960
}
961+
/* Ignore --recurse-submodules if --no-index is given or implied */
962+
if (!use_index)
963+
recurse_submodules = 0;
961964

962965
/*
963966
* skip a -- separator; we know it cannot be
@@ -1115,8 +1118,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11151118
}
11161119
}
11171120

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"));
11201123

11211124
if (!show_in_pager && !opt.status_only)
11221125
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)