gc: add tests for --cruft and friends
In 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects via loose, 2022-05-20) gc learned to respect '--cruft' and 'gc.cruftPacks'. '--cruft' is exercised in t5329-pack-objects-cruft.sh, but in a way that doesn't check whether a lone gc run generates these cruft packs. 'gc.cruftPacks' is never exercised. Add some tests to exercise these options to gc in the gc test suite. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Emily Shaffer committed
Oct 26, 2022 at 17:32 UTC
12253ab6d0033aa8214c8a15bc2ea37ff052ff1c
1 file changed
+43
t/t6500-gc.sh
+43
@@ -202,6 +202,49 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
202
grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
203
'
204
205
+prepare_cruft_history () {
206
+ test_commit base &&
207
+
208
+ test_commit --no-tag foo &&
209
+ test_commit --no-tag bar &&
210
+ git reset HEAD^^
211
+}
212
+
213
+assert_cruft_packs () {
214
+ find .git/objects/pack -name "*.mtimes" >mtimes &&
215
+ sed -e 's/\.mtimes$/\.pack/g' mtimes >packs &&
216
+
217
+ test_file_not_empty packs &&
218
+ while read pack
219
+ do
220
+ test_path_is_file "$pack" || return 1
221
+ done <packs
222
+}
223
+
224
+test_expect_success 'gc --cruft generates a cruft pack' '
225
+ test_when_finished "rm -fr crufts" &&
226
+ git init crufts &&
227
+ (
228
+ cd crufts &&
229
+
230
+ prepare_cruft_history &&
231
+ git gc --cruft &&
232
+ assert_cruft_packs
233
+ )
234
+'
235
+
236
+test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
237
+ test_when_finished "rm -fr crufts" &&
238
+ git init crufts &&
239
+ (
240
+ cd crufts &&
241
+
242
+ prepare_cruft_history &&
243
+ git -c gc.cruftPacks=true gc &&
244
+ assert_cruft_packs
245
+ )
246
+'
247
+
248
run_and_wait_for_auto_gc () {
249
# We read stdout from gc for the side effect of waiting until the
250
# background gc process exits, closing its fd 9. Furthermore, the