3 # Copyright (c) 2007 David Symonds
5 test_description
='git checkout from subdirectories'
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success setup
'
12 echo "base" > file0 &&
15 echo "hello" > dir1/file1 &&
18 echo "bonjour" > dir2/file2 &&
21 git commit -m "populate tree"
25 test_expect_success
'remove and restore with relative path' '
30 git checkout HEAD -- ../file0 &&
31 test "base" = "$(cat ../file0)" &&
33 git checkout HEAD -- ../dir2/file2 &&
34 test "bonjour" = "$(cat ../dir2/file2)" &&
35 rm ../file0 ./file1 &&
36 git checkout HEAD -- .. &&
37 test "base" = "$(cat ../file0)" &&
38 test "hello" = "$(cat file1)"
43 test_expect_success
'checkout with empty prefix' '
46 git checkout HEAD -- file0 &&
47 test "base" = "$(cat file0)"
51 test_expect_success
'checkout with simple prefix' '
54 git checkout HEAD -- dir1 &&
55 test "hello" = "$(cat dir1/file1)" &&
57 git checkout HEAD -- dir1/file1 &&
58 test "hello" = "$(cat dir1/file1)"
62 test_expect_success
'checkout with complex relative path' '
66 git checkout HEAD -- ../dir1/../dir1/file1 &&
67 test "hello" = "$(cat file1)"
71 test_expect_success
'relative path outside tree should fail' \
72 'test_must_fail git checkout HEAD -- ../../Makefile'
74 test_expect_success
'incorrect relative path to file should fail (1)' \
75 'test_must_fail git checkout HEAD -- ../file0'
77 test_expect_success
'incorrect relative path should fail (2)' \
78 '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )'
80 test_expect_success
'incorrect relative path should fail (3)' \
81 '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )'