]>
Commit | Line | Data |
---|---|---|
919a3c98 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Amos Waterland | |
4 | # Copyright (c) 2006 Christian Couder | |
5 | # | |
6 | ||
7 | test_description='git pack-refs should not change the branch semantic | |
8 | ||
9 | This test runs git pack-refs and git show-ref and checks that the branch | |
10 | semantic is still the same. | |
11 | ' | |
d6c6b108 | 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
14 | ||
b2e5d75d | 15 | TEST_PASSES_SANITIZE_LEAK=true |
919a3c98 CC |
16 | . ./test-lib.sh |
17 | ||
bbd61069 PS |
18 | if test_have_prereq !REFFILES |
19 | then | |
20 | skip_all='skipping files-backend specific pack-refs tests' | |
21 | test_done | |
22 | fi | |
23 | ||
cbe73331 JK |
24 | test_expect_success 'enable reflogs' ' |
25 | git config core.logallrefupdates true | |
26 | ' | |
3b463c3f | 27 | |
3c2f5d26 JC |
28 | test_expect_success 'prepare a trivial repository' ' |
29 | echo Hello > A && | |
30 | git update-index --add A && | |
31 | git commit -m "Initial commit." && | |
32 | HEAD=$(git rev-parse --verify HEAD) | |
33 | ' | |
919a3c98 CC |
34 | |
35 | SHA1= | |
36 | ||
3c2f5d26 JC |
37 | test_expect_success 'see if git show-ref works as expected' ' |
38 | git branch a && | |
39 | SHA1=$(cat .git/refs/heads/a) && | |
40 | echo "$SHA1 refs/heads/a" >expect && | |
41 | git show-ref a >result && | |
42 | test_cmp expect result | |
43 | ' | |
44 | ||
45 | test_expect_success 'see if a branch still exists when packed' ' | |
46 | git branch b && | |
47 | git pack-refs --all && | |
48 | rm -f .git/refs/heads/b && | |
49 | echo "$SHA1 refs/heads/b" >expect && | |
50 | git show-ref b >result && | |
51 | test_cmp expect result | |
52 | ' | |
919a3c98 | 53 | |
41ac414e | 54 | test_expect_success 'git branch c/d should barf if branch c exists' ' |
3c2f5d26 JC |
55 | git branch c && |
56 | git pack-refs --all && | |
57 | rm -f .git/refs/heads/c && | |
58 | test_must_fail git branch c/d | |
41ac414e | 59 | ' |
919a3c98 | 60 | |
3c2f5d26 JC |
61 | test_expect_success 'see if a branch still exists after git pack-refs --prune' ' |
62 | git branch e && | |
63 | git pack-refs --all --prune && | |
64 | echo "$SHA1 refs/heads/e" >expect && | |
65 | git show-ref e >result && | |
66 | test_cmp expect result | |
67 | ' | |
919a3c98 | 68 | |
41ac414e | 69 | test_expect_success 'see if git pack-refs --prune remove ref files' ' |
3c2f5d26 JC |
70 | git branch f && |
71 | git pack-refs --all --prune && | |
72 | ! test -f .git/refs/heads/f | |
41ac414e | 73 | ' |
919a3c98 | 74 | |
be7c6d46 | 75 | test_expect_success 'see if git pack-refs --prune removes empty dirs' ' |
3c2f5d26 JC |
76 | git branch r/s/t && |
77 | git pack-refs --all --prune && | |
78 | ! test -e .git/refs/heads/r | |
be7c6d46 GP |
79 | ' |
80 | ||
3c2f5d26 JC |
81 | test_expect_success 'git branch g should work when git branch g/h has been deleted' ' |
82 | git branch g/h && | |
83 | git pack-refs --all --prune && | |
84 | git branch -d g/h && | |
85 | git branch g && | |
86 | git pack-refs --all && | |
87 | git branch -d g | |
88 | ' | |
919a3c98 | 89 | |
41ac414e | 90 | test_expect_success 'git branch i/j/k should barf if branch i exists' ' |
3c2f5d26 JC |
91 | git branch i && |
92 | git pack-refs --all --prune && | |
93 | test_must_fail git branch i/j/k | |
94 | ' | |
95 | ||
96 | test_expect_success 'test git branch k after branch k/l/m and k/lm have been deleted' ' | |
97 | git branch k/l && | |
98 | git branch k/lm && | |
99 | git branch -d k/l && | |
100 | git branch k/l/m && | |
101 | git branch -d k/l/m && | |
102 | git branch -d k/lm && | |
103 | git branch k | |
104 | ' | |
105 | ||
106 | test_expect_success 'test git branch n after some branch deletion and pruning' ' | |
107 | git branch n/o && | |
108 | git branch n/op && | |
109 | git branch -d n/o && | |
110 | git branch n/o/p && | |
111 | git branch -d n/op && | |
112 | git pack-refs --all --prune && | |
113 | git branch -d n/o/p && | |
114 | git branch n | |
115 | ' | |
14c8a681 | 116 | |
826ae79f JC |
117 | test_expect_success 'test excluded refs are not packed' ' |
118 | git branch dont_pack1 && | |
119 | git branch dont_pack2 && | |
120 | git branch pack_this && | |
121 | git pack-refs --all --exclude "refs/heads/dont_pack*" && | |
122 | test -f .git/refs/heads/dont_pack1 && | |
123 | test -f .git/refs/heads/dont_pack2 && | |
124 | ! test -f .git/refs/heads/pack_this' | |
125 | ||
126 | test_expect_success 'test --no-exclude refs clears excluded refs' ' | |
127 | git branch dont_pack3 && | |
128 | git branch dont_pack4 && | |
129 | git pack-refs --all --exclude "refs/heads/dont_pack*" --no-exclude && | |
130 | ! test -f .git/refs/heads/dont_pack3 && | |
131 | ! test -f .git/refs/heads/dont_pack4' | |
132 | ||
4fe42f32 JC |
133 | test_expect_success 'test only included refs are packed' ' |
134 | git branch pack_this1 && | |
135 | git branch pack_this2 && | |
136 | git tag dont_pack5 && | |
137 | git pack-refs --include "refs/heads/pack_this*" && | |
138 | test -f .git/refs/tags/dont_pack5 && | |
139 | ! test -f .git/refs/heads/pack_this1 && | |
140 | ! test -f .git/refs/heads/pack_this2' | |
141 | ||
142 | test_expect_success 'test --no-include refs clears included refs' ' | |
143 | git branch pack1 && | |
144 | git branch pack2 && | |
145 | git pack-refs --include "refs/heads/pack*" --no-include && | |
146 | test -f .git/refs/heads/pack1 && | |
147 | test -f .git/refs/heads/pack2' | |
148 | ||
149 | test_expect_success 'test --exclude takes precedence over --include' ' | |
150 | git branch dont_pack5 && | |
151 | git pack-refs --include "refs/heads/pack*" --exclude "refs/heads/pack*" && | |
152 | test -f .git/refs/heads/dont_pack5' | |
153 | ||
3c2f5d26 JC |
154 | test_expect_success 'see if up-to-date packed refs are preserved' ' |
155 | git branch q && | |
156 | git pack-refs --all --prune && | |
157 | git update-ref refs/heads/q refs/heads/q && | |
158 | ! test -f .git/refs/heads/q | |
159 | ' | |
5bdd8d4a | 160 | |
1b555932 | 161 | test_expect_success 'pack, prune and repack' ' |
0cb0e143 | 162 | git tag foo && |
5be60078 JH |
163 | git pack-refs --all --prune && |
164 | git show-ref >all-of-them && | |
165 | git pack-refs && | |
166 | git show-ref >again && | |
4fdf71be | 167 | test_cmp all-of-them again |
1b555932 LT |
168 | ' |
169 | ||
0a0b8d15 MH |
170 | test_expect_success 'explicit pack-refs with dangling packed reference' ' |
171 | git commit --allow-empty -m "soon to be garbage-collected" && | |
172 | git pack-refs --all && | |
173 | git reset --hard HEAD^ && | |
174 | git reflog expire --expire=all --all && | |
175 | git prune --expire=all && | |
176 | git pack-refs --all 2>result && | |
ec21ac8c | 177 | test_must_be_empty result |
0a0b8d15 MH |
178 | ' |
179 | ||
180 | test_expect_success 'delete ref with dangling packed version' ' | |
181 | git checkout -b lamb && | |
182 | git commit --allow-empty -m "future garbage" && | |
183 | git pack-refs --all && | |
184 | git reset --hard HEAD^ && | |
d6c6b108 | 185 | git checkout main && |
0a0b8d15 MH |
186 | git reflog expire --expire=all --all && |
187 | git prune --expire=all && | |
188 | git branch -d lamb 2>result && | |
ec21ac8c | 189 | test_must_be_empty result |
0a0b8d15 MH |
190 | ' |
191 | ||
ab292bc4 | 192 | test_expect_success 'delete ref while another dangling packed ref' ' |
0a0b8d15 MH |
193 | git branch lamb && |
194 | git commit --allow-empty -m "future garbage" && | |
195 | git pack-refs --all && | |
196 | git reset --hard HEAD^ && | |
197 | git reflog expire --expire=all --all && | |
198 | git prune --expire=all && | |
199 | git branch -d lamb 2>result && | |
ec21ac8c | 200 | test_must_be_empty result |
0a0b8d15 MH |
201 | ' |
202 | ||
afd11d3e JK |
203 | test_expect_success 'pack ref directly below refs/' ' |
204 | git update-ref refs/top HEAD && | |
205 | git pack-refs --all --prune && | |
206 | grep refs/top .git/packed-refs && | |
207 | test_path_is_missing .git/refs/top | |
208 | ' | |
209 | ||
ce414b33 DT |
210 | test_expect_success 'do not pack ref in refs/bisect' ' |
211 | git update-ref refs/bisect/local HEAD && | |
212 | git pack-refs --all --prune && | |
213 | ! grep refs/bisect/local .git/packed-refs >/dev/null && | |
214 | test_path_is_file .git/refs/bisect/local | |
215 | ' | |
216 | ||
cbe73331 JK |
217 | test_expect_success 'disable reflogs' ' |
218 | git config core.logallrefupdates false && | |
219 | rm -rf .git/logs | |
220 | ' | |
221 | ||
222 | test_expect_success 'create packed foo/bar/baz branch' ' | |
223 | git branch foo/bar/baz && | |
224 | git pack-refs --all --prune && | |
225 | test_path_is_missing .git/refs/heads/foo/bar/baz && | |
d0ab0584 | 226 | test_must_fail git reflog exists refs/heads/foo/bar/baz |
cbe73331 JK |
227 | ' |
228 | ||
229 | test_expect_success 'notice d/f conflict with existing directory' ' | |
230 | test_must_fail git branch foo && | |
231 | test_must_fail git branch foo/bar | |
232 | ' | |
233 | ||
234 | test_expect_success 'existing directory reports concrete ref' ' | |
235 | test_must_fail git branch foo 2>stderr && | |
6789275d | 236 | test_grep refs/heads/foo/bar/baz stderr |
cbe73331 JK |
237 | ' |
238 | ||
239 | test_expect_success 'notice d/f conflict with existing ref' ' | |
240 | test_must_fail git branch foo/bar/baz/extra && | |
241 | test_must_fail git branch foo/bar/baz/lots/of/extra/components | |
242 | ' | |
243 | ||
9308b7f3 | 244 | test_expect_success 'reject packed-refs with unterminated line' ' |
02a1a420 MH |
245 | cp .git/packed-refs .git/packed-refs.bak && |
246 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
247 | printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs && | |
248 | echo "fatal: unterminated line in .git/packed-refs: $HEAD refs/zzzzz" >expected_err && | |
249 | test_must_fail git for-each-ref >out 2>err && | |
250 | test_cmp expected_err err | |
251 | ' | |
252 | ||
9308b7f3 | 253 | test_expect_success 'reject packed-refs containing junk' ' |
02a1a420 MH |
254 | cp .git/packed-refs .git/packed-refs.bak && |
255 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
256 | printf "%s\n" "bogus content" >>.git/packed-refs && | |
257 | echo "fatal: unexpected line in .git/packed-refs: bogus content" >expected_err && | |
258 | test_must_fail git for-each-ref >out 2>err && | |
259 | test_cmp expected_err err | |
260 | ' | |
261 | ||
9308b7f3 | 262 | test_expect_success 'reject packed-refs with a short SHA-1' ' |
02a1a420 MH |
263 | cp .git/packed-refs .git/packed-refs.bak && |
264 | test_when_finished "mv .git/packed-refs.bak .git/packed-refs" && | |
265 | printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs && | |
266 | printf "fatal: unexpected line in .git/packed-refs: %.7s %s\n" $HEAD refs/zzzzz >expected_err && | |
267 | test_must_fail git for-each-ref >out 2>err && | |
268 | test_cmp expected_err err | |
269 | ' | |
270 | ||
f4ab4f3a MH |
271 | test_expect_success 'timeout if packed-refs.lock exists' ' |
272 | LOCK=.git/packed-refs.lock && | |
273 | >"$LOCK" && | |
274 | test_when_finished "rm -f $LOCK" && | |
275 | test_must_fail git pack-refs --all --prune | |
276 | ' | |
277 | ||
278 | test_expect_success 'retry acquiring packed-refs.lock' ' | |
279 | LOCK=.git/packed-refs.lock && | |
280 | >"$LOCK" && | |
3ea67379 | 281 | test_when_finished "wait && rm -f $LOCK" && |
f4ab4f3a | 282 | { |
3ea67379 | 283 | ( sleep 1 && rm -f $LOCK ) & |
f4ab4f3a MH |
284 | } && |
285 | git -c core.packedrefstimeout=3000 pack-refs --all --prune | |
286 | ' | |
287 | ||
198b808e MH |
288 | test_expect_success SYMLINKS 'pack symlinked packed-refs' ' |
289 | # First make sure that symlinking works when reading: | |
d6c6b108 | 290 | git update-ref refs/heads/lossy refs/heads/main && |
198b808e MH |
291 | git for-each-ref >all-refs-before && |
292 | mv .git/packed-refs .git/my-deviant-packed-refs && | |
293 | ln -s my-deviant-packed-refs .git/packed-refs && | |
294 | git for-each-ref >all-refs-linked && | |
295 | test_cmp all-refs-before all-refs-linked && | |
296 | git pack-refs --all --prune && | |
297 | git for-each-ref >all-refs-packed && | |
298 | test_cmp all-refs-before all-refs-packed && | |
299 | test -h .git/packed-refs && | |
7c0afdf2 | 300 | test "$(test_readlink .git/packed-refs)" = "my-deviant-packed-refs" |
198b808e MH |
301 | ' |
302 | ||
919a3c98 | 303 | test_done |