]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2008-checkout-subdir.sh
The sixth batch
[thirdparty/git.git] / t / t2008-checkout-subdir.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 David Symonds
4
5 test_description='git checkout from subdirectories'
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success setup '
11
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"
22
23 '
24
25 test_expect_success 'remove and restore with relative path' '
26
27 (
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)"
39 )
40
41 '
42
43 test_expect_success 'checkout with empty prefix' '
44
45 rm file0 &&
46 git checkout HEAD -- file0 &&
47 test "base" = "$(cat file0)"
48
49 '
50
51 test_expect_success 'checkout with simple prefix' '
52
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)"
59
60 '
61
62 test_expect_success 'checkout with complex relative path' '
63 (
64 cd dir1 &&
65 rm file1 &&
66 git checkout HEAD -- ../dir1/../dir1/file1 &&
67 test "hello" = "$(cat file1)"
68 )
69 '
70
71 test_expect_success 'relative path outside tree should fail' \
72 'test_must_fail git checkout HEAD -- ../../Makefile'
73
74 test_expect_success 'incorrect relative path to file should fail (1)' \
75 'test_must_fail git checkout HEAD -- ../file0'
76
77 test_expect_success 'incorrect relative path should fail (2)' \
78 '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )'
79
80 test_expect_success 'incorrect relative path should fail (3)' \
81 '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )'
82
83 test_done