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 output
=$
(git fsck
--full)
28 echo "$output" |
grep "$1" ;;
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 test_line_count = 4 .git/logs/refs/heads/master
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 test_line_count = 5 .git/logs/refs/heads/master
122 test_expect_success
'corrupt and check' '
125 check_fsck "missing blob $F"
129 test_expect_success
'reflog expire --dry-run should not touch reflog' '
131 git reflog expire --dry-run \
132 --expire=$(($test_tick - 10000)) \
133 --expire-unreachable=$(($test_tick - 10000)) \
137 test_line_count = 5 .git/logs/refs/heads/master &&
139 check_fsck "missing blob $F"
142 test_expect_success
'reflog expire' '
144 git reflog expire --verbose \
145 --expire=$(($test_tick - 10000)) \
146 --expire-unreachable=$(($test_tick - 10000)) \
150 test_line_count = 2 .git/logs/refs/heads/master &&
152 check_fsck "dangling commit $K"
155 test_expect_success
'prune and fsck' '
160 check_have A B C D E H L &&
161 check_dont_have F G I J K
165 test_expect_success
'recover and check' '
168 check_fsck "dangling blob $F"
172 test_expect_success
'delete' '
175 git commit -m rat C &&
179 git commit -m ox C &&
183 git commit -m tiger C &&
185 HEAD_entry_count=$(git reflog | wc -l) &&
186 master_entry_count=$(git reflog show master | wc -l) &&
188 test $HEAD_entry_count = 5 &&
189 test $master_entry_count = 5 &&
192 git reflog delete master@{1} &&
193 git reflog show master > output &&
194 test $(($master_entry_count - 1)) = $(wc -l < output) &&
195 test $HEAD_entry_count = $(git reflog | wc -l) &&
196 ! grep ox < output &&
198 master_entry_count=$(wc -l < output) &&
200 git reflog delete HEAD@{1} &&
201 test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
202 test $master_entry_count = $(git reflog show master | wc -l) &&
204 HEAD_entry_count=$(git reflog | wc -l) &&
206 git reflog delete master@{07.04.2005.15:15:00.-0700} &&
207 git reflog show master > output &&
208 test $(($master_entry_count - 1)) = $(wc -l < output) &&
209 ! grep dragon < output
213 test_expect_success
'rewind2' '
215 test_tick && git reset --hard HEAD~2 &&
216 test_line_count = 4 .git/logs/refs/heads/master
219 test_expect_success
'--expire=never' '
221 git reflog expire --verbose \
223 --expire-unreachable=never \
225 test_line_count = 4 .git/logs/refs/heads/master
228 test_expect_success
'gc.reflogexpire=never' '
230 git config gc.reflogexpire never &&
231 git config gc.reflogexpireunreachable never &&
232 git reflog expire --verbose --all &&
233 test_line_count = 4 .git/logs/refs/heads/master
236 test_expect_success
'gc.reflogexpire=false' '
238 git config gc.reflogexpire false &&
239 git config gc.reflogexpireunreachable false &&
240 git reflog expire --verbose --all &&
241 test_line_count = 4 .git/logs/refs/heads/master &&
243 git config --unset gc.reflogexpire &&
244 git config --unset gc.reflogexpireunreachable
248 test_expect_success
'checkout should not delete log for packed ref' '
249 test $(git reflog master | wc -l) = 4 &&
251 git pack-refs --all &&
253 test $(git reflog master | wc -l) = 4
256 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs on)' '
257 test_when_finished "git branch -d a || git branch -d a/b" &&
259 git branch a/b master &&
260 echo "a/b@{0} branch: Created from master" >expect &&
261 git log -g --format="%gd %gs" a/b >actual &&
262 test_cmp expect actual &&
265 # now logs/refs/heads/a is a stale directory, but
266 # we should move it out of the way to create "a" reflog
267 git branch a master &&
268 echo "a@{0} branch: Created from master" >expect &&
269 git log -g --format="%gd %gs" a >actual &&
270 test_cmp expect actual
273 test_expect_success
'stale dirs do not cause d/f conflicts (reflogs off)' '
274 test_when_finished "git branch -d a || git branch -d a/b" &&
276 git branch a/b master &&
277 echo "a/b@{0} branch: Created from master" >expect &&
278 git log -g --format="%gd %gs" a/b >actual &&
279 test_cmp expect actual &&
282 # same as before, but we only create a reflog for "a" if
283 # it already exists, which it does not
284 git -c core.logallrefupdates=false branch a master &&
286 git log -g --format="%gd %gs" a >actual &&
287 test_cmp expect actual