Code

ls-tree $di $dir: do not mistakenly recurse into directories
authorJunio C Hamano <gitster@pobox.com>
Sat, 11 Sep 2010 18:47:09 +0000 (11:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 12 Sep 2010 20:52:03 +0000 (13:52 -0700)
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>
builtin/ls-tree.c
t/t3100-ls-tree-restrict.sh

index dc86b0d9a997f98ad43ca2897055a92b8a3eb7d0..a8187568bf99872e717c389b031331838544fe04 100644 (file)
@@ -52,6 +52,8 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
                speclen = strlen(spec);
                if (speclen <= len)
                        continue;
+               if (spec[len] && spec[len] != '/')
+                       continue;
                if (memcmp(pathname, spec, len))
                        continue;
                return 1;
index eee0d344d24623ad9928366729c8efaea699fcd7..81d90b66c50e75323a44aaf5e2e067d5a3569e6a 100755 (executable)
@@ -165,4 +165,13 @@ test_expect_success \
 EOF
      test_output'
 
+test_expect_success \
+    'ls-tree with one path a prefix of the other' \
+    'git ls-tree $tree path2/baz path2/bazbo >current &&
+     make_expected <<\EOF &&
+040000 tree X  path2/baz
+120000 blob X  path2/bazbo
+EOF
+     test_output'
+
 test_done