Skip to content

Commit 2e1e961

Browse files
committed
Merge branch 'dr/maint-ls-tree-prefix-recursion-fix'
* dr/maint-ls-tree-prefix-recursion-fix: ls-tree $di $dir: do not mistakenly recurse into directories
2 parents 0c61c6d + b294ed6 commit 2e1e961

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/ls-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
5252
speclen = strlen(spec);
5353
if (speclen <= len)
5454
continue;
55+
if (spec[len] && spec[len] != '/')
56+
continue;
5557
if (memcmp(pathname, spec, len))
5658
continue;
5759
return 1;

t/t3100-ls-tree-restrict.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,13 @@ test_expect_success \
165165
EOF
166166
test_output'
167167

168+
test_expect_success \
169+
'ls-tree with one path a prefix of the other' \
170+
'git ls-tree $tree path2/baz path2/bazbo >current &&
171+
make_expected <<\EOF &&
172+
040000 tree X path2/baz
173+
120000 blob X path2/bazbo
174+
EOF
175+
test_output'
176+
168177
test_done

0 commit comments

Comments
 (0)