]> Kevux Git Server - rit/commitdiff
get_pathspec(): die when an out-of-tree path is given
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 Mar 2008 07:18:08 +0000 (23:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Mar 2008 08:14:42 +0000 (00:14 -0800)
An earlier commit d089ebaa (setup: sanitize absolute and funny paths) made
get_pathspec() aware of absolute paths, but with a botched interface that
forced the callers to count the resulting pathspecs in order to detect
an error of giving a path that is outside the work tree.

This fixes it, by dying inside the function.

We had ls-tree test that relied on a misfeature in the original
implementation of its pathspec handling.  Leading slashes were silently
removed from them.  However we allow giving absolute pathnames (people
want to cut and paste from elsewhere) that are inside work tree these
days, so a pathspec that begin with slash _should_ be treated as a full
path.  The test is adjusted to match the updated rule for get_pathspec().

Earlier I mistook three tests given by Robin that they should succeed, but
these are attempts to add path outside work tree, which should fail
loudly.  These tests also have been fixed.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
setup.c
t/t3101-ls-tree-dirname.sh
t/t7010-setup.sh

diff --git a/setup.c b/setup.c
index 89c81e5..41e298b 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -202,6 +202,8 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
                const char *p = prefix_path(prefix, prefixlen, *src);
                if (p)
                        *(dst++) = p;
+               else
+                       exit(128); /* error message already given */
                src++;
        }
        *dst = NULL;
index 39fe267..70f9ce9 100755 (executable)
@@ -120,7 +120,7 @@ EOF
 # having 1.txt and path3
 test_expect_success \
     'ls-tree filter odd names' \
-    'git ls-tree $tree 1.txt /1.txt //1.txt path3/1.txt /path3/1.txt //path3//1.txt path3 /path3/ path3// >current &&
+    'git ls-tree $tree 1.txt ./1.txt .//1.txt path3/1.txt path3/./1.txt path3 path3// >current &&
      cat >expected <<\EOF &&
 100644 blob X  1.txt
 100644 blob X  path3/1.txt
index e809e0e..bc8ab6a 100755 (executable)
@@ -142,15 +142,16 @@ test_expect_success 'setup deeper work tree' '
 test_expect_success 'add a directory outside the work tree' '(
        cd tester &&
        d1="$(cd .. ; pwd)" &&
-       git add "$d1"
+       test_must_fail git add "$d1"
 )'
 
+
 test_expect_success 'add a file outside the work tree, nasty case 1' '(
        cd tester &&
        f="$(pwd)x" &&
        echo "$f" &&
        touch "$f" &&
-       git add "$f"
+       test_must_fail git add "$f"
 )'
 
 test_expect_success 'add a file outside the work tree, nasty case 2' '(
@@ -158,7 +159,7 @@ test_expect_success 'add a file outside the work tree, nasty case 2' '(
        f="$(pwd | sed "s/.$//")x" &&
        echo "$f" &&
        touch "$f" &&
-       git add "$f"
+       test_must_fail git add "$f"
 )'
 
 test_done