Merge branch 'pb/mergetool-tool-help-fix'
[git] / t / t7900-maintenance.sh
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_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
30 '
31
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
42 '
43
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
55 '
56
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
63 '
64
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
80 '
81
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
88 '
89
90 test_expect_success 'commit-graph auto condition' '
91         COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
92
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 &&
97
98         test_commit first &&
99
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 &&
104
105         git commit --allow-empty -m "second" &&
106         git commit --allow-empty -m "third" &&
107
108         GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
109                 git -c maintenance.commit-graph.auto=2 $COMMAND &&
110
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
117 '
118
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
122 '
123
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
127 '
128
129 test_expect_success 'run --task=prefetch with no remotes' '
130         git maintenance run --task=prefetch 2>err &&
131         test_must_be_empty err
132 '
133
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="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" &&
145         test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* <run-prefetch.txt &&
146         test_subcommand git fetch remote2 $fetchargs +refs/heads/\\*:refs/prefetch/remote2/\\* <run-prefetch.txt &&
147         test_path_is_missing .git/refs/remotes &&
148         git log prefetch/remote1/one &&
149         git log prefetch/remote2/two &&
150         git fetch --all &&
151         test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one &&
152         test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two
153 '
154
155 test_expect_success 'loose-objects task' '
156         # Repack everything so we know the state of the object dir
157         git repack -adk &&
158
159         # Hack to stop maintenance from running during "git commit"
160         echo in use >.git/objects/maintenance.lock &&
161
162         # Assuming that "git commit" creates at least one loose object
163         test_commit create-loose-object &&
164         rm .git/objects/maintenance.lock &&
165
166         ls .git/objects >obj-dir-before &&
167         test_file_not_empty obj-dir-before &&
168         ls .git/objects/pack/*.pack >packs-before &&
169         test_line_count = 1 packs-before &&
170
171         # The first run creates a pack-file
172         # but does not delete loose objects.
173         git maintenance run --task=loose-objects &&
174         ls .git/objects >obj-dir-between &&
175         test_cmp obj-dir-before obj-dir-between &&
176         ls .git/objects/pack/*.pack >packs-between &&
177         test_line_count = 2 packs-between &&
178         ls .git/objects/pack/loose-*.pack >loose-packs &&
179         test_line_count = 1 loose-packs &&
180
181         # The second run deletes loose objects
182         # but does not create a pack-file.
183         git maintenance run --task=loose-objects &&
184         ls .git/objects >obj-dir-after &&
185         cat >expect <<-\EOF &&
186         info
187         pack
188         EOF
189         test_cmp expect obj-dir-after &&
190         ls .git/objects/pack/*.pack >packs-after &&
191         test_cmp packs-between packs-after
192 '
193
194 test_expect_success 'maintenance.loose-objects.auto' '
195         git repack -adk &&
196         GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
197                 git -c maintenance.loose-objects.auto=1 maintenance \
198                 run --auto --task=loose-objects 2>/dev/null &&
199         test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
200         printf data-A | git hash-object -t blob --stdin -w &&
201         GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
202                 git -c maintenance.loose-objects.auto=2 \
203                 maintenance run --auto --task=loose-objects 2>/dev/null &&
204         test_subcommand ! git prune-packed --quiet <trace-loA &&
205         printf data-B | git hash-object -t blob --stdin -w &&
206         GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
207                 git -c maintenance.loose-objects.auto=2 \
208                 maintenance run --auto --task=loose-objects 2>/dev/null &&
209         test_subcommand git prune-packed --quiet <trace-loB &&
210         GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
211                 git -c maintenance.loose-objects.auto=2 \
212                 maintenance run --auto --task=loose-objects 2>/dev/null &&
213         test_subcommand git prune-packed --quiet <trace-loC
214 '
215
216 test_expect_success 'incremental-repack task' '
217         packDir=.git/objects/pack &&
218         for i in $(test_seq 1 5)
219         do
220                 test_commit $i || return 1
221         done &&
222
223         # Create three disjoint pack-files with size BIG, small, small.
224         echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
225         test_tick &&
226         git pack-objects --revs $packDir/test-2 <<-\EOF &&
227         HEAD~1
228         ^HEAD~2
229         EOF
230         test_tick &&
231         git pack-objects --revs $packDir/test-3 <<-\EOF &&
232         HEAD
233         ^HEAD~1
234         EOF
235         rm -f $packDir/pack-* &&
236         rm -f $packDir/loose-* &&
237         ls $packDir/*.pack >packs-before &&
238         test_line_count = 3 packs-before &&
239
240         # the job repacks the two into a new pack, but does not
241         # delete the old ones.
242         git maintenance run --task=incremental-repack &&
243         ls $packDir/*.pack >packs-between &&
244         test_line_count = 4 packs-between &&
245
246         # the job deletes the two old packs, and does not write
247         # a new one because the batch size is not high enough to
248         # pack the largest pack-file.
249         git maintenance run --task=incremental-repack &&
250         ls .git/objects/pack/*.pack >packs-after &&
251         test_line_count = 2 packs-after
252 '
253
254 test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
255         test_config core.compression 0 &&
256
257         for i in $(test_seq 1 5)
258         do
259                 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
260                 return 1
261         done &&
262         git add big &&
263         git commit -qm "Add big file (1)" &&
264
265         # ensure any possible loose objects are in a pack-file
266         git maintenance run --task=loose-objects &&
267
268         rm big &&
269         for i in $(test_seq 6 10)
270         do
271                 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
272                 return 1
273         done &&
274         git add big &&
275         git commit -qm "Add big file (2)" &&
276
277         # ensure any possible loose objects are in a pack-file
278         git maintenance run --task=loose-objects &&
279
280         # Now run the incremental-repack task and check the batch-size
281         GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
282                 --task=incremental-repack 2>/dev/null &&
283         test_subcommand git multi-pack-index repack \
284                  --no-progress --batch-size=2147483647 <run-2g.txt
285 '
286
287 test_expect_success 'maintenance.incremental-repack.auto' '
288         git repack -adk &&
289         git config core.multiPackIndex true &&
290         git multi-pack-index write &&
291         GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
292                 -c maintenance.incremental-repack.auto=1 \
293                 maintenance run --auto --task=incremental-repack 2>/dev/null &&
294         test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
295         test_commit A &&
296         git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
297         HEAD
298         ^HEAD~1
299         EOF
300         GIT_TRACE2_EVENT=$(pwd)/trace-A git \
301                 -c maintenance.incremental-repack.auto=2 \
302                 maintenance run --auto --task=incremental-repack 2>/dev/null &&
303         test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
304         test_commit B &&
305         git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
306         HEAD
307         ^HEAD~1
308         EOF
309         GIT_TRACE2_EVENT=$(pwd)/trace-B git \
310                 -c maintenance.incremental-repack.auto=2 \
311                 maintenance run --auto --task=incremental-repack 2>/dev/null &&
312         test_subcommand git multi-pack-index write --no-progress <trace-B
313 '
314
315 test_expect_success '--auto and --schedule incompatible' '
316         test_must_fail git maintenance run --auto --schedule=daily 2>err &&
317         test_i18ngrep "at most one" err
318 '
319
320 test_expect_success 'invalid --schedule value' '
321         test_must_fail git maintenance run --schedule=annually 2>err &&
322         test_i18ngrep "unrecognized --schedule" err
323 '
324
325 test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
326         git config maintenance.loose-objects.enabled true &&
327         git config maintenance.loose-objects.schedule hourly &&
328         git config maintenance.commit-graph.enabled true &&
329         git config maintenance.commit-graph.schedule daily &&
330         git config maintenance.incremental-repack.enabled true &&
331         git config maintenance.incremental-repack.schedule weekly &&
332
333         GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
334                 git maintenance run --schedule=hourly 2>/dev/null &&
335         test_subcommand git prune-packed --quiet <hourly.txt &&
336         test_subcommand ! git commit-graph write --split --reachable \
337                 --no-progress <hourly.txt &&
338         test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
339
340         GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
341                 git maintenance run --schedule=daily 2>/dev/null &&
342         test_subcommand git prune-packed --quiet <daily.txt &&
343         test_subcommand git commit-graph write --split --reachable \
344                 --no-progress <daily.txt &&
345         test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
346
347         GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
348                 git maintenance run --schedule=weekly 2>/dev/null &&
349         test_subcommand git prune-packed --quiet <weekly.txt &&
350         test_subcommand git commit-graph write --split --reachable \
351                 --no-progress <weekly.txt &&
352         test_subcommand git multi-pack-index write --no-progress <weekly.txt
353 '
354
355 test_expect_success 'maintenance.strategy inheritance' '
356         for task in commit-graph loose-objects incremental-repack
357         do
358                 git config --unset maintenance.$task.schedule || return 1
359         done &&
360
361         test_when_finished git config --unset maintenance.strategy &&
362         git config maintenance.strategy incremental &&
363
364         GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \
365                 git maintenance run --schedule=hourly --quiet &&
366         GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \
367                 git maintenance run --schedule=daily --quiet &&
368
369         test_subcommand git commit-graph write --split --reachable \
370                 --no-progress <incremental-hourly.txt &&
371         test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
372         test_subcommand ! git multi-pack-index write --no-progress \
373                 <incremental-hourly.txt &&
374
375         test_subcommand git commit-graph write --split --reachable \
376                 --no-progress <incremental-daily.txt &&
377         test_subcommand git prune-packed --quiet <incremental-daily.txt &&
378         test_subcommand git multi-pack-index write --no-progress \
379                 <incremental-daily.txt &&
380
381         # Modify defaults
382         git config maintenance.commit-graph.schedule daily &&
383         git config maintenance.loose-objects.schedule hourly &&
384         git config maintenance.incremental-repack.enabled false &&
385
386         GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \
387                 git maintenance run --schedule=hourly --quiet &&
388         GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
389                 git maintenance run --schedule=daily --quiet &&
390
391         test_subcommand ! git commit-graph write --split --reachable \
392                 --no-progress <modified-hourly.txt &&
393         test_subcommand git prune-packed --quiet <modified-hourly.txt &&
394         test_subcommand ! git multi-pack-index write --no-progress \
395                 <modified-hourly.txt &&
396
397         test_subcommand git commit-graph write --split --reachable \
398                 --no-progress <modified-daily.txt &&
399         test_subcommand git prune-packed --quiet <modified-daily.txt &&
400         test_subcommand ! git multi-pack-index write --no-progress \
401                 <modified-daily.txt
402 '
403
404 test_expect_success 'register and unregister' '
405         test_when_finished git config --global --unset-all maintenance.repo &&
406         git config --global --add maintenance.repo /existing1 &&
407         git config --global --add maintenance.repo /existing2 &&
408         git config --global --get-all maintenance.repo >before &&
409
410         git maintenance register &&
411         test_cmp_config false maintenance.auto &&
412         git config --global --get-all maintenance.repo >between &&
413         cp before expect &&
414         pwd >>expect &&
415         test_cmp expect between &&
416
417         git maintenance unregister &&
418         git config --global --get-all maintenance.repo >actual &&
419         test_cmp before actual
420 '
421
422 test_expect_success !MINGW 'register and unregister with regex metacharacters' '
423         META="a+b*c" &&
424         git init "$META" &&
425         git -C "$META" maintenance register &&
426         git config --get-all --show-origin maintenance.repo &&
427         git config --get-all --global --fixed-value \
428                 maintenance.repo "$(pwd)/$META" &&
429         git -C "$META" maintenance unregister &&
430         test_must_fail git config --get-all --global --fixed-value \
431                 maintenance.repo "$(pwd)/$META"
432 '
433
434 test_expect_success 'start from empty cron table' '
435         GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
436
437         # start registers the repo
438         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
439
440         grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt &&
441         grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt &&
442         grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt
443 '
444
445 test_expect_success 'stop from existing schedule' '
446         GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
447
448         # stop does not unregister the repo
449         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
450
451         # Operation is idempotent
452         GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
453         test_must_be_empty cron.txt
454 '
455
456 test_expect_success 'start preserves existing schedule' '
457         echo "Important information!" >cron.txt &&
458         GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
459         grep "Important information!" cron.txt
460 '
461
462 test_expect_success 'magic markers are correct' '
463         grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual &&
464         cat >expect <<-\EOF &&
465         # BEGIN GIT MAINTENANCE SCHEDULE
466         # END GIT MAINTENANCE SCHEDULE
467         EOF
468         test_cmp actual expect
469 '
470
471 test_expect_success 'stop preserves surrounding schedule' '
472         echo "Crucial information!" >>cron.txt &&
473         GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
474         grep "Important information!" cron.txt &&
475         grep "Crucial information!" cron.txt
476 '
477
478 test_expect_success 'start and stop macOS maintenance' '
479         # ensure $HOME can be compared against hook arguments on all platforms
480         pfx=$(cd "$HOME" && pwd) &&
481
482         write_script print-args <<-\EOF &&
483         echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
484         EOF
485
486         rm -f args &&
487         GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start &&
488
489         # start registers the repo
490         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
491
492         ls "$HOME/Library/LaunchAgents" >actual &&
493         cat >expect <<-\EOF &&
494         org.git-scm.git.daily.plist
495         org.git-scm.git.hourly.plist
496         org.git-scm.git.weekly.plist
497         EOF
498         test_cmp expect actual &&
499
500         rm -f expect &&
501         for frequency in hourly daily weekly
502         do
503                 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
504                 test_xmllint "$PLIST" &&
505                 grep schedule=$frequency "$PLIST" &&
506                 echo "bootout gui/[UID] $PLIST" >>expect &&
507                 echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
508         done &&
509         test_cmp expect args &&
510
511         rm -f args &&
512         GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
513
514         # stop does not unregister the repo
515         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
516
517         printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
518                 hourly daily weekly >expect &&
519         test_cmp expect args &&
520         ls "$HOME/Library/LaunchAgents" >actual &&
521         test_line_count = 0 actual
522 '
523
524 test_expect_success 'start and stop Windows maintenance' '
525         write_script print-args <<-\EOF &&
526         echo $* >>args
527         while test $# -gt 0
528         do
529                 case "$1" in
530                 /xml) shift; xmlfile=$1; break ;;
531                 *) shift ;;
532                 esac
533         done
534         test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
535         EOF
536
537         rm -f args &&
538         GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start &&
539
540         # start registers the repo
541         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
542
543         for frequency in hourly daily weekly
544         do
545                 grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
546                 file=$(ls .git/schedule_${frequency}*.xml) &&
547                 test_xmllint "$file" || return 1
548         done &&
549
550         rm -f args &&
551         GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
552
553         # stop does not unregister the repo
554         git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
555
556         printf "/delete /tn Git Maintenance (%s) /f\n" \
557                 hourly daily weekly >expect &&
558         test_cmp expect args
559 '
560
561 test_expect_success 'register preserves existing strategy' '
562         git config maintenance.strategy none &&
563         git maintenance register &&
564         test_config maintenance.strategy none &&
565         git config --unset maintenance.strategy &&
566         git maintenance register &&
567         test_config maintenance.strategy incremental
568 '
569
570 test_expect_success 'fails when running outside of a repository' '
571         nongit test_must_fail git maintenance run &&
572         nongit test_must_fail git maintenance stop &&
573         nongit test_must_fail git maintenance start &&
574         nongit test_must_fail git maintenance register &&
575         nongit test_must_fail git maintenance unregister
576 '
577
578 test_done