Skip to content

Commit 50685e0

Browse files
ttaylorrgitster
authored andcommitted
t/t6500-gc.sh: refactor cruft pack tests
In 12253ab (gc: add tests for --cruft and friends, 2022-10-26), we added a handful of tests to t6500 to ensure that `git gc` respected the value of `--cruft` and `gc.cruftPacks`. Then, in c695592 (config: let feature.experimental imply gc.cruftPacks=true, 2022-10-26), another set of similar tests was added to ensure that `feature.experimental` correctly implied enabling cruft pack generation (or not). These tests are similar and could be consolidated. Do so in this patch to prepare for expanding the set of command-line invocations that enable or disable writing cruft packs. This makes it possible to easily test more combinations of arguments without being overly repetitive. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b31d45b commit 50685e0

File tree

1 file changed

+44
-82
lines changed

1 file changed

+44
-82
lines changed

t/t6500-gc.sh

Lines changed: 44 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -210,93 +210,55 @@ prepare_cruft_history () {
210210
git reset HEAD^^
211211
}
212212

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-
224213
assert_no_cruft_packs () {
225214
find .git/objects/pack -name "*.mtimes" >mtimes &&
226215
test_must_be_empty mtimes
227216
}
228217

229-
test_expect_success 'gc --cruft generates a cruft pack' '
230-
test_when_finished "rm -fr crufts" &&
231-
git init crufts &&
232-
(
233-
cd crufts &&
234-
235-
prepare_cruft_history &&
236-
git gc --cruft &&
237-
assert_cruft_packs
238-
)
239-
'
240-
241-
test_expect_success 'gc.cruftPacks=true generates a cruft pack' '
242-
test_when_finished "rm -fr crufts" &&
243-
git init crufts &&
244-
(
245-
cd crufts &&
246-
247-
prepare_cruft_history &&
248-
git -c gc.cruftPacks=true gc &&
249-
assert_cruft_packs
250-
)
251-
'
252-
253-
test_expect_success 'feature.experimental=true generates a cruft pack' '
254-
git init crufts &&
255-
test_when_finished "rm -fr crufts" &&
256-
(
257-
cd crufts &&
258-
259-
prepare_cruft_history &&
260-
git -c feature.experimental=true gc &&
261-
assert_cruft_packs
262-
)
263-
'
264-
265-
test_expect_success 'feature.experimental=false allows explicit cruft packs' '
266-
git init crufts &&
267-
test_when_finished "rm -fr crufts" &&
268-
(
269-
cd crufts &&
270-
271-
prepare_cruft_history &&
272-
git -c gc.cruftPacks=true -c feature.experimental=false gc &&
273-
assert_cruft_packs
274-
)
275-
'
276-
277-
test_expect_success 'feature.experimental=true can be overridden' '
278-
git init crufts &&
279-
test_when_finished "rm -fr crufts" &&
280-
(
281-
cd crufts &&
282-
283-
prepare_cruft_history &&
284-
git -c feature.expiremental=true -c gc.cruftPacks=false gc &&
285-
assert_no_cruft_packs
286-
)
287-
'
288-
289-
test_expect_success 'feature.experimental=false avoids cruft packs by default' '
290-
git init crufts &&
291-
test_when_finished "rm -fr crufts" &&
292-
(
293-
cd crufts &&
294-
295-
prepare_cruft_history &&
296-
git -c feature.experimental=false gc &&
297-
assert_no_cruft_packs
298-
)
299-
'
218+
for argv in \
219+
"gc --cruft" \
220+
"-c gc.cruftPacks=true gc" \
221+
"-c feature.experimental=true gc" \
222+
"-c gc.cruftPacks=true -c feature.experimental=false gc"
223+
do
224+
test_expect_success "git $argv generates a cruft pack" '
225+
test_when_finished "rm -fr repo" &&
226+
git init repo &&
227+
(
228+
cd repo &&
229+
230+
prepare_cruft_history &&
231+
git $argv &&
232+
233+
find .git/objects/pack -name "*.mtimes" >mtimes &&
234+
sed -e 's/\.mtimes$/\.pack/g' mtimes >packs &&
235+
236+
test_file_not_empty packs &&
237+
while read pack
238+
do
239+
test_path_is_file "$pack" || return 1
240+
done <packs
241+
)
242+
'
243+
done
244+
245+
for argv in \
246+
"-c feature.expiremental=true -c gc.cruftPacks=false gc" \
247+
"-c feature.experimental=false gc"
248+
do
249+
test_expect_success "git $argv does not generate a cruft pack" '
250+
test_when_finished "rm -fr repo" &&
251+
git init repo &&
252+
(
253+
cd repo &&
254+
255+
prepare_cruft_history &&
256+
git $argv &&
257+
258+
assert_no_cruft_packs
259+
)
260+
'
261+
done
300262

301263
test_expect_success '--keep-largest-pack ignores cruft packs' '
302264
test_when_finished "rm -fr repo" &&

0 commit comments

Comments
 (0)