Skip to content

Commit f0946cb

Browse files
dotdashgitster
authored andcommitted
tree_entry_interesting: a pathspec only matches at directory boundary
Previously the code did a simple prefix match, which means that a path in a directory "frotz/" would have matched with pathspec "f". Signed-off-by: Björn Steinbrink <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5bd27eb commit f0946cb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

t/t4010-diff-pathspec.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ test_expect_success \
6262
'git diff-index --cached $tree -- file0/ >current &&
6363
compare_diff_raw current expected'
6464

65+
test_expect_success 'diff-tree pathspec' '
66+
tree2=$(git write-tree) &&
67+
echo "$tree2" &&
68+
git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
69+
>expected &&
70+
test_cmp expected current
71+
'
72+
6573
test_done

tree-diff.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,16 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
118118
continue;
119119

120120
/*
121-
* The base is a subdirectory of a path which
122-
* was specified, so all of them are interesting.
121+
* If the base is a subdirectory of a path which
122+
* was specified, all of them are interesting.
123123
*/
124-
return 2;
124+
if (!matchlen ||
125+
base[matchlen] == '/' ||
126+
match[matchlen - 1] == '/')
127+
return 2;
128+
129+
/* Just a random prefix match */
130+
continue;
125131
}
126132

127133
/* Does the base match? */

0 commit comments

Comments
 (0)