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/ .*//") &&
20 test_expect_success setup
'
25 git commit -m initial &&
30 test_expect_success
'prune stale packs' '
32 orig_pack=$(echo .git/objects/pack/*.pack) &&
33 : > .git/objects/tmp_1.pack &&
34 : > .git/objects/tmp_2.pack &&
35 test-chmtime =-86501 .git/objects/tmp_1.pack &&
36 git prune --expire 1.day &&
38 test -f .git/objects/tmp_2.pack &&
39 ! test -f .git/objects/tmp_1.pack
43 test_expect_success
'prune --expire' '
46 git prune --expire=1.hour.ago &&
47 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
49 test-chmtime =-86500 $BLOB_FILE &&
50 git prune --expire 1.day &&
51 test $before = $(git count-objects | sed "s/ .*//") &&
56 test_expect_success
'gc: implicit prune --expire' '
59 test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
61 test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
63 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
65 test $before = $(git count-objects | sed "s/ .*//") &&
70 test_expect_success
'gc: refuse to start with invalid gc.pruneExpire' '
72 git config gc.pruneExpire invalid &&
77 test_expect_success
'gc: start with ok gc.pruneExpire' '
79 git config gc.pruneExpire 2.days.ago &&
84 test_expect_success
'prune: prune nonsense parameters' '
86 test_must_fail git prune garbage &&
87 test_must_fail git prune --- &&
88 test_must_fail git prune --no-such-option
92 test_expect_success
'prune: prune unreachable heads' '
94 git config core.logAllRefUpdates false &&
95 mv .git/logs .git/logs.old &&
98 git commit -m temporary &&
99 tmp_head=$(git rev-list -1 HEAD) &&
102 test_must_fail git reset $tmp_head --
106 test_expect_success
'prune: do not prune heads listed as an argument' '
110 git commit -m temporary &&
111 tmp_head=$(git rev-list -1 HEAD) &&
113 git prune -- $tmp_head &&
114 git reset $tmp_head --
118 test_expect_success
'gc --no-prune' '
121 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
122 git config gc.pruneExpire 2.days.ago &&
124 test 1 = $(git count-objects | sed "s/ .*//") &&
129 test_expect_success
'gc respects gc.pruneExpire' '
131 git config gc.pruneExpire 5002.days.ago &&
133 test -f $BLOB_FILE &&
134 git config gc.pruneExpire 5000.days.ago &&
140 test_expect_success
'gc --prune=<date>' '
143 test-chmtime =-$((5001*$day)) $BLOB_FILE &&
144 git gc --prune=5002.days.ago &&
145 test -f $BLOB_FILE &&
146 git gc --prune=5000.days.ago &&
151 test_expect_success
'gc --prune=never' '
154 git gc --prune=never &&
155 test -f $BLOB_FILE &&
156 git gc --prune=now &&
161 test_expect_success
'gc respects gc.pruneExpire=never' '
163 git config gc.pruneExpire never &&
166 test -f $BLOB_FILE &&
167 git config gc.pruneExpire now &&
173 test_expect_success
'prune --expire=never' '
176 git prune --expire=never &&
177 test -f $BLOB_FILE &&
183 test_expect_success
'gc: prune old objects after local clone' '
185 test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
186 git clone --no-hardlinks . aclone &&
189 test 1 = $(git count-objects | sed "s/ .*//") &&
190 test -f $BLOB_FILE &&
192 test 0 = $(git count-objects | sed "s/ .*//") &&