Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Documentation/git-grep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ OPTIONS
Recursively search in each submodule that has been initialized and
checked out in the repository. When used in combination with the
<tree> option the prefix of all submodule output will be the name of
the parent project's <tree> object.
the parent project's <tree> object. This option has no effect
if `--no-index` is given.

-a::
--text::
Expand Down
7 changes: 5 additions & 2 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
/* die the same way as if we did it at the beginning */
setup_git_directory();
}
/* Ignore --recurse-submodules if --no-index is given or implied */
if (!use_index)
recurse_submodules = 0;

/*
* skip a -- separator; we know it cannot be
Expand Down Expand Up @@ -1115,8 +1118,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
}
}

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

if (!show_in_pager && !opt.status_only)
setup_pager();
Expand Down
11 changes: 10 additions & 1 deletion t/t7814-grep-recurse-submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,16 @@ test_incompatible_with_recurse_submodules ()
}

test_incompatible_with_recurse_submodules --untracked
test_incompatible_with_recurse_submodules --no-index

test_expect_success 'grep --recurse-submodules --no-index ignores --recurse-submodules' '
git grep --recurse-submodules --no-index -e "^(.|.)[\d]" >actual &&
cat >expect <<-\EOF &&
a:(1|2)d(3|4)
submodule/a:(1|2)d(3|4)
submodule/sub/a:(1|2)d(3|4)
EOF
test_cmp expect actual
'

test_expect_success 'grep --recurse-submodules should pass the pattern type along' '
# Fixed
Expand Down