Git fork
at reftables-rust 1193 lines 43 kB view raw
1#!/bin/sh 2 3test_description='git maintenance builtin' 4 5. ./test-lib.sh 6 7GIT_TEST_COMMIT_GRAPH=0 8GIT_TEST_MULTI_PACK_INDEX=0 9 10test_lazy_prereq XMLLINT ' 11 xmllint --version 12' 13 14test_xmllint () { 15 if test_have_prereq XMLLINT 16 then 17 xmllint --noout "$@" 18 else 19 true 20 fi 21} 22 23test_lazy_prereq SYSTEMD_ANALYZE ' 24 systemd-analyze verify /lib/systemd/system/basic.target 25' 26 27test_systemd_analyze_verify () { 28 if test_have_prereq SYSTEMD_ANALYZE 29 then 30 systemd-analyze verify "$@" 31 fi 32} 33 34test_expect_success 'help text' ' 35 test_expect_code 129 git maintenance -h >actual && 36 test_grep "usage: git maintenance <subcommand>" actual && 37 test_expect_code 129 git maintenance barf 2>err && 38 test_grep "unknown subcommand: \`barf'\''" err && 39 test_grep "usage: git maintenance" err && 40 test_expect_code 129 git maintenance 2>err && 41 test_grep "error: need a subcommand" err && 42 test_grep "usage: git maintenance" err 43' 44 45test_expect_success 'run [--auto|--quiet]' ' 46 GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \ 47 git maintenance run 2>/dev/null && 48 GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \ 49 git maintenance run --auto 2>/dev/null && 50 GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \ 51 git maintenance run --no-quiet 2>/dev/null && 52 test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-no-auto.txt && 53 test_subcommand ! git gc --auto --quiet --no-detach --skip-foreground-tasks <run-auto.txt && 54 test_subcommand git gc --no-quiet --no-detach --skip-foreground-tasks <run-no-quiet.txt 55' 56 57test_expect_success 'maintenance.auto config option' ' 58 GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 && 59 test_subcommand git maintenance run --auto --quiet --detach <default && 60 GIT_TRACE2_EVENT="$(pwd)/true" \ 61 git -c maintenance.auto=true \ 62 commit --quiet --allow-empty -m 2 && 63 test_subcommand git maintenance run --auto --quiet --detach <true && 64 GIT_TRACE2_EVENT="$(pwd)/false" \ 65 git -c maintenance.auto=false \ 66 commit --quiet --allow-empty -m 3 && 67 test_subcommand ! git maintenance run --auto --quiet --detach <false 68' 69 70for cfg in maintenance.autoDetach gc.autoDetach 71do 72 test_expect_success "$cfg=true config option" ' 73 test_when_finished "rm -f trace" && 74 test_config $cfg true && 75 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 && 76 test_subcommand git maintenance run --auto --quiet --detach <trace 77 ' 78 79 test_expect_success "$cfg=false config option" ' 80 test_when_finished "rm -f trace" && 81 test_config $cfg false && 82 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 && 83 test_subcommand git maintenance run --auto --quiet --no-detach <trace 84 ' 85done 86 87test_expect_success "maintenance.autoDetach overrides gc.autoDetach" ' 88 test_when_finished "rm -f trace" && 89 test_config maintenance.autoDetach false && 90 test_config gc.autoDetach true && 91 GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 && 92 test_subcommand git maintenance run --auto --quiet --no-detach <trace 93' 94 95test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' ' 96 test_when_finished rm -r .config/git/config && 97 ( 98 XDG_CONFIG_HOME=.config && 99 export XDG_CONFIG_HOME && 100 mkdir -p $XDG_CONFIG_HOME/git && 101 >$XDG_CONFIG_HOME/git/config && 102 git maintenance register && 103 git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual && 104 pwd >expect && 105 test_cmp expect actual 106 ) 107' 108 109test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' ' 110 test_when_finished git maintenance unregister && 111 test_path_is_missing $XDG_CONFIG_HOME/git/config && 112 git maintenance register && 113 git config --global --get maintenance.repo >actual && 114 pwd >expect && 115 test_cmp expect actual 116' 117 118test_expect_success 'unregister uses XDG_CONFIG_HOME config if it exists' ' 119 test_when_finished rm -r .config/git/config && 120 ( 121 XDG_CONFIG_HOME=.config && 122 export XDG_CONFIG_HOME && 123 mkdir -p $XDG_CONFIG_HOME/git && 124 >$XDG_CONFIG_HOME/git/config && 125 git maintenance register && 126 git maintenance unregister && 127 test_must_fail git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual && 128 test_must_be_empty actual 129 ) 130' 131 132test_expect_success 'unregister does not need XDG_CONFIG_HOME config to exist' ' 133 test_path_is_missing $XDG_CONFIG_HOME/git/config && 134 git maintenance register && 135 git maintenance unregister && 136 test_must_fail git config --global --get maintenance.repo >actual && 137 test_must_be_empty actual 138' 139 140test_expect_success 'maintenance.<task>.enabled' ' 141 git config maintenance.gc.enabled false && 142 git config maintenance.commit-graph.enabled true && 143 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err && 144 test_subcommand ! git gc --quiet <run-config.txt && 145 test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt 146' 147 148test_expect_success 'run --task=<task>' ' 149 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ 150 git maintenance run --task=commit-graph 2>/dev/null && 151 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \ 152 git maintenance run --task=gc 2>/dev/null && 153 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ 154 git maintenance run --task=commit-graph 2>/dev/null && 155 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \ 156 git maintenance run --task=commit-graph --task=gc 2>/dev/null && 157 test_subcommand ! git gc --quiet --no-detach --skip-foreground-tasks <run-commit-graph.txt && 158 test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-gc.txt && 159 test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-both.txt && 160 test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt && 161 test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt && 162 test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt 163' 164 165test_expect_success 'core.commitGraph=false prevents write process' ' 166 GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \ 167 git -c core.commitGraph=false maintenance run \ 168 --task=commit-graph 2>/dev/null && 169 test_subcommand ! git commit-graph write --split --reachable --no-progress \ 170 <no-commit-graph.txt 171' 172 173test_expect_success 'commit-graph auto condition' ' 174 COMMAND="maintenance run --task=commit-graph --auto --quiet" && 175 176 GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \ 177 git -c maintenance.commit-graph.auto=1 $COMMAND && 178 GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \ 179 git -c maintenance.commit-graph.auto="-1" $COMMAND && 180 181 test_commit first && 182 183 GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \ 184 git -c maintenance.commit-graph.auto=0 $COMMAND && 185 GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \ 186 git -c maintenance.commit-graph.auto=1 $COMMAND && 187 188 git commit --allow-empty -m "second" && 189 git commit --allow-empty -m "third" && 190 191 GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \ 192 git -c maintenance.commit-graph.auto=2 $COMMAND && 193 194 COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" && 195 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt && 196 test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt && 197 test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt && 198 test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt && 199 test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt 200' 201 202test_expect_success 'run --task=bogus' ' 203 test_must_fail git maintenance run --task=bogus 2>err && 204 test_grep "is not a valid task" err 205' 206 207test_expect_success 'run --task duplicate' ' 208 test_must_fail git maintenance run --task=gc --task=gc 2>err && 209 test_grep "cannot be selected multiple times" err 210' 211 212test_expect_success 'run --task=prefetch with no remotes' ' 213 git maintenance run --task=prefetch 2>err && 214 test_must_be_empty err 215' 216 217test_expect_success 'prefetch multiple remotes' ' 218 git clone . clone1 && 219 git clone . clone2 && 220 git remote add remote1 "file://$(pwd)/clone1" && 221 git remote add remote2 "file://$(pwd)/clone2" && 222 git -C clone1 switch -c one && 223 git -C clone2 switch -c two && 224 test_commit -C clone1 one && 225 test_commit -C clone2 two && 226 GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null && 227 fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" && 228 test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt && 229 test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt && 230 git for-each-ref refs/remotes >actual && 231 test_must_be_empty actual && 232 git log prefetch/remotes/remote1/one && 233 git log prefetch/remotes/remote2/two && 234 git fetch --all && 235 test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one && 236 test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two && 237 238 git log --oneline --decorate --all >log && 239 ! grep "prefetch" log && 240 241 test_when_finished git config --unset remote.remote1.skipFetchAll && 242 git config remote.remote1.skipFetchAll true && 243 GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null && 244 test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt && 245 test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt 246' 247 248test_expect_success 'loose-objects task' ' 249 # Repack everything so we know the state of the object dir 250 git repack -adk && 251 252 # Hack to stop maintenance from running during "git commit" 253 echo in use >.git/objects/maintenance.lock && 254 255 # Assuming that "git commit" creates at least one loose object 256 test_commit create-loose-object && 257 rm .git/objects/maintenance.lock && 258 259 ls .git/objects >obj-dir-before && 260 test_file_not_empty obj-dir-before && 261 ls .git/objects/pack/*.pack >packs-before && 262 test_line_count = 1 packs-before && 263 264 # The first run creates a pack-file 265 # but does not delete loose objects. 266 git maintenance run --task=loose-objects && 267 ls .git/objects >obj-dir-between && 268 test_cmp obj-dir-before obj-dir-between && 269 ls .git/objects/pack/*.pack >packs-between && 270 test_line_count = 2 packs-between && 271 ls .git/objects/pack/loose-*.pack >loose-packs && 272 test_line_count = 1 loose-packs && 273 274 # The second run deletes loose objects 275 # but does not create a pack-file. 276 git maintenance run --task=loose-objects && 277 ls .git/objects >obj-dir-after && 278 cat >expect <<-\EOF && 279 info 280 pack 281 EOF 282 test_cmp expect obj-dir-after && 283 ls .git/objects/pack/*.pack >packs-after && 284 test_cmp packs-between packs-after 285' 286 287test_expect_success 'maintenance.loose-objects.auto' ' 288 git repack -adk && 289 GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \ 290 git -c maintenance.loose-objects.auto=1 maintenance \ 291 run --auto --task=loose-objects 2>/dev/null && 292 test_subcommand ! git prune-packed --quiet <trace-lo1.txt && 293 printf data-A | git hash-object -t blob --stdin -w && 294 GIT_TRACE2_EVENT="$(pwd)/trace-loA" \ 295 git -c maintenance.loose-objects.auto=2 \ 296 maintenance run --auto --task=loose-objects 2>/dev/null && 297 test_subcommand ! git prune-packed --quiet <trace-loA && 298 printf data-B | git hash-object -t blob --stdin -w && 299 GIT_TRACE2_EVENT="$(pwd)/trace-loB" \ 300 git -c maintenance.loose-objects.auto=2 \ 301 maintenance run --auto --task=loose-objects 2>/dev/null && 302 test_subcommand git prune-packed --quiet <trace-loB && 303 GIT_TRACE2_EVENT="$(pwd)/trace-loC" \ 304 git -c maintenance.loose-objects.auto=2 \ 305 maintenance run --auto --task=loose-objects 2>/dev/null && 306 test_subcommand git prune-packed --quiet <trace-loC 307' 308 309test_expect_success 'maintenance.loose-objects.batchSize' ' 310 git init loose-batch && 311 312 # This creates three objects per commit. 313 test_commit_bulk -C loose-batch 34 && 314 pack=$(ls loose-batch/.git/objects/pack/pack-*.pack) && 315 index="${pack%pack}idx" && 316 rm "$index" && 317 git -C loose-batch unpack-objects <"$pack" && 318 git -C loose-batch config maintenance.loose-objects.batchSize 50 && 319 320 GIT_PROGRESS_DELAY=0 \ 321 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err && 322 grep "Enumerating objects: 50, done." err && 323 324 GIT_PROGRESS_DELAY=0 \ 325 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err && 326 grep "Enumerating objects: 50, done." err && 327 328 GIT_PROGRESS_DELAY=0 \ 329 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err && 330 grep "Enumerating objects: 2, done." err && 331 332 GIT_PROGRESS_DELAY=0 \ 333 git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err && 334 test_must_be_empty err 335' 336 337test_expect_success 'incremental-repack task' ' 338 packDir=.git/objects/pack && 339 for i in $(test_seq 1 5) 340 do 341 test_commit $i || return 1 342 done && 343 344 # Create three disjoint pack-files with size BIG, small, small. 345 echo HEAD~2 | git pack-objects --revs $packDir/test-1 && 346 test_tick && 347 git pack-objects --revs $packDir/test-2 <<-\EOF && 348 HEAD~1 349 ^HEAD~2 350 EOF 351 test_tick && 352 git pack-objects --revs $packDir/test-3 <<-\EOF && 353 HEAD 354 ^HEAD~1 355 EOF 356 357 # Delete refs that have not been repacked in these packs. 358 git for-each-ref --format="delete %(refname)" \ 359 refs/prefetch refs/tags refs/remotes \ 360 --exclude=refs/remotes/*/HEAD >refs && 361 git update-ref --stdin <refs && 362 363 # Replace the object directory with this pack layout. 364 rm -f $packDir/pack-* && 365 rm -f $packDir/loose-* && 366 ls $packDir/*.pack >packs-before && 367 test_line_count = 3 packs-before && 368 369 # make sure we do not have any broken refs that were 370 # missed in the deletion above 371 git for-each-ref && 372 373 # the job repacks the two into a new pack, but does not 374 # delete the old ones. 375 git maintenance run --task=incremental-repack && 376 ls $packDir/*.pack >packs-between && 377 test_line_count = 4 packs-between && 378 379 # the job deletes the two old packs, and does not write 380 # a new one because the batch size is not high enough to 381 # pack the largest pack-file. 382 git maintenance run --task=incremental-repack && 383 ls .git/objects/pack/*.pack >packs-after && 384 test_line_count = 2 packs-after 385' 386 387test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' 388 test_config core.compression 0 && 389 390 for i in $(test_seq 1 5) 391 do 392 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || 393 return 1 394 done && 395 git add big && 396 git commit -qm "Add big file (1)" && 397 398 # ensure any possible loose objects are in a pack-file 399 git maintenance run --task=loose-objects && 400 401 rm big && 402 for i in $(test_seq 6 10) 403 do 404 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || 405 return 1 406 done && 407 git add big && 408 git commit -qm "Add big file (2)" && 409 410 # ensure any possible loose objects are in a pack-file 411 git maintenance run --task=loose-objects && 412 413 # Now run the incremental-repack task and check the batch-size 414 GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \ 415 --task=incremental-repack 2>/dev/null && 416 test_subcommand git multi-pack-index repack \ 417 --no-progress --batch-size=2147483647 <run-2g.txt 418' 419 420run_incremental_repack_and_verify () { 421 test_commit A && 422 git repack -adk && 423 git multi-pack-index write && 424 GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \ 425 -c maintenance.incremental-repack.auto=1 \ 426 maintenance run --auto --task=incremental-repack 2>/dev/null && 427 test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt && 428 test_commit B && 429 git pack-objects --revs .git/objects/pack/pack <<-\EOF && 430 HEAD 431 ^HEAD~1 432 EOF 433 GIT_TRACE2_EVENT=$(pwd)/trace-A git \ 434 -c maintenance.incremental-repack.auto=2 \ 435 maintenance run --auto --task=incremental-repack 2>/dev/null && 436 test_subcommand ! git multi-pack-index write --no-progress <trace-A && 437 test_commit C && 438 git pack-objects --revs .git/objects/pack/pack <<-\EOF && 439 HEAD 440 ^HEAD~1 441 EOF 442 GIT_TRACE2_EVENT=$(pwd)/trace-B git \ 443 -c maintenance.incremental-repack.auto=2 \ 444 maintenance run --auto --task=incremental-repack 2>/dev/null && 445 test_subcommand git multi-pack-index write --no-progress <trace-B 446} 447 448test_expect_success 'maintenance.incremental-repack.auto' ' 449 rm -rf incremental-repack-true && 450 git init incremental-repack-true && 451 ( 452 cd incremental-repack-true && 453 git config core.multiPackIndex true && 454 run_incremental_repack_and_verify 455 ) 456' 457 458test_expect_success 'maintenance.incremental-repack.auto (when config is unset)' ' 459 rm -rf incremental-repack-unset && 460 git init incremental-repack-unset && 461 ( 462 cd incremental-repack-unset && 463 test_unconfig core.multiPackIndex && 464 run_incremental_repack_and_verify 465 ) 466' 467 468test_expect_success 'pack-refs task' ' 469 for n in $(test_seq 1 5) 470 do 471 git branch -f to-pack/$n HEAD || return 1 472 done && 473 GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \ 474 git maintenance run --task=pack-refs && 475 test_subcommand git pack-refs --all --prune <pack-refs.txt 476' 477 478test_expect_success 'reflog-expire task' ' 479 GIT_TRACE2_EVENT="$(pwd)/reflog-expire.txt" \ 480 git maintenance run --task=reflog-expire && 481 test_subcommand git reflog expire --all <reflog-expire.txt 482' 483 484test_expect_success 'reflog-expire task --auto only packs when exceeding limits' ' 485 git reflog expire --all --expire=now && 486 test_commit reflog-one && 487 test_commit reflog-two && 488 GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \ 489 git -c maintenance.reflog-expire.auto=3 maintenance run --auto --task=reflog-expire && 490 test_subcommand ! git reflog expire --all <reflog-expire-auto.txt && 491 GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \ 492 git -c maintenance.reflog-expire.auto=2 maintenance run --auto --task=reflog-expire && 493 test_subcommand git reflog expire --all <reflog-expire-auto.txt 494' 495 496test_expect_worktree_prune () { 497 negate= 498 if test "$1" = "!" 499 then 500 negate="!" 501 shift 502 fi 503 504 rm -f "worktree-prune.txt" && 505 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" "$@" && 506 test_subcommand $negate git worktree prune --expire 3.months.ago <worktree-prune.txt 507} 508 509test_expect_success 'worktree-prune task without --auto always prunes' ' 510 test_expect_worktree_prune git maintenance run --task=worktree-prune 511' 512 513test_expect_success 'worktree-prune task --auto only prunes with prunable worktree' ' 514 test_expect_worktree_prune ! git maintenance run --auto --task=worktree-prune && 515 mkdir .git/worktrees && 516 : >.git/worktrees/abc && 517 test_expect_worktree_prune git maintenance run --auto --task=worktree-prune 518' 519 520test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' ' 521 # A negative value should always prune. 522 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune && 523 524 mkdir .git/worktrees && 525 : >.git/worktrees/first && 526 : >.git/worktrees/second && 527 : >.git/worktrees/third && 528 529 # Zero should never prune. 530 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune && 531 # A positive value should require at least this many prunable worktrees. 532 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune && 533 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune 534' 535 536test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' ' 537 # A negative value should always prune. 538 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune && 539 540 mkdir .git/worktrees && 541 : >.git/worktrees/first && 542 : >.git/worktrees/second && 543 : >.git/worktrees/third && 544 545 # Zero should never prune. 546 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune && 547 # A positive value should require at least this many prunable worktrees. 548 test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune && 549 test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune 550' 551 552test_expect_success 'worktree-prune task honors gc.worktreePruneExpire' ' 553 git worktree add worktree && 554 rm -rf worktree && 555 556 rm -f worktree-prune.txt && 557 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=1.week.ago maintenance run --auto --task=worktree-prune && 558 test_subcommand ! git worktree prune --expire 1.week.ago <worktree-prune.txt && 559 test_path_is_dir .git/worktrees/worktree && 560 561 rm -f worktree-prune.txt && 562 GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=now maintenance run --auto --task=worktree-prune && 563 test_subcommand git worktree prune --expire now <worktree-prune.txt && 564 test_path_is_missing .git/worktrees/worktree 565' 566 567test_expect_rerere_gc () { 568 negate= 569 if test "$1" = "!" 570 then 571 negate="!" 572 shift 573 fi 574 575 rm -f "rerere-gc.txt" && 576 GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" && 577 test_subcommand $negate git rerere gc <rerere-gc.txt 578} 579 580test_expect_success 'rerere-gc task without --auto always collects garbage' ' 581 test_expect_rerere_gc git maintenance run --task=rerere-gc 582' 583 584test_expect_success 'rerere-gc task with --auto only prunes with prunable entries' ' 585 test_when_finished "rm -rf .git/rr-cache" && 586 test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc && 587 mkdir .git/rr-cache && 588 test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc && 589 : >.git/rr-cache/entry && 590 test_expect_rerere_gc git maintenance run --auto --task=rerere-gc 591' 592 593test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.auto' ' 594 test_when_finished "rm -rf .git/rr-cache" && 595 596 # A negative value should always prune. 597 test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc && 598 599 # A positive value prunes when there is at least one entry. 600 test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc && 601 mkdir .git/rr-cache && 602 test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc && 603 : >.git/rr-cache/entry-1 && 604 test_expect_rerere_gc git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc && 605 606 # Zero should never prune. 607 : >.git/rr-cache/entry-1 && 608 test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc 609' 610 611test_expect_success '--auto and --schedule incompatible' ' 612 test_must_fail git maintenance run --auto --schedule=daily 2>err && 613 test_grep "cannot be used together" err 614' 615 616test_expect_success '--task and --schedule incompatible' ' 617 test_must_fail git maintenance run --task=pack-refs --schedule=daily 2>err && 618 test_grep "cannot be used together" err 619' 620 621test_expect_success 'invalid --schedule value' ' 622 test_must_fail git maintenance run --schedule=annually 2>err && 623 test_grep "unrecognized --schedule" err 624' 625 626test_expect_success '--schedule inheritance weekly -> daily -> hourly' ' 627 git config maintenance.loose-objects.enabled true && 628 git config maintenance.loose-objects.schedule hourly && 629 git config maintenance.commit-graph.enabled true && 630 git config maintenance.commit-graph.schedule daily && 631 git config maintenance.incremental-repack.enabled true && 632 git config maintenance.incremental-repack.schedule weekly && 633 634 GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \ 635 git maintenance run --schedule=hourly 2>/dev/null && 636 test_subcommand git prune-packed --quiet <hourly.txt && 637 test_subcommand ! git commit-graph write --split --reachable \ 638 --no-progress <hourly.txt && 639 test_subcommand ! git multi-pack-index write --no-progress <hourly.txt && 640 641 GIT_TRACE2_EVENT="$(pwd)/daily.txt" \ 642 git maintenance run --schedule=daily 2>/dev/null && 643 test_subcommand git prune-packed --quiet <daily.txt && 644 test_subcommand git commit-graph write --split --reachable \ 645 --no-progress <daily.txt && 646 test_subcommand ! git multi-pack-index write --no-progress <daily.txt && 647 648 GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \ 649 git maintenance run --schedule=weekly 2>/dev/null && 650 test_subcommand git prune-packed --quiet <weekly.txt && 651 test_subcommand git commit-graph write --split --reachable \ 652 --no-progress <weekly.txt && 653 test_subcommand git multi-pack-index write --no-progress <weekly.txt 654' 655 656test_expect_success 'maintenance.strategy inheritance' ' 657 for task in commit-graph loose-objects incremental-repack 658 do 659 git config --unset maintenance.$task.schedule || return 1 660 done && 661 662 test_when_finished git config --unset maintenance.strategy && 663 git config maintenance.strategy incremental && 664 665 GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \ 666 git maintenance run --schedule=hourly --quiet && 667 GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \ 668 git maintenance run --schedule=daily --quiet && 669 GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \ 670 git maintenance run --schedule=weekly --quiet && 671 672 test_subcommand git commit-graph write --split --reachable \ 673 --no-progress <incremental-hourly.txt && 674 test_subcommand ! git prune-packed --quiet <incremental-hourly.txt && 675 test_subcommand ! git multi-pack-index write --no-progress \ 676 <incremental-hourly.txt && 677 test_subcommand ! git pack-refs --all --prune \ 678 <incremental-hourly.txt && 679 680 test_subcommand git commit-graph write --split --reachable \ 681 --no-progress <incremental-daily.txt && 682 test_subcommand git prune-packed --quiet <incremental-daily.txt && 683 test_subcommand git multi-pack-index write --no-progress \ 684 <incremental-daily.txt && 685 test_subcommand ! git pack-refs --all --prune \ 686 <incremental-daily.txt && 687 688 test_subcommand git commit-graph write --split --reachable \ 689 --no-progress <incremental-weekly.txt && 690 test_subcommand git prune-packed --quiet <incremental-weekly.txt && 691 test_subcommand git multi-pack-index write --no-progress \ 692 <incremental-weekly.txt && 693 test_subcommand git pack-refs --all --prune \ 694 <incremental-weekly.txt && 695 696 # Modify defaults 697 git config maintenance.commit-graph.schedule daily && 698 git config maintenance.loose-objects.schedule hourly && 699 git config maintenance.incremental-repack.enabled false && 700 701 GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \ 702 git maintenance run --schedule=hourly --quiet && 703 GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \ 704 git maintenance run --schedule=daily --quiet && 705 706 test_subcommand ! git commit-graph write --split --reachable \ 707 --no-progress <modified-hourly.txt && 708 test_subcommand git prune-packed --quiet <modified-hourly.txt && 709 test_subcommand ! git multi-pack-index write --no-progress \ 710 <modified-hourly.txt && 711 712 test_subcommand git commit-graph write --split --reachable \ 713 --no-progress <modified-daily.txt && 714 test_subcommand git prune-packed --quiet <modified-daily.txt && 715 test_subcommand ! git multi-pack-index write --no-progress \ 716 <modified-daily.txt 717' 718 719test_expect_success 'register and unregister' ' 720 test_when_finished git config --global --unset-all maintenance.repo && 721 722 test_must_fail git maintenance unregister 2>err && 723 grep "is not registered" err && 724 git maintenance unregister --force && 725 726 git config --global --add maintenance.repo /existing1 && 727 git config --global --add maintenance.repo /existing2 && 728 git config --global --get-all maintenance.repo >before && 729 730 git maintenance register && 731 test_cmp_config false maintenance.auto && 732 git config --global --get-all maintenance.repo >between && 733 cp before expect && 734 pwd >>expect && 735 test_cmp expect between && 736 737 git maintenance unregister && 738 git config --global --get-all maintenance.repo >actual && 739 test_cmp before actual && 740 741 git config --file ./other --add maintenance.repo /existing1 && 742 git config --file ./other --add maintenance.repo /existing2 && 743 git config --file ./other --get-all maintenance.repo >before && 744 745 git maintenance register --config-file ./other && 746 test_cmp_config false maintenance.auto && 747 git config --file ./other --get-all maintenance.repo >between && 748 cp before expect && 749 pwd >>expect && 750 test_cmp expect between && 751 752 git maintenance unregister --config-file ./other && 753 git config --file ./other --get-all maintenance.repo >actual && 754 test_cmp before actual && 755 756 test_must_fail git maintenance unregister 2>err && 757 grep "is not registered" err && 758 git maintenance unregister --force && 759 760 test_must_fail git maintenance unregister --config-file ./other 2>err && 761 grep "is not registered" err && 762 git maintenance unregister --config-file ./other --force 763' 764 765test_expect_success 'register with no value for maintenance.repo' ' 766 cp .git/config .git/config.orig && 767 test_when_finished mv .git/config.orig .git/config && 768 769 cat >>.git/config <<-\EOF && 770 [maintenance] 771 repo 772 EOF 773 cat >expect <<-\EOF && 774 error: missing value for '\''maintenance.repo'\'' 775 EOF 776 git maintenance register 2>actual && 777 test_cmp expect actual && 778 git config maintenance.repo 779' 780 781test_expect_success 'unregister with no value for maintenance.repo' ' 782 cp .git/config .git/config.orig && 783 test_when_finished mv .git/config.orig .git/config && 784 785 cat >>.git/config <<-\EOF && 786 [maintenance] 787 repo 788 EOF 789 cat >expect <<-\EOF && 790 error: missing value for '\''maintenance.repo'\'' 791 EOF 792 test_expect_code 128 git maintenance unregister 2>actual.raw && 793 grep ^error actual.raw >actual && 794 test_cmp expect actual && 795 git config maintenance.repo && 796 797 git maintenance unregister --force 2>actual.raw && 798 grep ^error actual.raw >actual && 799 test_cmp expect actual && 800 git config maintenance.repo 801' 802 803test_expect_success !MINGW 'register and unregister with regex metacharacters' ' 804 META="a+b*c" && 805 git init "$META" && 806 git -C "$META" maintenance register && 807 git config --get-all --show-origin maintenance.repo && 808 git config --get-all --global --fixed-value \ 809 maintenance.repo "$(pwd)/$META" && 810 git -C "$META" maintenance unregister && 811 test_must_fail git config --get-all --global --fixed-value \ 812 maintenance.repo "$(pwd)/$META" 813' 814 815test_expect_success 'start without GIT_TEST_MAINT_SCHEDULER' ' 816 test_when_finished "rm -rf systemctl.log script repo" && 817 mkdir script && 818 write_script script/systemctl <<-\EOF && 819 echo "$*" >>../systemctl.log 820 EOF 821 git init repo && 822 ( 823 cd repo && 824 sane_unset GIT_TEST_MAINT_SCHEDULER && 825 PATH="$PWD/../script:$PATH" git maintenance start --scheduler=systemd 826 ) && 827 test_grep -- "--user list-timers" systemctl.log && 828 test_grep -- "enable --now git-maintenance@" systemctl.log 829' 830 831test_expect_success 'start --scheduler=<scheduler>' ' 832 test_expect_code 129 git maintenance start --scheduler=foo 2>err && 833 test_grep "unrecognized --scheduler argument" err && 834 835 test_expect_code 129 git maintenance start --no-scheduler 2>err && 836 test_grep "unknown option" err && 837 838 test_expect_code 128 \ 839 env GIT_TEST_MAINT_SCHEDULER="launchctl:true,schtasks:true" \ 840 git maintenance start --scheduler=crontab 2>err && 841 test_grep "fatal: crontab scheduler is not available" err 842' 843 844test_expect_success 'start from empty cron table' ' 845 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && 846 847 # start registers the repo 848 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 849 850 grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=daily" cron.txt && 851 grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=hourly" cron.txt && 852 grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=weekly" cron.txt 853' 854 855test_expect_success 'stop from existing schedule' ' 856 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && 857 858 # stop does not unregister the repo 859 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 860 861 # Operation is idempotent 862 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && 863 test_must_be_empty cron.txt 864' 865 866test_expect_success 'start preserves existing schedule' ' 867 echo "Important information!" >cron.txt && 868 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && 869 grep "Important information!" cron.txt 870' 871 872test_expect_success 'magic markers are correct' ' 873 grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual && 874 cat >expect <<-\EOF && 875 # BEGIN GIT MAINTENANCE SCHEDULE 876 # END GIT MAINTENANCE SCHEDULE 877 EOF 878 test_cmp actual expect 879' 880 881test_expect_success 'stop preserves surrounding schedule' ' 882 echo "Crucial information!" >>cron.txt && 883 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && 884 grep "Important information!" cron.txt && 885 grep "Crucial information!" cron.txt 886' 887 888test_expect_success 'start and stop macOS maintenance' ' 889 # ensure $HOME can be compared against hook arguments on all platforms 890 pfx=$(cd "$HOME" && pwd) && 891 892 write_script print-args <<-\EOF && 893 echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args 894 EOF 895 896 rm -f args && 897 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && 898 899 # start registers the repo 900 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 901 902 ls "$HOME/Library/LaunchAgents" >actual && 903 cat >expect <<-\EOF && 904 org.git-scm.git.daily.plist 905 org.git-scm.git.hourly.plist 906 org.git-scm.git.weekly.plist 907 EOF 908 test_cmp expect actual && 909 910 rm -f expect && 911 for frequency in hourly daily weekly 912 do 913 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && 914 test_xmllint "$PLIST" && 915 grep schedule=$frequency "$PLIST" && 916 echo "bootout gui/[UID] $PLIST" >>expect && 917 echo "bootstrap gui/[UID] $PLIST" >>expect || return 1 918 done && 919 test_cmp expect args && 920 921 rm -f args && 922 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop && 923 924 # stop does not unregister the repo 925 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 926 927 printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ 928 hourly daily weekly >expect && 929 test_cmp expect args && 930 ls "$HOME/Library/LaunchAgents" >actual && 931 test_line_count = 0 actual 932' 933 934test_expect_success 'use launchctl list to prevent extra work' ' 935 # ensure we are registered 936 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && 937 938 # do it again on a fresh args file 939 rm -f args && 940 GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && 941 942 ls "$HOME/Library/LaunchAgents" >actual && 943 cat >expect <<-\EOF && 944 list org.git-scm.git.hourly 945 list org.git-scm.git.daily 946 list org.git-scm.git.weekly 947 EOF 948 test_cmp expect args 949' 950 951test_expect_success 'start and stop Windows maintenance' ' 952 write_script print-args <<-\EOF && 953 echo $* >>args 954 while test $# -gt 0 955 do 956 case "$1" in 957 /xml) shift; xmlfile=$1; break ;; 958 *) shift ;; 959 esac 960 done 961 test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml" 962 EOF 963 964 rm -f args && 965 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start --scheduler=schtasks && 966 967 # start registers the repo 968 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 969 970 for frequency in hourly daily weekly 971 do 972 grep "/create /tn Git Maintenance ($frequency) /f /xml" args && 973 file=$(ls .git/schedule_${frequency}*.xml) && 974 test_xmllint "$file" || return 1 975 done && 976 977 rm -f args && 978 GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop && 979 980 # stop does not unregister the repo 981 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 982 983 printf "/delete /tn Git Maintenance (%s) /f\n" \ 984 hourly daily weekly >expect && 985 test_cmp expect args 986' 987 988test_expect_success 'start and stop Linux/systemd maintenance' ' 989 write_script print-args <<-\EOF && 990 printf "%s\n" "$*" >>args 991 EOF 992 993 XDG_CONFIG_HOME="$PWD" && 994 export XDG_CONFIG_HOME && 995 rm -f args && 996 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance start --scheduler=systemd-timer && 997 998 # start registers the repo 999 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 1000 1001 for schedule in hourly daily weekly 1002 do 1003 test_path_is_file "systemd/user/git-maintenance@$schedule.timer" || return 1 1004 done && 1005 test_path_is_file "systemd/user/git-maintenance@.service" && 1006 1007 test_systemd_analyze_verify "systemd/user/git-maintenance@hourly.service" && 1008 test_systemd_analyze_verify "systemd/user/git-maintenance@daily.service" && 1009 test_systemd_analyze_verify "systemd/user/git-maintenance@weekly.service" && 1010 1011 grep "core.askPass=true" "systemd/user/git-maintenance@.service" && 1012 grep "credential.interactive=false" "systemd/user/git-maintenance@.service" && 1013 1014 printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && 1015 test_cmp expect args && 1016 1017 rm -f args && 1018 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance stop && 1019 1020 # stop does not unregister the repo 1021 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 1022 1023 for schedule in hourly daily weekly 1024 do 1025 test_path_is_missing "systemd/user/git-maintenance@$schedule.timer" || return 1 1026 done && 1027 test_path_is_missing "systemd/user/git-maintenance@.service" && 1028 1029 printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && 1030 test_cmp expect args 1031' 1032 1033test_expect_success 'start and stop when several schedulers are available' ' 1034 write_script print-args <<-\EOF && 1035 printf "%s\n" "$*" | sed "s:gui/[0-9][0-9]*:gui/[UID]:; s:\(schtasks /create .* /xml\).*:\1:;" >>args 1036 EOF 1037 1038 rm -f args && 1039 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=systemd-timer && 1040 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ 1041 hourly daily weekly >expect && 1042 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ 1043 hourly daily weekly >>expect && 1044 printf -- "systemctl --user enable --now git-maintenance@%s.timer\n" hourly daily weekly >>expect && 1045 test_cmp expect args && 1046 1047 rm -f args && 1048 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=launchctl && 1049 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && 1050 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ 1051 hourly daily weekly >>expect && 1052 for frequency in hourly daily weekly 1053 do 1054 PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && 1055 echo "launchctl bootout gui/[UID] $PLIST" >>expect && 1056 echo "launchctl bootstrap gui/[UID] $PLIST" >>expect || return 1 1057 done && 1058 test_cmp expect args && 1059 1060 rm -f args && 1061 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=schtasks && 1062 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && 1063 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ 1064 hourly daily weekly >>expect && 1065 printf "schtasks /create /tn Git Maintenance (%s) /f /xml\n" \ 1066 hourly daily weekly >>expect && 1067 test_cmp expect args && 1068 1069 rm -f args && 1070 GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance stop && 1071 printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && 1072 printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ 1073 hourly daily weekly >>expect && 1074 printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ 1075 hourly daily weekly >>expect && 1076 test_cmp expect args 1077' 1078 1079test_expect_success 'register preserves existing strategy' ' 1080 git config maintenance.strategy none && 1081 git maintenance register && 1082 test_config maintenance.strategy none && 1083 git config --unset maintenance.strategy && 1084 git maintenance register && 1085 test_config maintenance.strategy incremental 1086' 1087 1088test_expect_success 'fails when running outside of a repository' ' 1089 nongit test_must_fail git maintenance run && 1090 nongit test_must_fail git maintenance stop && 1091 nongit test_must_fail git maintenance start && 1092 nongit test_must_fail git maintenance register && 1093 nongit test_must_fail git maintenance unregister 1094' 1095 1096test_expect_success 'register and unregister bare repo' ' 1097 test_when_finished "git config --global --unset-all maintenance.repo || :" && 1098 test_might_fail git config --global --unset-all maintenance.repo && 1099 git init --bare barerepo && 1100 ( 1101 cd barerepo && 1102 git maintenance register && 1103 git config --get --global --fixed-value maintenance.repo "$(pwd)" && 1104 git maintenance unregister && 1105 test_must_fail git config --global --get-all maintenance.repo 1106 ) 1107' 1108 1109test_expect_success 'failed schedule prevents config change' ' 1110 git init --bare failcase && 1111 1112 for scheduler in crontab launchctl schtasks systemctl 1113 do 1114 GIT_TEST_MAINT_SCHEDULER="$scheduler:false" && 1115 export GIT_TEST_MAINT_SCHEDULER && 1116 test_must_fail \ 1117 git -C failcase maintenance start && 1118 test_must_fail git -C failcase config maintenance.auto || return 1 1119 done 1120' 1121 1122test_expect_success '--no-detach causes maintenance to not run in background' ' 1123 test_when_finished "rm -rf repo" && 1124 git init repo && 1125 ( 1126 cd repo && 1127 1128 # Prepare the repository such that git-maintenance(1) ends up 1129 # outputting something. 1130 test_commit something && 1131 git config set maintenance.gc.enabled false && 1132 git config set maintenance.loose-objects.enabled true && 1133 git config set maintenance.loose-objects.auto 1 && 1134 git config set maintenance.incremental-repack.enabled true && 1135 1136 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ 1137 git maintenance run --no-detach >out 2>&1 && 1138 ! test_region maintenance detach trace.txt 1139 ) 1140' 1141 1142test_expect_success '--detach causes maintenance to run in background' ' 1143 test_when_finished "rm -rf repo" && 1144 git init repo && 1145 ( 1146 cd repo && 1147 1148 test_commit something && 1149 git config set maintenance.gc.enabled false && 1150 git config set maintenance.loose-objects.enabled true && 1151 git config set maintenance.loose-objects.auto 1 && 1152 git config set maintenance.incremental-repack.enabled true && 1153 1154 # The extra file descriptor gets inherited to the child 1155 # process, and by reading stdout we thus essentially wait for 1156 # that descriptor to get closed, which indicates that the child 1157 # is done, too. 1158 does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ 1159 git maintenance run --detach 9>&1) && 1160 test_region maintenance detach trace.txt 1161 ) 1162' 1163 1164test_expect_success 'repacking loose objects is quiet' ' 1165 test_when_finished "rm -rf repo" && 1166 git init repo && 1167 ( 1168 cd repo && 1169 1170 test_commit something && 1171 git config set maintenance.gc.enabled false && 1172 git config set maintenance.loose-objects.enabled true && 1173 git config set maintenance.loose-objects.auto 1 && 1174 1175 git maintenance run --quiet >out 2>&1 && 1176 test_must_be_empty out 1177 ) 1178' 1179 1180test_expect_success 'maintenance aborts with existing lock file' ' 1181 test_when_finished "rm -rf repo script" && 1182 mkdir script && 1183 write_script script/systemctl <<-\EOF && 1184 true 1185 EOF 1186 1187 git init repo && 1188 : >repo/.git/objects/schedule.lock && 1189 test_must_fail env PATH="$PWD/script:$PATH" git -C repo maintenance start --scheduler=systemd 2>err && 1190 test_grep "Another scheduled git-maintenance(1) process seems to be running" err 1191' 1192 1193test_done