ci: use upload-artifacts v1 for dockerized jobs
[git/debian.git] / t / t7900-maintenance.sh
blob58f46c77e66604020b15806453719374cfddd18e
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_expect_success 'help text' '
24 test_expect_code 129 git maintenance -h 2>err &&
25 test_i18ngrep "usage: git maintenance <subcommand>" err &&
26 test_expect_code 128 git maintenance barf 2>err &&
27 test_i18ngrep "invalid subcommand: barf" err &&
28 test_expect_code 129 git maintenance 2>err &&
29 test_i18ngrep "usage: git maintenance" err
32 test_expect_success 'run [--auto|--quiet]' '
33 GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
34 git maintenance run 2>/dev/null &&
35 GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
36 git maintenance run --auto 2>/dev/null &&
37 GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
38 git maintenance run --no-quiet 2>/dev/null &&
39 test_subcommand git gc --quiet <run-no-auto.txt &&
40 test_subcommand ! git gc --auto --quiet <run-auto.txt &&
41 test_subcommand git gc --no-quiet <run-no-quiet.txt
44 test_expect_success 'maintenance.auto config option' '
45 GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
46 test_subcommand git maintenance run --auto --quiet <default &&
47 GIT_TRACE2_EVENT="$(pwd)/true" \
48 git -c maintenance.auto=true \
49 commit --quiet --allow-empty -m 2 &&
50 test_subcommand git maintenance run --auto --quiet <true &&
51 GIT_TRACE2_EVENT="$(pwd)/false" \
52 git -c maintenance.auto=false \
53 commit --quiet --allow-empty -m 3 &&
54 test_subcommand ! git maintenance run --auto --quiet <false
57 test_expect_success 'maintenance.<task>.enabled' '
58 git config maintenance.gc.enabled false &&
59 git config maintenance.commit-graph.enabled true &&
60 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
61 test_subcommand ! git gc --quiet <run-config.txt &&
62 test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
65 test_expect_success 'run --task=<task>' '
66 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
67 git maintenance run --task=commit-graph 2>/dev/null &&
68 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
69 git maintenance run --task=gc 2>/dev/null &&
70 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
71 git maintenance run --task=commit-graph 2>/dev/null &&
72 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
73 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
74 test_subcommand ! git gc --quiet <run-commit-graph.txt &&
75 test_subcommand git gc --quiet <run-gc.txt &&
76 test_subcommand git gc --quiet <run-both.txt &&
77 test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
78 test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
79 test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
82 test_expect_success 'core.commitGraph=false prevents write process' '
83 GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
84 git -c core.commitGraph=false maintenance run \
85 --task=commit-graph 2>/dev/null &&
86 test_subcommand ! git commit-graph write --split --reachable --no-progress \
87 <no-commit-graph.txt
90 test_expect_success 'commit-graph auto condition' '
91 COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
93 GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
94 git -c maintenance.commit-graph.auto=1 $COMMAND &&
95 GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
96 git -c maintenance.commit-graph.auto="-1" $COMMAND &&
98 test_commit first &&
100 GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
101 git -c maintenance.commit-graph.auto=0 $COMMAND &&
102 GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
103 git -c maintenance.commit-graph.auto=1 $COMMAND &&
105 git commit --allow-empty -m "second" &&
106 git commit --allow-empty -m "third" &&
108 GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
109 git -c maintenance.commit-graph.auto=2 $COMMAND &&
111 COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
112 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
113 test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
114 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
115 test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
116 test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
119 test_expect_success 'run --task=bogus' '
120 test_must_fail git maintenance run --task=bogus 2>err &&
121 test_i18ngrep "is not a valid task" err
124 test_expect_success 'run --task duplicate' '
125 test_must_fail git maintenance run --task=gc --task=gc 2>err &&
126 test_i18ngrep "cannot be selected multiple times" err
129 test_expect_success 'run --task=prefetch with no remotes' '
130 git maintenance run --task=prefetch 2>err &&
131 test_must_be_empty err
134 test_expect_success 'prefetch multiple remotes' '
135 git clone . clone1 &&
136 git clone . clone2 &&
137 git remote add remote1 "file://$(pwd)/clone1" &&
138 git remote add remote2 "file://$(pwd)/clone2" &&
139 git -C clone1 switch -c one &&
140 git -C clone2 switch -c two &&
141 test_commit -C clone1 one &&
142 test_commit -C clone2 two &&
143 GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
144 fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" &&
145 test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt &&
146 test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt &&
147 test_path_is_missing .git/refs/remotes &&
148 git log prefetch/remotes/remote1/one &&
149 git log prefetch/remotes/remote2/two &&
150 git fetch --all &&
151 test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one &&
152 test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two &&
154 test_cmp_config refs/prefetch/ log.excludedecoration &&
155 git log --oneline --decorate --all >log &&
156 ! grep "prefetch" log &&
158 test_when_finished git config --unset remote.remote1.skipFetchAll &&
159 git config remote.remote1.skipFetchAll true &&
160 GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null &&
161 test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt &&
162 test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt
165 test_expect_success 'prefetch and existing log.excludeDecoration values' '
166 git config --unset-all log.excludeDecoration &&
167 git config log.excludeDecoration refs/remotes/remote1/ &&
168 git maintenance run --task=prefetch &&
170 git config --get-all log.excludeDecoration >out &&
171 grep refs/remotes/remote1/ out &&
172 grep refs/prefetch/ out &&
174 git log --oneline --decorate --all >log &&
175 ! grep "prefetch" log &&
176 ! grep "remote1" log &&
177 grep "remote2" log &&
179 # a second run does not change the config
180 git maintenance run --task=prefetch &&
181 git log --oneline --decorate --all >log2 &&
182 test_cmp log log2
185 test_expect_success 'loose-objects task' '
186 # Repack everything so we know the state of the object dir
187 git repack -adk &&
189 # Hack to stop maintenance from running during "git commit"
190 echo in use >.git/objects/maintenance.lock &&
192 # Assuming that "git commit" creates at least one loose object
193 test_commit create-loose-object &&
194 rm .git/objects/maintenance.lock &&
196 ls .git/objects >obj-dir-before &&
197 test_file_not_empty obj-dir-before &&
198 ls .git/objects/pack/*.pack >packs-before &&
199 test_line_count = 1 packs-before &&
201 # The first run creates a pack-file
202 # but does not delete loose objects.
203 git maintenance run --task=loose-objects &&
204 ls .git/objects >obj-dir-between &&
205 test_cmp obj-dir-before obj-dir-between &&
206 ls .git/objects/pack/*.pack >packs-between &&
207 test_line_count = 2 packs-between &&
208 ls .git/objects/pack/loose-*.pack >loose-packs &&
209 test_line_count = 1 loose-packs &&
211 # The second run deletes loose objects
212 # but does not create a pack-file.
213 git maintenance run --task=loose-objects &&
214 ls .git/objects >obj-dir-after &&
215 cat >expect <<-\EOF &&
216 info
217 pack
219 test_cmp expect obj-dir-after &&
220 ls .git/objects/pack/*.pack >packs-after &&
221 test_cmp packs-between packs-after
224 test_expect_success 'maintenance.loose-objects.auto' '
225 git repack -adk &&
226 GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
227 git -c maintenance.loose-objects.auto=1 maintenance \
228 run --auto --task=loose-objects 2>/dev/null &&
229 test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
230 printf data-A | git hash-object -t blob --stdin -w &&
231 GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
232 git -c maintenance.loose-objects.auto=2 \
233 maintenance run --auto --task=loose-objects 2>/dev/null &&
234 test_subcommand ! git prune-packed --quiet <trace-loA &&
235 printf data-B | git hash-object -t blob --stdin -w &&
236 GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
237 git -c maintenance.loose-objects.auto=2 \
238 maintenance run --auto --task=loose-objects 2>/dev/null &&
239 test_subcommand git prune-packed --quiet <trace-loB &&
240 GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
241 git -c maintenance.loose-objects.auto=2 \
242 maintenance run --auto --task=loose-objects 2>/dev/null &&
243 test_subcommand git prune-packed --quiet <trace-loC
246 test_expect_success 'incremental-repack task' '
247 packDir=.git/objects/pack &&
248 for i in $(test_seq 1 5)
250 test_commit $i || return 1
251 done &&
253 # Create three disjoint pack-files with size BIG, small, small.
254 echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
255 test_tick &&
256 git pack-objects --revs $packDir/test-2 <<-\EOF &&
257 HEAD~1
258 ^HEAD~2
260 test_tick &&
261 git pack-objects --revs $packDir/test-3 <<-\EOF &&
262 HEAD
263 ^HEAD~1
266 # Delete refs that have not been repacked in these packs.
267 git for-each-ref --format="delete %(refname)" \
268 refs/prefetch refs/tags >refs &&
269 git update-ref --stdin <refs &&
271 # Replace the object directory with this pack layout.
272 rm -f $packDir/pack-* &&
273 rm -f $packDir/loose-* &&
274 ls $packDir/*.pack >packs-before &&
275 test_line_count = 3 packs-before &&
277 # the job repacks the two into a new pack, but does not
278 # delete the old ones.
279 git maintenance run --task=incremental-repack &&
280 ls $packDir/*.pack >packs-between &&
281 test_line_count = 4 packs-between &&
283 # the job deletes the two old packs, and does not write
284 # a new one because the batch size is not high enough to
285 # pack the largest pack-file.
286 git maintenance run --task=incremental-repack &&
287 ls .git/objects/pack/*.pack >packs-after &&
288 test_line_count = 2 packs-after
291 test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
292 test_config core.compression 0 &&
294 for i in $(test_seq 1 5)
296 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
297 return 1
298 done &&
299 git add big &&
300 git commit -qm "Add big file (1)" &&
302 # ensure any possible loose objects are in a pack-file
303 git maintenance run --task=loose-objects &&
305 rm big &&
306 for i in $(test_seq 6 10)
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 (2)" &&
314 # ensure any possible loose objects are in a pack-file
315 git maintenance run --task=loose-objects &&
317 # Now run the incremental-repack task and check the batch-size
318 GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
319 --task=incremental-repack 2>/dev/null &&
320 test_subcommand git multi-pack-index repack \
321 --no-progress --batch-size=2147483647 <run-2g.txt
324 test_expect_success 'maintenance.incremental-repack.auto' '
325 git repack -adk &&
326 git config core.multiPackIndex true &&
327 git multi-pack-index write &&
328 GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
329 -c maintenance.incremental-repack.auto=1 \
330 maintenance run --auto --task=incremental-repack 2>/dev/null &&
331 test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
332 test_commit A &&
333 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
334 HEAD
335 ^HEAD~1
337 GIT_TRACE2_EVENT=$(pwd)/trace-A git \
338 -c maintenance.incremental-repack.auto=2 \
339 maintenance run --auto --task=incremental-repack 2>/dev/null &&
340 test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
341 test_commit B &&
342 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
343 HEAD
344 ^HEAD~1
346 GIT_TRACE2_EVENT=$(pwd)/trace-B git \
347 -c maintenance.incremental-repack.auto=2 \
348 maintenance run --auto --task=incremental-repack 2>/dev/null &&
349 test_subcommand git multi-pack-index write --no-progress <trace-B
352 test_expect_success 'pack-refs task' '
353 for n in $(test_seq 1 5)
355 git branch -f to-pack/$n HEAD || return 1
356 done &&
357 GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
358 git maintenance run --task=pack-refs &&
359 test_subcommand git pack-refs --all --prune <pack-refs.txt
362 test_expect_success '--auto and --schedule incompatible' '
363 test_must_fail git maintenance run --auto --schedule=daily 2>err &&
364 test_i18ngrep "at most one" err
367 test_expect_success 'invalid --schedule value' '
368 test_must_fail git maintenance run --schedule=annually 2>err &&
369 test_i18ngrep "unrecognized --schedule" err
372 test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
373 git config maintenance.loose-objects.enabled true &&
374 git config maintenance.loose-objects.schedule hourly &&
375 git config maintenance.commit-graph.enabled true &&
376 git config maintenance.commit-graph.schedule daily &&
377 git config maintenance.incremental-repack.enabled true &&
378 git config maintenance.incremental-repack.schedule weekly &&
380 GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
381 git maintenance run --schedule=hourly 2>/dev/null &&
382 test_subcommand git prune-packed --quiet <hourly.txt &&
383 test_subcommand ! git commit-graph write --split --reachable \
384 --no-progress <hourly.txt &&
385 test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
387 GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
388 git maintenance run --schedule=daily 2>/dev/null &&
389 test_subcommand git prune-packed --quiet <daily.txt &&
390 test_subcommand git commit-graph write --split --reachable \
391 --no-progress <daily.txt &&
392 test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
394 GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
395 git maintenance run --schedule=weekly 2>/dev/null &&
396 test_subcommand git prune-packed --quiet <weekly.txt &&
397 test_subcommand git commit-graph write --split --reachable \
398 --no-progress <weekly.txt &&
399 test_subcommand git multi-pack-index write --no-progress <weekly.txt
402 test_expect_success 'maintenance.strategy inheritance' '
403 for task in commit-graph loose-objects incremental-repack
405 git config --unset maintenance.$task.schedule || return 1
406 done &&
408 test_when_finished git config --unset maintenance.strategy &&
409 git config maintenance.strategy incremental &&
411 GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
412 git maintenance run --schedule=hourly --quiet &&
413 GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
414 git maintenance run --schedule=daily --quiet &&
415 GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
416 git maintenance run --schedule=weekly --quiet &&
418 test_subcommand git commit-graph write --split --reachable \
419 --no-progress <incremental-hourly.txt &&
420 test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
421 test_subcommand ! git multi-pack-index write --no-progress \
422 <incremental-hourly.txt &&
423 test_subcommand ! git pack-refs --all --prune \
424 <incremental-hourly.txt &&
426 test_subcommand git commit-graph write --split --reachable \
427 --no-progress <incremental-daily.txt &&
428 test_subcommand git prune-packed --quiet <incremental-daily.txt &&
429 test_subcommand git multi-pack-index write --no-progress \
430 <incremental-daily.txt &&
431 test_subcommand ! git pack-refs --all --prune \
432 <incremental-daily.txt &&
434 test_subcommand git commit-graph write --split --reachable \
435 --no-progress <incremental-weekly.txt &&
436 test_subcommand git prune-packed --quiet <incremental-weekly.txt &&
437 test_subcommand git multi-pack-index write --no-progress \
438 <incremental-weekly.txt &&
439 test_subcommand git pack-refs --all --prune \
440 <incremental-weekly.txt &&
442 # Modify defaults
443 git config maintenance.commit-graph.schedule daily &&
444 git config maintenance.loose-objects.schedule hourly &&
445 git config maintenance.incremental-repack.enabled false &&
447 GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
448 git maintenance run --schedule=hourly --quiet &&
449 GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
450 git maintenance run --schedule=daily --quiet &&
452 test_subcommand ! git commit-graph write --split --reachable \
453 --no-progress <modified-hourly.txt &&
454 test_subcommand git prune-packed --quiet <modified-hourly.txt &&
455 test_subcommand ! git multi-pack-index write --no-progress \
456 <modified-hourly.txt &&
458 test_subcommand git commit-graph write --split --reachable \
459 --no-progress <modified-daily.txt &&
460 test_subcommand git prune-packed --quiet <modified-daily.txt &&
461 test_subcommand ! git multi-pack-index write --no-progress \
462 <modified-daily.txt
465 test_expect_success 'register and unregister' '
466 test_when_finished git config --global --unset-all maintenance.repo &&
467 git config --global --add maintenance.repo /existing1 &&
468 git config --global --add maintenance.repo /existing2 &&
469 git config --global --get-all maintenance.repo >before &&
471 git maintenance register &&
472 test_cmp_config false maintenance.auto &&
473 git config --global --get-all maintenance.repo >between &&
474 cp before expect &&
475 pwd >>expect &&
476 test_cmp expect between &&
478 git maintenance unregister &&
479 git config --global --get-all maintenance.repo >actual &&
480 test_cmp before actual
483 test_expect_success !MINGW 'register and unregister with regex metacharacters' '
484 META="a+b*c" &&
485 git init "$META" &&
486 git -C "$META" maintenance register &&
487 git config --get-all --show-origin maintenance.repo &&
488 git config --get-all --global --fixed-value \
489 maintenance.repo "$(pwd)/$META" &&
490 git -C "$META" maintenance unregister &&
491 test_must_fail git config --get-all --global --fixed-value \
492 maintenance.repo "$(pwd)/$META"
495 test_expect_success 'start from empty cron table' '
496 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
498 # start registers the repo
499 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
501 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt &&
502 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt &&
503 grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt
506 test_expect_success 'stop from existing schedule' '
507 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
509 # stop does not unregister the repo
510 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
512 # Operation is idempotent
513 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
514 test_must_be_empty cron.txt
517 test_expect_success 'start preserves existing schedule' '
518 echo "Important information!" >cron.txt &&
519 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
520 grep "Important information!" cron.txt
523 test_expect_success 'magic markers are correct' '
524 grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual &&
525 cat >expect <<-\EOF &&
526 # BEGIN GIT MAINTENANCE SCHEDULE
527 # END GIT MAINTENANCE SCHEDULE
529 test_cmp actual expect
532 test_expect_success 'stop preserves surrounding schedule' '
533 echo "Crucial information!" >>cron.txt &&
534 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
535 grep "Important information!" cron.txt &&
536 grep "Crucial information!" cron.txt
539 test_expect_success 'start and stop macOS maintenance' '
540 # ensure $HOME can be compared against hook arguments on all platforms
541 pfx=$(cd "$HOME" && pwd) &&
543 write_script print-args <<-\EOF &&
544 echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
547 rm -f args &&
548 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start &&
550 # start registers the repo
551 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
553 ls "$HOME/Library/LaunchAgents" >actual &&
554 cat >expect <<-\EOF &&
555 org.git-scm.git.daily.plist
556 org.git-scm.git.hourly.plist
557 org.git-scm.git.weekly.plist
559 test_cmp expect actual &&
561 rm -f expect &&
562 for frequency in hourly daily weekly
564 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
565 test_xmllint "$PLIST" &&
566 grep schedule=$frequency "$PLIST" &&
567 echo "bootout gui/[UID] $PLIST" >>expect &&
568 echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
569 done &&
570 test_cmp expect args &&
572 rm -f args &&
573 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
575 # stop does not unregister the repo
576 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
578 printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
579 hourly daily weekly >expect &&
580 test_cmp expect args &&
581 ls "$HOME/Library/LaunchAgents" >actual &&
582 test_line_count = 0 actual
585 test_expect_success 'start and stop Windows maintenance' '
586 write_script print-args <<-\EOF &&
587 echo $* >>args
588 while test $# -gt 0
590 case "$1" in
591 /xml) shift; xmlfile=$1; break ;;
592 *) shift ;;
593 esac
594 done
595 test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
598 rm -f args &&
599 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start &&
601 # start registers the repo
602 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
604 for frequency in hourly daily weekly
606 grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
607 file=$(ls .git/schedule_${frequency}*.xml) &&
608 test_xmllint "$file" || return 1
609 done &&
611 rm -f args &&
612 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
614 # stop does not unregister the repo
615 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
617 printf "/delete /tn Git Maintenance (%s) /f\n" \
618 hourly daily weekly >expect &&
619 test_cmp expect args
622 test_expect_success 'register preserves existing strategy' '
623 git config maintenance.strategy none &&
624 git maintenance register &&
625 test_config maintenance.strategy none &&
626 git config --unset maintenance.strategy &&
627 git maintenance register &&
628 test_config maintenance.strategy incremental
631 test_expect_success 'fails when running outside of a repository' '
632 nongit test_must_fail git maintenance run &&
633 nongit test_must_fail git maintenance stop &&
634 nongit test_must_fail git maintenance start &&
635 nongit test_must_fail git maintenance register &&
636 nongit test_must_fail git maintenance unregister
639 test_expect_success 'register and unregister bare repo' '
640 test_when_finished "git config --global --unset-all maintenance.repo || :" &&
641 test_might_fail git config --global --unset-all maintenance.repo &&
642 git init --bare barerepo &&
644 cd barerepo &&
645 git maintenance register &&
646 git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
647 git maintenance unregister &&
648 test_must_fail git config --global --get-all maintenance.repo
652 test_done