758
)
759
'
760
761
+test_expect_success 'pre-auto-gc hook runs exactly once' '
762
+ test_when_finished "rm -rf repo" &&
763
+ git init repo &&
764
+ (
765
+ cd repo &&
766
+ write_script .git/hooks/pre-auto-gc <<-\EOF &&
767
+ echo hook >>hook.log
768
+ EOF
769
+
770
+ # Satisfy the auto condition for multiple tasks, both in the
771
+ # foreground and in the background phase.
772
+ git config set maintenance.reflog-expire.auto -1 &&
773
+ git config set maintenance.geometric-repack.auto -1 &&
774
+ git config set maintenance.rerere-gc.auto -1 &&
775
+
776
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
777
+ git maintenance run --auto 2>/dev/null &&
778
+
779
+ # The successful hook does not inhibit any of the tasks...
780
+ test_maintenance_tasks trace2.txt <<-\EOF &&
781
+ reflog-expire foreground
782
+ geometric-repack
783
+ rerere-gc
784
+ EOF
785
+ # ... but it must only have been executed a single time.
786
+ test_line_count = 1 hook.log
787
+ )
788
+'
789
+
790
+test_expect_success 'pre-auto-gc hook can inhibit geometric strategy' '
791
+ test_when_finished "rm -rf repo" &&
792
+ git init repo &&
793
+ (
794
+ cd repo &&
795
+ write_script .git/hooks/pre-auto-gc <<-\EOF &&
796
+ echo hook >>hook.log
797
+ exit 1
798
+ EOF
799
+
800
+ git config set maintenance.reflog-expire.auto -1 &&
801
+ git config set maintenance.geometric-repack.auto -1 &&
802
+ git config set maintenance.rerere-gc.auto -1 &&
803
+
804
+ # Maintenance would be required...
805
+ git maintenance is-needed --auto &&
806
+
807
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
808
+ git maintenance run --auto 2>/dev/null &&
809
+
810
+ # ... but the failing hook inhibits all tasks. The hook itself
811
+ # is expected to be the only child process being spawned, and
812
+ # it must only run a single time.
813
+ test_grep "child_start.*pre-auto-gc" trace2.txt &&
814
+ test_maintenance_tasks trace2.txt <<-\EOF &&
815
+ EOF
816
+ test_line_count = 1 hook.log
817
+ )
818
+'
819
+
820
+test_expect_success 'pre-auto-gc hook can inhibit gc strategy' '
821
+ test_when_finished "rm -rf repo" &&
822
+ git init repo &&
823
+ (
824
+ cd repo &&
825
+ write_script .git/hooks/pre-auto-gc <<-\EOF &&
826
+ echo hook >>hook.log
827
+ exit 1
828
+ EOF
829
+
830
+ git config set maintenance.strategy gc &&
831
+ git config set maintenance.auto false &&
832
+ git config set gc.auto 3 &&
833
+
834
+ test_oid_init &&
835
+
836
+ # We need to create two objects whose hashes start with 17
837
+ # since this is what the gc task counts.
838
+ test_commit "$(test_oid blob17_1)" &&
839
+ test_commit "$(test_oid blob17_2)" &&
840
+
841
+ # Maintenance would be required...
842
+ git maintenance is-needed --auto &&
843
+
844
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
845
+ git maintenance run --auto 2>/dev/null &&
846
+
847
+ # ... but the failing hook inhibits all tasks. The hook itself
848
+ # is expected to be the only child process being spawned, and
849
+ # it must only run a single time.
850
+ test_grep "child_start.*pre-auto-gc" trace2.txt &&
851
+ test_maintenance_tasks trace2.txt <<-\EOF &&
852
+ EOF
853
+ test_subcommand_flex ! git trace2 &&
854
+ test_line_count = 1 hook.log
855
+ )
856
+'
857
+
858
+test_expect_success 'pre-auto-gc hook does not run when no maintenance is needed' '
859
+ test_when_finished "rm -rf repo" &&
860
+ git init repo &&
861
+ (
862
+ cd repo &&
863
+ write_script .git/hooks/pre-auto-gc <<-\EOF &&
864
+ echo hook >>hook.log
865
+ EOF
866
+ test_must_fail git maintenance is-needed --auto &&
867
+ git maintenance run --auto 2>/dev/null &&
868
+ test_path_is_missing hook.log
869
+ )
870
+'
871
+
872
+test_expect_success 'pre-auto-gc hook does not run without --auto' '
873
+ test_when_finished "rm -rf repo" &&
874
+ git init repo &&
875
+ test_hook -C repo pre-auto-gc <<-\EOF &&
876
+ echo hook >>hook.log
877
+ EOF
878
+ (
879
+ cd repo &&
880
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
881
+ git maintenance run 2>/dev/null &&
882
+ test_grep "\[\"git\",\"repack\"," trace2.txt &&
883
+ test_path_is_missing hook.log
884
+ )
885
+'
886
+
887
test_expect_success 'pack-refs task' '
888
for n in $(test_seq 1 5)
889
do