]>
Commit | Line | Data |
---|---|---|
1389d9dd JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test prune and reflog expiration' | |
7 | . ./test-lib.sh | |
8 | ||
9 | check_have () { | |
10 | gaah= && | |
11 | for N in "$@" | |
12 | do | |
13 | eval "o=\$$N" && git cat-file -t $o || { | |
14 | echo Gaah $N | |
15 | gaah=$N | |
16 | break | |
17 | } | |
18 | done && | |
19 | test -z "$gaah" | |
20 | } | |
21 | ||
22 | check_fsck () { | |
674ba340 | 23 | git fsck --full >fsck.output |
1389d9dd JH |
24 | case "$1" in |
25 | '') | |
674ba340 | 26 | test_must_be_empty fsck.output ;; |
1389d9dd | 27 | *) |
674ba340 | 28 | test_i18ngrep "$1" fsck.output ;; |
1389d9dd JH |
29 | esac |
30 | } | |
31 | ||
32 | corrupt () { | |
ff4cb42e | 33 | mv .git/objects/$(test_oid_to_path $1) .git/$1 |
1389d9dd JH |
34 | } |
35 | ||
36 | recover () { | |
ff4cb42e | 37 | aa=$(echo $1 | cut -c 1-2) |
1389d9dd | 38 | mkdir -p .git/objects/$aa |
ff4cb42e | 39 | mv .git/$1 .git/objects/$(test_oid_to_path $1) |
1389d9dd JH |
40 | } |
41 | ||
42 | check_dont_have () { | |
43 | gaah= && | |
44 | for N in "$@" | |
45 | do | |
46 | eval "o=\$$N" | |
47 | git cat-file -t $o && { | |
48 | echo Gaah $N | |
49 | gaah=$N | |
50 | break | |
51 | } | |
52 | done | |
53 | test -z "$gaah" | |
54 | } | |
55 | ||
56 | test_expect_success setup ' | |
57 | mkdir -p A/B && | |
58 | echo rat >C && | |
59 | echo ox >A/D && | |
60 | echo tiger >A/B/E && | |
61 | git add . && | |
62 | ||
63 | test_tick && git commit -m rabbit && | |
2c25eaa1 EP |
64 | H=$(git rev-parse --verify HEAD) && |
65 | A=$(git rev-parse --verify HEAD:A) && | |
66 | B=$(git rev-parse --verify HEAD:A/B) && | |
67 | C=$(git rev-parse --verify HEAD:C) && | |
68 | D=$(git rev-parse --verify HEAD:A/D) && | |
69 | E=$(git rev-parse --verify HEAD:A/B/E) && | |
1389d9dd JH |
70 | check_fsck && |
71 | ||
1f553918 | 72 | test_chmod +x C && |
1389d9dd JH |
73 | git add C && |
74 | test_tick && git commit -m dragon && | |
2c25eaa1 | 75 | L=$(git rev-parse --verify HEAD) && |
1389d9dd JH |
76 | check_fsck && |
77 | ||
78 | rm -f C A/B/E && | |
79 | echo snake >F && | |
80 | echo horse >A/G && | |
81 | git add F A/G && | |
82 | test_tick && git commit -a -m sheep && | |
2c25eaa1 EP |
83 | F=$(git rev-parse --verify HEAD:F) && |
84 | G=$(git rev-parse --verify HEAD:A/G) && | |
85 | I=$(git rev-parse --verify HEAD:A) && | |
86 | J=$(git rev-parse --verify HEAD) && | |
1389d9dd JH |
87 | check_fsck && |
88 | ||
89 | rm -f A/G && | |
90 | test_tick && git commit -a -m monkey && | |
2c25eaa1 | 91 | K=$(git rev-parse --verify HEAD) && |
1389d9dd JH |
92 | check_fsck && |
93 | ||
94 | check_have A B C D E F G H I J K L && | |
95 | ||
026aa938 | 96 | git prune && |
1389d9dd JH |
97 | |
98 | check_have A B C D E F G H I J K L && | |
99 | ||
100 | check_fsck && | |
101 | ||
d0ab0584 DT |
102 | git reflog refs/heads/master >output && |
103 | test_line_count = 4 output | |
1389d9dd JH |
104 | ' |
105 | ||
106 | test_expect_success rewind ' | |
107 | test_tick && git reset --hard HEAD~2 && | |
108 | test -f C && | |
109 | test -f A/B/E && | |
110 | ! test -f F && | |
111 | ! test -f A/G && | |
112 | ||
113 | check_have A B C D E F G H I J K L && | |
114 | ||
026aa938 | 115 | git prune && |
1389d9dd JH |
116 | |
117 | check_have A B C D E F G H I J K L && | |
118 | ||
d0ab0584 DT |
119 | git reflog refs/heads/master >output && |
120 | test_line_count = 5 output | |
1389d9dd JH |
121 | ' |
122 | ||
123 | test_expect_success 'corrupt and check' ' | |
124 | ||
125 | corrupt $F && | |
126 | check_fsck "missing blob $F" | |
127 | ||
128 | ' | |
129 | ||
130 | test_expect_success 'reflog expire --dry-run should not touch reflog' ' | |
131 | ||
132 | git reflog expire --dry-run \ | |
133 | --expire=$(($test_tick - 10000)) \ | |
134 | --expire-unreachable=$(($test_tick - 10000)) \ | |
135 | --stale-fix \ | |
136 | --all && | |
137 | ||
d0ab0584 DT |
138 | git reflog refs/heads/master >output && |
139 | test_line_count = 5 output && | |
1389d9dd JH |
140 | |
141 | check_fsck "missing blob $F" | |
142 | ' | |
143 | ||
144 | test_expect_success 'reflog expire' ' | |
145 | ||
146 | git reflog expire --verbose \ | |
147 | --expire=$(($test_tick - 10000)) \ | |
148 | --expire-unreachable=$(($test_tick - 10000)) \ | |
149 | --stale-fix \ | |
150 | --all && | |
151 | ||
d0ab0584 DT |
152 | git reflog refs/heads/master >output && |
153 | test_line_count = 2 output && | |
1389d9dd JH |
154 | |
155 | check_fsck "dangling commit $K" | |
156 | ' | |
157 | ||
158 | test_expect_success 'prune and fsck' ' | |
159 | ||
026aa938 | 160 | git prune && |
1389d9dd JH |
161 | check_fsck && |
162 | ||
163 | check_have A B C D E H L && | |
164 | check_dont_have F G I J K | |
165 | ||
166 | ' | |
167 | ||
168 | test_expect_success 'recover and check' ' | |
169 | ||
170 | recover $F && | |
171 | check_fsck "dangling blob $F" | |
172 | ||
173 | ' | |
174 | ||
55beff4f | 175 | test_expect_success 'delete' ' |
552cecc2 JS |
176 | echo 1 > C && |
177 | test_tick && | |
178 | git commit -m rat C && | |
179 | ||
180 | echo 2 > C && | |
181 | test_tick && | |
182 | git commit -m ox C && | |
183 | ||
184 | echo 3 > C && | |
185 | test_tick && | |
186 | git commit -m tiger C && | |
187 | ||
a48fcd83 JN |
188 | HEAD_entry_count=$(git reflog | wc -l) && |
189 | master_entry_count=$(git reflog show master | wc -l) && | |
38881a90 PB |
190 | |
191 | test $HEAD_entry_count = 5 && | |
192 | test $master_entry_count = 5 && | |
193 | ||
552cecc2 JS |
194 | |
195 | git reflog delete master@{1} && | |
196 | git reflog show master > output && | |
6e4826ea | 197 | test_line_count = $(($master_entry_count - 1)) output && |
38881a90 | 198 | test $HEAD_entry_count = $(git reflog | wc -l) && |
552cecc2 JS |
199 | ! grep ox < output && |
200 | ||
a48fcd83 | 201 | master_entry_count=$(wc -l < output) && |
38881a90 PB |
202 | |
203 | git reflog delete HEAD@{1} && | |
204 | test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) && | |
205 | test $master_entry_count = $(git reflog show master | wc -l) && | |
206 | ||
a48fcd83 | 207 | HEAD_entry_count=$(git reflog | wc -l) && |
38881a90 | 208 | |
552cecc2 JS |
209 | git reflog delete master@{07.04.2005.15:15:00.-0700} && |
210 | git reflog show master > output && | |
6e4826ea | 211 | test_line_count = $(($master_entry_count - 1)) output && |
552cecc2 | 212 | ! grep dragon < output |
50f3ac29 JH |
213 | |
214 | ' | |
215 | ||
4a9f4394 AS |
216 | test_expect_success 'rewind2' ' |
217 | ||
218 | test_tick && git reset --hard HEAD~2 && | |
d0ab0584 DT |
219 | git reflog refs/heads/master >output && |
220 | test_line_count = 4 output | |
4a9f4394 AS |
221 | ' |
222 | ||
223 | test_expect_success '--expire=never' ' | |
224 | ||
225 | git reflog expire --verbose \ | |
226 | --expire=never \ | |
227 | --expire-unreachable=never \ | |
228 | --all && | |
d0ab0584 DT |
229 | git reflog refs/heads/master >output && |
230 | test_line_count = 4 output | |
4a9f4394 AS |
231 | ' |
232 | ||
233 | test_expect_success 'gc.reflogexpire=never' ' | |
a65bf78c ÆAB |
234 | test_config gc.reflogexpire never && |
235 | test_config gc.reflogexpireunreachable never && | |
4a9f4394 | 236 | |
978f4307 ÆAB |
237 | git reflog expire --verbose --all >output && |
238 | test_line_count = 9 output && | |
239 | ||
d0ab0584 DT |
240 | git reflog refs/heads/master >output && |
241 | test_line_count = 4 output | |
4a9f4394 AS |
242 | ' |
243 | ||
244 | test_expect_success 'gc.reflogexpire=false' ' | |
a65bf78c ÆAB |
245 | test_config gc.reflogexpire false && |
246 | test_config gc.reflogexpireunreachable false && | |
4a9f4394 | 247 | |
4a9f4394 | 248 | git reflog expire --verbose --all && |
d0ab0584 | 249 | git reflog refs/heads/master >output && |
a65bf78c | 250 | test_line_count = 4 output |
4a9f4394 AS |
251 | |
252 | ' | |
253 | ||
fe66776d ÆAB |
254 | test_expect_success 'git reflog expire unknown reference' ' |
255 | test_config gc.reflogexpire never && | |
256 | test_config gc.reflogexpireunreachable never && | |
257 | ||
258 | test_must_fail git reflog expire master@{123} 2>stderr && | |
259 | test_i18ngrep "points nowhere" stderr && | |
260 | test_must_fail git reflog expire does-not-exist 2>stderr && | |
261 | test_i18ngrep "points nowhere" stderr | |
262 | ' | |
263 | ||
482b8f32 RS |
264 | test_expect_success 'checkout should not delete log for packed ref' ' |
265 | test $(git reflog master | wc -l) = 4 && | |
266 | git branch foo && | |
267 | git pack-refs --all && | |
268 | git checkout foo && | |
269 | test $(git reflog master | wc -l) = 4 | |
270 | ' | |
271 | ||
9233887c | 272 | test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' ' |
aae828b9 | 273 | test_when_finished "git branch -d one || git branch -d one/two" && |
9233887c | 274 | |
aae828b9 JK |
275 | git branch one/two master && |
276 | echo "one/two@{0} branch: Created from master" >expect && | |
277 | git log -g --format="%gd %gs" one/two >actual && | |
9233887c | 278 | test_cmp expect actual && |
aae828b9 | 279 | git branch -d one/two && |
9233887c | 280 | |
aae828b9 JK |
281 | # now logs/refs/heads/one is a stale directory, but |
282 | # we should move it out of the way to create "one" reflog | |
283 | git branch one master && | |
284 | echo "one@{0} branch: Created from master" >expect && | |
285 | git log -g --format="%gd %gs" one >actual && | |
9233887c JK |
286 | test_cmp expect actual |
287 | ' | |
288 | ||
289 | test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' ' | |
aae828b9 | 290 | test_when_finished "git branch -d one || git branch -d one/two" && |
9233887c | 291 | |
aae828b9 JK |
292 | git branch one/two master && |
293 | echo "one/two@{0} branch: Created from master" >expect && | |
294 | git log -g --format="%gd %gs" one/two >actual && | |
9233887c | 295 | test_cmp expect actual && |
aae828b9 | 296 | git branch -d one/two && |
9233887c | 297 | |
aae828b9 | 298 | # same as before, but we only create a reflog for "one" if |
9233887c | 299 | # it already exists, which it does not |
aae828b9 | 300 | git -c core.logallrefupdates=false branch one master && |
aae828b9 | 301 | git log -g --format="%gd %gs" one >actual && |
1c5e94f4 | 302 | test_must_be_empty actual |
9233887c JK |
303 | ' |
304 | ||
e5e73ff2 JK |
305 | # Triggering the bug detected by this test requires a newline to fall |
306 | # exactly BUFSIZ-1 bytes from the end of the file. We don't know | |
307 | # what that value is, since it's platform dependent. However, if | |
308 | # we choose some value N, we also catch any D which divides N evenly | |
309 | # (since we will read backwards in chunks of D). So we choose 8K, | |
310 | # which catches glibc (with an 8K BUFSIZ) and *BSD (1K). | |
311 | # | |
312 | # Each line is 114 characters, so we need 75 to still have a few before the | |
313 | # last 8K. The 89-character padding on the final entry lines up our | |
314 | # newline exactly. | |
ff4cb42e | 315 | test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' ' |
e5e73ff2 | 316 | git checkout -b reflogskip && |
ff4cb42e | 317 | zf=$(test_oid zero_2) && |
e5e73ff2 JK |
318 | ident="abc <xyz> 0000000001 +0000" && |
319 | for i in $(test_seq 1 75); do | |
ff4cb42e | 320 | printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" && |
e5e73ff2 JK |
321 | if test $i = 75; then |
322 | for j in $(test_seq 1 89); do | |
323 | printf X | |
324 | done | |
325 | else | |
326 | printf X | |
327 | fi && | |
328 | printf "\n" | |
329 | done >.git/logs/refs/heads/reflogskip && | |
330 | git rev-parse reflogskip@{73} >actual && | |
ff4cb42e | 331 | echo ${zf}03 >expect && |
e5e73ff2 JK |
332 | test_cmp expect actual |
333 | ' | |
334 | ||
aecad374 DK |
335 | test_expect_success 'no segfaults for reflog containing non-commit sha1s' ' |
336 | git update-ref --create-reflog -m "Creating ref" \ | |
337 | refs/tests/tree-in-reflog HEAD && | |
338 | git update-ref -m "Forcing tree" refs/tests/tree-in-reflog HEAD^{tree} && | |
339 | git update-ref -m "Restoring to commit" refs/tests/tree-in-reflog HEAD && | |
340 | git reflog refs/tests/tree-in-reflog | |
341 | ' | |
342 | ||
343 | test_expect_failure 'reflog with non-commit entries displays all entries' ' | |
344 | git reflog refs/tests/tree-in-reflog >actual && | |
345 | test_line_count = 3 actual | |
346 | ' | |
347 | ||
41d796ed | 348 | test_expect_success 'reflog expire operates on symref not referrent' ' |
7687f19e JK |
349 | git branch --create-reflog the_symref && |
350 | git branch --create-reflog referrent && | |
41d796ed DT |
351 | git update-ref referrent HEAD && |
352 | git symbolic-ref refs/heads/the_symref refs/heads/referrent && | |
353 | test_when_finished "rm -f .git/refs/heads/referrent.lock" && | |
354 | touch .git/refs/heads/referrent.lock && | |
355 | git reflog expire --expire=all the_symref | |
356 | ' | |
357 | ||
71abeb75 SG |
358 | test_expect_success 'continue walking past root commits' ' |
359 | git init orphanage && | |
360 | ( | |
361 | cd orphanage && | |
362 | cat >expect <<-\EOF && | |
363 | HEAD@{0} commit (initial): orphan2-1 | |
364 | HEAD@{1} commit: orphan1-2 | |
365 | HEAD@{2} commit (initial): orphan1-1 | |
366 | HEAD@{3} commit (initial): initial | |
367 | EOF | |
368 | test_commit initial && | |
71abeb75 SG |
369 | git checkout --orphan orphan1 && |
370 | test_commit orphan1-1 && | |
371 | test_commit orphan1-2 && | |
372 | git checkout --orphan orphan2 && | |
373 | test_commit orphan2-1 && | |
374 | git log -g --format="%gd %gs" >actual && | |
375 | test_cmp expect actual | |
376 | ) | |
377 | ' | |
378 | ||
c9ef0d95 NTND |
379 | test_expect_success 'expire with multiple worktrees' ' |
380 | git init main-wt && | |
381 | ( | |
382 | cd main-wt && | |
383 | test_tick && | |
384 | test_commit foo && | |
385 | git worktree add link-wt && | |
386 | test_tick && | |
387 | test_commit -C link-wt foobar && | |
388 | test_tick && | |
389 | git reflog expire --verbose --all --expire=$test_tick && | |
390 | test_must_be_empty .git/worktrees/link-wt/logs/HEAD | |
391 | ) | |
392 | ' | |
393 | ||
1389d9dd | 394 | test_done |