t7900: simplify how we check for maintenance tasks

We have several tests in t7900 that verify whether specific maintenance tasks did or did not run. This is done rather ad-hoc by checking for spawned Git commands, which is awfully fragile: - We have to adjust tests whenever arguments to the spawned Git commands change. - We don't have a way to verify that negative matches are still working as expected. - We rely on maintenance tasks spawning a Git command in the first place. We can do much better though, as we already have trace2 regions for each of the maintenance tasks. Introduce a helper function that extracts all such regions so that we can get a direct list of all maintenance tasks that a certain command ran. Adapt tests that care about whether or not a specific task ran to use this new helper. Note that many tests still use `test_subcommand` though, as they really care about the exact command that was executed. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 13, 2026 at 07:52 UTC 368565e55d5cff377efaee5cf86f092709480314
1 file changed +102 -92
t/t7900-maintenance.sh
+102 -92
@@ -23,6 +23,12 @@ test_xmllint () {
23 fi
24 }
25
26 +test_maintenance_tasks () {
27 + cat >expect &&
28 + sed -ne "s/.*\"region_enter\".*\"category\":\"maintenance\([^\"]*\)\".*\"label\":\"\([^\"][^\"]*\)\".*/\2\1/p" "$1" >actual &&
29 + test_cmp expect actual
30 +}
31 +
32 test_lazy_prereq SYSTEMD_ANALYZE '
33 systemd-analyze verify /lib/systemd/system/basic.target
34 '
@@ -180,8 +186,9 @@ test_expect_success 'maintenance.<task>.enabled' '
186 git config maintenance.gc.enabled false &&
187 git config maintenance.commit-graph.enabled true &&
188 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
183 - test_subcommand ! git gc --quiet <run-config.txt &&
184 - test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
189 + test_maintenance_tasks run-config.txt <<-\EOF
190 + commit-graph
191 + EOF
192 '
193
194 test_expect_success 'run --task=<task>' '
@@ -189,16 +196,20 @@ test_expect_success 'run --task=<task>' '
196 git maintenance run --task=commit-graph 2>/dev/null &&
197 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
198 git maintenance run --task=gc 2>/dev/null &&
192 - GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
193 - git maintenance run --task=commit-graph 2>/dev/null &&
199 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
200 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
196 - test_subcommand ! git gc --quiet --no-detach --skip-foreground-tasks <run-commit-graph.txt &&
197 - test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-gc.txt &&
198 - test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-both.txt &&
199 - test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
200 - test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
201 - test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
201 + test_maintenance_tasks run-commit-graph.txt <<-\EOF &&
202 + commit-graph
203 + EOF
204 + test_maintenance_tasks run-gc.txt <<-\EOF &&
205 + gc foreground
206 + gc
207 + EOF
208 + test_maintenance_tasks run-both.txt <<-\EOF
209 + gc foreground
210 + commit-graph
211 + gc
212 + EOF
213 '
214
215 test_expect_success 'core.commitGraph=false prevents write process' '
@@ -235,12 +246,19 @@ test_expect_success 'commit-graph auto condition' '
246 GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
247 git -c maintenance.commit-graph.auto=2 $COMMAND &&
248
238 - COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
239 - test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
240 - test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
241 - test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
242 - test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
243 - test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
249 + test_maintenance_tasks cg-no.txt <<-\EOF &&
250 + EOF
251 + test_maintenance_tasks cg-negative-means-yes.txt <<-\EOF &&
252 + commit-graph
253 + EOF
254 + test_maintenance_tasks cg-zero-means-no.txt <<-\EOF &&
255 + EOF
256 + test_maintenance_tasks cg-one-satisfied.txt <<-\EOF &&
257 + commit-graph
258 + EOF
259 + test_maintenance_tasks cg-two-satisfied.txt <<-\EOF
260 + commit-graph
261 + EOF
262 '
263
264 test_expect_success 'commit-graph auto condition with merges' '
@@ -910,24 +928,28 @@ test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
928
929 GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
930 git maintenance run --schedule=hourly 2>/dev/null &&
913 - test_subcommand git prune-packed --quiet <hourly.txt &&
914 - test_subcommand ! git commit-graph write --split --reachable \
915 - --no-progress <hourly.txt &&
916 - test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
931 + test_maintenance_tasks hourly.txt <<-\EOF &&
932 + prefetch
933 + loose-objects
934 + EOF
935
936 GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
937 git maintenance run --schedule=daily 2>/dev/null &&
920 - test_subcommand git prune-packed --quiet <daily.txt &&
921 - test_subcommand git commit-graph write --split --reachable \
922 - --no-progress <daily.txt &&
923 - test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
938 + test_maintenance_tasks daily.txt <<-\EOF &&
939 + prefetch
940 + loose-objects
941 + commit-graph
942 + EOF
943
944 GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
945 git maintenance run --schedule=weekly 2>/dev/null &&
927 - test_subcommand git prune-packed --quiet <weekly.txt &&
928 - test_subcommand git commit-graph write --split --reachable \
929 - --no-progress <weekly.txt &&
930 - test_subcommand git multi-pack-index write --no-progress <weekly.txt
946 + test_maintenance_tasks weekly.txt <<-\EOF
947 + pack-refs foreground
948 + prefetch
949 + loose-objects
950 + incremental-repack
951 + commit-graph
952 + EOF
953 '
954
955 test_expect_success 'maintenance.strategy inheritance' '
@@ -946,29 +968,25 @@ test_expect_success 'maintenance.strategy inheritance' '
968 GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \
969 git maintenance run --schedule=weekly --quiet &&
970
949 - test_subcommand git commit-graph write --split --reachable \
950 - --no-progress <incremental-hourly.txt &&
951 - test_subcommand ! git prune-packed --quiet <incremental-hourly.txt &&
952 - test_subcommand ! git multi-pack-index write --no-progress \
953 - <incremental-hourly.txt &&
954 - test_subcommand ! git pack-refs --all --prune \
955 - <incremental-hourly.txt &&
956 -
957 - test_subcommand git commit-graph write --split --reachable \
958 - --no-progress <incremental-daily.txt &&
959 - test_subcommand git prune-packed --quiet <incremental-daily.txt &&
960 - test_subcommand git multi-pack-index write --no-progress \
961 - <incremental-daily.txt &&
962 - test_subcommand ! git pack-refs --all --prune \
963 - <incremental-daily.txt &&
964 -
965 - test_subcommand git commit-graph write --split --reachable \
966 - --no-progress <incremental-weekly.txt &&
967 - test_subcommand git prune-packed --quiet <incremental-weekly.txt &&
968 - test_subcommand git multi-pack-index write --no-progress \
969 - <incremental-weekly.txt &&
970 - test_subcommand git pack-refs --all --prune \
971 - <incremental-weekly.txt &&
971 + test_maintenance_tasks incremental-hourly.txt <<-\EOF &&
972 + prefetch
973 + commit-graph
974 + EOF
975 +
976 + test_maintenance_tasks incremental-daily.txt <<-\EOF &&
977 + prefetch
978 + loose-objects
979 + incremental-repack
980 + commit-graph
981 + EOF
982 +
983 + test_maintenance_tasks incremental-weekly.txt <<-\EOF &&
984 + pack-refs foreground
985 + prefetch
986 + loose-objects
987 + incremental-repack
988 + commit-graph
989 + EOF
990
991 # Modify defaults
992 git config maintenance.commit-graph.schedule daily &&
@@ -980,30 +998,26 @@ test_expect_success 'maintenance.strategy inheritance' '
998 GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \
999 git maintenance run --schedule=daily --quiet &&
1000
983 - test_subcommand ! git commit-graph write --split --reachable \
984 - --no-progress <modified-hourly.txt &&
985 - test_subcommand git prune-packed --quiet <modified-hourly.txt &&
986 - test_subcommand ! git multi-pack-index write --no-progress \
987 - <modified-hourly.txt &&
1001 + test_maintenance_tasks modified-hourly.txt <<-\EOF &&
1002 + prefetch
1003 + loose-objects
1004 + EOF
1005
989 - test_subcommand git commit-graph write --split --reachable \
990 - --no-progress <modified-daily.txt &&
991 - test_subcommand git prune-packed --quiet <modified-daily.txt &&
992 - test_subcommand ! git multi-pack-index write --no-progress \
993 - <modified-daily.txt
1006 + test_maintenance_tasks modified-daily.txt <<-\EOF
1007 + prefetch
1008 + loose-objects
1009 + commit-graph
1010 + EOF
1011 '
1012
1013 test_strategy () {
1014 STRATEGY="$1"
1015 shift
1016
1000 - cat >expect &&
1017 rm -f trace2.txt &&
1018 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1019 git -c maintenance.strategy=$STRATEGY maintenance run --quiet "$@" &&
1004 - sed -n 's/{"event":"child_start","sid":"[^/"]*",.*,"argv":\["\(.*\)\"]}/\1/p' <trace2.txt |
1005 - sed 's/","/ /g' >actual
1006 - test_cmp expect actual
1020 + test_maintenance_tasks trace2.txt
1021 }
1022
1023 test_expect_success 'maintenance.strategy is respected' '
@@ -1017,48 +1031,44 @@ test_expect_success 'maintenance.strategy is respected' '
1031 test_grep "unknown maintenance strategy: .unknown." err &&
1032
1033 test_strategy incremental <<-\EOF &&
1020 - git pack-refs --all --prune
1021 - git reflog expire --all
1022 - git gc --quiet --no-detach --skip-foreground-tasks
1034 + gc foreground
1035 + gc
1036 EOF
1037
1038 test_strategy incremental --schedule=weekly <<-\EOF &&
1026 - git pack-refs --all --prune
1027 - git prune-packed --quiet
1028 - git multi-pack-index write --no-progress
1029 - git multi-pack-index expire --no-progress
1030 - git multi-pack-index repack --no-progress --batch-size=1
1031 - git commit-graph write --split --reachable --no-progress
1039 + pack-refs foreground
1040 + prefetch
1041 + loose-objects
1042 + incremental-repack
1043 + commit-graph
1044 EOF
1045
1046 test_strategy gc <<-\EOF &&
1035 - git pack-refs --all --prune
1036 - git reflog expire --all
1037 - git gc --quiet --no-detach --skip-foreground-tasks
1047 + gc foreground
1048 + gc
1049 EOF
1050
1051 test_strategy gc --schedule=weekly <<-\EOF &&
1041 - git pack-refs --all --prune
1042 - git reflog expire --all
1043 - git gc --quiet --no-detach --skip-foreground-tasks
1052 + gc foreground
1053 + gc
1054 EOF
1055
1056 test_strategy geometric <<-\EOF &&
1047 - git pack-refs --all --prune
1048 - git reflog expire --all
1049 - git repack -d -l --geometric=2 --quiet --write-midx
1050 - git commit-graph write --split --reachable --no-progress
1051 - git worktree prune --expire 3.months.ago
1052 - git rerere gc
1057 + pack-refs foreground
1058 + reflog-expire foreground
1059 + geometric-repack
1060 + commit-graph
1061 + worktree-prune
1062 + rerere-gc
1063 EOF
1064
1065 test_strategy geometric --schedule=weekly <<-\EOF
1056 - git pack-refs --all --prune
1057 - git reflog expire --all
1058 - git repack -d -l --geometric=2 --quiet --write-midx
1059 - git commit-graph write --split --reachable --no-progress
1060 - git worktree prune --expire 3.months.ago
1061 - git rerere gc
1066 + pack-refs foreground
1067 + reflog-expire foreground
1068 + geometric-repack
1069 + commit-graph
1070 + worktree-prune
1071 + rerere-gc
1072 EOF
1073 )
1074 '