Skip to content

Commit f4f233e

Browse files
committed
Merge branch 'bw/pathspec-match-submodule-boundary'
An v2.12-era regression in pathspec match logic, which made it look into submodule tree even when it is not desired, has been fixed. * bw/pathspec-match-submodule-boundary: pathspec: only match across submodule boundaries when requested
2 parents d7c6c23 + eef3df5 commit f4f233e

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

builtin/grep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10151015
prefix, argv + i);
10161016
pathspec.max_depth = opt.max_depth;
10171017
pathspec.recursive = 1;
1018+
pathspec.recurse_submodules = !!recurse_submodules;
10181019

10191020
#ifndef NO_PTHREADS
10201021
if (list.nr || cached || show_in_pager)

pathspec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct pathspec {
2424
int nr;
2525
unsigned int has_wildcard:1;
2626
unsigned int recursive:1;
27+
unsigned int recurse_submodules:1;
2728
unsigned magic;
2829
int max_depth;
2930
struct pathspec_item {

t/t4208-log-magic-pathspec.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,23 @@ test_expect_success 'command line pathspec parsing for "git log"' '
9393
git log --merge -- a
9494
'
9595

96+
test_expect_success 'tree_entry_interesting does not match past submodule boundaries' '
97+
test_when_finished "rm -rf repo submodule" &&
98+
git init submodule &&
99+
test_commit -C submodule initial &&
100+
git init repo &&
101+
>"repo/[bracket]" &&
102+
git -C repo add "[bracket]" &&
103+
test_tick &&
104+
git -C repo commit -m bracket &&
105+
git -C repo rev-list HEAD -- "[bracket]" >expect &&
106+
107+
git -C repo submodule add ../submodule &&
108+
test_tick &&
109+
git -C repo commit -m submodule &&
110+
111+
git -C repo rev-list HEAD -- "[bracket]" >actual &&
112+
test_cmp expect actual
113+
'
114+
96115
test_done

tree-walk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,8 @@ static enum interesting do_match(const struct name_entry *entry,
10111011
* character. More accurate matching can then
10121012
* be performed in the submodule itself.
10131013
*/
1014-
if (ps->recursive && S_ISGITLINK(entry->mode) &&
1014+
if (ps->recurse_submodules &&
1015+
S_ISGITLINK(entry->mode) &&
10151016
!ps_strncmp(item, match + baselen,
10161017
entry->path,
10171018
item->nowildcard_len - baselen))
@@ -1060,7 +1061,7 @@ static enum interesting do_match(const struct name_entry *entry,
10601061
* character. More accurate matching can then
10611062
* be performed in the submodule itself.
10621063
*/
1063-
if (ps->recursive && S_ISGITLINK(entry->mode) &&
1064+
if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
10641065
!ps_strncmp(item, match, base->buf + base_offset,
10651066
item->nowildcard_len)) {
10661067
strbuf_setlen(base, base_offset + baselen);

0 commit comments

Comments
 (0)