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