3 # Copyright (c) 2007 Junio C Hamano
6 test_description
='Test prune and reflog expiration'
13 eval "o=\$$N" && git cat-file
-t $o ||
{
23 git fsck
--full >fsck.output
26 test_must_be_empty fsck.output
;;
28 test_i18ngrep
"$1" fsck.output
;;
33 mv .git
/objects
/$
(test_oid_to_path
$1) .git
/$1
37 aa
=$
(echo $1 | cut
-c 1-2)
38 mkdir
-p .git
/objects
/$aa
39 mv .git
/$1 .git
/objects
/$
(test_oid_to_path
$1)
47 git cat-file
-t $o && {
56 test_expect_success setup
'
63 test_tick && git commit -m rabbit &&
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) &&
74 test_tick && git commit -m dragon &&
75 L=$(git rev-parse --verify HEAD) &&
82 test_tick && git commit -a -m sheep &&
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) &&
90 test_tick && git commit -a -m monkey &&
91 K=$(git rev-parse --verify HEAD) &&
94 check_have A B C D E F G H I J K L &&
98 check_have A B C D E F G H I J K L &&
102 git reflog refs/heads/master >output &&
103 test_line_count = 4 output
106 test_expect_success rewind
'
107 test_tick && git reset --hard HEAD~2 &&
113 check_have A B C D E F G H I J K L &&
117 check_have A B C D E F G H I J K L &&
119 git reflog refs/heads/master >output &&
120 test_line_count = 5 output
123 test_expect_success
'corrupt and check' '
126 check_fsck "missing blob $F"
130 test_expect_success
'reflog expire --dry-run should not touch reflog' '
132 git reflog expire --dry-run \
133 --expire=$(($test_tick - 10000)) \
134 --expire-unreachable=$(($test_tick - 10000)) \
138 git reflog refs/heads/master >output &&
139 test_line_count = 5 output &&
141 check_fsck "missing blob $F"
144 test_expect_success
'reflog expire' '
146 git reflog expire --verbose \
147 --expire=$(($test_tick - 10000)) \
148 --expire-unreachable=$(($test_tick - 10000)) \
152 git reflog refs/heads/master >output &&
153 test_line_count = 2 output &&
155 check_fsck "dangling commit $K"
158 test_expect_success
'prune and fsck' '
163 check_have A B C D E H L &&
164 check_dont_have F G I J K
168 test_expect_success
'recover and check' '
171 check_fsck "dangling blob $F"
175 test_expect_success
'delete' '
178 git commit -m rat C &&
182 git commit -m ox C &&
186 git commit -m tiger C &&
188 HEAD_entry_count=$(git reflog | wc -l) &&
189 master_entry_count=$(git reflog show master | wc -l) &&
191 test $HEAD_entry_count = 5 &&
192 test $master_entry_count = 5 &&
195 git reflog delete master@{1} &&
196 git reflog show master > output &&
197 test_line_count = $(($master_entry_count - 1)) output &&
198 test $HEAD_entry_count = $(git reflog | wc -l) &&
199 ! grep ox < output &&
201 master_entry_count=$(wc -l < output) &&
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) &&
207 HEAD_entry_count=$(git reflog | wc -l) &&
209 git reflog delete master@{07.04.2005.15:15:00.-0700} &&
210 git reflog show master > output &&
211 test_line_count = $(($master_entry_count - 1)) output &&
212 ! grep dragon < output
216 test_expect_success
'rewind2' '
218 test_tick && git reset --hard HEAD~2 &&
219 git reflog refs/heads/master >output &&
220 test_line_count = 4 output
223 test_expect_success
'--expire=never' '
225 git reflog expire --verbose \
227 --expire-unreachable=never \
229 git reflog refs/heads/master >output &&
230 test_line_count = 4 output
233 test_expect_success
'gc.reflogexpire=never' '
234 test_config gc.reflogexpire never &&
235 test_config gc.reflogexpireunreachable never &&
237 git reflog expire --verbose --all >output &&
238 test_line_count = 9 output &&
240 git reflog refs/heads/master >output &&
241 test_line_count = 4 output
244 test_expect_success
'gc.reflogexpire=false' '
245 test_config gc.reflogexpire false &&
246 test_config gc.reflogexpireunreachable false &&
248 git reflog expire --verbose --all &&
249 git reflog refs/heads/master >output &&
250 test_line_count = 4 output
254 test_expect_success
'git reflog expire unknown reference' '
255 test_config gc.reflogexpire never &&
256 test_config gc.reflogexpireunreachable never &&
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
264 test_expect_success
'checkout should not delete log for packed ref' '
265 test $(git reflog master | wc -l) = 4 &&
267 git pack-refs --all &&
269 test $(git reflog master | wc -l) = 4
272 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs on)' '
273 test_when_finished "git branch -d one || git branch -d one/two" &&
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 &&
278 test_cmp expect actual &&
279 git branch -d one/two &&
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 &&
286 test_cmp expect actual
289 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs off)' '
290 test_when_finished "git branch -d one || git branch -d one/two" &&
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 &&
295 test_cmp expect actual &&
296 git branch -d one/two &&
298 # same as before, but we only create a reflog for "one" if
299 # it already exists, which it does not
300 git -c core.logallrefupdates=false branch one master &&
301 git log -g --format="%gd %gs" one >actual &&
302 test_must_be_empty actual
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).
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
315 test_expect_success SHA1
'parsing reverse reflogs at BUFSIZ boundaries' '
316 git checkout -b reflogskip &&
317 zf=$(test_oid zero_2) &&
318 ident="abc <xyz> 0000000001 +0000" &&
319 for i in $(test_seq 1 75); do
320 printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" &&
321 if test $i = 75; then
322 for j in $(test_seq 1 89); do
329 done >.git/logs/refs/heads/reflogskip &&
330 git rev-parse reflogskip@{73} >actual &&
331 echo ${zf}03 >expect &&
332 test_cmp expect actual
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
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
348 test_expect_success
'reflog expire operates on symref not referrent' '
349 git branch --create-reflog the_symref &&
350 git branch --create-reflog referrent &&
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
358 test_expect_success
'continue walking past root commits' '
359 git init 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
368 test_commit initial &&
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
379 test_expect_success
'expire with multiple worktrees' '
385 git worktree add link-wt &&
387 test_commit -C link-wt foobar &&
389 git reflog expire --verbose --all --expire=$test_tick &&
390 test_must_be_empty .git/worktrees/link-wt/logs/HEAD