Skip to content

Commit 12253ab

Browse files
nasamuffingitster
authored andcommitted
gc: add tests for --cruft and friends
In 5b92477 (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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4af7188 commit 12253ab

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

t/t6500-gc.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,49 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e
202202
grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out
203203
'
204204

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+
205248
run_and_wait_for_auto_gc () {
206249
# We read stdout from gc for the side effect of waiting until the
207250
# background gc process exits, closing its fd 9. Furthermore, the

0 commit comments

Comments
 (0)