3 # Copyright (c) 2008 Johannes E. Schindelin
6 test_description='prune'
13 before=$(git count-objects | sed "s/ .*//") &&
14 BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
15 BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
16 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
18 test-chmtime =+0 $BLOB_FILE
21 test_expect_success setup '
26 git commit -m initial &&
31 test_expect_success 'prune stale packs' '
33 orig_pack=$(echo .git/objects/pack/*.pack) &&
34 : > .git/objects/tmp_1.pack &&
35 : > .git/objects/tmp_2.pack &&
36 test-chmtime =-86501 .git/objects/tmp_1.pack &&
37 git prune --expire 1.day &&
39 test -f .git/objects/tmp_2.pack &&
40 ! test -f .git/objects/tmp_1.pack
44 test_expect_success 'prune --expire' '
47 git prune --expire=1.hour.ago &&
48 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
50 test-chmtime =-86500 $BLOB_FILE &&
51 git prune --expire 1.day &&
52 test $before = $(git count-objects | sed "s/ .*//") &&
57 test_expect_success 'gc: implicit prune --expire' '
60 test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
62 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
64 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
66 test $before = $(git count-objects | sed "s/ .*//") &&
71 test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
73 git config gc.pruneExpire invalid &&
78 test_expect_success 'gc: start with ok gc.pruneExpire' '
80 git config gc.pruneExpire 2.days.ago &&
85 test_expect_success 'prune: prune nonsense parameters' '
87 test_must_fail git prune garbage &&
88 test_must_fail git prune --- &&
89 test_must_fail git prune --no-such-option
93 test_expect_success 'prune: prune unreachable heads' '
95 git config core.logAllRefUpdates false &&
96 mv .git/logs .git/logs.old &&
99 git commit -m temporary &&
100 tmp_head=$(git rev-list -1 HEAD) &&
103 test_must_fail git reset $tmp_head --
107 test_expect_success 'prune: do not prune heads listed as an argument' '
111 git commit -m temporary &&
112 tmp_head=$(git rev-list -1 HEAD) &&
114 git prune -- $tmp_head &&
115 git reset $tmp_head --
119 test_expect_success 'gc --no-prune' '
122 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
123 git config gc.pruneExpire 2.days.ago &&
125 test 1 = $(git count-objects | sed "s/ .*//") &&
130 test_expect_success 'gc respects gc.pruneExpire' '
132 git config gc.pruneExpire 5002.days.ago &&
134 test -f $BLOB_FILE &&
135 git config gc.pruneExpire 5000.days.ago &&
141 test_expect_success 'gc --prune=<date>' '
144 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
145 git gc --prune=5002.days.ago &&
146 test -f $BLOB_FILE &&
147 git gc --prune=5000.days.ago &&
152 test_expect_success 'gc --prune=never' '
155 git gc --prune=never &&
156 test -f $BLOB_FILE &&
157 git gc --prune=now &&
162 test_expect_success 'gc respects gc.pruneExpire=never' '
164 git config gc.pruneExpire never &&
167 test -f $BLOB_FILE &&
168 git config gc.pruneExpire now &&
174 test_expect_success 'prune --expire=never' '
177 git prune --expire=never &&
178 test -f $BLOB_FILE &&
184 test_expect_success 'gc: prune old objects after local clone' '
186 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
187 git clone --no-hardlinks . aclone &&
190 test 1 = $(git count-objects | sed "s/ .*//") &&
191 test -f $BLOB_FILE &&
193 test 0 = $(git count-objects | sed "s/ .*//") &&
198 test_expect_success 'garbage report in count-objects -v' '
199 : >.git/objects/pack/foo &&
200 : >.git/objects/pack/foo.bar &&
201 : >.git/objects/pack/foo.keep &&
202 : >.git/objects/pack/foo.pack &&
203 : >.git/objects/pack/fake.bar &&
204 : >.git/objects/pack/fake.keep &&
205 : >.git/objects/pack/fake.pack &&
206 : >.git/objects/pack/fake.idx &&
207 : >.git/objects/pack/fake2.keep &&
208 : >.git/objects/pack/fake3.idx &&
209 git count-objects -v 2>stderr &&
210 grep "index file .git/objects/pack/fake.idx is too small" stderr &&
211 grep "^warning:" stderr | sort >actual &&
212 cat >expected <<\EOF &&
213 warning: garbage found: .git/objects/pack/fake.bar
214 warning: garbage found: .git/objects/pack/foo
215 warning: garbage found: .git/objects/pack/foo.bar
216 warning: no corresponding .idx nor .pack: .git/objects/pack/fake2.keep
217 warning: no corresponding .idx: .git/objects/pack/foo.keep
218 warning: no corresponding .idx: .git/objects/pack/foo.pack
219 warning: no corresponding .pack: .git/objects/pack/fake3.idx
221 test_cmp expected actual
224 test_expect_success 'prune .git/shallow' '
225 SHA1=`echo hi|git commit-tree HEAD^{tree}` &&
226 echo $SHA1 >.git/shallow &&
227 git prune --dry-run >out &&
228 grep $SHA1 .git/shallow &&
231 ! test -f .git/shallow