t/t6500-gc.sh: refactor cruft pack tests

In 12253ab6d0 (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 c695592850 (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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 18, 2023 at 16:40 UTC 50685e0e0ba743892c9832c414494093ae3e8703
1 file changed +44 -82
t/t6500-gc.sh
+44 -82
@@ -210,93 +210,55 @@ prepare_cruft_history () {
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 -
213 assert_no_cruft_packs () {
214 find .git/objects/pack -name "*.mtimes" >mtimes &&
215 test_must_be_empty mtimes
216 }
217
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
262
263 test_expect_success '--keep-largest-pack ignores cruft packs' '
264 test_when_finished "rm -fr repo" &&