at commit e77f412d

1 #!/bin/sh
2
3 test_description='git maintenance builtin'
4
5 . ./test-lib.sh
6
7 GIT_TEST_COMMIT_GRAPH=0
8 GIT_TEST_MULTI_PACK_INDEX=0
9
10 test_lazy_prereq XMLLINT '
11 xmllint --version
12 '
13
14 test_xmllint () {
15 if test_have_prereq XMLLINT
16 then
17 xmllint --noout "$@"
18 else
19 true
20 fi
21 }
22
23 test_maintenance_tasks () {
24 cat >expect &&
25 sed -ne "s/.*\"region_enter\".*\"category\":\"maintenance\([^\"]*\)\".*\"label\":\"\([^\"][^\"]*\)\".*/\2\1/p" "$1" >actual &&
26 test_cmp expect actual
27 }
28
29 test_lazy_prereq SYSTEMD_ANALYZE '
30 systemd-analyze verify /lib/systemd/system/basic.target
31 '
32
33 test_systemd_analyze_verify () {
34 if test_have_prereq SYSTEMD_ANALYZE
35 then
36 systemd-analyze verify "$@"
37 fi
38 }
39
40 test_expect_success 'help text' '
41 git maintenance -h >actual &&
42 test_grep "usage: git maintenance <subcommand>" actual &&
43 test_expect_code 129 git maintenance barf 2>err &&
44 test_grep "unknown subcommand: \`barf'\''" err &&
45 test_grep "usage: git maintenance" err &&
46 test_expect_code 129 git maintenance 2>err &&
47 test_grep "error: need a subcommand" err &&
48 test_grep "usage: git maintenance" err
49 '
50
51 test_expect_success 'run [--auto|--quiet] with gc strategy' '
52 test_config maintenance.strategy gc &&
53 GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
54 git maintenance run 2>/dev/null &&
55 GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
56 git maintenance run --auto 2>/dev/null &&
57 GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
58 git maintenance run --no-quiet 2>/dev/null &&
59 git maintenance is-needed &&
60 test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-no-auto.txt &&
61 ! git maintenance is-needed --auto &&
62 test_subcommand ! git gc --auto --quiet --no-detach --skip-foreground-tasks <run-auto.txt &&
63 test_subcommand git gc --no-quiet --no-detach --skip-foreground-tasks <run-no-quiet.txt
64 '
65
66 test_expect_success 'maintenance.auto config option' '
67 test_when_finished "rm -rf repo" &&
68 git init repo &&
69 (
70 cd repo &&
71 sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
72
73 GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
74 test_subcommand git maintenance run --auto --quiet --detach <default &&
75 GIT_TRACE2_EVENT="$(pwd)/true" \
76 git -c maintenance.auto=true \
77 commit --quiet --allow-empty -m 2 &&
78 test_subcommand git maintenance run --auto --quiet --detach <true &&
79 GIT_TRACE2_EVENT="$(pwd)/false" \
80 git -c maintenance.auto=false \
81 commit --quiet --allow-empty -m 3 &&
82 test_subcommand ! git maintenance run --auto --quiet --detach <false
83 )
84 '
85
86 test_expect_success 'gc.auto config option' '
87 test_when_finished "rm -rf repo" &&
88 git init repo &&
89 (
90 cd repo &&
91 sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
92
93 GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
94 test_subcommand git maintenance run --auto --quiet --detach <default &&
95 GIT_TRACE2_EVENT="$(pwd)/true" \
96 git -c gc.auto=1 commit --quiet --allow-empty -m 2 &&
97 test_subcommand git maintenance run --auto --quiet --detach <true &&
98 GIT_TRACE2_EVENT="$(pwd)/false" \
99 git -c gc.auto=0 commit --quiet --allow-empty -m 3 &&
100 test_subcommand ! git maintenance run --auto --quiet --detach <false
101 )
102 '
103
104 test_expect_success 'maintenance.auto overrides gc.auto' '
105 test_when_finished "rm -rf repo" &&
106 git init repo &&
107 (
108 cd repo &&
109 sane_unset GIT_TEST_MAINT_AUTO_DETACH &&
110
111 git config set maintenance.auto false &&
112 git config set gc.auto 1 &&
113 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
114 test_subcommand ! git maintenance run --auto --quiet --detach <trace &&
115
116 git config set maintenance.auto true &&
117 git config set gc.auto 0 &&
118 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
119 test_subcommand git maintenance run --auto --quiet --detach <trace
120 )
121 '
122
123 for cfg in maintenance.autoDetach gc.autoDetach
124 do
125 test_expect_success "$cfg=true config option" '
126 test_when_finished "rm -f trace" &&
127 test_config $cfg true &&
128 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
129 test_subcommand git maintenance run --auto --quiet --detach <trace
130 '
131
132 test_expect_success "$cfg=false config option" '
133 test_when_finished "rm -f trace" &&
134 test_config $cfg false &&
135 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
136 test_subcommand git maintenance run --auto --quiet --no-detach <trace
137 '
138 done
139
140 test_expect_success "maintenance.autoDetach overrides gc.autoDetach" '
141 test_when_finished "rm -f trace" &&
142 test_config maintenance.autoDetach false &&
143 test_config gc.autoDetach true &&
144 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
145 test_subcommand git maintenance run --auto --quiet --no-detach <trace
146 '
147
148 test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
149 test_when_finished rm -r .config/git/config &&
150 (
151 # Override HOME so that .gitconfig (which test-lib.sh may
152 # have created, e.g. to set safe.bareRepository) does not
153 # take precedence over the XDG location.
154 HOME=$PWD/must-not-exist &&
155 XDG_CONFIG_HOME=.config &&
156 export HOME XDG_CONFIG_HOME &&
157 mkdir -p $XDG_CONFIG_HOME/git &&
158 >$XDG_CONFIG_HOME/git/config &&
159 git maintenance register &&
160 git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual &&
161 pwd >expect &&
162 test_cmp expect actual
163 )
164 '
165
166 test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' '
167 test_when_finished git maintenance unregister &&
168 test_path_is_missing $XDG_CONFIG_HOME/git/config &&
169 git maintenance register &&
170 git config --global --get maintenance.repo >actual &&
171 pwd >expect &&
172 test_cmp expect actual
173 '
174
175 test_expect_success 'unregister uses XDG_CONFIG_HOME config if it exists' '
176 test_when_finished rm -r .config/git/config &&
177 (
178 # Override HOME so that .gitconfig (which test-lib.sh may
179 # have created, e.g. to set safe.bareRepository) does not
180 # take precedence over the XDG location.
181 HOME=$PWD/must-not-exist &&
182 XDG_CONFIG_HOME=.config &&
183 export HOME XDG_CONFIG_HOME &&
184 mkdir -p $XDG_CONFIG_HOME/git &&
185 >$XDG_CONFIG_HOME/git/config &&
186 git maintenance register &&
187 git maintenance unregister &&
188 test_must_fail git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual &&
189 test_must_be_empty actual
190 )
191 '
192
193 test_expect_success 'unregister does not need XDG_CONFIG_HOME config to exist' '
194 test_path_is_missing $XDG_CONFIG_HOME/git/config &&
195 git maintenance register &&
196 git maintenance unregister &&
197 test_must_fail git config --global --get maintenance.repo >actual &&
198 test_must_be_empty actual
199 '
200
201 test_expect_success 'maintenance.<task>.enabled' '
202 git config maintenance.gc.enabled false &&
203 git config maintenance.commit-graph.enabled true &&
204 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
205 test_maintenance_tasks run-config.txt <<-\EOF
206 commit-graph
207 EOF
208 '
209
210 test_expect_success 'run --task=<task>' '
211 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
212 git maintenance run --task=commit-graph 2>/dev/null &&
213 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
214 git maintenance run --task=gc 2>/dev/null &&
215 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
216 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
217 test_maintenance_tasks run-commit-graph.txt <<-\EOF &&
218 commit-graph
219 EOF
220 test_maintenance_tasks run-gc.txt <<-\EOF &&
221 gc foreground
222 gc
223 EOF
224 test_maintenance_tasks run-both.txt <<-\EOF
225 gc foreground
226 commit-graph
227 gc
228 EOF
229 '
230
231 test_expect_success 'core.commitGraph=false prevents write process' '
232 GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
233 git -c core.commitGraph=false maintenance run \
234 --task=commit-graph 2>/dev/null &&
235 test_subcommand ! git commit-graph write --split --reachable --no-progress \
236 <no-commit-graph.txt
237 '
238
239 test_expect_success 'commit-graph auto condition' '
240 COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
241
242 GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
243 git -c maintenance.commit-graph.auto=1 $COMMAND &&
244 GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
245 git -c maintenance.commit-graph.auto="-1" $COMMAND &&
246
247 test_commit first &&
248
249 ! git -c maintenance.commit-graph.auto=0 \
250 maintenance is-needed --auto --task=commit-graph &&
251 git -c maintenance.commit-graph.auto=1 \
252 maintenance is-needed --auto --task=commit-graph &&
253
254 GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
255 git -c maintenance.commit-graph.auto=0 $COMMAND &&
256 GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
257 git -c maintenance.commit-graph.auto=1 $COMMAND &&
258
259 git commit --allow-empty -m "second" &&
260 git commit --allow-empty -m "third" &&
261
262 GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
263 git -c maintenance.commit-graph.auto=2 $COMMAND &&
264
265 test_maintenance_tasks cg-no.txt <<-\EOF &&
266 EOF
267 test_maintenance_tasks cg-negative-means-yes.txt <<-\EOF &&
268 commit-graph
269 EOF
270 test_maintenance_tasks cg-zero-means-no.txt <<-\EOF &&
271 EOF
272 test_maintenance_tasks cg-one-satisfied.txt <<-\EOF &&
273 commit-graph
274 EOF
275 test_maintenance_tasks cg-two-satisfied.txt <<-\EOF
276 commit-graph
277 EOF
278 '
279
280 test_expect_success 'commit-graph auto condition with merges' '
281 test_when_finished "rm -rf repo" &&
282 git init repo &&
283 (
284 cd repo &&
285 git config set maintenance.auto false &&
286 test_commit initial &&
287 git switch --create feature &&
288 test_commit feature-1 &&
289 test_commit feature-2 &&
290 git switch - &&
291 test_commit main-1 &&
292 test_commit main-2 &&
293 git merge feature &&
294
295 # We have 6 commits, none of which are covered by a commit
296 # graph. So this must be the boundary at which we start to
297 # perform maintenance.
298 test_must_fail git -c maintenance.commit-graph.auto=7 \
299 maintenance is-needed --auto --task=commit-graph &&
300 git -c maintenance.commit-graph.auto=6 \
301 maintenance is-needed --auto --task=commit-graph
302 )
303 '
304
305 test_expect_success 'run --task=bogus' '
306 test_must_fail git maintenance run --task=bogus 2>err &&
307 test_grep "is not a valid task" err
308 '
309
310 test_expect_success 'run --task duplicate' '
311 test_must_fail git maintenance run --task=gc --task=gc 2>err &&
312 test_grep "cannot be selected multiple times" err
313 '
314
315 test_expect_success 'run --task=prefetch with no remotes' '
316 git maintenance run --task=prefetch 2>err &&
317 test_must_be_empty err
318 '
319
320 test_expect_success 'prefetch multiple remotes' '
321 git clone . clone1 &&
322 git clone . clone2 &&
323 git remote add remote1 "file://$(pwd)/clone1" &&
324 git remote add remote2 "file://$(pwd)/clone2" &&
325 git -C clone1 switch -c one &&
326 git -C clone2 switch -c two &&
327 test_commit -C clone1 one &&
328 test_commit -C clone2 two &&
329 GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
330 fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" &&
331 test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt &&
332 test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt &&
333 git for-each-ref refs/remotes >actual &&
334 test_must_be_empty actual &&
335 git log prefetch/remotes/remote1/one &&
336 git log prefetch/remotes/remote2/two &&
337 git fetch --all &&
338 test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one &&
339 test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two &&
340
341 git log --oneline --decorate --all >log &&
342 test_grep ! "prefetch" log &&
343
344 test_when_finished git config --unset remote.remote1.skipFetchAll &&
345 git config remote.remote1.skipFetchAll true &&
346 GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null &&
347 test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt &&
348 test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt
349 '
350
351 test_expect_success 'loose-objects task' '
352 # Repack everything so we know the state of the object dir
353 git repack -adk &&
354
355 # Hack to stop maintenance from running during "git commit"
356 echo in use >.git/objects/maintenance.lock &&
357
358 # Assuming that "git commit" creates at least one loose object
359 test_commit create-loose-object &&
360 rm .git/objects/maintenance.lock &&
361
362 ls .git/objects >obj-dir-before &&
363 test_file_not_empty obj-dir-before &&
364 ls .git/objects/pack/*.pack >packs-before &&
365 test_line_count = 1 packs-before &&
366
367 # The first run creates a pack-file
368 # but does not delete loose objects.
369 git maintenance run --task=loose-objects &&
370 ls .git/objects >obj-dir-between &&
371 test_cmp obj-dir-before obj-dir-between &&
372 ls .git/objects/pack/*.pack >packs-between &&
373 test_line_count = 2 packs-between &&
374 ls .git/objects/pack/loose-*.pack >loose-packs &&
375 test_line_count = 1 loose-packs &&
376
377 # The second run deletes loose objects
378 # but does not create a pack-file.
379 git maintenance run --task=loose-objects &&
380 ls .git/objects >obj-dir-after &&
381 cat >expect <<-\EOF &&
382 info
383 pack
384 EOF
385 test_cmp expect obj-dir-after &&
386 ls .git/objects/pack/*.pack >packs-after &&
387 test_cmp packs-between packs-after
388 '
389
390 test_expect_success 'maintenance.loose-objects.auto' '
391 git repack -adk &&
392 GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
393 git -c maintenance.loose-objects.auto=1 maintenance \
394 run --auto --task=loose-objects 2>/dev/null &&
395 test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
396
397 printf data-A | git hash-object -t blob --stdin -w &&
398 ! git -c maintenance.loose-objects.auto=2 \
399 maintenance is-needed --auto --task=loose-objects &&
400 GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
401 git -c maintenance.loose-objects.auto=2 \
402 maintenance run --auto --task=loose-objects 2>/dev/null &&
403 test_subcommand ! git prune-packed --quiet <trace-loA &&
404
405 printf data-B | git hash-object -t blob --stdin -w &&
406 git -c maintenance.loose-objects.auto=2 \
407 maintenance is-needed --auto --task=loose-objects &&
408 GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
409 git -c maintenance.loose-objects.auto=2 \
410 maintenance run --auto --task=loose-objects 2>/dev/null &&
411 test_subcommand git prune-packed --quiet <trace-loB &&
412
413 GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
414 git -c maintenance.loose-objects.auto=2 \
415 maintenance run --auto --task=loose-objects 2>/dev/null &&
416 test_subcommand git prune-packed --quiet <trace-loC
417 '
418
419 test_expect_success 'maintenance.loose-objects.batchSize' '
420 git init loose-batch &&
421
422 # This creates three objects per commit.
423 test_commit_bulk -C loose-batch 34 &&
424 pack=$(ls loose-batch/.git/objects/pack/pack-*.pack) &&
425 index="${pack%pack}idx" &&
426 rm "$index" &&
427 git -C loose-batch unpack-objects <"$pack" &&
428 git -C loose-batch config maintenance.loose-objects.batchSize 50 &&
429
430 GIT_PROGRESS_DELAY=0 \
431 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
432 test_grep "Enumerating objects: 50, done." err &&
433
434 GIT_PROGRESS_DELAY=0 \
435 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
436 test_grep "Enumerating objects: 50, done." err &&
437
438 GIT_PROGRESS_DELAY=0 \
439 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
440 test_grep "Enumerating objects: 2, done." err &&
441
442 GIT_PROGRESS_DELAY=0 \
443 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
444 test_must_be_empty err
445 '
446
447 test_expect_success 'incremental-repack task' '
448 packDir=.git/objects/pack &&
449 for i in $(test_seq 1 5)
450 do
451 test_commit $i || return 1
452 done &&
453
454 # Create three disjoint pack-files with size BIG, small, small.
455 echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
456 test_tick &&
457 git pack-objects --revs $packDir/test-2 <<-\EOF &&
458 HEAD~1
459 ^HEAD~2
460 EOF
461 test_tick &&
462 git pack-objects --revs $packDir/test-3 <<-\EOF &&
463 HEAD
464 ^HEAD~1
465 EOF
466
467 # Delete refs that have not been repacked in these packs.
468 git for-each-ref --format="delete %(refname)" \
469 refs/prefetch refs/tags refs/remotes \
470 --exclude=refs/remotes/*/HEAD >refs &&
471 git update-ref --stdin <refs &&
472
473 # Replace the object directory with this pack layout.
474 rm -f $packDir/pack-* &&
475 rm -f $packDir/loose-* &&
476 ls $packDir/*.pack >packs-before &&
477 test_line_count = 3 packs-before &&
478
479 # make sure we do not have any broken refs that were
480 # missed in the deletion above
481 git for-each-ref &&
482
483 # the job repacks the two into a new pack, but does not
484 # delete the old ones.
485 git maintenance run --task=incremental-repack &&
486 ls $packDir/*.pack >packs-between &&
487 test_line_count = 4 packs-between &&
488
489 # the job deletes the two old packs, and does not write
490 # a new one because the batch size is not high enough to
491 # pack the largest pack-file.
492 git maintenance run --task=incremental-repack &&
493 ls .git/objects/pack/*.pack >packs-after &&
494 test_line_count = 2 packs-after
495 '
496
497 test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
498 test_when_finished rm -rf expensive-repo &&
499 git init expensive-repo &&
500 (
501 cd expensive-repo &&
502 git config set core.compression 0 &&
503 git config set maintenance.auto false &&
504
505 for i in $(test_seq 1 5)
506 do
507 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
508 return 1
509 done &&
510 git add big &&
511 git commit -qm "Add big file (1)" &&
512
513 # ensure any possible loose objects are in a pack-file
514 git maintenance run --task=loose-objects &&
515
516 rm big &&
517 for i in $(test_seq 6 10)
518 do
519 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
520 return 1
521 done &&
522 git add big &&
523 git commit -qm "Add big file (2)" &&
524
525 # ensure any possible loose objects are in a pack-file
526 git maintenance run --task=loose-objects &&
527
528 # Now run the incremental-repack task and check the batch-size
529 GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
530 --task=incremental-repack 2>/dev/null &&
531 test_subcommand git multi-pack-index repack \
532 --no-progress --batch-size=2147483647 <run-2g.txt
533 )
534 '
535
536 run_incremental_repack_and_verify () {
537 test_commit A &&
538 git repack -adk &&
539 git multi-pack-index write &&
540 ! git -c maintenance.incremental-repack.auto=1 \
541 maintenance is-needed --auto --task=incremental-repack &&
542 GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
543 -c maintenance.incremental-repack.auto=1 \
544 maintenance run --auto --task=incremental-repack 2>/dev/null &&
545 test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
546
547 test_commit B &&
548 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
549 HEAD
550 ^HEAD~1
551 EOF
552 GIT_TRACE2_EVENT=$(pwd)/trace-A git \
553 -c maintenance.incremental-repack.auto=2 \
554 maintenance run --auto --task=incremental-repack 2>/dev/null &&
555 test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
556
557 test_commit C &&
558 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
559 HEAD
560 ^HEAD~1
561 EOF
562 git -c maintenance.incremental-repack.auto=2 \
563 maintenance is-needed --auto --task=incremental-repack &&
564 GIT_TRACE2_EVENT=$(pwd)/trace-B git \
565 -c maintenance.incremental-repack.auto=2 \
566 maintenance run --auto --task=incremental-repack 2>/dev/null &&
567 test_subcommand git multi-pack-index write --no-progress <trace-B
568 }
569
570 test_expect_success 'maintenance.incremental-repack.auto' '
571 rm -rf incremental-repack-true &&
572 git init incremental-repack-true &&
573 (
574 cd incremental-repack-true &&
575 git config core.multiPackIndex true &&
576 git config maintenance.auto false &&
577 run_incremental_repack_and_verify
578 )
579 '
580
581 test_expect_success 'maintenance.incremental-repack.auto (when config is unset)' '
582 rm -rf incremental-repack-unset &&
583 git init incremental-repack-unset &&
584 (
585 cd incremental-repack-unset &&
586 test_unconfig core.multiPackIndex &&
587 git config maintenance.auto false &&
588 run_incremental_repack_and_verify
589 )
590 '
591
592 run_and_verify_geometric_pack () {
593 EXPECTED_PACKS="$1" &&
594
595 # Verify that we perform a geometric repack.
596 rm -f "trace2.txt" &&
597 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
598 git maintenance run --task=geometric-repack 2>/dev/null &&
599 test_subcommand git repack -d -l -q --geometric=2 \
600 --write-midx <trace2.txt &&
601
602 # Verify that the number of packfiles matches our expectation.
603 ls -l .git/objects/pack/*.pack >packfiles &&
604 test_line_count = "$EXPECTED_PACKS" packfiles &&
605
606 # And verify that there are no loose objects anymore.
607 git count-objects -v >count &&
608 test_grep '^count: 0$' count &&
609
610 # Verify that no orphaned .idx files were left behind. On
611 # Windows, a missing odb_to_close causes the parent to hold
612 # mmap handles on .idx files, silently preventing their
613 # deletion by the child git-repack process.
614 ls .git/objects/pack/pack-*.idx .git/objects/pack/pack-*.pack |
615 sed "s/\.pack$/.idx/" |
616 sort | uniq -u >orphaned-idx &&
617 test_must_be_empty orphaned-idx
618 }
619
620 test_expect_success 'geometric repacking task' '
621 test_when_finished "rm -rf repo" &&
622 git init repo &&
623 (
624 cd repo &&
625 git config set maintenance.auto false &&
626 test_commit initial &&
627
628 # The initial repack causes an all-into-one repack.
629 GIT_TRACE2_EVENT="$(pwd)/initial-repack.txt" \
630 git maintenance run --task=geometric-repack 2>/dev/null &&
631 test_subcommand git repack -d -l -q --cruft --cruft-expiration=2.weeks.ago \
632 --write-midx <initial-repack.txt &&
633
634 # Repacking should now cause a no-op geometric repack because
635 # no packfiles need to be combined.
636 ls -l .git/objects/pack/*.pack >before &&
637 run_and_verify_geometric_pack 1 &&
638 ls -l .git/objects/pack/*.pack >after &&
639 test_cmp before after &&
640
641 # This incremental change creates a new packfile that only
642 # soaks up loose objects. The packfiles are not getting merged
643 # at this point.
644 test_commit loose &&
645 run_and_verify_geometric_pack 2 &&
646
647 # Both packfiles have 3 objects, so the next run would cause us
648 # to merge all packfiles together. This should be turned into
649 # an all-into-one-repack.
650 GIT_TRACE2_EVENT="$(pwd)/all-into-one-repack.txt" \
651 git maintenance run --task=geometric-repack 2>/dev/null &&
652 test_subcommand git repack -d -l -q --cruft --cruft-expiration=2.weeks.ago \
653 --write-midx <all-into-one-repack.txt &&
654
655 # The geometric repack soaks up unreachable objects.
656 echo blob-1 | git hash-object -w --stdin -t blob &&
657 run_and_verify_geometric_pack 2 &&
658
659 # A second unreachable object should be written into another packfile.
660 echo blob-2 | git hash-object -w --stdin -t blob &&
661 run_and_verify_geometric_pack 3 &&
662
663 # And these two small packs should now be merged via the
664 # geometric repack. The large packfile should remain intact.
665 cp -R .git/objects .git/objects.save &&
666 run_and_verify_geometric_pack 2 &&
667
668 # On Windows, verify the same with legacy delete semantics
669 # that reject deletion of mmap-held .idx files.
670 if test_have_prereq MINGW
671 then
672 rm -rf .git/objects &&
673 mv .git/objects.save .git/objects &&
674 test_env GIT_TEST_LEGACY_DELETE=1 \
675 run_and_verify_geometric_pack 2
676 fi &&
677
678 # If we now add two more objects and repack twice we should
679 # then see another all-into-one repack. This time around
680 # though, as we have unreachable objects, we should also see a
681 # cruft pack.
682 echo blob-3 | git hash-object -w --stdin -t blob &&
683 echo blob-4 | git hash-object -w --stdin -t blob &&
684 run_and_verify_geometric_pack 3 &&
685 GIT_TRACE2_EVENT="$(pwd)/cruft-repack.txt" \
686 git maintenance run --task=geometric-repack 2>/dev/null &&
687 test_subcommand git repack -d -l -q --cruft --cruft-expiration=2.weeks.ago \
688 --write-midx <cruft-repack.txt &&
689 ls .git/objects/pack/*.pack >packs &&
690 test_line_count = 2 packs &&
691 ls .git/objects/pack/*.mtimes >cruft &&
692 test_line_count = 1 cruft
693 )
694 '
695
696 test_geometric_repack_needed () {
697 NEEDED="$1"
698 GEOMETRIC_CONFIG="$2" &&
699 rm -f trace2.txt &&
700 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
701 git ${GEOMETRIC_CONFIG:+-c maintenance.geometric-repack.$GEOMETRIC_CONFIG} \
702 maintenance run --auto --task=geometric-repack 2>/dev/null &&
703 case "$NEEDED" in
704 true)
705 test_grep "\[\"git\",\"repack\"," trace2.txt;;
706 false)
707 ! test_grep "\[\"git\",\"repack\"," trace2.txt;;
708 *)
709 BUG "invalid parameter: $NEEDED";;
710 esac
711 }
712
713 test_expect_success 'geometric repacking with --auto' '
714 test_when_finished "rm -rf repo" &&
715 git init repo &&
716 (
717 cd repo &&
718 git config set maintenance.auto false &&
719
720 # An empty repository does not need repacking, except when
721 # explicitly told to do it.
722 test_geometric_repack_needed false &&
723 test_geometric_repack_needed false auto=0 &&
724 test_geometric_repack_needed false auto=1 &&
725 test_geometric_repack_needed true auto=-1 &&
726
727 test_oid_init &&
728
729 # Loose objects cause a repack when crossing the limit. Note
730 # that the number of objects gets extrapolated by having a look
731 # at the "objects/17/" shard.
732 test_commit "$(test_oid blob17_1)" &&
733 test_geometric_repack_needed false &&
734 test_commit "$(test_oid blob17_2)" &&
735 test_geometric_repack_needed false auto=257 &&
736 test_geometric_repack_needed true auto=256 &&
737
738 # Force another repack.
739 test_commit first &&
740 test_commit second &&
741 test_geometric_repack_needed true auto=-1 &&
742
743 # We now have two packfiles that would be merged together. As
744 # such, the repack should always happen unless the user has
745 # disabled the auto task.
746 test_geometric_repack_needed false auto=0 &&
747 test_geometric_repack_needed true auto=9000
748 )
749 '
750
751 test_expect_success 'geometric repacking honors configured split factor' '
752 test_when_finished "rm -rf repo" &&
753 git init repo &&
754 (
755 cd repo &&
756 git config set maintenance.auto false &&
757
758 # Create three different packs with 9, 2 and 1 object, respectively.
759 # This is done so that only a subset of packs would be merged
760 # together so that we can verify that `git repack` receives the
761 # correct geometric factor.
762 for i in $(test_seq 9)
763 do
764 echo first-$i | git hash-object -w --stdin -t blob || return 1
765 done &&
766 git repack --geometric=2 -d &&
767
768 for i in $(test_seq 2)
769 do
770 echo second-$i | git hash-object -w --stdin -t blob || return 1
771 done &&
772 git repack --geometric=2 -d &&
773
774 echo third | git hash-object -w --stdin -t blob &&
775 git repack --geometric=2 -d &&
776
777 test_geometric_repack_needed false splitFactor=2 &&
778 test_geometric_repack_needed true splitFactor=3 &&
779 test_subcommand git repack -d -l -q --geometric=3 --write-midx <trace2.txt
780 )
781 '
782
783 test_expect_success 'pre-auto-gc hook runs exactly once' '
784 test_when_finished "rm -rf repo" &&
785 git init repo &&
786 (
787 cd repo &&
788 write_script .git/hooks/pre-auto-gc <<-\EOF &&
789 echo hook >>hook.log
790 EOF
791
792 # Satisfy the auto condition for multiple tasks, both in the
793 # foreground and in the background phase.
794 git config set maintenance.reflog-expire.auto -1 &&
795 git config set maintenance.geometric-repack.auto -1 &&
796 git config set maintenance.rerere-gc.auto -1 &&
797
798 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
799 git maintenance run --auto 2>/dev/null &&
800
801 # The successful hook does not inhibit any of the tasks...
802 test_maintenance_tasks trace2.txt <<-\EOF &&
803 reflog-expire foreground
804 geometric-repack
805 rerere-gc
806 EOF
807 # ... but it must only have been executed a single time.
808 test_line_count = 1 hook.log
809 )
810 '
811
812 test_expect_success 'pre-auto-gc hook can inhibit geometric strategy' '
813 test_when_finished "rm -rf repo" &&
814 git init repo &&
815 (
816 cd repo &&
817 write_script .git/hooks/pre-auto-gc <<-\EOF &&
818 echo hook >>hook.log
819 exit 1
820 EOF
821
822 git config set maintenance.reflog-expire.auto -1 &&
823 git config set maintenance.geometric-repack.auto -1 &&
824 git config set maintenance.rerere-gc.auto -1 &&
825
826 # Maintenance would be required...
827 git maintenance is-needed --auto &&
828
829 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
830 git maintenance run --auto 2>/dev/null &&
831
832 # ... but the failing hook inhibits all tasks. The hook itself
833 # is expected to be the only child process being spawned, and
834 # it must only run a single time.
835 test_grep "child_start.*pre-auto-gc" trace2.txt &&
836 test_maintenance_tasks trace2.txt <<-\EOF &&
837 EOF
838 test_line_count = 1 hook.log
839 )
840 '
841
842 test_expect_success 'pre-auto-gc hook can inhibit gc strategy' '
843 test_when_finished "rm -rf repo" &&
844 git init repo &&
845 (
846 cd repo &&
847 write_script .git/hooks/pre-auto-gc <<-\EOF &&
848 echo hook >>hook.log
849 exit 1
850 EOF
851
852 git config set maintenance.strategy gc &&
853 git config set maintenance.auto false &&
854 git config set gc.auto 3 &&
855
856 test_oid_init &&
857
858 # We need to create two objects whose hashes start with 17
859 # since this is what the gc task counts.
860 test_commit "$(test_oid blob17_1)" &&
861 test_commit "$(test_oid blob17_2)" &&
862
863 # Maintenance would be required...
864 git maintenance is-needed --auto &&
865
866 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
867 git maintenance run --auto 2>/dev/null &&
868
869 # ... but the failing hook inhibits all tasks. The hook itself
870 # is expected to be the only child process being spawned, and
871 # it must only run a single time.
872 test_grep "child_start.*pre-auto-gc" trace2.txt &&
873 test_maintenance_tasks trace2.txt <<-\EOF &&
874 EOF
875 test_subcommand_flex ! git trace2 &&
876 test_line_count = 1 hook.log
877 )
878 '
879
880 test_expect_success 'pre-auto-gc hook does not run when no maintenance is needed' '
881 test_when_finished "rm -rf repo" &&
882 git init repo &&
883 (
884 cd repo &&
885 write_script .git/hooks/pre-auto-gc <<-\EOF &&
886 echo hook >>hook.log
887 EOF
888 test_must_fail git maintenance is-needed --auto &&
889 git maintenance run --auto 2>/dev/null &&
890 test_path_is_missing hook.log
891 )
892 '
893
894 test_expect_success 'pre-auto-gc hook does not run without --auto' '
895 test_when_finished "rm -rf repo" &&
896 git init repo &&
897 test_hook -C repo pre-auto-gc <<-\EOF &&
898 echo hook >>hook.log
899 EOF
900 (
901 cd repo &&
902 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
903 git maintenance run 2>/dev/null &&
904 test_grep "\[\"git\",\"repack\"," trace2.txt &&
905 test_path_is_missing hook.log
906 )
907 '
908
909 test_expect_success 'pack-refs task' '
910 for n in $(test_seq 1 5)
911 do
912 git branch -f to-pack/$n HEAD || return 1
913 done &&
914 GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
915 git maintenance run --task=pack-refs &&
916 test_subcommand git pack-refs --all --prune <pack-refs.txt
917 '
918
919 test_expect_success 'reflog-expire task' '
920 GIT_TRACE2_EVENT="$(pwd)/reflog-expire.txt" \
921 git maintenance run --task=reflog-expire &&
922 test_subcommand git reflog expire --all <reflog-expire.txt
923 '
924
925 test_expect_success 'reflog-expire task --auto only packs when exceeding limits' '
926 git reflog expire --all --expire=now &&
927 test_commit reflog-one &&
928 test_commit reflog-two &&
929
930 ! git -c maintenance.reflog-expire.auto=3 \
931 maintenance is-needed --auto --task=reflog-expire &&
932 GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \
933 git -c maintenance.reflog-expire.auto=3 maintenance run --auto --task=reflog-expire &&
934 test_subcommand ! git reflog expire --all <reflog-expire-auto.txt &&
935
936 git -c maintenance.reflog-expire.auto=2 \
937 maintenance is-needed --auto --task=reflog-expire &&
938 GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \
939 git -c maintenance.reflog-expire.auto=2 maintenance run --auto --task=reflog-expire &&
940 test_subcommand git reflog expire --all <reflog-expire-auto.txt
941 '
942
943 test_expect_worktree_prune () {
944 negate=
945 if test "$1" = "!"
946 then
947 negate="!"
948 shift
949 fi
950
951 rm -f "worktree-prune.txt" &&
952 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" "$@" &&
953 test_subcommand $negate git worktree prune --expire 3.months.ago <worktree-prune.txt
954 }
955
956 test_expect_success 'worktree-prune task without --auto always prunes' '
957 test_expect_worktree_prune git maintenance run --task=worktree-prune
958 '
959
960 test_expect_success 'worktree-prune task --auto only prunes with prunable worktree' '
961 test_expect_worktree_prune ! git maintenance run --auto --task=worktree-prune &&
962 mkdir .git/worktrees &&
963 : >.git/worktrees/abc &&
964 git maintenance is-needed --auto --task=worktree-prune &&
965 test_expect_worktree_prune git maintenance run --auto --task=worktree-prune
966 '
967
968 test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' '
969 # A negative value should always prune.
970 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune &&
971
972 mkdir .git/worktrees &&
973 : >.git/worktrees/first &&
974 : >.git/worktrees/second &&
975 : >.git/worktrees/third &&
976
977 # Zero should never prune.
978 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune &&
979 # A positive value should require at least this many prunable worktrees.
980 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune &&
981 git -c maintenance.worktree-prune.auto=3 maintenance is-needed --auto --task=worktree-prune &&
982 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune
983 '
984
985 test_expect_success 'worktree-prune task honors gc.worktreePruneExpire' '
986 git worktree add worktree &&
987 rm -rf worktree &&
988
989 rm -f worktree-prune.txt &&
990 ! git -c gc.worktreePruneExpire=1.week.ago maintenance is-needed --auto --task=worktree-prune &&
991 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=1.week.ago maintenance run --auto --task=worktree-prune &&
992 test_subcommand ! git worktree prune --expire 1.week.ago <worktree-prune.txt &&
993 test_path_is_dir .git/worktrees/worktree &&
994
995 rm -f worktree-prune.txt &&
996 git -c gc.worktreePruneExpire=now maintenance is-needed --auto --task=worktree-prune &&
997 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=now maintenance run --auto --task=worktree-prune &&
998 test_subcommand git worktree prune --expire now <worktree-prune.txt &&
999 test_path_is_missing .git/worktrees/worktree
1000 '
1001
1002 test_expect_rerere_gc () {
1003 negate=
1004 if test "$1" = "!"
1005 then
1006 negate="!"
1007 shift
1008 fi
1009
1010 rm -f "rerere-gc.txt" &&
1011 GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" &&
1012 test_subcommand $negate git rerere gc <rerere-gc.txt
1013 }
1014
1015 test_expect_success 'rerere-gc task without --auto always collects garbage' '
1016 test_expect_rerere_gc git maintenance run --task=rerere-gc
1017 '
1018
1019 test_expect_success 'rerere-gc task with --auto only prunes with stale entries' '
1020 test_when_finished "rm -rf .git/rr-cache" &&
1021 entry_1=.git/rr-cache/171$(echo $ZERO_OID | cut -c4-) &&
1022 entry_2=.git/rr-cache/172$(echo $ZERO_OID | cut -c4-) &&
1023 entry_3=.git/rr-cache/173$(echo $ZERO_OID | cut -c4-) &&
1024
1025 # Without the "rr-cache" directory there is nothing to prune.
1026 ! git maintenance is-needed --auto --task=rerere-gc &&
1027 test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
1028
1029 # Fresh unresolved entries are not stale.
1030 for e in $entry_1 $entry_2 $entry_3
1031 do
1032 mkdir -p $e &&
1033 echo preimage >$e/preimage || return 1
1034 done &&
1035 ! git maintenance is-needed --auto --task=rerere-gc &&
1036 test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
1037
1038 # Entries are sampled using the "17" prefix, so we scale up the
1039 # estimate by 256. A single entry is not sufficient to reach the
1040 # default limit of 512.
1041 test-tool chmtime =-$((16 * 86400)) $entry_1/preimage &&
1042 ! git maintenance is-needed --auto --task=rerere-gc &&
1043
1044 # A second prunable entry will reach the limit though and will thus get
1045 # pruned.
1046 test-tool chmtime =-$((16 * 86400)) $entry_2/preimage &&
1047 git maintenance is-needed --auto --task=rerere-gc &&
1048
1049 # The prunable entries are gone, the other one remains.
1050 test_expect_rerere_gc git maintenance run --auto --task=rerere-gc &&
1051 test_path_is_missing $entry_1 &&
1052 test_path_is_missing $entry_2 &&
1053 test_path_is_dir $entry_3
1054 '
1055
1056 test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.auto' '
1057 test_when_finished "rm -rf .git/rr-cache" &&
1058 entry=.git/rr-cache/171$(echo $ZERO_OID | cut -c4-) &&
1059
1060 # A negative value should always prune.
1061 git -c maintenance.rerere-gc.auto=-1 maintenance is-needed --auto --task=rerere-gc &&
1062 test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc &&
1063
1064 # A positive value prunes only when the estimated number of stale
1065 # entries is at least as big. A single sampled entry counts for 256
1066 # estimated entries.
1067 mkdir -p $entry &&
1068 echo preimage >$entry/preimage &&
1069 test-tool chmtime =-$((16 * 86400)) $entry/preimage &&
1070
1071 ! git -c maintenance.rerere-gc.auto=257 maintenance is-needed --auto --task=rerere-gc &&
1072 test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=257 maintenance run --auto --task=rerere-gc &&
1073 test_path_is_dir $entry &&
1074
1075 git -c maintenance.rerere-gc.auto=256 maintenance is-needed --auto --task=rerere-gc &&
1076 test_expect_rerere_gc git -c maintenance.rerere-gc.auto=256 maintenance run --auto --task=rerere-gc &&
1077 test_path_is_missing $entry &&
1078
1079 # Zero should never prune.
1080 mkdir -p $entry &&
1081 echo preimage >$entry/preimage &&
1082 test-tool chmtime =-$((16 * 86400)) $entry/preimage &&
1083 ! git -c maintenance.rerere-gc.auto=0 maintenance is-needed --auto --task=rerere-gc &&
1084 test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc
1085 '
1086
1087 test_expect_success '--auto and --schedule incompatible' '
1088 test_must_fail git maintenance run --auto --schedule=daily 2>err &&
1089 test_grep "cannot be used together" err
1090 '
1091
1092 test_expect_success '--task and --schedule incompatible' '
1093 test_must_fail git maintenance run --task=pack-refs --schedule=daily 2>err &&
1094 test_grep "cannot be used together" err
1095 '
1096
1097 test_expect_success 'invalid --schedule value' '
1098 test_must_fail git maintenance run --schedule=annually 2>err &&
1099 test_grep "unrecognized --schedule" err
1100 '
1101
1102 test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
1103 git config maintenance.loose-objects.enabled true &&
1104 git config maintenance.loose-objects.schedule hourly &&
1105 git config maintenance.commit-graph.enabled true &&
1106 git config maintenance.commit-graph.schedule daily &&
1107 git config maintenance.incremental-repack.enabled true &&
1108 git config maintenance.incremental-repack.schedule weekly &&
1109
1110 GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
1111 git maintenance run --schedule=hourly 2>/dev/null &&
1112 test_maintenance_tasks hourly.txt <<-\EOF &&
1113 prefetch
1114 loose-objects
1115 EOF
1116
1117 GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
1118 git maintenance run --schedule=daily 2>/dev/null &&
1119 test_maintenance_tasks daily.txt <<-\EOF &&
1120 prefetch
1121 loose-objects
1122 commit-graph
1123 EOF
1124
1125 GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
1126 git maintenance run --schedule=weekly 2>/dev/null &&
1127 test_maintenance_tasks weekly.txt <<-\EOF
1128 pack-refs foreground
1129 prefetch
1130 loose-objects
1131 incremental-repack
1132 commit-graph
1133 EOF
1134 '
1135
1136 test_expect_success 'maintenance.strategy inheritance' '
1137 for task in commit-graph loose-objects incremental-repack
1138 do
1139 git config --unset maintenance.$task.schedule || return 1
1140 done &&
1141
1142 test_when_finished git config --unset maintenance.strategy &&
1143 git config maintenance.strategy incremental &&
1144
1145 GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
1146 git maintenance run --schedule=hourly --quiet &&
1147 GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
1148 git maintenance run --schedule=daily --quiet &&
1149 GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
1150 git maintenance run --schedule=weekly --quiet &&
1151
1152 test_maintenance_tasks incremental-hourly.txt <<-\EOF &&
1153 prefetch
1154 commit-graph
1155 EOF
1156
1157 test_maintenance_tasks incremental-daily.txt <<-\EOF &&
1158 prefetch
1159 loose-objects
1160 incremental-repack
1161 commit-graph
1162 EOF
1163
1164 test_maintenance_tasks incremental-weekly.txt <<-\EOF &&
1165 pack-refs foreground
1166 prefetch
1167 loose-objects
1168 incremental-repack
1169 commit-graph
1170 EOF
1171
1172 # Modify defaults
1173 git config maintenance.commit-graph.schedule daily &&
1174 git config maintenance.loose-objects.schedule hourly &&
1175 git config maintenance.incremental-repack.enabled false &&
1176
1177 GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
1178 git maintenance run --schedule=hourly --quiet &&
1179 GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
1180 git maintenance run --schedule=daily --quiet &&
1181
1182 test_maintenance_tasks modified-hourly.txt <<-\EOF &&
1183 prefetch
1184 loose-objects
1185 EOF
1186
1187 test_maintenance_tasks modified-daily.txt <<-\EOF
1188 prefetch
1189 loose-objects
1190 commit-graph
1191 EOF
1192 '
1193
1194 test_strategy () {
1195 STRATEGY="$1"
1196 shift
1197
1198 rm -f trace2.txt &&
1199 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1200 git -c maintenance.strategy=$STRATEGY maintenance run --quiet "$@" &&
1201 test_maintenance_tasks trace2.txt
1202 }
1203
1204 test_expect_success 'maintenance.strategy is respected' '
1205 test_when_finished "rm -rf repo" &&
1206 git init repo &&
1207 (
1208 cd repo &&
1209 test_commit initial &&
1210
1211 test_must_fail git -c maintenance.strategy=unknown maintenance run 2>err &&
1212 test_grep "unknown maintenance strategy: .unknown." err &&
1213
1214 test_strategy incremental <<-\EOF &&
1215 gc foreground
1216 gc
1217 EOF
1218
1219 test_strategy incremental --schedule=weekly <<-\EOF &&
1220 pack-refs foreground
1221 prefetch
1222 loose-objects
1223 incremental-repack
1224 commit-graph
1225 EOF
1226
1227 test_strategy gc <<-\EOF &&
1228 gc foreground
1229 gc
1230 EOF
1231
1232 test_strategy gc --schedule=weekly <<-\EOF &&
1233 gc foreground
1234 gc
1235 EOF
1236
1237 test_strategy geometric <<-\EOF &&
1238 pack-refs foreground
1239 reflog-expire foreground
1240 geometric-repack
1241 commit-graph
1242 worktree-prune
1243 rerere-gc
1244 EOF
1245
1246 test_strategy geometric --schedule=weekly <<-\EOF
1247 pack-refs foreground
1248 reflog-expire foreground
1249 geometric-repack
1250 commit-graph
1251 worktree-prune
1252 rerere-gc
1253 EOF
1254 )
1255 '
1256
1257 test_expect_success 'register and unregister' '
1258 test_when_finished git config --global --unset-all maintenance.repo &&
1259
1260 test_must_fail git maintenance unregister 2>err &&
1261 test_grep "is not registered" err &&
1262 git maintenance unregister --force &&
1263
1264 git config --global --add maintenance.repo /existing1 &&
1265 git config --global --add maintenance.repo /existing2 &&
1266 git config --global --get-all maintenance.repo >before &&
1267
1268 git maintenance register &&
1269 test_cmp_config false maintenance.auto &&
1270 git config --global --get-all maintenance.repo >between &&
1271 cp before expect &&
1272 pwd >>expect &&
1273 test_cmp expect between &&
1274
1275 git maintenance unregister &&
1276 git config --global --get-all maintenance.repo >actual &&
1277 test_cmp before actual &&
1278
1279 git config --file ./other --add maintenance.repo /existing1 &&
1280 git config --file ./other --add maintenance.repo /existing2 &&
1281 git config --file ./other --get-all maintenance.repo >before &&
1282
1283 git maintenance register --config-file ./other &&
1284 test_cmp_config false maintenance.auto &&
1285 git config --file ./other --get-all maintenance.repo >between &&
1286 cp before expect &&
1287 pwd >>expect &&
1288 test_cmp expect between &&
1289
1290 git maintenance unregister --config-file ./other &&
1291 git config --file ./other --get-all maintenance.repo >actual &&
1292 test_cmp before actual &&
1293
1294 test_must_fail git maintenance unregister 2>err &&
1295 test_grep "is not registered" err &&
1296 git maintenance unregister --force &&
1297
1298 test_must_fail git maintenance unregister --config-file ./other 2>err &&
1299 test_grep "is not registered" err &&
1300 git maintenance unregister --config-file ./other --force
1301 '
1302
1303 test_expect_success 'register with no value for maintenance.repo' '
1304 cp .git/config .git/config.orig &&
1305 test_when_finished mv .git/config.orig .git/config &&
1306
1307 cat >>.git/config <<-\EOF &&
1308 [maintenance]
1309 repo
1310 EOF
1311 cat >expect <<-\EOF &&
1312 error: missing value for '\''maintenance.repo'\''
1313 EOF
1314 git maintenance register 2>actual &&
1315 test_cmp expect actual &&
1316 git config maintenance.repo
1317 '
1318
1319 test_expect_success 'unregister with no value for maintenance.repo' '
1320 cp .git/config .git/config.orig &&
1321 test_when_finished mv .git/config.orig .git/config &&
1322
1323 cat >>.git/config <<-\EOF &&
1324 [maintenance]
1325 repo
1326 EOF
1327 cat >expect <<-\EOF &&
1328 error: missing value for '\''maintenance.repo'\''
1329 EOF
1330 test_expect_code 128 git maintenance unregister 2>actual.raw &&
1331 grep ^error actual.raw >actual &&
1332 test_cmp expect actual &&
1333 git config maintenance.repo &&
1334
1335 git maintenance unregister --force 2>actual.raw &&
1336 grep ^error actual.raw >actual &&
1337 test_cmp expect actual &&
1338 git config maintenance.repo
1339 '
1340
1341 test_expect_success !MINGW 'register and unregister with regex metacharacters' '
1342 META="a+b*c" &&
1343 git init "$META" &&
1344 git -C "$META" maintenance register &&
1345 git config --get-all --show-origin maintenance.repo &&
1346 git config --get-all --global --fixed-value \
1347 maintenance.repo "$(pwd)/$META" &&
1348 git -C "$META" maintenance unregister &&
1349 test_must_fail git config --get-all --global --fixed-value \
1350 maintenance.repo "$(pwd)/$META"
1351 '
1352
1353 test_expect_success 'start without GIT_TEST_MAINT_SCHEDULER' '
1354 test_when_finished "rm -rf systemctl.log script repo" &&
1355 mkdir script &&
1356 write_script script/systemctl <<-\EOF &&
1357 echo "$*" >>../systemctl.log
1358 EOF
1359 git init repo &&
1360 (
1361 cd repo &&
1362 sane_unset GIT_TEST_MAINT_SCHEDULER &&
1363 PATH="$PWD/../script:$PATH" git maintenance start --scheduler=systemd
1364 ) &&
1365 test_grep -- "--user list-timers" systemctl.log &&
1366 test_grep -- "enable --now git-maintenance@" systemctl.log
1367 '
1368
1369 test_expect_success 'start --scheduler=<scheduler>' '
1370 test_expect_code 129 git maintenance start --scheduler=foo 2>err &&
1371 test_grep "unrecognized --scheduler argument" err &&
1372
1373 test_expect_code 129 git maintenance start --no-scheduler 2>err &&
1374 test_grep "unknown option" err &&
1375
1376 test_expect_code 128 \
1377 env GIT_TEST_MAINT_SCHEDULER="launchctl:true,schtasks:true" \
1378 git maintenance start --scheduler=crontab 2>err &&
1379 test_grep "fatal: crontab scheduler is not available" err
1380 '
1381
1382 test_expect_success 'start from empty cron table' '
1383 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab &&
1384
1385 # start registers the repo
1386 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1387
1388 test_grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=daily" cron.txt &&
1389 test_grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=hourly" cron.txt &&
1390 test_grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=weekly" cron.txt
1391 '
1392
1393 test_expect_success 'stop from existing schedule' '
1394 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
1395
1396 # stop does not unregister the repo
1397 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1398
1399 # Operation is idempotent
1400 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
1401 test_must_be_empty cron.txt
1402 '
1403
1404 test_expect_success 'start preserves existing schedule' '
1405 echo "Important information!" >cron.txt &&
1406 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab &&
1407 test_grep "Important information!" cron.txt
1408 '
1409
1410 test_expect_success 'magic markers are correct' '
1411 grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual &&
1412 cat >expect <<-\EOF &&
1413 # BEGIN GIT MAINTENANCE SCHEDULE
1414 # END GIT MAINTENANCE SCHEDULE
1415 EOF
1416 test_cmp actual expect
1417 '
1418
1419 test_expect_success 'stop preserves surrounding schedule' '
1420 echo "Crucial information!" >>cron.txt &&
1421 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
1422 test_grep "Important information!" cron.txt &&
1423 test_grep "Crucial information!" cron.txt
1424 '
1425
1426 test_expect_success 'start and stop macOS maintenance' '
1427 # ensure $HOME can be compared against hook arguments on all platforms
1428 pfx=$(cd "$HOME" && pwd) &&
1429
1430 write_script print-args <<-\EOF &&
1431 echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
1432 EOF
1433
1434 rm -f args &&
1435 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
1436
1437 # start registers the repo
1438 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1439
1440 ls "$HOME/Library/LaunchAgents" >actual &&
1441 cat >expect <<-\EOF &&
1442 org.git-scm.git.daily.plist
1443 org.git-scm.git.hourly.plist
1444 org.git-scm.git.weekly.plist
1445 EOF
1446 test_cmp expect actual &&
1447
1448 rm -f expect &&
1449 for frequency in hourly daily weekly
1450 do
1451 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
1452 test_xmllint "$PLIST" &&
1453 test_grep schedule=$frequency "$PLIST" &&
1454 echo "bootout gui/[UID] $PLIST" >>expect &&
1455 echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
1456 done &&
1457 test_cmp expect args &&
1458
1459 rm -f args &&
1460 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
1461
1462 # stop does not unregister the repo
1463 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1464
1465 printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
1466 hourly daily weekly >expect &&
1467 test_cmp expect args &&
1468 ls "$HOME/Library/LaunchAgents" >actual &&
1469 test_line_count = 0 actual
1470 '
1471
1472 test_expect_success 'use launchctl list to prevent extra work' '
1473 # ensure we are registered
1474 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
1475
1476 # do it again on a fresh args file
1477 rm -f args &&
1478 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
1479
1480 ls "$HOME/Library/LaunchAgents" >actual &&
1481 cat >expect <<-\EOF &&
1482 list org.git-scm.git.hourly
1483 list org.git-scm.git.daily
1484 list org.git-scm.git.weekly
1485 EOF
1486 test_cmp expect args
1487 '
1488
1489 test_expect_success 'start and stop Windows maintenance' '
1490 write_script print-args <<-\EOF &&
1491 echo $* >>args
1492 while test $# -gt 0
1493 do
1494 case "$1" in
1495 /xml) shift; xmlfile=$1; break ;;
1496 *) shift ;;
1497 esac
1498 done
1499 test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
1500 EOF
1501
1502 rm -f args &&
1503 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start --scheduler=schtasks &&
1504
1505 # start registers the repo
1506 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1507
1508 for frequency in hourly daily weekly
1509 do
1510 test_grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
1511 file=$(ls .git/schedule_${frequency}*.xml) &&
1512 test_xmllint "$file" || return 1
1513 done &&
1514
1515 rm -f args &&
1516 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
1517
1518 # stop does not unregister the repo
1519 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1520
1521 printf "/delete /tn Git Maintenance (%s) /f\n" \
1522 hourly daily weekly >expect &&
1523 test_cmp expect args
1524 '
1525
1526 test_expect_success 'start and stop Linux/systemd maintenance' '
1527 write_script print-args <<-\EOF &&
1528 printf "%s\n" "$*" >>args
1529 EOF
1530
1531 XDG_CONFIG_HOME="$PWD" &&
1532 export XDG_CONFIG_HOME &&
1533 rm -f args &&
1534 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance start --scheduler=systemd-timer &&
1535
1536 # start registers the repo
1537 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1538
1539 for schedule in hourly daily weekly
1540 do
1541 test_path_is_file "systemd/user/git-maintenance@$schedule.timer" || return 1
1542 done &&
1543 test_path_is_file "systemd/user/git-maintenance@.service" &&
1544
1545 test_systemd_analyze_verify "systemd/user/git-maintenance@hourly.service" &&
1546 test_systemd_analyze_verify "systemd/user/git-maintenance@daily.service" &&
1547 test_systemd_analyze_verify "systemd/user/git-maintenance@weekly.service" &&
1548
1549 test_grep "core.askPass=true" "systemd/user/git-maintenance@.service" &&
1550 test_grep "credential.interactive=false" "systemd/user/git-maintenance@.service" &&
1551
1552 printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
1553 test_cmp expect args &&
1554
1555 rm -f args &&
1556 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance stop &&
1557
1558 # stop does not unregister the repo
1559 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1560
1561 for schedule in hourly daily weekly
1562 do
1563 test_path_is_missing "systemd/user/git-maintenance@$schedule.timer" || return 1
1564 done &&
1565 test_path_is_missing "systemd/user/git-maintenance@.service" &&
1566
1567 printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
1568 test_cmp expect args
1569 '
1570
1571 test_expect_success 'start and stop when several schedulers are available' '
1572 write_script print-args <<-\EOF &&
1573 printf "%s\n" "$*" | sed "s:gui/[0-9][0-9]*:gui/[UID]:; s:\(schtasks /create .* /xml\).*:\1:;" >>args
1574 EOF
1575
1576 rm -f args &&
1577 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=systemd-timer &&
1578 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
1579 hourly daily weekly >expect &&
1580 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
1581 hourly daily weekly >>expect &&
1582 printf -- "systemctl --user enable --now git-maintenance@%s.timer\n" hourly daily weekly >>expect &&
1583 test_cmp expect args &&
1584
1585 rm -f args &&
1586 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=launchctl &&
1587 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
1588 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
1589 hourly daily weekly >>expect &&
1590 for frequency in hourly daily weekly
1591 do
1592 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
1593 echo "launchctl bootout gui/[UID] $PLIST" >>expect &&
1594 echo "launchctl bootstrap gui/[UID] $PLIST" >>expect || return 1
1595 done &&
1596 test_cmp expect args &&
1597
1598 rm -f args &&
1599 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=schtasks &&
1600 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
1601 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
1602 hourly daily weekly >>expect &&
1603 printf "schtasks /create /tn Git Maintenance (%s) /f /xml\n" \
1604 hourly daily weekly >>expect &&
1605 test_cmp expect args &&
1606
1607 rm -f args &&
1608 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance stop &&
1609 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
1610 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
1611 hourly daily weekly >>expect &&
1612 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
1613 hourly daily weekly >>expect &&
1614 test_cmp expect args
1615 '
1616
1617 test_expect_success 'register preserves existing strategy' '
1618 git config maintenance.strategy none &&
1619 git maintenance register &&
1620 test_config maintenance.strategy none &&
1621 git config --unset maintenance.strategy &&
1622 git maintenance register &&
1623 test_config maintenance.strategy incremental
1624 '
1625
1626 test_expect_success 'fails when running outside of a repository' '
1627 nongit test_must_fail git maintenance run &&
1628 nongit test_must_fail git maintenance stop &&
1629 nongit test_must_fail git maintenance start &&
1630 nongit test_must_fail git maintenance register &&
1631 nongit test_must_fail git maintenance unregister
1632 '
1633
1634 test_expect_success 'fails when configured to use an invalid strategy' '
1635 test_must_fail git -c maintenance.strategy=invalid maintenance run --schedule=hourly 2>err &&
1636 test_grep "unknown maintenance strategy: .invalid." err
1637 '
1638
1639 test_expect_success 'register and unregister bare repo' '
1640 test_when_finished "git config --global --unset-all maintenance.repo || :" &&
1641 test_might_fail git config --global --unset-all maintenance.repo &&
1642 git init --bare barerepo &&
1643 (
1644 cd barerepo &&
1645 git maintenance register &&
1646 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
1647 git maintenance unregister &&
1648 test_must_fail git config --global --get-all maintenance.repo
1649 )
1650 '
1651
1652 test_expect_success 'failed schedule prevents config change' '
1653 git init --bare failcase &&
1654
1655 for scheduler in crontab launchctl schtasks systemctl
1656 do
1657 GIT_TEST_MAINT_SCHEDULER="$scheduler:false" &&
1658 export GIT_TEST_MAINT_SCHEDULER &&
1659 test_must_fail \
1660 git -C failcase maintenance start &&
1661 test_must_fail git -C failcase config maintenance.auto || return 1
1662 done
1663 '
1664
1665 test_expect_success '--no-detach causes maintenance to not run in background' '
1666 test_when_finished "rm -rf repo" &&
1667 git init repo &&
1668 (
1669 cd repo &&
1670
1671 # Prepare the repository such that git-maintenance(1) ends up
1672 # outputting something.
1673 test_commit something &&
1674 git config set maintenance.gc.enabled false &&
1675 git config set maintenance.loose-objects.enabled true &&
1676 git config set maintenance.loose-objects.auto 1 &&
1677 git config set maintenance.incremental-repack.enabled true &&
1678
1679 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
1680 git maintenance run --no-detach >out 2>&1 &&
1681 ! test_region maintenance detach trace.txt
1682 )
1683 '
1684
1685 test_expect_success PIPE '--detach holds maintenance lock until daemonized child exits' '
1686 test_when_finished "rm -rf repo" &&
1687 git init repo &&
1688 (
1689 cd repo &&
1690
1691 git config maintenance.auto false &&
1692 git config core.lockfilepid true &&
1693
1694 git remote add origin /does/not/exist &&
1695 git config set remote.origin.uploadpack "cat fifo-uploadpack" &&
1696
1697 mkfifo fifo-uploadpack fifo-maint &&
1698
1699 # Open the maintenance FIFO, as otherwise spawning
1700 # git-maintenance(1) would block. Note that we need to open it
1701 # as read-write, as otherwise we would block here already.
1702 exec 9<>fifo-maint &&
1703
1704 { git maintenance run --task=prefetch --detach 7>&9 & } &&
1705 parent="$!" &&
1706
1707 # Reap the parent process so that the exec call below will not
1708 # get SIGCHLD.
1709 wait "$parent" &&
1710
1711 # Open the git-upload-pack(1) FIFO for writing, which will
1712 # block until the upload-pack script opens it for reading. Once
1713 # exec returns, we know that the daemonized child is alive and
1714 # pinned.
1715 exec 8>fifo-uploadpack &&
1716
1717 test_path_is_file .git/objects/maintenance.lock &&
1718 test_path_is_file .git/objects/"maintenance~pid.lock" &&
1719
1720 # Verify that the maintenance.lock still exists, and
1721 # that it was created by the parent process, not the
1722 # child.
1723 echo "pid $parent" >expect &&
1724 test_cmp expect .git/objects/"maintenance~pid.lock" &&
1725
1726 # Reopen the maintenance FIFO as read-only so that
1727 # git-maintenance(1) is the only writer. This will cause it to
1728 # close the FIFO once the process exits.
1729 exec 9<&- &&
1730 exec 9<fifo-maint &&
1731
1732 # Close the FIFO used by git-upload-pack(1) to unblock it and
1733 # then wait until the maintenance FIFO is closed by
1734 # git-maintenance(1), indicating that it has exited.
1735 exec 8>&- &&
1736 cat <&9 &&
1737
1738 test_path_is_missing .git/objects/maintenance.lock &&
1739 test_path_is_missing .git/objects/"maintenance~pid.lock"
1740 )
1741 '
1742
1743 test_expect_success '--detach causes maintenance to run in background' '
1744 test_when_finished "rm -rf repo" &&
1745 git init repo &&
1746 (
1747 cd repo &&
1748
1749 test_commit something &&
1750 git config set maintenance.gc.enabled false &&
1751 git config set maintenance.loose-objects.enabled true &&
1752 git config set maintenance.loose-objects.auto 1 &&
1753 git config set maintenance.incremental-repack.enabled true &&
1754
1755 # The extra file descriptor gets inherited to the child
1756 # process, and by reading stdout we thus essentially wait for
1757 # that descriptor to get closed, which indicates that the child
1758 # is done, too.
1759 does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
1760 git maintenance run --detach 9>&1) &&
1761 test_region maintenance detach trace.txt
1762 )
1763 '
1764
1765 test_expect_success 'repacking loose objects is quiet' '
1766 test_when_finished "rm -rf repo" &&
1767 git init repo &&
1768 (
1769 cd repo &&
1770
1771 test_commit something &&
1772 git config set maintenance.gc.enabled false &&
1773 git config set maintenance.loose-objects.enabled true &&
1774 git config set maintenance.loose-objects.auto 1 &&
1775
1776 git maintenance run --quiet >out 2>&1 &&
1777 test_must_be_empty out
1778 )
1779 '
1780
1781 test_expect_success 'maintenance aborts with existing lock file' '
1782 test_when_finished "rm -rf repo script" &&
1783 mkdir script &&
1784 write_script script/systemctl <<-\EOF &&
1785 true
1786 EOF
1787
1788 git init repo &&
1789 : >repo/.git/objects/schedule.lock &&
1790 test_must_fail env PATH="$PWD/script:$PATH" git -C repo maintenance start --scheduler=systemd 2>err &&
1791 test_grep "Another scheduled git-maintenance(1) process seems to be running" err
1792 '
1793
1794 test_done