Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git maintenance builtin' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Derrick Stolee | 663b2b1 | 2020-09-17 18:11:46 +0000 | [diff] [blame] | 7 | GIT_TEST_COMMIT_GRAPH=0 |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 8 | GIT_TEST_MULTI_PACK_INDEX=0 |
Derrick Stolee | 663b2b1 | 2020-09-17 18:11:46 +0000 | [diff] [blame] | 9 | |
Derrick Stolee | 2afe7e3 | 2021-01-05 13:08:27 +0000 | [diff] [blame] | 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 | |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 23 | test_lazy_prereq SYSTEMD_ANALYZE ' |
Lénaïc Huard | 670e597 | 2021-09-27 23:30:16 +0200 | [diff] [blame] | 24 | systemd-analyze verify /lib/systemd/system/basic.target |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 25 | ' |
| 26 | |
| 27 | test_systemd_analyze_verify () { |
| 28 | if test_have_prereq SYSTEMD_ANALYZE |
| 29 | then |
| 30 | systemd-analyze verify "$@" |
| 31 | fi |
| 32 | } |
| 33 | |
Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 34 | test_expect_success 'help text' ' |
SZEDER Gábor | 0350954 | 2022-08-19 18:04:03 +0200 | [diff] [blame] | 35 | test_expect_code 129 git maintenance -h >actual && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 36 | test_grep "usage: git maintenance <subcommand>" actual && |
SZEDER Gábor | 0350954 | 2022-08-19 18:04:03 +0200 | [diff] [blame] | 37 | test_expect_code 129 git maintenance barf 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 38 | test_grep "unknown subcommand: \`barf'\''" err && |
| 39 | test_grep "usage: git maintenance" err && |
Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 40 | test_expect_code 129 git maintenance 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 41 | test_grep "error: need a subcommand" err && |
| 42 | test_grep "usage: git maintenance" err |
Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 43 | ' |
| 44 | |
Derrick Stolee | 3ddaad0 | 2020-09-17 18:11:43 +0000 | [diff] [blame] | 45 | test_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 <run-no-auto.txt && |
Derrick Stolee | 916d062 | 2020-09-17 18:11:50 +0000 | [diff] [blame] | 53 | test_subcommand ! git gc --auto --quiet <run-auto.txt && |
Derrick Stolee | 3ddaad0 | 2020-09-17 18:11:43 +0000 | [diff] [blame] | 54 | test_subcommand git gc --no-quiet <run-no-quiet.txt |
Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 55 | ' |
| 56 | |
Derrick Stolee | 1942d48 | 2020-08-28 15:45:12 +0000 | [diff] [blame] | 57 | test_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 <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 <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 <false |
| 68 | ' |
| 69 | |
Kristoffer Haugsbakk | 74e1219 | 2024-01-18 17:12:52 +0100 | [diff] [blame] | 70 | test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' ' |
| 71 | test_when_finished rm -r .config/git/config && |
| 72 | ( |
| 73 | XDG_CONFIG_HOME=.config && |
| 74 | export XDG_CONFIG_HOME && |
| 75 | mkdir -p $XDG_CONFIG_HOME/git && |
| 76 | >$XDG_CONFIG_HOME/git/config && |
| 77 | git maintenance register && |
| 78 | git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual && |
| 79 | pwd >expect && |
| 80 | test_cmp expect actual |
| 81 | ) |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'register does not need XDG_CONFIG_HOME config to exist' ' |
| 85 | test_when_finished git maintenance unregister && |
| 86 | test_path_is_missing $XDG_CONFIG_HOME/git/config && |
| 87 | git maintenance register && |
| 88 | git config --global --get maintenance.repo >actual && |
| 89 | pwd >expect && |
| 90 | test_cmp expect actual |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'unregister uses XDG_CONFIG_HOME config if it exists' ' |
| 94 | test_when_finished rm -r .config/git/config && |
| 95 | ( |
| 96 | XDG_CONFIG_HOME=.config && |
| 97 | export XDG_CONFIG_HOME && |
| 98 | mkdir -p $XDG_CONFIG_HOME/git && |
| 99 | >$XDG_CONFIG_HOME/git/config && |
| 100 | git maintenance register && |
| 101 | git maintenance unregister && |
| 102 | test_must_fail git config --file=$XDG_CONFIG_HOME/git/config --get maintenance.repo >actual && |
| 103 | test_must_be_empty actual |
| 104 | ) |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'unregister does not need XDG_CONFIG_HOME config to exist' ' |
| 108 | test_path_is_missing $XDG_CONFIG_HOME/git/config && |
| 109 | git maintenance register && |
| 110 | git maintenance unregister && |
| 111 | test_must_fail git config --global --get maintenance.repo >actual && |
| 112 | test_must_be_empty actual |
| 113 | ' |
| 114 | |
Derrick Stolee | 65d655b | 2020-09-17 18:11:49 +0000 | [diff] [blame] | 115 | test_expect_success 'maintenance.<task>.enabled' ' |
| 116 | git config maintenance.gc.enabled false && |
| 117 | git config maintenance.commit-graph.enabled true && |
| 118 | GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err && |
| 119 | test_subcommand ! git gc --quiet <run-config.txt && |
| 120 | test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt |
| 121 | ' |
| 122 | |
Derrick Stolee | 090511b | 2020-09-17 18:11:47 +0000 | [diff] [blame] | 123 | test_expect_success 'run --task=<task>' ' |
| 124 | GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ |
| 125 | git maintenance run --task=commit-graph 2>/dev/null && |
| 126 | GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \ |
| 127 | git maintenance run --task=gc 2>/dev/null && |
| 128 | GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ |
| 129 | git maintenance run --task=commit-graph 2>/dev/null && |
| 130 | GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \ |
| 131 | git maintenance run --task=commit-graph --task=gc 2>/dev/null && |
| 132 | test_subcommand ! git gc --quiet <run-commit-graph.txt && |
| 133 | test_subcommand git gc --quiet <run-gc.txt && |
| 134 | test_subcommand git gc --quiet <run-both.txt && |
| 135 | test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt && |
| 136 | test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt && |
| 137 | test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt |
| 138 | ' |
| 139 | |
Derrick Stolee | d334107 | 2020-10-12 13:28:34 +0000 | [diff] [blame] | 140 | test_expect_success 'core.commitGraph=false prevents write process' ' |
| 141 | GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \ |
| 142 | git -c core.commitGraph=false maintenance run \ |
| 143 | --task=commit-graph 2>/dev/null && |
| 144 | test_subcommand ! git commit-graph write --split --reachable --no-progress \ |
| 145 | <no-commit-graph.txt |
| 146 | ' |
| 147 | |
Derrick Stolee | 8f80180 | 2020-10-08 00:50:39 +0000 | [diff] [blame] | 148 | test_expect_success 'commit-graph auto condition' ' |
| 149 | COMMAND="maintenance run --task=commit-graph --auto --quiet" && |
| 150 | |
| 151 | GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \ |
| 152 | git -c maintenance.commit-graph.auto=1 $COMMAND && |
| 153 | GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \ |
| 154 | git -c maintenance.commit-graph.auto="-1" $COMMAND && |
| 155 | |
| 156 | test_commit first && |
| 157 | |
| 158 | GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \ |
| 159 | git -c maintenance.commit-graph.auto=0 $COMMAND && |
| 160 | GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \ |
| 161 | git -c maintenance.commit-graph.auto=1 $COMMAND && |
| 162 | |
| 163 | git commit --allow-empty -m "second" && |
| 164 | git commit --allow-empty -m "third" && |
| 165 | |
| 166 | GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \ |
| 167 | git -c maintenance.commit-graph.auto=2 $COMMAND && |
| 168 | |
| 169 | COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" && |
| 170 | test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt && |
| 171 | test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt && |
| 172 | test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt && |
| 173 | test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt && |
| 174 | test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt |
| 175 | ' |
| 176 | |
Derrick Stolee | 090511b | 2020-09-17 18:11:47 +0000 | [diff] [blame] | 177 | test_expect_success 'run --task=bogus' ' |
| 178 | test_must_fail git maintenance run --task=bogus 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 179 | test_grep "is not a valid task" err |
Derrick Stolee | 090511b | 2020-09-17 18:11:47 +0000 | [diff] [blame] | 180 | ' |
| 181 | |
| 182 | test_expect_success 'run --task duplicate' ' |
| 183 | test_must_fail git maintenance run --task=gc --task=gc 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 184 | test_grep "cannot be selected multiple times" err |
Derrick Stolee | 090511b | 2020-09-17 18:11:47 +0000 | [diff] [blame] | 185 | ' |
| 186 | |
Derrick Stolee | 28cb5e6 | 2020-09-25 12:33:31 +0000 | [diff] [blame] | 187 | test_expect_success 'run --task=prefetch with no remotes' ' |
| 188 | git maintenance run --task=prefetch 2>err && |
| 189 | test_must_be_empty err |
| 190 | ' |
| 191 | |
| 192 | test_expect_success 'prefetch multiple remotes' ' |
| 193 | git clone . clone1 && |
| 194 | git clone . clone2 && |
| 195 | git remote add remote1 "file://$(pwd)/clone1" && |
| 196 | git remote add remote2 "file://$(pwd)/clone2" && |
| 197 | git -C clone1 switch -c one && |
| 198 | git -C clone2 switch -c two && |
| 199 | test_commit -C clone1 one && |
| 200 | test_commit -C clone2 two && |
| 201 | GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null && |
Derrick Stolee | cfd781e | 2021-04-16 12:49:58 +0000 | [diff] [blame] | 202 | fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" && |
| 203 | test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt && |
| 204 | test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt && |
Patrick Steinhardt | 170ba45 | 2023-11-02 09:47:10 +0100 | [diff] [blame] | 205 | git for-each-ref refs/remotes >actual && |
| 206 | test_must_be_empty actual && |
Derrick Stolee | cfd781e | 2021-04-16 12:49:58 +0000 | [diff] [blame] | 207 | git log prefetch/remotes/remote1/one && |
| 208 | git log prefetch/remotes/remote2/two && |
Derrick Stolee | 28cb5e6 | 2020-09-25 12:33:31 +0000 | [diff] [blame] | 209 | git fetch --all && |
Derrick Stolee | cfd781e | 2021-04-16 12:49:58 +0000 | [diff] [blame] | 210 | test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one && |
| 211 | test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two && |
Derrick Stolee | 96eaffe | 2021-01-19 12:52:03 +0000 | [diff] [blame] | 212 | |
Derrick Stolee | 96eaffe | 2021-01-19 12:52:03 +0000 | [diff] [blame] | 213 | git log --oneline --decorate --all >log && |
Derrick Stolee | 32f6788 | 2021-04-16 12:49:59 +0000 | [diff] [blame] | 214 | ! grep "prefetch" log && |
| 215 | |
| 216 | test_when_finished git config --unset remote.remote1.skipFetchAll && |
| 217 | git config remote.remote1.skipFetchAll true && |
| 218 | GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null && |
| 219 | test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt && |
| 220 | test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt |
Derrick Stolee | 96eaffe | 2021-01-19 12:52:03 +0000 | [diff] [blame] | 221 | ' |
| 222 | |
Derrick Stolee | 252cfb7 | 2020-09-25 12:33:32 +0000 | [diff] [blame] | 223 | test_expect_success 'loose-objects task' ' |
| 224 | # Repack everything so we know the state of the object dir |
| 225 | git repack -adk && |
| 226 | |
| 227 | # Hack to stop maintenance from running during "git commit" |
| 228 | echo in use >.git/objects/maintenance.lock && |
| 229 | |
| 230 | # Assuming that "git commit" creates at least one loose object |
| 231 | test_commit create-loose-object && |
| 232 | rm .git/objects/maintenance.lock && |
| 233 | |
| 234 | ls .git/objects >obj-dir-before && |
| 235 | test_file_not_empty obj-dir-before && |
| 236 | ls .git/objects/pack/*.pack >packs-before && |
| 237 | test_line_count = 1 packs-before && |
| 238 | |
| 239 | # The first run creates a pack-file |
| 240 | # but does not delete loose objects. |
| 241 | git maintenance run --task=loose-objects && |
| 242 | ls .git/objects >obj-dir-between && |
| 243 | test_cmp obj-dir-before obj-dir-between && |
| 244 | ls .git/objects/pack/*.pack >packs-between && |
| 245 | test_line_count = 2 packs-between && |
| 246 | ls .git/objects/pack/loose-*.pack >loose-packs && |
| 247 | test_line_count = 1 loose-packs && |
| 248 | |
| 249 | # The second run deletes loose objects |
| 250 | # but does not create a pack-file. |
| 251 | git maintenance run --task=loose-objects && |
| 252 | ls .git/objects >obj-dir-after && |
| 253 | cat >expect <<-\EOF && |
| 254 | info |
| 255 | pack |
| 256 | EOF |
| 257 | test_cmp expect obj-dir-after && |
| 258 | ls .git/objects/pack/*.pack >packs-after && |
| 259 | test_cmp packs-between packs-after |
| 260 | ' |
| 261 | |
Derrick Stolee | 3e220e6 | 2020-09-25 12:33:33 +0000 | [diff] [blame] | 262 | test_expect_success 'maintenance.loose-objects.auto' ' |
| 263 | git repack -adk && |
| 264 | GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \ |
| 265 | git -c maintenance.loose-objects.auto=1 maintenance \ |
| 266 | run --auto --task=loose-objects 2>/dev/null && |
| 267 | test_subcommand ! git prune-packed --quiet <trace-lo1.txt && |
| 268 | printf data-A | git hash-object -t blob --stdin -w && |
| 269 | GIT_TRACE2_EVENT="$(pwd)/trace-loA" \ |
| 270 | git -c maintenance.loose-objects.auto=2 \ |
| 271 | maintenance run --auto --task=loose-objects 2>/dev/null && |
| 272 | test_subcommand ! git prune-packed --quiet <trace-loA && |
| 273 | printf data-B | git hash-object -t blob --stdin -w && |
| 274 | GIT_TRACE2_EVENT="$(pwd)/trace-loB" \ |
| 275 | git -c maintenance.loose-objects.auto=2 \ |
| 276 | maintenance run --auto --task=loose-objects 2>/dev/null && |
| 277 | test_subcommand git prune-packed --quiet <trace-loB && |
| 278 | GIT_TRACE2_EVENT="$(pwd)/trace-loC" \ |
| 279 | git -c maintenance.loose-objects.auto=2 \ |
| 280 | maintenance run --auto --task=loose-objects 2>/dev/null && |
| 281 | test_subcommand git prune-packed --quiet <trace-loC |
| 282 | ' |
| 283 | |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 284 | test_expect_success 'incremental-repack task' ' |
| 285 | packDir=.git/objects/pack && |
| 286 | for i in $(test_seq 1 5) |
| 287 | do |
| 288 | test_commit $i || return 1 |
| 289 | done && |
| 290 | |
| 291 | # Create three disjoint pack-files with size BIG, small, small. |
| 292 | echo HEAD~2 | git pack-objects --revs $packDir/test-1 && |
| 293 | test_tick && |
| 294 | git pack-objects --revs $packDir/test-2 <<-\EOF && |
| 295 | HEAD~1 |
| 296 | ^HEAD~2 |
| 297 | EOF |
| 298 | test_tick && |
| 299 | git pack-objects --revs $packDir/test-3 <<-\EOF && |
| 300 | HEAD |
| 301 | ^HEAD~1 |
| 302 | EOF |
Derrick Stolee | 3cf5f22 | 2021-01-19 12:52:04 +0000 | [diff] [blame] | 303 | |
| 304 | # Delete refs that have not been repacked in these packs. |
| 305 | git for-each-ref --format="delete %(refname)" \ |
Jeff King | b472424 | 2021-09-24 14:32:17 -0400 | [diff] [blame] | 306 | refs/prefetch refs/tags refs/remotes >refs && |
Derrick Stolee | 3cf5f22 | 2021-01-19 12:52:04 +0000 | [diff] [blame] | 307 | git update-ref --stdin <refs && |
| 308 | |
| 309 | # Replace the object directory with this pack layout. |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 310 | rm -f $packDir/pack-* && |
| 311 | rm -f $packDir/loose-* && |
| 312 | ls $packDir/*.pack >packs-before && |
| 313 | test_line_count = 3 packs-before && |
| 314 | |
Jeff King | b472424 | 2021-09-24 14:32:17 -0400 | [diff] [blame] | 315 | # make sure we do not have any broken refs that were |
| 316 | # missed in the deletion above |
| 317 | git for-each-ref && |
| 318 | |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 319 | # the job repacks the two into a new pack, but does not |
| 320 | # delete the old ones. |
| 321 | git maintenance run --task=incremental-repack && |
| 322 | ls $packDir/*.pack >packs-between && |
| 323 | test_line_count = 4 packs-between && |
| 324 | |
| 325 | # the job deletes the two old packs, and does not write |
Derrick Stolee | a13e3d0 | 2020-09-25 12:33:37 +0000 | [diff] [blame] | 326 | # a new one because the batch size is not high enough to |
| 327 | # pack the largest pack-file. |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 328 | git maintenance run --task=incremental-repack && |
| 329 | ls .git/objects/pack/*.pack >packs-after && |
Derrick Stolee | a13e3d0 | 2020-09-25 12:33:37 +0000 | [diff] [blame] | 330 | test_line_count = 2 packs-after |
| 331 | ' |
| 332 | |
| 333 | test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' |
Jeff King | a0c5ccc | 2020-12-01 21:47:56 -0500 | [diff] [blame] | 334 | test_config core.compression 0 && |
| 335 | |
Derrick Stolee | a13e3d0 | 2020-09-25 12:33:37 +0000 | [diff] [blame] | 336 | for i in $(test_seq 1 5) |
| 337 | do |
| 338 | test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || |
| 339 | return 1 |
| 340 | done && |
| 341 | git add big && |
Jeff King | a0c5ccc | 2020-12-01 21:47:56 -0500 | [diff] [blame] | 342 | git commit -qm "Add big file (1)" && |
Derrick Stolee | a13e3d0 | 2020-09-25 12:33:37 +0000 | [diff] [blame] | 343 | |
| 344 | # ensure any possible loose objects are in a pack-file |
| 345 | git maintenance run --task=loose-objects && |
| 346 | |
| 347 | rm big && |
| 348 | for i in $(test_seq 6 10) |
| 349 | do |
| 350 | test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || |
| 351 | return 1 |
| 352 | done && |
| 353 | git add big && |
Jeff King | a0c5ccc | 2020-12-01 21:47:56 -0500 | [diff] [blame] | 354 | git commit -qm "Add big file (2)" && |
Derrick Stolee | a13e3d0 | 2020-09-25 12:33:37 +0000 | [diff] [blame] | 355 | |
| 356 | # ensure any possible loose objects are in a pack-file |
| 357 | git maintenance run --task=loose-objects && |
| 358 | |
| 359 | # Now run the incremental-repack task and check the batch-size |
| 360 | GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \ |
| 361 | --task=incremental-repack 2>/dev/null && |
| 362 | test_subcommand git multi-pack-index repack \ |
| 363 | --no-progress --batch-size=2147483647 <run-2g.txt |
Derrick Stolee | 52fe41f | 2020-09-25 12:33:36 +0000 | [diff] [blame] | 364 | ' |
| 365 | |
Glen Choo | a897ab7 | 2021-10-15 13:16:31 -0700 | [diff] [blame] | 366 | run_incremental_repack_and_verify () { |
| 367 | test_commit A && |
Derrick Stolee | e841a79 | 2020-09-25 12:33:38 +0000 | [diff] [blame] | 368 | git repack -adk && |
Derrick Stolee | e841a79 | 2020-09-25 12:33:38 +0000 | [diff] [blame] | 369 | git multi-pack-index write && |
| 370 | GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \ |
| 371 | -c maintenance.incremental-repack.auto=1 \ |
| 372 | maintenance run --auto --task=incremental-repack 2>/dev/null && |
| 373 | test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt && |
Glen Choo | a897ab7 | 2021-10-15 13:16:31 -0700 | [diff] [blame] | 374 | test_commit B && |
Derrick Stolee | e841a79 | 2020-09-25 12:33:38 +0000 | [diff] [blame] | 375 | git pack-objects --revs .git/objects/pack/pack <<-\EOF && |
| 376 | HEAD |
| 377 | ^HEAD~1 |
| 378 | EOF |
| 379 | GIT_TRACE2_EVENT=$(pwd)/trace-A git \ |
| 380 | -c maintenance.incremental-repack.auto=2 \ |
| 381 | maintenance run --auto --task=incremental-repack 2>/dev/null && |
| 382 | test_subcommand ! git multi-pack-index write --no-progress <trace-A && |
Glen Choo | a897ab7 | 2021-10-15 13:16:31 -0700 | [diff] [blame] | 383 | test_commit C && |
Derrick Stolee | e841a79 | 2020-09-25 12:33:38 +0000 | [diff] [blame] | 384 | git pack-objects --revs .git/objects/pack/pack <<-\EOF && |
| 385 | HEAD |
| 386 | ^HEAD~1 |
| 387 | EOF |
| 388 | GIT_TRACE2_EVENT=$(pwd)/trace-B git \ |
| 389 | -c maintenance.incremental-repack.auto=2 \ |
| 390 | maintenance run --auto --task=incremental-repack 2>/dev/null && |
| 391 | test_subcommand git multi-pack-index write --no-progress <trace-B |
Glen Choo | a897ab7 | 2021-10-15 13:16:31 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | test_expect_success 'maintenance.incremental-repack.auto' ' |
| 395 | rm -rf incremental-repack-true && |
| 396 | git init incremental-repack-true && |
| 397 | ( |
| 398 | cd incremental-repack-true && |
| 399 | git config core.multiPackIndex true && |
| 400 | run_incremental_repack_and_verify |
| 401 | ) |
| 402 | ' |
| 403 | |
| 404 | test_expect_success 'maintenance.incremental-repack.auto (when config is unset)' ' |
| 405 | rm -rf incremental-repack-unset && |
| 406 | git init incremental-repack-unset && |
| 407 | ( |
| 408 | cd incremental-repack-unset && |
| 409 | test_unconfig core.multiPackIndex && |
| 410 | run_incremental_repack_and_verify |
| 411 | ) |
Derrick Stolee | e841a79 | 2020-09-25 12:33:38 +0000 | [diff] [blame] | 412 | ' |
| 413 | |
Derrick Stolee | 41abfe1 | 2021-02-09 13:42:28 +0000 | [diff] [blame] | 414 | test_expect_success 'pack-refs task' ' |
| 415 | for n in $(test_seq 1 5) |
| 416 | do |
| 417 | git branch -f to-pack/$n HEAD || return 1 |
| 418 | done && |
| 419 | GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \ |
| 420 | git maintenance run --task=pack-refs && |
Derrick Stolee | 41abfe1 | 2021-02-09 13:42:28 +0000 | [diff] [blame] | 421 | test_subcommand git pack-refs --all --prune <pack-refs.txt |
| 422 | ' |
| 423 | |
Derrick Stolee | b08ff1f | 2020-09-11 17:49:15 +0000 | [diff] [blame] | 424 | test_expect_success '--auto and --schedule incompatible' ' |
| 425 | test_must_fail git maintenance run --auto --schedule=daily 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 426 | test_grep "at most one" err |
Derrick Stolee | b08ff1f | 2020-09-11 17:49:15 +0000 | [diff] [blame] | 427 | ' |
| 428 | |
| 429 | test_expect_success 'invalid --schedule value' ' |
| 430 | test_must_fail git maintenance run --schedule=annually 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 431 | test_grep "unrecognized --schedule" err |
Derrick Stolee | b08ff1f | 2020-09-11 17:49:15 +0000 | [diff] [blame] | 432 | ' |
| 433 | |
| 434 | test_expect_success '--schedule inheritance weekly -> daily -> hourly' ' |
| 435 | git config maintenance.loose-objects.enabled true && |
| 436 | git config maintenance.loose-objects.schedule hourly && |
| 437 | git config maintenance.commit-graph.enabled true && |
| 438 | git config maintenance.commit-graph.schedule daily && |
| 439 | git config maintenance.incremental-repack.enabled true && |
| 440 | git config maintenance.incremental-repack.schedule weekly && |
| 441 | |
| 442 | GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \ |
| 443 | git maintenance run --schedule=hourly 2>/dev/null && |
| 444 | test_subcommand git prune-packed --quiet <hourly.txt && |
| 445 | test_subcommand ! git commit-graph write --split --reachable \ |
| 446 | --no-progress <hourly.txt && |
| 447 | test_subcommand ! git multi-pack-index write --no-progress <hourly.txt && |
| 448 | |
| 449 | GIT_TRACE2_EVENT="$(pwd)/daily.txt" \ |
| 450 | git maintenance run --schedule=daily 2>/dev/null && |
| 451 | test_subcommand git prune-packed --quiet <daily.txt && |
| 452 | test_subcommand git commit-graph write --split --reachable \ |
| 453 | --no-progress <daily.txt && |
| 454 | test_subcommand ! git multi-pack-index write --no-progress <daily.txt && |
| 455 | |
| 456 | GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \ |
| 457 | git maintenance run --schedule=weekly 2>/dev/null && |
| 458 | test_subcommand git prune-packed --quiet <weekly.txt && |
| 459 | test_subcommand git commit-graph write --split --reachable \ |
| 460 | --no-progress <weekly.txt && |
| 461 | test_subcommand git multi-pack-index write --no-progress <weekly.txt |
| 462 | ' |
| 463 | |
Derrick Stolee | a4cb1a2 | 2020-10-15 17:22:02 +0000 | [diff] [blame] | 464 | test_expect_success 'maintenance.strategy inheritance' ' |
| 465 | for task in commit-graph loose-objects incremental-repack |
| 466 | do |
| 467 | git config --unset maintenance.$task.schedule || return 1 |
| 468 | done && |
| 469 | |
| 470 | test_when_finished git config --unset maintenance.strategy && |
| 471 | git config maintenance.strategy incremental && |
| 472 | |
| 473 | GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \ |
| 474 | git maintenance run --schedule=hourly --quiet && |
| 475 | GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \ |
| 476 | git maintenance run --schedule=daily --quiet && |
Derrick Stolee | acc1c4d | 2021-02-09 13:42:29 +0000 | [diff] [blame] | 477 | GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \ |
| 478 | git maintenance run --schedule=weekly --quiet && |
Derrick Stolee | a4cb1a2 | 2020-10-15 17:22:02 +0000 | [diff] [blame] | 479 | |
| 480 | test_subcommand git commit-graph write --split --reachable \ |
| 481 | --no-progress <incremental-hourly.txt && |
| 482 | test_subcommand ! git prune-packed --quiet <incremental-hourly.txt && |
| 483 | test_subcommand ! git multi-pack-index write --no-progress \ |
| 484 | <incremental-hourly.txt && |
Derrick Stolee | acc1c4d | 2021-02-09 13:42:29 +0000 | [diff] [blame] | 485 | test_subcommand ! git pack-refs --all --prune \ |
| 486 | <incremental-hourly.txt && |
Derrick Stolee | a4cb1a2 | 2020-10-15 17:22:02 +0000 | [diff] [blame] | 487 | |
| 488 | test_subcommand git commit-graph write --split --reachable \ |
| 489 | --no-progress <incremental-daily.txt && |
| 490 | test_subcommand git prune-packed --quiet <incremental-daily.txt && |
| 491 | test_subcommand git multi-pack-index write --no-progress \ |
| 492 | <incremental-daily.txt && |
Derrick Stolee | acc1c4d | 2021-02-09 13:42:29 +0000 | [diff] [blame] | 493 | test_subcommand ! git pack-refs --all --prune \ |
| 494 | <incremental-daily.txt && |
| 495 | |
| 496 | test_subcommand git commit-graph write --split --reachable \ |
| 497 | --no-progress <incremental-weekly.txt && |
| 498 | test_subcommand git prune-packed --quiet <incremental-weekly.txt && |
| 499 | test_subcommand git multi-pack-index write --no-progress \ |
| 500 | <incremental-weekly.txt && |
| 501 | test_subcommand git pack-refs --all --prune \ |
| 502 | <incremental-weekly.txt && |
Derrick Stolee | a4cb1a2 | 2020-10-15 17:22:02 +0000 | [diff] [blame] | 503 | |
| 504 | # Modify defaults |
| 505 | git config maintenance.commit-graph.schedule daily && |
| 506 | git config maintenance.loose-objects.schedule hourly && |
| 507 | git config maintenance.incremental-repack.enabled false && |
| 508 | |
| 509 | GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \ |
| 510 | git maintenance run --schedule=hourly --quiet && |
| 511 | GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \ |
| 512 | git maintenance run --schedule=daily --quiet && |
| 513 | |
| 514 | test_subcommand ! git commit-graph write --split --reachable \ |
| 515 | --no-progress <modified-hourly.txt && |
| 516 | test_subcommand git prune-packed --quiet <modified-hourly.txt && |
| 517 | test_subcommand ! git multi-pack-index write --no-progress \ |
| 518 | <modified-hourly.txt && |
| 519 | |
| 520 | test_subcommand git commit-graph write --split --reachable \ |
| 521 | --no-progress <modified-daily.txt && |
| 522 | test_subcommand git prune-packed --quiet <modified-daily.txt && |
| 523 | test_subcommand ! git multi-pack-index write --no-progress \ |
| 524 | <modified-daily.txt |
| 525 | ' |
| 526 | |
Derrick Stolee | 0c18b70 | 2020-09-11 17:49:17 +0000 | [diff] [blame] | 527 | test_expect_success 'register and unregister' ' |
| 528 | test_when_finished git config --global --unset-all maintenance.repo && |
Derrick Stolee | 1ebe6b0 | 2022-09-27 13:56:58 +0000 | [diff] [blame] | 529 | |
| 530 | test_must_fail git maintenance unregister 2>err && |
| 531 | grep "is not registered" err && |
| 532 | git maintenance unregister --force && |
| 533 | |
Derrick Stolee | 0c18b70 | 2020-09-11 17:49:17 +0000 | [diff] [blame] | 534 | git config --global --add maintenance.repo /existing1 && |
| 535 | git config --global --add maintenance.repo /existing2 && |
| 536 | git config --global --get-all maintenance.repo >before && |
Derrick Stolee | 61f7a38 | 2020-10-15 17:22:03 +0000 | [diff] [blame] | 537 | |
Derrick Stolee | 0c18b70 | 2020-09-11 17:49:17 +0000 | [diff] [blame] | 538 | git maintenance register && |
Derrick Stolee | 61f7a38 | 2020-10-15 17:22:03 +0000 | [diff] [blame] | 539 | test_cmp_config false maintenance.auto && |
| 540 | git config --global --get-all maintenance.repo >between && |
| 541 | cp before expect && |
| 542 | pwd >>expect && |
| 543 | test_cmp expect between && |
| 544 | |
Derrick Stolee | 0c18b70 | 2020-09-11 17:49:17 +0000 | [diff] [blame] | 545 | git maintenance unregister && |
| 546 | git config --global --get-all maintenance.repo >actual && |
Derrick Stolee | 1ebe6b0 | 2022-09-27 13:56:58 +0000 | [diff] [blame] | 547 | test_cmp before actual && |
| 548 | |
Ronan Pigott | 1f80129 | 2022-11-09 12:07:08 -0700 | [diff] [blame] | 549 | git config --file ./other --add maintenance.repo /existing1 && |
| 550 | git config --file ./other --add maintenance.repo /existing2 && |
| 551 | git config --file ./other --get-all maintenance.repo >before && |
| 552 | |
| 553 | git maintenance register --config-file ./other && |
| 554 | test_cmp_config false maintenance.auto && |
| 555 | git config --file ./other --get-all maintenance.repo >between && |
| 556 | cp before expect && |
| 557 | pwd >>expect && |
| 558 | test_cmp expect between && |
| 559 | |
| 560 | git maintenance unregister --config-file ./other && |
| 561 | git config --file ./other --get-all maintenance.repo >actual && |
| 562 | test_cmp before actual && |
| 563 | |
Derrick Stolee | 1ebe6b0 | 2022-09-27 13:56:58 +0000 | [diff] [blame] | 564 | test_must_fail git maintenance unregister 2>err && |
| 565 | grep "is not registered" err && |
Ronan Pigott | 1f80129 | 2022-11-09 12:07:08 -0700 | [diff] [blame] | 566 | git maintenance unregister --force && |
| 567 | |
| 568 | test_must_fail git maintenance unregister --config-file ./other 2>err && |
| 569 | grep "is not registered" err && |
| 570 | git maintenance unregister --config-file ./other --force |
Derrick Stolee | 0c18b70 | 2020-09-11 17:49:17 +0000 | [diff] [blame] | 571 | ' |
| 572 | |
Ævar Arnfjörð Bjarmason | 9e2d884 | 2023-03-28 16:04:27 +0200 | [diff] [blame] | 573 | test_expect_success 'register with no value for maintenance.repo' ' |
Ævar Arnfjörð Bjarmason | 1c7e239 | 2023-03-28 16:04:26 +0200 | [diff] [blame] | 574 | cp .git/config .git/config.orig && |
| 575 | test_when_finished mv .git/config.orig .git/config && |
| 576 | |
| 577 | cat >>.git/config <<-\EOF && |
| 578 | [maintenance] |
| 579 | repo |
| 580 | EOF |
Ævar Arnfjörð Bjarmason | 9e2d884 | 2023-03-28 16:04:27 +0200 | [diff] [blame] | 581 | cat >expect <<-\EOF && |
| 582 | error: missing value for '\''maintenance.repo'\'' |
| 583 | EOF |
| 584 | git maintenance register 2>actual && |
| 585 | test_cmp expect actual && |
| 586 | git config maintenance.repo |
Ævar Arnfjörð Bjarmason | 1c7e239 | 2023-03-28 16:04:26 +0200 | [diff] [blame] | 587 | ' |
| 588 | |
Ævar Arnfjörð Bjarmason | 9e2d884 | 2023-03-28 16:04:27 +0200 | [diff] [blame] | 589 | test_expect_success 'unregister with no value for maintenance.repo' ' |
Ævar Arnfjörð Bjarmason | 1c7e239 | 2023-03-28 16:04:26 +0200 | [diff] [blame] | 590 | cp .git/config .git/config.orig && |
| 591 | test_when_finished mv .git/config.orig .git/config && |
| 592 | |
| 593 | cat >>.git/config <<-\EOF && |
| 594 | [maintenance] |
| 595 | repo |
| 596 | EOF |
Ævar Arnfjörð Bjarmason | 9e2d884 | 2023-03-28 16:04:27 +0200 | [diff] [blame] | 597 | cat >expect <<-\EOF && |
| 598 | error: missing value for '\''maintenance.repo'\'' |
| 599 | EOF |
| 600 | test_expect_code 128 git maintenance unregister 2>actual.raw && |
| 601 | grep ^error actual.raw >actual && |
| 602 | test_cmp expect actual && |
| 603 | git config maintenance.repo && |
| 604 | |
| 605 | git maintenance unregister --force 2>actual.raw && |
| 606 | grep ^error actual.raw >actual && |
| 607 | test_cmp expect actual && |
| 608 | git config maintenance.repo |
Ævar Arnfjörð Bjarmason | 1c7e239 | 2023-03-28 16:04:26 +0200 | [diff] [blame] | 609 | ' |
| 610 | |
Derrick Stolee | 483a6d9 | 2020-11-25 22:12:56 +0000 | [diff] [blame] | 611 | test_expect_success !MINGW 'register and unregister with regex metacharacters' ' |
| 612 | META="a+b*c" && |
| 613 | git init "$META" && |
| 614 | git -C "$META" maintenance register && |
| 615 | git config --get-all --show-origin maintenance.repo && |
| 616 | git config --get-all --global --fixed-value \ |
| 617 | maintenance.repo "$(pwd)/$META" && |
| 618 | git -C "$META" maintenance unregister && |
| 619 | test_must_fail git config --get-all --global --fixed-value \ |
| 620 | maintenance.repo "$(pwd)/$META" |
| 621 | ' |
| 622 | |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 623 | test_expect_success 'start --scheduler=<scheduler>' ' |
| 624 | test_expect_code 129 git maintenance start --scheduler=foo 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 625 | test_grep "unrecognized --scheduler argument" err && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 626 | |
| 627 | test_expect_code 129 git maintenance start --no-scheduler 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 628 | test_grep "unknown option" err && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 629 | |
| 630 | test_expect_code 128 \ |
| 631 | env GIT_TEST_MAINT_SCHEDULER="launchctl:true,schtasks:true" \ |
| 632 | git maintenance start --scheduler=crontab 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 633 | test_grep "fatal: crontab scheduler is not available" err |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 634 | ' |
| 635 | |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 636 | test_expect_success 'start from empty cron table' ' |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 637 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 638 | |
| 639 | # start registers the repo |
Josh Steadmon | 610a3fc | 2020-12-09 11:16:16 -0800 | [diff] [blame] | 640 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 641 | |
Johannes Schindelin | c75662b | 2024-04-24 16:14:59 +0000 | [diff] [blame] | 642 | grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=daily" cron.txt && |
| 643 | grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=hourly" cron.txt && |
| 644 | grep "for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=weekly" cron.txt |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 645 | ' |
| 646 | |
| 647 | test_expect_success 'stop from existing schedule' ' |
Derrick Stolee | 31345d5 | 2020-11-24 04:16:42 +0000 | [diff] [blame] | 648 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 649 | |
| 650 | # stop does not unregister the repo |
Josh Steadmon | 610a3fc | 2020-12-09 11:16:16 -0800 | [diff] [blame] | 651 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 652 | |
| 653 | # Operation is idempotent |
Derrick Stolee | 31345d5 | 2020-11-24 04:16:42 +0000 | [diff] [blame] | 654 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 655 | test_must_be_empty cron.txt |
| 656 | ' |
| 657 | |
| 658 | test_expect_success 'start preserves existing schedule' ' |
| 659 | echo "Important information!" >cron.txt && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 660 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 661 | grep "Important information!" cron.txt |
| 662 | ' |
| 663 | |
Martin Ågren | a52df25 | 2020-12-21 22:26:33 +0100 | [diff] [blame] | 664 | test_expect_success 'magic markers are correct' ' |
| 665 | grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual && |
| 666 | cat >expect <<-\EOF && |
| 667 | # BEGIN GIT MAINTENANCE SCHEDULE |
| 668 | # END GIT MAINTENANCE SCHEDULE |
| 669 | EOF |
| 670 | test_cmp actual expect |
| 671 | ' |
| 672 | |
Martin Ågren | 66dc0a3 | 2020-12-21 22:26:32 +0100 | [diff] [blame] | 673 | test_expect_success 'stop preserves surrounding schedule' ' |
| 674 | echo "Crucial information!" >>cron.txt && |
Junio C Hamano | b2ace18 | 2021-01-15 21:48:45 -0800 | [diff] [blame] | 675 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
Martin Ågren | 66dc0a3 | 2020-12-21 22:26:32 +0100 | [diff] [blame] | 676 | grep "Important information!" cron.txt && |
| 677 | grep "Crucial information!" cron.txt |
| 678 | ' |
| 679 | |
Derrick Stolee | 2afe7e3 | 2021-01-05 13:08:27 +0000 | [diff] [blame] | 680 | test_expect_success 'start and stop macOS maintenance' ' |
| 681 | # ensure $HOME can be compared against hook arguments on all platforms |
| 682 | pfx=$(cd "$HOME" && pwd) && |
| 683 | |
| 684 | write_script print-args <<-\EOF && |
| 685 | echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args |
| 686 | EOF |
| 687 | |
| 688 | rm -f args && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 689 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
Derrick Stolee | 2afe7e3 | 2021-01-05 13:08:27 +0000 | [diff] [blame] | 690 | |
| 691 | # start registers the repo |
Junio C Hamano | b2ace18 | 2021-01-15 21:48:45 -0800 | [diff] [blame] | 692 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 2afe7e3 | 2021-01-05 13:08:27 +0000 | [diff] [blame] | 693 | |
| 694 | ls "$HOME/Library/LaunchAgents" >actual && |
| 695 | cat >expect <<-\EOF && |
| 696 | org.git-scm.git.daily.plist |
| 697 | org.git-scm.git.hourly.plist |
| 698 | org.git-scm.git.weekly.plist |
| 699 | EOF |
| 700 | test_cmp expect actual && |
| 701 | |
| 702 | rm -f expect && |
| 703 | for frequency in hourly daily weekly |
| 704 | do |
| 705 | PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && |
| 706 | test_xmllint "$PLIST" && |
| 707 | grep schedule=$frequency "$PLIST" && |
| 708 | echo "bootout gui/[UID] $PLIST" >>expect && |
| 709 | echo "bootstrap gui/[UID] $PLIST" >>expect || return 1 |
| 710 | done && |
| 711 | test_cmp expect args && |
| 712 | |
| 713 | rm -f args && |
| 714 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop && |
| 715 | |
| 716 | # stop does not unregister the repo |
Junio C Hamano | b2ace18 | 2021-01-15 21:48:45 -0800 | [diff] [blame] | 717 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 2afe7e3 | 2021-01-05 13:08:27 +0000 | [diff] [blame] | 718 | |
| 719 | printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
| 720 | hourly daily weekly >expect && |
| 721 | test_cmp expect args && |
| 722 | ls "$HOME/Library/LaunchAgents" >actual && |
| 723 | test_line_count = 0 actual |
| 724 | ' |
| 725 | |
Derrick Stolee | a16eb6b | 2021-08-24 15:44:00 +0000 | [diff] [blame] | 726 | test_expect_success 'use launchctl list to prevent extra work' ' |
| 727 | # ensure we are registered |
Junio C Hamano | ed8794e | 2021-09-20 15:20:40 -0700 | [diff] [blame] | 728 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
Derrick Stolee | a16eb6b | 2021-08-24 15:44:00 +0000 | [diff] [blame] | 729 | |
| 730 | # do it again on a fresh args file |
| 731 | rm -f args && |
Junio C Hamano | ed8794e | 2021-09-20 15:20:40 -0700 | [diff] [blame] | 732 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
Derrick Stolee | a16eb6b | 2021-08-24 15:44:00 +0000 | [diff] [blame] | 733 | |
| 734 | ls "$HOME/Library/LaunchAgents" >actual && |
| 735 | cat >expect <<-\EOF && |
| 736 | list org.git-scm.git.hourly |
| 737 | list org.git-scm.git.daily |
| 738 | list org.git-scm.git.weekly |
| 739 | EOF |
| 740 | test_cmp expect args |
| 741 | ' |
| 742 | |
Derrick Stolee | 3797a0a | 2021-01-05 13:08:28 +0000 | [diff] [blame] | 743 | test_expect_success 'start and stop Windows maintenance' ' |
| 744 | write_script print-args <<-\EOF && |
| 745 | echo $* >>args |
| 746 | while test $# -gt 0 |
| 747 | do |
| 748 | case "$1" in |
| 749 | /xml) shift; xmlfile=$1; break ;; |
| 750 | *) shift ;; |
| 751 | esac |
| 752 | done |
| 753 | test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml" |
| 754 | EOF |
| 755 | |
| 756 | rm -f args && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 757 | GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start --scheduler=schtasks && |
Derrick Stolee | 3797a0a | 2021-01-05 13:08:28 +0000 | [diff] [blame] | 758 | |
| 759 | # start registers the repo |
Junio C Hamano | b2ace18 | 2021-01-15 21:48:45 -0800 | [diff] [blame] | 760 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 3797a0a | 2021-01-05 13:08:28 +0000 | [diff] [blame] | 761 | |
| 762 | for frequency in hourly daily weekly |
| 763 | do |
| 764 | grep "/create /tn Git Maintenance ($frequency) /f /xml" args && |
| 765 | file=$(ls .git/schedule_${frequency}*.xml) && |
| 766 | test_xmllint "$file" || return 1 |
| 767 | done && |
| 768 | |
| 769 | rm -f args && |
| 770 | GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop && |
| 771 | |
| 772 | # stop does not unregister the repo |
Junio C Hamano | b2ace18 | 2021-01-15 21:48:45 -0800 | [diff] [blame] | 773 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
Derrick Stolee | 3797a0a | 2021-01-05 13:08:28 +0000 | [diff] [blame] | 774 | |
| 775 | printf "/delete /tn Git Maintenance (%s) /f\n" \ |
| 776 | hourly daily weekly >expect && |
| 777 | test_cmp expect args |
| 778 | ' |
| 779 | |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 780 | test_expect_success 'start and stop Linux/systemd maintenance' ' |
| 781 | write_script print-args <<-\EOF && |
| 782 | printf "%s\n" "$*" >>args |
| 783 | EOF |
| 784 | |
| 785 | XDG_CONFIG_HOME="$PWD" && |
| 786 | export XDG_CONFIG_HOME && |
| 787 | rm -f args && |
| 788 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance start --scheduler=systemd-timer && |
| 789 | |
| 790 | # start registers the repo |
| 791 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
| 792 | |
Derrick Stolee | daa7870 | 2023-08-10 20:39:45 +0000 | [diff] [blame] | 793 | for schedule in hourly daily weekly |
| 794 | do |
| 795 | test_path_is_file "systemd/user/git-maintenance@$schedule.timer" || return 1 |
| 796 | done && |
| 797 | test_path_is_file "systemd/user/git-maintenance@.service" && |
| 798 | |
| 799 | test_systemd_analyze_verify "systemd/user/git-maintenance@hourly.service" && |
| 800 | test_systemd_analyze_verify "systemd/user/git-maintenance@daily.service" && |
| 801 | test_systemd_analyze_verify "systemd/user/git-maintenance@weekly.service" && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 802 | |
| 803 | printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && |
| 804 | test_cmp expect args && |
| 805 | |
| 806 | rm -f args && |
| 807 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance stop && |
| 808 | |
| 809 | # stop does not unregister the repo |
| 810 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
| 811 | |
Derrick Stolee | daa7870 | 2023-08-10 20:39:45 +0000 | [diff] [blame] | 812 | for schedule in hourly daily weekly |
| 813 | do |
| 814 | test_path_is_missing "systemd/user/git-maintenance@$schedule.timer" || return 1 |
| 815 | done && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 816 | test_path_is_missing "systemd/user/git-maintenance@.service" && |
| 817 | |
| 818 | printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && |
| 819 | test_cmp expect args |
| 820 | ' |
| 821 | |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 822 | test_expect_success 'start and stop when several schedulers are available' ' |
| 823 | write_script print-args <<-\EOF && |
| 824 | printf "%s\n" "$*" | sed "s:gui/[0-9][0-9]*:gui/[UID]:; s:\(schtasks /create .* /xml\).*:\1:;" >>args |
| 825 | EOF |
| 826 | |
| 827 | rm -f args && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 828 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=systemd-timer && |
| 829 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 830 | hourly daily weekly >expect && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 831 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ |
| 832 | hourly daily weekly >>expect && |
| 833 | printf -- "systemctl --user enable --now git-maintenance@%s.timer\n" hourly daily weekly >>expect && |
| 834 | test_cmp expect args && |
| 835 | |
| 836 | rm -f args && |
| 837 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=launchctl && |
| 838 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && |
| 839 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ |
| 840 | hourly daily weekly >>expect && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 841 | for frequency in hourly daily weekly |
| 842 | do |
| 843 | PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && |
| 844 | echo "launchctl bootout gui/[UID] $PLIST" >>expect && |
| 845 | echo "launchctl bootstrap gui/[UID] $PLIST" >>expect || return 1 |
| 846 | done && |
| 847 | test_cmp expect args && |
| 848 | |
| 849 | rm -f args && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 850 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=schtasks && |
| 851 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 852 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 853 | hourly daily weekly >>expect && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 854 | printf "schtasks /create /tn Git Maintenance (%s) /f /xml\n" \ |
| 855 | hourly daily weekly >>expect && |
| 856 | test_cmp expect args && |
| 857 | |
| 858 | rm -f args && |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 859 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance stop && |
| 860 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 861 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
Lénaïc Huard | b681b19 | 2021-09-04 22:55:00 +0200 | [diff] [blame] | 862 | hourly daily weekly >>expect && |
Lénaïc Huard | eba1ba9 | 2021-09-04 22:54:59 +0200 | [diff] [blame] | 863 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ |
| 864 | hourly daily weekly >>expect && |
| 865 | test_cmp expect args |
| 866 | ' |
| 867 | |
Derrick Stolee | 61f7a38 | 2020-10-15 17:22:03 +0000 | [diff] [blame] | 868 | test_expect_success 'register preserves existing strategy' ' |
| 869 | git config maintenance.strategy none && |
| 870 | git maintenance register && |
| 871 | test_config maintenance.strategy none && |
| 872 | git config --unset maintenance.strategy && |
| 873 | git maintenance register && |
| 874 | test_config maintenance.strategy incremental |
| 875 | ' |
| 876 | |
Josh Steadmon | 0a1f2d0 | 2020-12-08 12:12:56 -0800 | [diff] [blame] | 877 | test_expect_success 'fails when running outside of a repository' ' |
Rafael Silva | e72f7de | 2020-11-26 20:41:41 +0000 | [diff] [blame] | 878 | nongit test_must_fail git maintenance run && |
| 879 | nongit test_must_fail git maintenance stop && |
| 880 | nongit test_must_fail git maintenance start && |
| 881 | nongit test_must_fail git maintenance register && |
| 882 | nongit test_must_fail git maintenance unregister |
| 883 | ' |
| 884 | |
Eric Sunshine | 26c7974 | 2021-02-23 02:31:07 -0500 | [diff] [blame] | 885 | test_expect_success 'register and unregister bare repo' ' |
| 886 | test_when_finished "git config --global --unset-all maintenance.repo || :" && |
| 887 | test_might_fail git config --global --unset-all maintenance.repo && |
| 888 | git init --bare barerepo && |
| 889 | ( |
| 890 | cd barerepo && |
| 891 | git maintenance register && |
| 892 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
| 893 | git maintenance unregister && |
| 894 | test_must_fail git config --global --get-all maintenance.repo |
| 895 | ) |
| 896 | ' |
| 897 | |
Derrick Stolee | 69ecfca | 2023-08-10 20:39:47 +0000 | [diff] [blame] | 898 | test_expect_success 'failed schedule prevents config change' ' |
| 899 | git init --bare failcase && |
| 900 | |
| 901 | for scheduler in crontab launchctl schtasks systemctl |
| 902 | do |
| 903 | GIT_TEST_MAINT_SCHEDULER="$scheduler:false" && |
| 904 | export GIT_TEST_MAINT_SCHEDULER && |
| 905 | test_must_fail \ |
| 906 | git -C failcase maintenance start && |
| 907 | test_must_fail git -C failcase config maintenance.auto || return 1 |
| 908 | done |
| 909 | ' |
| 910 | |
Derrick Stolee | 2057d75 | 2020-09-17 18:11:42 +0000 | [diff] [blame] | 911 | test_done |