@@ -493,6 +493,77 @@ test_expect_success 'reflog-expire task --auto only packs when exceeding limits'
493
493
test_subcommand git reflog expire --all <reflog-expire-auto.txt
494
494
'
495
495
496
+ test_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
+
509
+ test_expect_success ' worktree-prune task without --auto always prunes' '
510
+ test_expect_worktree_prune git maintenance run --task=worktree-prune
511
+ '
512
+
513
+ test_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
+
520
+ test_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
+
536
+ test_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
+
552
+ test_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
+
496
567
test_expect_success ' --auto and --schedule incompatible' '
497
568
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
498
569
test_grep "at most one" err
0 commit comments