Skip to content

Commit 556ccd4

Browse files
committed
Merge branch 'pb/do-not-recurse-grep-no-index'
"git grep --no-index" should not get affected by the contents of the .gitmodules file but when "--recurse-submodules" is given or the "submodule.recurse" variable is set, it did. Now these settings are ignored in the "--no-index" mode. * pb/do-not-recurse-grep-no-index: grep: ignore --recurse-submodules if --no-index is given
2 parents 17e4a1b + c56c48d commit 556ccd4

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)