3 # Copyright (c) 2007 David Symonds
5 test_description='git checkout from subdirectories'
9 test_expect_success setup '
11 echo "base" > file0 &&
14 echo "hello" > dir1/file1 &&
17 echo "bonjour" > dir2/file2 &&
20 git commit -m "populate tree"
24 test_expect_success 'remove and restore with relative path' '
29 git checkout HEAD -- ../file0 &&
30 test "base" = "$(cat ../file0)" &&
32 git checkout HEAD -- ../dir2/file2 &&
33 test "bonjour" = "$(cat ../dir2/file2)" &&
34 rm ../file0 ./file1 &&
35 git checkout HEAD -- .. &&
36 test "base" = "$(cat ../file0)" &&
37 test "hello" = "$(cat file1)"
42 test_expect_success 'checkout with empty prefix' '
45 git checkout HEAD -- file0 &&
46 test "base" = "$(cat file0)"
50 test_expect_success 'checkout with simple prefix' '
53 git checkout HEAD -- dir1 &&
54 test "hello" = "$(cat dir1/file1)" &&
56 git checkout HEAD -- dir1/file1 &&
57 test "hello" = "$(cat dir1/file1)"
61 test_expect_success 'checkout with complex relative path' '
65 git checkout HEAD -- ../dir1/../dir1/file1 &&
66 test "hello" = "$(cat file1)"
70 test_expect_success 'relative path outside tree should fail' \
71 'test_must_fail git checkout HEAD -- ../../Makefile'
73 test_expect_success 'incorrect relative path to file should fail (1)' \
74 'test_must_fail git checkout HEAD -- ../file0'
76 test_expect_success 'incorrect relative path should fail (2)' \
77 '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )'
79 test_expect_success 'incorrect relative path should fail (3)' \
80 '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )'