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