Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t2008-checkout-subdir.sh
blob8a518a44ea2d2a65f6ee2d9d88c5a8233476c902
1 #!/bin/sh
3 # Copyright (c) 2007 David Symonds
5 test_description='git checkout from subdirectories'
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success setup '
12 echo "base" > file0 &&
13 git add file0 &&
14 mkdir dir1 &&
15 echo "hello" > dir1/file1 &&
16 git add dir1/file1 &&
17 mkdir dir2 &&
18 echo "bonjour" > dir2/file2 &&
19 git add dir2/file2 &&
20 test_tick &&
21 git commit -m "populate tree"
25 test_expect_success 'remove and restore with relative path' '
28 cd dir1 &&
29 rm ../file0 &&
30 git checkout HEAD -- ../file0 &&
31 test "base" = "$(cat ../file0)" &&
32 rm ../dir2/file2 &&
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' '
45 rm file0 &&
46 git checkout HEAD -- file0 &&
47 test "base" = "$(cat file0)"
51 test_expect_success 'checkout with simple prefix' '
53 rm dir1/file1 &&
54 git checkout HEAD -- dir1 &&
55 test "hello" = "$(cat dir1/file1)" &&
56 rm dir1/file1 &&
57 git checkout HEAD -- dir1/file1 &&
58 test "hello" = "$(cat dir1/file1)"
62 test_expect_success 'checkout with complex relative path' '
64 cd dir1 &&
65 rm file1 &&
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 )'
83 test_done