Skip to content

Commit 8092bfb

Browse files
committed
match_tree_entry(): a pathspec only matches at directory boundaries
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: Junio C Hamano <[email protected]>
1 parent f0946cb commit 8092bfb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

t/t3101-ls-tree-dirname.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@ test_expect_success \
135135
EOF
136136
test_output'
137137

138+
test_expect_success 'ls-tree filter is leading path match' '
139+
git ls-tree $tree pa path3/a >current &&
140+
>expected &&
141+
test_output
142+
'
143+
138144
test_done

tree.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
6060
/* If it doesn't match, move along... */
6161
if (strncmp(base, match, matchlen))
6262
continue;
63-
/* The base is a subdirectory of a path which was specified. */
64-
return 1;
63+
/* pathspecs match only at the directory boundaries */
64+
if (!matchlen ||
65+
base[matchlen] == '/' ||
66+
match[matchlen - 1] == '/')
67+
return 1;
68+
continue;
6569
}
6670

6771
/* Does the base match? */

0 commit comments

Comments
 (0)