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 aa
=${1%??????????????????????????????????????} zz
=${1#??}
34 mv .git
/objects
/$aa/$zz .git
/$aa$zz
38 aa
=${1%??????????????????????????????????????} zz
=${1#??}
39 mkdir
-p .git
/objects
/$aa
40 mv .git
/$aa$zz .git
/objects
/$aa/$zz
48 git cat-file
-t $o && {
57 test_expect_success setup
'
64 test_tick && git commit -m rabbit &&
65 H=$(git rev-parse --verify HEAD) &&
66 A=$(git rev-parse --verify HEAD:A) &&
67 B=$(git rev-parse --verify HEAD:A/B) &&
68 C=$(git rev-parse --verify HEAD:C) &&
69 D=$(git rev-parse --verify HEAD:A/D) &&
70 E=$(git rev-parse --verify HEAD:A/B/E) &&
75 test_tick && git commit -m dragon &&
76 L=$(git rev-parse --verify HEAD) &&
83 test_tick && git commit -a -m sheep &&
84 F=$(git rev-parse --verify HEAD:F) &&
85 G=$(git rev-parse --verify HEAD:A/G) &&
86 I=$(git rev-parse --verify HEAD:A) &&
87 J=$(git rev-parse --verify HEAD) &&
91 test_tick && git commit -a -m monkey &&
92 K=$(git rev-parse --verify HEAD) &&
95 check_have A B C D E F G H I J K L &&
99 check_have A B C D E F G H I J K L &&
103 git reflog refs/heads/master >output &&
104 test_line_count = 4 output
107 test_expect_success rewind
'
108 test_tick && git reset --hard HEAD~2 &&
114 check_have A B C D E F G H I J K L &&
118 check_have A B C D E F G H I J K L &&
120 git reflog refs/heads/master >output &&
121 test_line_count = 5 output
124 test_expect_success
'corrupt and check' '
127 check_fsck "missing blob $F"
131 test_expect_success
'reflog expire --dry-run should not touch reflog' '
133 git reflog expire --dry-run \
134 --expire=$(($test_tick - 10000)) \
135 --expire-unreachable=$(($test_tick - 10000)) \
139 git reflog refs/heads/master >output &&
140 test_line_count = 5 output &&
142 check_fsck "missing blob $F"
145 test_expect_success
'reflog expire' '
147 git reflog expire --verbose \
148 --expire=$(($test_tick - 10000)) \
149 --expire-unreachable=$(($test_tick - 10000)) \
153 git reflog refs/heads/master >output &&
154 test_line_count = 2 output &&
156 check_fsck "dangling commit $K"
159 test_expect_success
'prune and fsck' '
164 check_have A B C D E H L &&
165 check_dont_have F G I J K
169 test_expect_success
'recover and check' '
172 check_fsck "dangling blob $F"
176 test_expect_success
'delete' '
179 git commit -m rat C &&
183 git commit -m ox C &&
187 git commit -m tiger C &&
189 HEAD_entry_count=$(git reflog | wc -l) &&
190 master_entry_count=$(git reflog show master | wc -l) &&
192 test $HEAD_entry_count = 5 &&
193 test $master_entry_count = 5 &&
196 git reflog delete master@{1} &&
197 git reflog show master > output &&
198 test $(($master_entry_count - 1)) = $(wc -l < output) &&
199 test $HEAD_entry_count = $(git reflog | wc -l) &&
200 ! grep ox < output &&
202 master_entry_count=$(wc -l < output) &&
204 git reflog delete HEAD@{1} &&
205 test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
206 test $master_entry_count = $(git reflog show master | wc -l) &&
208 HEAD_entry_count=$(git reflog | wc -l) &&
210 git reflog delete master@{07.04.2005.15:15:00.-0700} &&
211 git reflog show master > output &&
212 test $(($master_entry_count - 1)) = $(wc -l < output) &&
213 ! grep dragon < output
217 test_expect_success
'rewind2' '
219 test_tick && git reset --hard HEAD~2 &&
220 git reflog refs/heads/master >output &&
221 test_line_count = 4 output
224 test_expect_success
'--expire=never' '
226 git reflog expire --verbose \
228 --expire-unreachable=never \
230 git reflog refs/heads/master >output &&
231 test_line_count = 4 output
234 test_expect_success
'gc.reflogexpire=never' '
236 git config gc.reflogexpire never &&
237 git config gc.reflogexpireunreachable never &&
238 git reflog expire --verbose --all &&
239 git reflog refs/heads/master >output &&
240 test_line_count = 4 output
243 test_expect_success
'gc.reflogexpire=false' '
245 git config gc.reflogexpire false &&
246 git config gc.reflogexpireunreachable false &&
247 git reflog expire --verbose --all &&
248 git reflog refs/heads/master >output &&
249 test_line_count = 4 output &&
251 git config --unset gc.reflogexpire &&
252 git config --unset gc.reflogexpireunreachable
256 test_expect_success
'checkout should not delete log for packed ref' '
257 test $(git reflog master | wc -l) = 4 &&
259 git pack-refs --all &&
261 test $(git reflog master | wc -l) = 4
264 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs on)' '
265 test_when_finished "git branch -d one || git branch -d one/two" &&
267 git branch one/two master &&
268 echo "one/two@{0} branch: Created from master" >expect &&
269 git log -g --format="%gd %gs" one/two >actual &&
270 test_cmp expect actual &&
271 git branch -d one/two &&
273 # now logs/refs/heads/one is a stale directory, but
274 # we should move it out of the way to create "one" reflog
275 git branch one master &&
276 echo "one@{0} branch: Created from master" >expect &&
277 git log -g --format="%gd %gs" one >actual &&
278 test_cmp expect actual
281 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs off)' '
282 test_when_finished "git branch -d one || git branch -d one/two" &&
284 git branch one/two master &&
285 echo "one/two@{0} branch: Created from master" >expect &&
286 git log -g --format="%gd %gs" one/two >actual &&
287 test_cmp expect actual &&
288 git branch -d one/two &&
290 # same as before, but we only create a reflog for "one" if
291 # it already exists, which it does not
292 git -c core.logallrefupdates=false branch one master &&
293 git log -g --format="%gd %gs" one >actual &&
294 test_must_be_empty actual
297 # Triggering the bug detected by this test requires a newline to fall
298 # exactly BUFSIZ-1 bytes from the end of the file. We don't know
299 # what that value is, since it's platform dependent. However, if
300 # we choose some value N, we also catch any D which divides N evenly
301 # (since we will read backwards in chunks of D). So we choose 8K,
302 # which catches glibc (with an 8K BUFSIZ) and *BSD (1K).
304 # Each line is 114 characters, so we need 75 to still have a few before the
305 # last 8K. The 89-character padding on the final entry lines up our
307 test_expect_success
'parsing reverse reflogs at BUFSIZ boundaries' '
308 git checkout -b reflogskip &&
309 z38=00000000000000000000000000000000000000 &&
310 ident="abc <xyz> 0000000001 +0000" &&
311 for i in $(test_seq 1 75); do
312 printf "$z38%02d $z38%02d %s\t" $i $(($i+1)) "$ident" &&
313 if test $i = 75; then
314 for j in $(test_seq 1 89); do
321 done >.git/logs/refs/heads/reflogskip &&
322 git rev-parse reflogskip@{73} >actual &&
323 echo ${z38}03 >expect &&
324 test_cmp expect actual
327 test_expect_success
'no segfaults for reflog containing non-commit sha1s' '
328 git update-ref --create-reflog -m "Creating ref" \
329 refs/tests/tree-in-reflog HEAD &&
330 git update-ref -m "Forcing tree" refs/tests/tree-in-reflog HEAD^{tree} &&
331 git update-ref -m "Restoring to commit" refs/tests/tree-in-reflog HEAD &&
332 git reflog refs/tests/tree-in-reflog
335 test_expect_failure
'reflog with non-commit entries displays all entries' '
336 git reflog refs/tests/tree-in-reflog >actual &&
337 test_line_count = 3 actual
340 test_expect_success
'reflog expire operates on symref not referrent' '
341 git branch --create-reflog the_symref &&
342 git branch --create-reflog referrent &&
343 git update-ref referrent HEAD &&
344 git symbolic-ref refs/heads/the_symref refs/heads/referrent &&
345 test_when_finished "rm -f .git/refs/heads/referrent.lock" &&
346 touch .git/refs/heads/referrent.lock &&
347 git reflog expire --expire=all the_symref
350 test_expect_success
'continue walking past root commits' '
351 git init orphanage &&
354 cat >expect <<-\EOF &&
355 HEAD@{0} commit (initial): orphan2-1
356 HEAD@{1} commit: orphan1-2
357 HEAD@{2} commit (initial): orphan1-1
358 HEAD@{3} commit (initial): initial
360 test_commit initial &&
361 git checkout --orphan orphan1 &&
362 test_commit orphan1-1 &&
363 test_commit orphan1-2 &&
364 git checkout --orphan orphan2 &&
365 test_commit orphan2-1 &&
366 git log -g --format="%gd %gs" >actual &&
367 test_cmp expect actual
371 test_expect_success
'expire with multiple worktrees' '
377 git worktree add link-wt &&
379 test_commit -C link-wt foobar &&
381 git reflog expire --verbose --all --expire=$test_tick &&
382 test_must_be_empty .git/worktrees/link-wt/logs/HEAD