ls-tree $di $dir: do not mistakenly recurse into directories
When applying two pathspecs, one of which is named as a prefix to the other, we mistakenly recursed into the shorter one. Noticed and fixed by David Reis. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 11, 2010 at 11:47 UTC
b294ed637d3c13cd96ba6f0e464e02e170cc54a6
2 files changed
+11
builtin/ls-tree.c
+2
@@ -52,6 +52,8 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
52
speclen = strlen(spec);
53
if (speclen <= len)
54
continue;
55
+ if (spec[len] && spec[len] != '/')
56
+ continue;
57
if (memcmp(pathname, spec, len))
58
continue;
59
return 1;
t/t3100-ls-tree-restrict.sh
+9
@@ -165,4 +165,13 @@ test_expect_success \
165
EOF
166
test_output'
167
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
+
177
test_done