]>
Commit | Line | Data |
---|---|---|
4eb0346f TR |
1 | #!/bin/sh |
2 | ||
3 | test_description="Test whether cache-tree is properly updated | |
4 | ||
5 | Tests whether various commands properly update and/or rewrite the | |
6 | cache-tree extension. | |
7 | " | |
8 | . ./test-lib.sh | |
9 | ||
10 | cmp_cache_tree () { | |
06ccb29e | 11 | test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual && |
2ece6ad2 | 12 | sed "s/$OID_REGEX/SHA/" <actual >filtered && |
3f96d75e ÆAB |
13 | test_cmp "$1" filtered && |
14 | rm filtered | |
4eb0346f TR |
15 | } |
16 | ||
17 | # We don't bother with actually checking the SHA1: | |
06ccb29e | 18 | # test-tool dump-cache-tree already verifies that all existing data is |
4eb0346f | 19 | # correct. |
fa6edee7 | 20 | generate_expected_cache_tree () { |
ef839700 ÆAB |
21 | pathspec="$1" && |
22 | dir="$2${2:+/}" && | |
23 | git ls-tree --name-only HEAD -- "$pathspec" >files && | |
24 | git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees && | |
25 | printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) && | |
26 | while read subtree | |
9c4d6c02 | 27 | do |
ef839700 ÆAB |
28 | generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1 |
29 | done <subtrees | |
9c4d6c02 DT |
30 | } |
31 | ||
9c4d6c02 | 32 | test_cache_tree () { |
ef839700 ÆAB |
33 | generate_expected_cache_tree "." >expect && |
34 | cmp_cache_tree expect && | |
35 | rm expect actual files subtrees && | |
36 | git status --porcelain -- ':!status' ':!expected.status' >status && | |
37 | if test -n "$1" | |
38 | then | |
39 | test_cmp "$1" status | |
40 | else | |
41 | test_must_be_empty status | |
42 | fi | |
4eb0346f TR |
43 | } |
44 | ||
45 | test_invalid_cache_tree () { | |
59a8adb6 | 46 | printf "invalid %s ()\n" "" "$@" >expect && |
06ccb29e | 47 | test-tool dump-cache-tree | |
59a8adb6 DT |
48 | sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual && |
49 | test_cmp expect actual | |
4eb0346f TR |
50 | } |
51 | ||
52 | test_no_cache_tree () { | |
3f96d75e | 53 | >expect && |
4eb0346f TR |
54 | cmp_cache_tree expect |
55 | } | |
56 | ||
9c4d6c02 | 57 | test_expect_success 'initial commit has cache-tree' ' |
4eb0346f | 58 | test_commit foo && |
9c4d6c02 | 59 | test_cache_tree |
4eb0346f TR |
60 | ' |
61 | ||
62 | test_expect_success 'read-tree HEAD establishes cache-tree' ' | |
63 | git read-tree HEAD && | |
9c4d6c02 | 64 | test_cache_tree |
4eb0346f TR |
65 | ' |
66 | ||
67 | test_expect_success 'git-add invalidates cache-tree' ' | |
68 | test_when_finished "git reset --hard; git read-tree HEAD" && | |
aecf567c | 69 | echo "I changed this file" >foo && |
4eb0346f TR |
70 | git add foo && |
71 | test_invalid_cache_tree | |
72 | ' | |
73 | ||
59a8adb6 DT |
74 | test_expect_success 'git-add in subdir invalidates cache-tree' ' |
75 | test_when_finished "git reset --hard; git read-tree HEAD" && | |
76 | mkdir dirx && | |
77 | echo "I changed this file" >dirx/foo && | |
78 | git add dirx/foo && | |
79 | test_invalid_cache_tree | |
80 | ' | |
81 | ||
82 | test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' | |
83 | git tag no-children && | |
84 | test_when_finished "git reset --hard no-children; git read-tree HEAD" && | |
85 | mkdir dir1 dir2 && | |
86 | test_commit dir1/a && | |
87 | test_commit dir2/b && | |
88 | echo "I changed this file" >dir1/a && | |
3f96d75e ÆAB |
89 | test_when_finished "rm before" && |
90 | cat >before <<-\EOF && | |
91 | SHA (3 entries, 2 subtrees) | |
92 | SHA dir1/ (1 entries, 0 subtrees) | |
93 | SHA dir2/ (1 entries, 0 subtrees) | |
94 | EOF | |
9c4d6c02 DT |
95 | cmp_cache_tree before && |
96 | echo "I changed this file" >dir1/a && | |
59a8adb6 | 97 | git add dir1/a && |
3f96d75e ÆAB |
98 | cat >expect <<-\EOF && |
99 | invalid (2 subtrees) | |
100 | invalid dir1/ (0 subtrees) | |
101 | SHA dir2/ (1 entries, 0 subtrees) | |
102 | EOF | |
9c4d6c02 | 103 | cmp_cache_tree expect |
59a8adb6 DT |
104 | ' |
105 | ||
4eb0346f TR |
106 | test_expect_success 'update-index invalidates cache-tree' ' |
107 | test_when_finished "git reset --hard; git read-tree HEAD" && | |
aecf567c | 108 | echo "I changed this file" >foo && |
4eb0346f TR |
109 | git update-index --add foo && |
110 | test_invalid_cache_tree | |
111 | ' | |
112 | ||
113 | test_expect_success 'write-tree establishes cache-tree' ' | |
ff5fb8b0 | 114 | test-tool scrap-cache-tree && |
4eb0346f | 115 | git write-tree && |
9c4d6c02 | 116 | test_cache_tree |
4eb0346f TR |
117 | ' |
118 | ||
ff5fb8b0 | 119 | test_expect_success 'test-tool scrap-cache-tree works' ' |
4eb0346f | 120 | git read-tree HEAD && |
ff5fb8b0 | 121 | test-tool scrap-cache-tree && |
4eb0346f TR |
122 | test_no_cache_tree |
123 | ' | |
124 | ||
11c8a74a | 125 | test_expect_success 'second commit has cache-tree' ' |
4eb0346f | 126 | test_commit bar && |
9c4d6c02 DT |
127 | test_cache_tree |
128 | ' | |
129 | ||
5a97639b | 130 | test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' ' |
ef839700 | 131 | test_when_finished "git reset --hard" && |
9c4d6c02 DT |
132 | cat <<-\EOT >foo.c && |
133 | int foo() | |
134 | { | |
135 | return 42; | |
136 | } | |
137 | int bar() | |
138 | { | |
139 | return 42; | |
140 | } | |
141 | EOT | |
142 | git add foo.c && | |
143 | test_invalid_cache_tree && | |
144 | git commit -m "add a file" && | |
145 | test_cache_tree && | |
146 | cat <<-\EOT >foo.c && | |
147 | int foo() | |
148 | { | |
149 | return 43; | |
150 | } | |
151 | int bar() | |
152 | { | |
153 | return 44; | |
154 | } | |
155 | EOT | |
0590ff26 | 156 | test_write_lines p 1 "" s n y q | |
9c4d6c02 | 157 | git commit --interactive -m foo && |
ef839700 ÆAB |
158 | cat <<-\EOF >expected.status && |
159 | M foo.c | |
160 | EOF | |
161 | test_cache_tree expected.status | |
9c4d6c02 DT |
162 | ' |
163 | ||
6c003d6f | 164 | test_expect_success PERL 'commit -p with shrinking cache-tree' ' |
b0d3c42e | 165 | mkdir -p deep/very-long-subdir && |
166 | echo content >deep/very-long-subdir/file && | |
6c003d6f JK |
167 | git add deep && |
168 | git commit -m add && | |
169 | git rm -r deep && | |
170 | ||
171 | before=$(wc -c <.git/index) && | |
172 | git commit -m delete -p && | |
173 | after=$(wc -c <.git/index) && | |
174 | ||
175 | # double check that the index shrank | |
176 | test $before -gt $after && | |
177 | ||
178 | # and that our index was not corrupted | |
179 | git fsck | |
180 | ' | |
181 | ||
9c4d6c02 DT |
182 | test_expect_success 'commit in child dir has cache-tree' ' |
183 | mkdir dir && | |
184 | >dir/child.t && | |
185 | git add dir/child.t && | |
186 | git commit -m dir/child.t && | |
187 | test_cache_tree | |
4eb0346f TR |
188 | ' |
189 | ||
6c52ec8a | 190 | test_expect_success 'reset --hard gives cache-tree' ' |
ff5fb8b0 | 191 | test-tool scrap-cache-tree && |
4eb0346f | 192 | git reset --hard && |
9c4d6c02 | 193 | test_cache_tree |
4eb0346f TR |
194 | ' |
195 | ||
6c52ec8a | 196 | test_expect_success 'reset --hard without index gives cache-tree' ' |
4eb0346f TR |
197 | rm -f .git/index && |
198 | git reset --hard && | |
9c4d6c02 | 199 | test_cache_tree |
4eb0346f TR |
200 | ' |
201 | ||
aecf567c DT |
202 | test_expect_success 'checkout gives cache-tree' ' |
203 | git tag current && | |
4eb0346f | 204 | git checkout HEAD^ && |
9c4d6c02 | 205 | test_cache_tree |
4eb0346f TR |
206 | ' |
207 | ||
aecf567c DT |
208 | test_expect_success 'checkout -b gives cache-tree' ' |
209 | git checkout current && | |
210 | git checkout -b prev HEAD^ && | |
9c4d6c02 | 211 | test_cache_tree |
aecf567c DT |
212 | ' |
213 | ||
214 | test_expect_success 'checkout -B gives cache-tree' ' | |
215 | git checkout current && | |
216 | git checkout -B prev HEAD^ && | |
9c4d6c02 DT |
217 | test_cache_tree |
218 | ' | |
219 | ||
52fca218 BD |
220 | test_expect_success 'merge --ff-only maintains cache-tree' ' |
221 | git checkout current && | |
222 | git checkout -b changes && | |
223 | test_commit llamas && | |
224 | test_commit pachyderm && | |
225 | test_cache_tree && | |
226 | git checkout current && | |
227 | test_cache_tree && | |
228 | git merge --ff-only changes && | |
229 | test_cache_tree | |
230 | ' | |
231 | ||
232 | test_expect_success 'merge maintains cache-tree' ' | |
233 | git checkout current && | |
234 | git checkout -b changes2 && | |
235 | test_commit alpacas && | |
236 | test_cache_tree && | |
237 | git checkout current && | |
238 | test_commit struthio && | |
239 | test_cache_tree && | |
240 | git merge changes2 && | |
241 | test_cache_tree | |
242 | ' | |
243 | ||
9c4d6c02 DT |
244 | test_expect_success 'partial commit gives cache-tree' ' |
245 | git checkout -b partial no-children && | |
246 | test_commit one && | |
247 | test_commit two && | |
248 | echo "some change" >one.t && | |
249 | git add one.t && | |
250 | echo "some other change" >two.t && | |
251 | git commit two.t -m partial && | |
ef839700 ÆAB |
252 | cat <<-\EOF >expected.status && |
253 | M one.t | |
254 | EOF | |
255 | test_cache_tree expected.status | |
aecf567c DT |
256 | ' |
257 | ||
4ed115e9 JH |
258 | test_expect_success 'no phantom error when switching trees' ' |
259 | mkdir newdir && | |
260 | >newdir/one && | |
261 | git add newdir/one && | |
262 | git checkout 2>errors && | |
ec10b018 | 263 | test_must_be_empty errors |
4ed115e9 JH |
264 | ' |
265 | ||
475a3445 | 266 | test_expect_success 'switching trees does not invalidate shared index' ' |
456d7cd3 SG |
267 | ( |
268 | sane_unset GIT_TEST_SPLIT_INDEX && | |
269 | git update-index --split-index && | |
270 | >split && | |
271 | git add split && | |
272 | test-tool dump-split-index .git/index | grep -v ^own >before && | |
273 | git commit -m "as-is" && | |
274 | test-tool dump-split-index .git/index | grep -v ^own >after && | |
275 | test_cmp before after | |
276 | ) | |
475a3445 DT |
277 | ' |
278 | ||
4eb0346f | 279 | test_done |