]>
Commit | Line | Data |
---|---|---|
c43ce6d6 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Try various core-level commands in subdirectory. | |
7 | ' | |
8 | ||
055e57b7 | 9 | TEST_PASSES_SANITIZE_LEAK=true |
c43ce6d6 | 10 | . ./test-lib.sh |
ea5070c9 | 11 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
c43ce6d6 JH |
12 | |
13 | test_expect_success setup ' | |
14 | long="a b c d e f g h i j k l m n o p q r s t u v w x y z" && | |
08495412 | 15 | test_write_lines $long >one && |
c43ce6d6 | 16 | mkdir dir && |
08495412 | 17 | test_write_lines x y z $long a b c >dir/two && |
c43ce6d6 JH |
18 | cp one original.one && |
19 | cp dir/two original.two | |
20 | ' | |
c43ce6d6 JH |
21 | |
22 | test_expect_success 'update-index and ls-files' ' | |
5be60078 | 23 | git update-index --add one && |
c9e454cc | 24 | case "$(git ls-files)" in |
335f8787 | 25 | one) echo pass one ;; |
fe13adb1 | 26 | *) echo bad one; return 1 ;; |
c43ce6d6 | 27 | esac && |
18a82692 JN |
28 | ( |
29 | cd dir && | |
30 | git update-index --add two && | |
c9e454cc | 31 | case "$(git ls-files)" in |
18a82692 JN |
32 | two) echo pass two ;; |
33 | *) echo bad two; exit 1 ;; | |
34 | esac | |
fd4ec4f2 | 35 | ) && |
c9e454cc | 36 | case "$(git ls-files)" in |
335f8787 | 37 | dir/two"$LF"one) echo pass both ;; |
fe13adb1 | 38 | *) echo bad; return 1 ;; |
c43ce6d6 JH |
39 | esac |
40 | ' | |
41 | ||
42 | test_expect_success 'cat-file' ' | |
c9e454cc EP |
43 | two=$(git ls-files -s dir/two) && |
44 | two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") && | |
c43ce6d6 | 45 | echo "$two" && |
5be60078 | 46 | git cat-file -p "$two" >actual && |
c43ce6d6 | 47 | cmp dir/two actual && |
fd3c32c9 JL |
48 | ( |
49 | cd dir && | |
50 | git cat-file -p "$two" >actual && | |
51 | cmp two actual | |
52 | ) | |
c43ce6d6 JH |
53 | ' |
54 | rm -f actual dir/actual | |
55 | ||
56 | test_expect_success 'diff-files' ' | |
c43ce6d6 JH |
57 | echo a >>one && |
58 | echo d >>dir/two && | |
c9e454cc | 59 | case "$(git diff-files --name-only)" in |
335f8787 | 60 | dir/two"$LF"one) echo pass top ;; |
fe13adb1 | 61 | *) echo bad top; return 1 ;; |
c43ce6d6 JH |
62 | esac && |
63 | # diff should not omit leading paths | |
fd3c32c9 JL |
64 | ( |
65 | cd dir && | |
c9e454cc | 66 | case "$(git diff-files --name-only)" in |
fd3c32c9 JL |
67 | dir/two"$LF"one) echo pass subdir ;; |
68 | *) echo bad subdir; exit 1 ;; | |
69 | esac && | |
c9e454cc | 70 | case "$(git diff-files --name-only .)" in |
fd3c32c9 JL |
71 | dir/two) echo pass subdir limited ;; |
72 | *) echo bad subdir limited; exit 1 ;; | |
73 | esac | |
74 | ) | |
c43ce6d6 JH |
75 | ' |
76 | ||
77 | test_expect_success 'write-tree' ' | |
c9e454cc | 78 | top=$(git write-tree) && |
c43ce6d6 | 79 | echo $top && |
fd3c32c9 JL |
80 | ( |
81 | cd dir && | |
c9e454cc | 82 | sub=$(git write-tree) && |
fd3c32c9 JL |
83 | echo $sub && |
84 | test "z$top" = "z$sub" | |
85 | ) | |
c43ce6d6 JH |
86 | ' |
87 | ||
88 | test_expect_success 'checkout-index' ' | |
5be60078 | 89 | git checkout-index -f -u one && |
c43ce6d6 | 90 | cmp one original.one && |
fd3c32c9 JL |
91 | ( |
92 | cd dir && | |
93 | git checkout-index -f -u two && | |
94 | cmp two ../original.two | |
95 | ) | |
c43ce6d6 JH |
96 | ' |
97 | ||
98 | test_expect_success 'read-tree' ' | |
c43ce6d6 | 99 | rm -f one dir/two && |
c9e454cc | 100 | tree=$(git write-tree) && |
ea5070c9 | 101 | read_tree_u_must_succeed --reset -u "$tree" && |
c43ce6d6 JH |
102 | cmp one original.one && |
103 | cmp dir/two original.two && | |
fd3c32c9 JL |
104 | ( |
105 | cd dir && | |
106 | rm -f two && | |
ea5070c9 | 107 | read_tree_u_must_succeed --reset -u "$tree" && |
fd3c32c9 JL |
108 | cmp two ../original.two && |
109 | cmp ../one ../original.one | |
110 | ) | |
c43ce6d6 JH |
111 | ' |
112 | ||
101662c2 MG |
113 | test_expect_success 'alias expansion' ' |
114 | ( | |
d16ece20 | 115 | git config alias.test-status-alias status && |
101662c2 MG |
116 | cd dir && |
117 | git status && | |
d16ece20 | 118 | git test-status-alias |
101662c2 MG |
119 | ) |
120 | ' | |
0daed417 | 121 | |
f57a8715 | 122 | test_expect_success !MINGW '!alias expansion' ' |
0daed417 MG |
123 | pwd >expect && |
124 | ( | |
d16ece20 | 125 | git config alias.test-alias-directory !pwd && |
0daed417 | 126 | cd dir && |
d16ece20 | 127 | git test-alias-directory >../actual |
0daed417 MG |
128 | ) && |
129 | test_cmp expect actual | |
130 | ' | |
131 | ||
7cf16a14 MG |
132 | test_expect_success 'GIT_PREFIX for !alias' ' |
133 | printf "dir/" >expect && | |
134 | ( | |
d16ece20 | 135 | git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" && |
7cf16a14 | 136 | cd dir && |
d16ece20 | 137 | git test-alias-directory >../actual |
7cf16a14 MG |
138 | ) && |
139 | test_cmp expect actual | |
140 | ' | |
141 | ||
1f5d271f DA |
142 | test_expect_success 'GIT_PREFIX for built-ins' ' |
143 | # Use GIT_EXTERNAL_DIFF to test that the "diff" built-in | |
144 | # receives the GIT_PREFIX variable. | |
a3bb8ca7 JH |
145 | echo "dir/" >expect && |
146 | write_script diff <<-\EOF && | |
147 | printf "%s\n" "$GIT_PREFIX" | |
148 | EOF | |
1f5d271f DA |
149 | ( |
150 | cd dir && | |
a3bb8ca7 | 151 | echo "change" >two && |
f2deabfc | 152 | GIT_EXTERNAL_DIFF=./diff git diff >../actual && |
1f5d271f DA |
153 | git checkout -- two |
154 | ) && | |
155 | test_cmp expect actual | |
156 | ' | |
157 | ||
3dff5379 | 158 | test_expect_success 'no file/rev ambiguity check inside .git' ' |
68025633 | 159 | git commit -a -m 1 && |
fd3c32c9 JL |
160 | ( |
161 | cd .git && | |
162 | git show -s HEAD | |
163 | ) | |
68025633 JS |
164 | ' |
165 | ||
66d2e04e SB |
166 | test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' ' |
167 | test_when_finished "rm -fr foo.git" && | |
68025633 | 168 | git clone -s --bare .git foo.git && |
fd3c32c9 JL |
169 | ( |
170 | cd foo.git && | |
66d2e04e SB |
171 | # older Git needed help by exporting GIT_DIR=. |
172 | # to realize that it is inside a bare repository. | |
173 | # We keep this test around for regression testing. | |
fd3c32c9 JL |
174 | GIT_DIR=. git show -s HEAD |
175 | ) | |
68025633 JS |
176 | ' |
177 | ||
66d2e04e SB |
178 | test_expect_success 'no file/rev ambiguity check inside a bare repo' ' |
179 | test_when_finished "rm -fr foo.git" && | |
68025633 | 180 | git clone -s --bare .git foo.git && |
fd3c32c9 JL |
181 | ( |
182 | cd foo.git && | |
183 | git show -s HEAD | |
184 | ) | |
68025633 JS |
185 | ' |
186 | ||
704a3143 | 187 | test_expect_success SYMLINKS 'detection should not be fooled by a symlink' ' |
68025633 JS |
188 | git clone -s .git another && |
189 | ln -s another yetanother && | |
fd3c32c9 JL |
190 | ( |
191 | cd yetanother/.git && | |
192 | git show -s HEAD | |
193 | ) | |
68025633 JS |
194 | ' |
195 | ||
c43ce6d6 | 196 | test_done |