]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t0060: add tests for prefix_path when path begins with work tree
authorMartin Erik Werner <martinerikwerner@gmail.com>
Tue, 4 Feb 2014 14:25:18 +0000 (15:25 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Feb 2014 20:08:47 +0000 (12:08 -0800)
One edge-case that isn't currently checked in the tests is the beginning
of the path matching the work tree, despite the target not actually
being the work tree, for example:

  path = /dir/repoa
  work_tree = /dir/repo

should fail since the path is outside the repo. However, if /dir/repoa
is in fact a symlink that points to /dir/repo, it should instead
succeed.

Add two tests covering these cases, since they might be potential
regression points.

Signed-off-by: Martin Erik Werner <martinerikwerner@gmail.com>
Reviewed-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0060-path-utils.sh

index b8e92e1a2affe8a60caecc770db188e5090a29f0..f8286b1c3f211d49cc8341b979a57f4b2fb16ec4 100755 (executable)
@@ -201,6 +201,16 @@ test_expect_success 'prefix_path works with only absolute path to work tree' '
        test_cmp expected actual
 '
 
+test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
+       test_must_fail test-path-utils prefix_path prefix "$(pwd)a"
+'
+
+test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having  same beginning as work tree' '
+       git init repo &&
+       ln -s repo repolink &&
+       test "a" = "$(cd repo && test-path-utils prefix_path prefix "$(pwd)/../repolink/a")"
+'
+
 relative_path /foo/a/b/c/      /foo/a/b/       c/
 relative_path /foo/a/b/c/      /foo/a/b        c/
 relative_path /foo/a//b//c/    ///foo/a/b//    c/              POSIX