submodule-config.h: remove unused SUBMODULE_INIT macro
[git/debian.git] / t / t7900-maintenance.sh
blob36a4218745bda747e5d3f3c8252ea1913130318a
1 #!/bin/sh
3 test_description='git maintenance builtin'
5 . ./test-lib.sh
7 GIT_TEST_COMMIT_GRAPH=0
8 GIT_TEST_MULTI_PACK_INDEX=0
10 test_lazy_prereq XMLLINT '
11 xmllint --version
14 test_xmllint () {
15 if test_have_prereq XMLLINT
16 then
17 xmllint --noout "$@"
18 else
19 true
23 test_lazy_prereq SYSTEMD_ANALYZE '
24 systemd-analyze --help >out &&
25 grep verify out
28 test_systemd_analyze_verify () {
29 if test_have_prereq SYSTEMD_ANALYZE
30 then
31 systemd-analyze verify "$@"
35 test_expect_success 'help text' '
36 test_expect_code 129 git maintenance -h 2>err &&
37 test_i18ngrep "usage: git maintenance <subcommand>" err &&
38 test_expect_code 128 git maintenance barf 2>err &&
39 test_i18ngrep "invalid subcommand: barf" err &&
40 test_expect_code 129 git maintenance 2>err &&
41 test_i18ngrep "usage: git maintenance" err
44 test_expect_success 'run [--auto|--quiet]' '
45 GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
46 git maintenance run 2>/dev/null &&
47 GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
48 git maintenance run --auto 2>/dev/null &&
49 GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
50 git maintenance run --no-quiet 2>/dev/null &&
51 test_subcommand git gc --quiet <run-no-auto.txt &&
52 test_subcommand ! git gc --auto --quiet <run-auto.txt &&
53 test_subcommand git gc --no-quiet <run-no-quiet.txt
56 test_expect_success 'maintenance.auto config option' '
57 GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
58 test_subcommand git maintenance run --auto --quiet <default &&
59 GIT_TRACE2_EVENT="$(pwd)/true" \
60 git -c maintenance.auto=true \
61 commit --quiet --allow-empty -m 2 &&
62 test_subcommand git maintenance run --auto --quiet <true &&
63 GIT_TRACE2_EVENT="$(pwd)/false" \
64 git -c maintenance.auto=false \
65 commit --quiet --allow-empty -m 3 &&
66 test_subcommand ! git maintenance run --auto --quiet <false
69 test_expect_success 'maintenance.<task>.enabled' '
70 git config maintenance.gc.enabled false &&
71 git config maintenance.commit-graph.enabled true &&
72 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
73 test_subcommand ! git gc --quiet <run-config.txt &&
74 test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
77 test_expect_success 'run --task=<task>' '
78 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
79 git maintenance run --task=commit-graph 2>/dev/null &&
80 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
81 git maintenance run --task=gc 2>/dev/null &&
82 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
83 git maintenance run --task=commit-graph 2>/dev/null &&
84 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
85 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
86 test_subcommand ! git gc --quiet <run-commit-graph.txt &&
87 test_subcommand git gc --quiet <run-gc.txt &&
88 test_subcommand git gc --quiet <run-both.txt &&
89 test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
90 test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
91 test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
94 test_expect_success 'core.commitGraph=false prevents write process' '
95 GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
96 git -c core.commitGraph=false maintenance run \
97 --task=commit-graph 2>/dev/null &&
98 test_subcommand ! git commit-graph write --split --reachable --no-progress \
99 <no-commit-graph.txt
102 test_expect_success 'commit-graph auto condition' '
103 COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
105 GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
106 git -c maintenance.commit-graph.auto=1 $COMMAND &&
107 GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
108 git -c maintenance.commit-graph.auto="-1" $COMMAND &&
110 test_commit first &&
112 GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
113 git -c maintenance.commit-graph.auto=0 $COMMAND &&
114 GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
115 git -c maintenance.commit-graph.auto=1 $COMMAND &&
117 git commit --allow-empty -m "second" &&
118 git commit --allow-empty -m "third" &&
120 GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
121 git -c maintenance.commit-graph.auto=2 $COMMAND &&
123 COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
124 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
125 test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
126 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
127 test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
128 test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
131 test_expect_success 'run --task=bogus' '
132 test_must_fail git maintenance run --task=bogus 2>err &&
133 test_i18ngrep "is not a valid task" err
136 test_expect_success 'run --task duplicate' '
137 test_must_fail git maintenance run --task=gc --task=gc 2>err &&
138 test_i18ngrep "cannot be selected multiple times" err
141 test_expect_success 'run --task=prefetch with no remotes' '
142 git maintenance run --task=prefetch 2>err &&
143 test_must_be_empty err
146 test_expect_success 'prefetch multiple remotes' '
147 git clone . clone1 &&
148 git clone . clone2 &&
149 git remote add remote1 "file://$(pwd)/clone1" &&
150 git remote add remote2 "file://$(pwd)/clone2" &&
151 git -C clone1 switch -c one &&
152 git -C clone2 switch -c two &&
153 test_commit -C clone1 one &&
154 test_commit -C clone2 two &&
155 GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
156 fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" &&
157 test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt &&
158 test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt &&
159 test_path_is_missing .git/refs/remotes &&
160 git log prefetch/remotes/remote1/one &&
161 git log prefetch/remotes/remote2/two &&
162 git fetch --all &&
163 test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one &&
164 test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two &&
166 test_cmp_config refs/prefetch/ log.excludedecoration &&
167 git log --oneline --decorate --all >log &&
168 ! grep "prefetch" log &&
170 test_when_finished git config --unset remote.remote1.skipFetchAll &&
171 git config remote.remote1.skipFetchAll true &&
172 GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null &&
173 test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt &&
174 test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt
177 test_expect_success 'prefetch and existing log.excludeDecoration values' '
178 git config --unset-all log.excludeDecoration &&
179 git config log.excludeDecoration refs/remotes/remote1/ &&
180 git maintenance run --task=prefetch &&
182 git config --get-all log.excludeDecoration >out &&
183 grep refs/remotes/remote1/ out &&
184 grep refs/prefetch/ out &&
186 git log --oneline --decorate --all >log &&
187 ! grep "prefetch" log &&
188 ! grep "remote1" log &&
189 grep "remote2" log &&
191 # a second run does not change the config
192 git maintenance run --task=prefetch &&
193 git log --oneline --decorate --all >log2 &&
194 test_cmp log log2
197 test_expect_success 'loose-objects task' '
198 # Repack everything so we know the state of the object dir
199 git repack -adk &&
201 # Hack to stop maintenance from running during "git commit"
202 echo in use >.git/objects/maintenance.lock &&
204 # Assuming that "git commit" creates at least one loose object
205 test_commit create-loose-object &&
206 rm .git/objects/maintenance.lock &&
208 ls .git/objects >obj-dir-before &&
209 test_file_not_empty obj-dir-before &&
210 ls .git/objects/pack/*.pack >packs-before &&
211 test_line_count = 1 packs-before &&
213 # The first run creates a pack-file
214 # but does not delete loose objects.
215 git maintenance run --task=loose-objects &&
216 ls .git/objects >obj-dir-between &&
217 test_cmp obj-dir-before obj-dir-between &&
218 ls .git/objects/pack/*.pack >packs-between &&
219 test_line_count = 2 packs-between &&
220 ls .git/objects/pack/loose-*.pack >loose-packs &&
221 test_line_count = 1 loose-packs &&
223 # The second run deletes loose objects
224 # but does not create a pack-file.
225 git maintenance run --task=loose-objects &&
226 ls .git/objects >obj-dir-after &&
227 cat >expect <<-\EOF &&
228 info
229 pack
231 test_cmp expect obj-dir-after &&
232 ls .git/objects/pack/*.pack >packs-after &&
233 test_cmp packs-between packs-after
236 test_expect_success 'maintenance.loose-objects.auto' '
237 git repack -adk &&
238 GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
239 git -c maintenance.loose-objects.auto=1 maintenance \
240 run --auto --task=loose-objects 2>/dev/null &&
241 test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
242 printf data-A | git hash-object -t blob --stdin -w &&
243 GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
244 git -c maintenance.loose-objects.auto=2 \
245 maintenance run --auto --task=loose-objects 2>/dev/null &&
246 test_subcommand ! git prune-packed --quiet <trace-loA &&
247 printf data-B | git hash-object -t blob --stdin -w &&
248 GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
249 git -c maintenance.loose-objects.auto=2 \
250 maintenance run --auto --task=loose-objects 2>/dev/null &&
251 test_subcommand git prune-packed --quiet <trace-loB &&
252 GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
253 git -c maintenance.loose-objects.auto=2 \
254 maintenance run --auto --task=loose-objects 2>/dev/null &&
255 test_subcommand git prune-packed --quiet <trace-loC
258 test_expect_success 'incremental-repack task' '
259 packDir=.git/objects/pack &&
260 for i in $(test_seq 1 5)
262 test_commit $i || return 1
263 done &&
265 # Create three disjoint pack-files with size BIG, small, small.
266 echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
267 test_tick &&
268 git pack-objects --revs $packDir/test-2 <<-\EOF &&
269 HEAD~1
270 ^HEAD~2
272 test_tick &&
273 git pack-objects --revs $packDir/test-3 <<-\EOF &&
274 HEAD
275 ^HEAD~1
278 # Delete refs that have not been repacked in these packs.
279 git for-each-ref --format="delete %(refname)" \
280 refs/prefetch refs/tags >refs &&
281 git update-ref --stdin <refs &&
283 # Replace the object directory with this pack layout.
284 rm -f $packDir/pack-* &&
285 rm -f $packDir/loose-* &&
286 ls $packDir/*.pack >packs-before &&
287 test_line_count = 3 packs-before &&
289 # the job repacks the two into a new pack, but does not
290 # delete the old ones.
291 git maintenance run --task=incremental-repack &&
292 ls $packDir/*.pack >packs-between &&
293 test_line_count = 4 packs-between &&
295 # the job deletes the two old packs, and does not write
296 # a new one because the batch size is not high enough to
297 # pack the largest pack-file.
298 git maintenance run --task=incremental-repack &&
299 ls .git/objects/pack/*.pack >packs-after &&
300 test_line_count = 2 packs-after
303 test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
304 test_config core.compression 0 &&
306 for i in $(test_seq 1 5)
308 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
309 return 1
310 done &&
311 git add big &&
312 git commit -qm "Add big file (1)" &&
314 # ensure any possible loose objects are in a pack-file
315 git maintenance run --task=loose-objects &&
317 rm big &&
318 for i in $(test_seq 6 10)
320 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
321 return 1
322 done &&
323 git add big &&
324 git commit -qm "Add big file (2)" &&
326 # ensure any possible loose objects are in a pack-file
327 git maintenance run --task=loose-objects &&
329 # Now run the incremental-repack task and check the batch-size
330 GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
331 --task=incremental-repack 2>/dev/null &&
332 test_subcommand git multi-pack-index repack \
333 --no-progress --batch-size=2147483647 <run-2g.txt
336 test_expect_success 'maintenance.incremental-repack.auto' '
337 git repack -adk &&
338 git config core.multiPackIndex true &&
339 git multi-pack-index write &&
340 GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
341 -c maintenance.incremental-repack.auto=1 \
342 maintenance run --auto --task=incremental-repack 2>/dev/null &&
343 test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
344 test_commit A &&
345 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
346 HEAD
347 ^HEAD~1
349 GIT_TRACE2_EVENT=$(pwd)/trace-A git \
350 -c maintenance.incremental-repack.auto=2 \
351 maintenance run --auto --task=incremental-repack 2>/dev/null &&
352 test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
353 test_commit B &&
354 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
355 HEAD
356 ^HEAD~1
358 GIT_TRACE2_EVENT=$(pwd)/trace-B git \
359 -c maintenance.incremental-repack.auto=2 \
360 maintenance run --auto --task=incremental-repack 2>/dev/null &&
361 test_subcommand git multi-pack-index write --no-progress <trace-B
364 test_expect_success 'pack-refs task' '
365 for n in $(test_seq 1 5)
367 git branch -f to-pack/$n HEAD || return 1
368 done &&
369 GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
370 git maintenance run --task=pack-refs &&
371 test_subcommand git pack-refs --all --prune <pack-refs.txt
374 test_expect_success '--auto and --schedule incompatible' '
375 test_must_fail git maintenance run --auto --schedule=daily 2>err &&
376 test_i18ngrep "at most one" err
379 test_expect_success 'invalid --schedule value' '
380 test_must_fail git maintenance run --schedule=annually 2>err &&
381 test_i18ngrep "unrecognized --schedule" err
384 test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
385 git config maintenance.loose-objects.enabled true &&
386 git config maintenance.loose-objects.schedule hourly &&
387 git config maintenance.commit-graph.enabled true &&
388 git config maintenance.commit-graph.schedule daily &&
389 git config maintenance.incremental-repack.enabled true &&
390 git config maintenance.incremental-repack.schedule weekly &&
392 GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
393 git maintenance run --schedule=hourly 2>/dev/null &&
394 test_subcommand git prune-packed --quiet <hourly.txt &&
395 test_subcommand ! git commit-graph write --split --reachable \
396 --no-progress <hourly.txt &&
397 test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
399 GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
400 git maintenance run --schedule=daily 2>/dev/null &&
401 test_subcommand git prune-packed --quiet <daily.txt &&
402 test_subcommand git commit-graph write --split --reachable \
403 --no-progress <daily.txt &&
404 test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
406 GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
407 git maintenance run --schedule=weekly 2>/dev/null &&
408 test_subcommand git prune-packed --quiet <weekly.txt &&
409 test_subcommand git commit-graph write --split --reachable \
410 --no-progress <weekly.txt &&
411 test_subcommand git multi-pack-index write --no-progress <weekly.txt
414 test_expect_success 'maintenance.strategy inheritance' '
415 for task in commit-graph loose-objects incremental-repack
417 git config --unset maintenance.$task.schedule || return 1
418 done &&
420 test_when_finished git config --unset maintenance.strategy &&
421 git config maintenance.strategy incremental &&
423 GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
424 git maintenance run --schedule=hourly --quiet &&
425 GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
426 git maintenance run --schedule=daily --quiet &&
427 GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
428 git maintenance run --schedule=weekly --quiet &&
430 test_subcommand git commit-graph write --split --reachable \
431 --no-progress <incremental-hourly.txt &&
432 test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
433 test_subcommand ! git multi-pack-index write --no-progress \
434 <incremental-hourly.txt &&
435 test_subcommand ! git pack-refs --all --prune \
436 <incremental-hourly.txt &&
438 test_subcommand git commit-graph write --split --reachable \
439 --no-progress <incremental-daily.txt &&
440 test_subcommand git prune-packed --quiet <incremental-daily.txt &&
441 test_subcommand git multi-pack-index write --no-progress \
442 <incremental-daily.txt &&
443 test_subcommand ! git pack-refs --all --prune \
444 <incremental-daily.txt &&
446 test_subcommand git commit-graph write --split --reachable \
447 --no-progress <incremental-weekly.txt &&
448 test_subcommand git prune-packed --quiet <incremental-weekly.txt &&
449 test_subcommand git multi-pack-index write --no-progress \
450 <incremental-weekly.txt &&
451 test_subcommand git pack-refs --all --prune \
452 <incremental-weekly.txt &&
454 # Modify defaults
455 git config maintenance.commit-graph.schedule daily &&
456 git config maintenance.loose-objects.schedule hourly &&
457 git config maintenance.incremental-repack.enabled false &&
459 GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
460 git maintenance run --schedule=hourly --quiet &&
461 GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
462 git maintenance run --schedule=daily --quiet &&
464 test_subcommand ! git commit-graph write --split --reachable \
465 --no-progress <modified-hourly.txt &&
466 test_subcommand git prune-packed --quiet <modified-hourly.txt &&
467 test_subcommand ! git multi-pack-index write --no-progress \
468 <modified-hourly.txt &&
470 test_subcommand git commit-graph write --split --reachable \
471 --no-progress <modified-daily.txt &&
472 test_subcommand git prune-packed --quiet <modified-daily.txt &&
473 test_subcommand ! git multi-pack-index write --no-progress \
474 <modified-daily.txt
477 test_expect_success 'register and unregister' '
478 test_when_finished git config --global --unset-all maintenance.repo &&
479 git config --global --add maintenance.repo /existing1 &&
480 git config --global --add maintenance.repo /existing2 &&
481 git config --global --get-all maintenance.repo >before &&
483 git maintenance register &&
484 test_cmp_config false maintenance.auto &&
485 git config --global --get-all maintenance.repo >between &&
486 cp before expect &&
487 pwd >>expect &&
488 test_cmp expect between &&
490 git maintenance unregister &&
491 git config --global --get-all maintenance.repo >actual &&
492 test_cmp before actual
495 test_expect_success !MINGW 'register and unregister with regex metacharacters' '
496 META="a+b*c" &&
497 git init "$META" &&
498 git -C "$META" maintenance register &&
499 git config --get-all --show-origin maintenance.repo &&
500 git config --get-all --global --fixed-value \
501 maintenance.repo "$(pwd)/$META" &&
502 git -C "$META" maintenance unregister &&
503 test_must_fail git config --get-all --global --fixed-value \
504 maintenance.repo "$(pwd)/$META"
507 test_expect_success 'start --scheduler=<scheduler>' '
508 test_expect_code 129 git maintenance start --scheduler=foo 2>err &&
509 test_i18ngrep "unrecognized --scheduler argument" err &&
511 test_expect_code 129 git maintenance start --no-scheduler 2>err &&
512 test_i18ngrep "unknown option" err &&
514 test_expect_code 128 \
515 env GIT_TEST_MAINT_SCHEDULER="launchctl:true,schtasks:true" \
516 git maintenance start --scheduler=crontab 2>err &&
517 test_i18ngrep "fatal: crontab scheduler is not available" err
520 test_expect_success 'start from empty cron table' '
521 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab &&
523 # start registers the repo
524 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
526 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt &&
527 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt &&
528 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt
531 test_expect_success 'stop from existing schedule' '
532 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
534 # stop does not unregister the repo
535 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
537 # Operation is idempotent
538 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
539 test_must_be_empty cron.txt
542 test_expect_success 'start preserves existing schedule' '
543 echo "Important information!" >cron.txt &&
544 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab &&
545 grep "Important information!" cron.txt
548 test_expect_success 'magic markers are correct' '
549 grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual &&
550 cat >expect <<-\EOF &&
551 # BEGIN GIT MAINTENANCE SCHEDULE
552 # END GIT MAINTENANCE SCHEDULE
554 test_cmp actual expect
557 test_expect_success 'stop preserves surrounding schedule' '
558 echo "Crucial information!" >>cron.txt &&
559 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
560 grep "Important information!" cron.txt &&
561 grep "Crucial information!" cron.txt
564 test_expect_success 'start and stop macOS maintenance' '
565 # ensure $HOME can be compared against hook arguments on all platforms
566 pfx=$(cd "$HOME" && pwd) &&
568 write_script print-args <<-\EOF &&
569 echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
572 rm -f args &&
573 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
575 # start registers the repo
576 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
578 ls "$HOME/Library/LaunchAgents" >actual &&
579 cat >expect <<-\EOF &&
580 org.git-scm.git.daily.plist
581 org.git-scm.git.hourly.plist
582 org.git-scm.git.weekly.plist
584 test_cmp expect actual &&
586 rm -f expect &&
587 for frequency in hourly daily weekly
589 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
590 test_xmllint "$PLIST" &&
591 grep schedule=$frequency "$PLIST" &&
592 echo "bootout gui/[UID] $PLIST" >>expect &&
593 echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
594 done &&
595 test_cmp expect args &&
597 rm -f args &&
598 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
600 # stop does not unregister the repo
601 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
603 printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
604 hourly daily weekly >expect &&
605 test_cmp expect args &&
606 ls "$HOME/Library/LaunchAgents" >actual &&
607 test_line_count = 0 actual
610 test_expect_success 'use launchctl list to prevent extra work' '
611 # ensure we are registered
612 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
614 # do it again on a fresh args file
615 rm -f args &&
616 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl &&
618 ls "$HOME/Library/LaunchAgents" >actual &&
619 cat >expect <<-\EOF &&
620 list org.git-scm.git.hourly
621 list org.git-scm.git.daily
622 list org.git-scm.git.weekly
624 test_cmp expect args
627 test_expect_success 'start and stop Windows maintenance' '
628 write_script print-args <<-\EOF &&
629 echo $* >>args
630 while test $# -gt 0
632 case "$1" in
633 /xml) shift; xmlfile=$1; break ;;
634 *) shift ;;
635 esac
636 done
637 test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
640 rm -f args &&
641 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start --scheduler=schtasks &&
643 # start registers the repo
644 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
646 for frequency in hourly daily weekly
648 grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
649 file=$(ls .git/schedule_${frequency}*.xml) &&
650 test_xmllint "$file" || return 1
651 done &&
653 rm -f args &&
654 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
656 # stop does not unregister the repo
657 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
659 printf "/delete /tn Git Maintenance (%s) /f\n" \
660 hourly daily weekly >expect &&
661 test_cmp expect args
664 test_expect_success 'start and stop Linux/systemd maintenance' '
665 write_script print-args <<-\EOF &&
666 printf "%s\n" "$*" >>args
669 XDG_CONFIG_HOME="$PWD" &&
670 export XDG_CONFIG_HOME &&
671 rm -f args &&
672 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance start --scheduler=systemd-timer &&
674 # start registers the repo
675 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
677 test_systemd_analyze_verify "systemd/user/git-maintenance@.service" &&
679 printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
680 test_cmp expect args &&
682 rm -f args &&
683 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance stop &&
685 # stop does not unregister the repo
686 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
688 test_path_is_missing "systemd/user/git-maintenance@.timer" &&
689 test_path_is_missing "systemd/user/git-maintenance@.service" &&
691 printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
692 test_cmp expect args
695 test_expect_success 'start and stop when several schedulers are available' '
696 write_script print-args <<-\EOF &&
697 printf "%s\n" "$*" | sed "s:gui/[0-9][0-9]*:gui/[UID]:; s:\(schtasks /create .* /xml\).*:\1:;" >>args
700 rm -f args &&
701 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=systemd-timer &&
702 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
703 hourly daily weekly >expect &&
704 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
705 hourly daily weekly >>expect &&
706 printf -- "systemctl --user enable --now git-maintenance@%s.timer\n" hourly daily weekly >>expect &&
707 test_cmp expect args &&
709 rm -f args &&
710 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=launchctl &&
711 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
712 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
713 hourly daily weekly >>expect &&
714 for frequency in hourly daily weekly
716 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
717 echo "launchctl bootout gui/[UID] $PLIST" >>expect &&
718 echo "launchctl bootstrap gui/[UID] $PLIST" >>expect || return 1
719 done &&
720 test_cmp expect args &&
722 rm -f args &&
723 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=schtasks &&
724 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
725 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
726 hourly daily weekly >>expect &&
727 printf "schtasks /create /tn Git Maintenance (%s) /f /xml\n" \
728 hourly daily weekly >>expect &&
729 test_cmp expect args &&
731 rm -f args &&
732 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance stop &&
733 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect &&
734 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
735 hourly daily weekly >>expect &&
736 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \
737 hourly daily weekly >>expect &&
738 test_cmp expect args
741 test_expect_success 'register preserves existing strategy' '
742 git config maintenance.strategy none &&
743 git maintenance register &&
744 test_config maintenance.strategy none &&
745 git config --unset maintenance.strategy &&
746 git maintenance register &&
747 test_config maintenance.strategy incremental
750 test_expect_success 'fails when running outside of a repository' '
751 nongit test_must_fail git maintenance run &&
752 nongit test_must_fail git maintenance stop &&
753 nongit test_must_fail git maintenance start &&
754 nongit test_must_fail git maintenance register &&
755 nongit test_must_fail git maintenance unregister
758 test_expect_success 'register and unregister bare repo' '
759 test_when_finished "git config --global --unset-all maintenance.repo || :" &&
760 test_might_fail git config --global --unset-all maintenance.repo &&
761 git init --bare barerepo &&
763 cd barerepo &&
764 git maintenance register &&
765 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
766 git maintenance unregister &&
767 test_must_fail git config --global --get-all maintenance.repo
771 test_done