git-checkout: Test for relative path use.
Signed-off-by: David Symonds <dsymonds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Symonds committed
Nov 9, 2007 at 20:12 UTC
fed1b5cac0cc3ae324dc004181a276ea16589951
1 file changed
+82
t/t2008-checkout-subdir.sh
new
+82
@@ -0,0 +1,82 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2007 David Symonds
4
+
5
+test_description='git checkout from subdirectories'
6
+
7
+. ./test-lib.sh
8
+
9
+test_expect_success setup '
10
+
11
+ echo "base" > file0 &&
12
+ git add file0 &&
13
+ mkdir dir1 &&
14
+ echo "hello" > dir1/file1 &&
15
+ git add dir1/file1 &&
16
+ mkdir dir2 &&
17
+ echo "bonjour" > dir2/file2 &&
18
+ git add dir2/file2 &&
19
+ test_tick &&
20
+ git commit -m "populate tree"
21
+
22
+'
23
+
24
+test_expect_success 'remove and restore with relative path' '
25
+
26
+ (
27
+ cd dir1 &&
28
+ rm ../file0 &&
29
+ git checkout HEAD -- ../file0 &&
30
+ test "base" = "$(cat ../file0)" &&
31
+ rm ../dir2/file2 &&
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)"
38
+ )
39
+
40
+'
41
+
42
+test_expect_success 'checkout with empty prefix' '
43
+
44
+ rm file0 &&
45
+ git checkout HEAD -- file0 &&
46
+ test "base" = "$(cat file0)"
47
+
48
+'
49
+
50
+test_expect_success 'checkout with simple prefix' '
51
+
52
+ rm dir1/file1 &&
53
+ git checkout HEAD -- dir1 &&
54
+ test "hello" = "$(cat dir1/file1)" &&
55
+ rm dir1/file1 &&
56
+ git checkout HEAD -- dir1/file1 &&
57
+ test "hello" = "$(cat dir1/file1)"
58
+
59
+'
60
+
61
+# This is not expected to work as ls-files was not designed
62
+# to deal with such. Enable it when ls-files is updated.
63
+: test_expect_success 'checkout with complex relative path' '
64
+
65
+ rm file1 &&
66
+ git checkout HEAD -- ../dir1/../dir1/file1 && test -f ./file1
67
+
68
+'
69
+
70
+test_expect_failure 'relative path outside tree should fail' \
71
+ 'git checkout HEAD -- ../../Makefile'
72
+
73
+test_expect_failure 'incorrect relative path to file should fail (1)' \
74
+ 'git checkout HEAD -- ../file0'
75
+
76
+test_expect_failure 'incorrect relative path should fail (2)' \
77
+ '( cd dir1 && git checkout HEAD -- ./file0 )'
78
+
79
+test_expect_failure 'incorrect relative path should fail (3)' \
80
+ '( cd dir1 && git checkout HEAD -- ../../file0 )'
81
+
82
+test_done