]>
Commit | Line | Data |
---|---|---|
2057d750 DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git maintenance builtin' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
663b2b1b | 7 | GIT_TEST_COMMIT_GRAPH=0 |
52fe41ff | 8 | GIT_TEST_MULTI_PACK_INDEX=0 |
663b2b1b | 9 | |
2afe7e35 DS |
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 | ||
b681b191 | 23 | test_lazy_prereq SYSTEMD_ANALYZE ' |
670e5973 | 24 | systemd-analyze verify /lib/systemd/system/basic.target |
b681b191 LH |
25 | ' |
26 | ||
27 | test_systemd_analyze_verify () { | |
28 | if test_have_prereq SYSTEMD_ANALYZE | |
29 | then | |
30 | systemd-analyze verify "$@" | |
31 | fi | |
32 | } | |
33 | ||
2057d750 DS |
34 | test_expect_success 'help text' ' |
35 | test_expect_code 129 git maintenance -h 2>err && | |
0c18b700 | 36 | test_i18ngrep "usage: git maintenance <subcommand>" err && |
2057d750 DS |
37 | test_expect_code 128 git maintenance barf 2>err && |
38 | test_i18ngrep "invalid subcommand: barf" err && | |
39 | test_expect_code 129 git maintenance 2>err && | |
40 | test_i18ngrep "usage: git maintenance" err | |
41 | ' | |
42 | ||
3ddaad0e DS |
43 | test_expect_success 'run [--auto|--quiet]' ' |
44 | GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \ | |
45 | git maintenance run 2>/dev/null && | |
46 | GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \ | |
47 | git maintenance run --auto 2>/dev/null && | |
48 | GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \ | |
49 | git maintenance run --no-quiet 2>/dev/null && | |
50 | test_subcommand git gc --quiet <run-no-auto.txt && | |
916d0626 | 51 | test_subcommand ! git gc --auto --quiet <run-auto.txt && |
3ddaad0e | 52 | test_subcommand git gc --no-quiet <run-no-quiet.txt |
2057d750 DS |
53 | ' |
54 | ||
1942d483 DS |
55 | test_expect_success 'maintenance.auto config option' ' |
56 | GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 && | |
57 | test_subcommand git maintenance run --auto --quiet <default && | |
58 | GIT_TRACE2_EVENT="$(pwd)/true" \ | |
59 | git -c maintenance.auto=true \ | |
60 | commit --quiet --allow-empty -m 2 && | |
61 | test_subcommand git maintenance run --auto --quiet <true && | |
62 | GIT_TRACE2_EVENT="$(pwd)/false" \ | |
63 | git -c maintenance.auto=false \ | |
64 | commit --quiet --allow-empty -m 3 && | |
65 | test_subcommand ! git maintenance run --auto --quiet <false | |
66 | ' | |
67 | ||
65d655b5 DS |
68 | test_expect_success 'maintenance.<task>.enabled' ' |
69 | git config maintenance.gc.enabled false && | |
70 | git config maintenance.commit-graph.enabled true && | |
71 | GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err && | |
72 | test_subcommand ! git gc --quiet <run-config.txt && | |
73 | test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt | |
74 | ' | |
75 | ||
090511bc DS |
76 | test_expect_success 'run --task=<task>' ' |
77 | GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ | |
78 | git maintenance run --task=commit-graph 2>/dev/null && | |
79 | GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \ | |
80 | git maintenance run --task=gc 2>/dev/null && | |
81 | GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \ | |
82 | git maintenance run --task=commit-graph 2>/dev/null && | |
83 | GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \ | |
84 | git maintenance run --task=commit-graph --task=gc 2>/dev/null && | |
85 | test_subcommand ! git gc --quiet <run-commit-graph.txt && | |
86 | test_subcommand git gc --quiet <run-gc.txt && | |
87 | test_subcommand git gc --quiet <run-both.txt && | |
88 | test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt && | |
89 | test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt && | |
90 | test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt | |
91 | ' | |
92 | ||
d334107c DS |
93 | test_expect_success 'core.commitGraph=false prevents write process' ' |
94 | GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \ | |
95 | git -c core.commitGraph=false maintenance run \ | |
96 | --task=commit-graph 2>/dev/null && | |
97 | test_subcommand ! git commit-graph write --split --reachable --no-progress \ | |
98 | <no-commit-graph.txt | |
99 | ' | |
100 | ||
8f801804 DS |
101 | test_expect_success 'commit-graph auto condition' ' |
102 | COMMAND="maintenance run --task=commit-graph --auto --quiet" && | |
103 | ||
104 | GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \ | |
105 | git -c maintenance.commit-graph.auto=1 $COMMAND && | |
106 | GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \ | |
107 | git -c maintenance.commit-graph.auto="-1" $COMMAND && | |
108 | ||
109 | test_commit first && | |
110 | ||
111 | GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \ | |
112 | git -c maintenance.commit-graph.auto=0 $COMMAND && | |
113 | GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \ | |
114 | git -c maintenance.commit-graph.auto=1 $COMMAND && | |
115 | ||
116 | git commit --allow-empty -m "second" && | |
117 | git commit --allow-empty -m "third" && | |
118 | ||
119 | GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \ | |
120 | git -c maintenance.commit-graph.auto=2 $COMMAND && | |
121 | ||
122 | COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" && | |
123 | test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt && | |
124 | test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt && | |
125 | test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt && | |
126 | test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt && | |
127 | test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt | |
128 | ' | |
129 | ||
090511bc DS |
130 | test_expect_success 'run --task=bogus' ' |
131 | test_must_fail git maintenance run --task=bogus 2>err && | |
132 | test_i18ngrep "is not a valid task" err | |
133 | ' | |
134 | ||
135 | test_expect_success 'run --task duplicate' ' | |
136 | test_must_fail git maintenance run --task=gc --task=gc 2>err && | |
137 | test_i18ngrep "cannot be selected multiple times" err | |
138 | ' | |
139 | ||
28cb5e66 DS |
140 | test_expect_success 'run --task=prefetch with no remotes' ' |
141 | git maintenance run --task=prefetch 2>err && | |
142 | test_must_be_empty err | |
143 | ' | |
144 | ||
145 | test_expect_success 'prefetch multiple remotes' ' | |
146 | git clone . clone1 && | |
147 | git clone . clone2 && | |
148 | git remote add remote1 "file://$(pwd)/clone1" && | |
149 | git remote add remote2 "file://$(pwd)/clone2" && | |
150 | git -C clone1 switch -c one && | |
151 | git -C clone2 switch -c two && | |
152 | test_commit -C clone1 one && | |
153 | test_commit -C clone2 two && | |
154 | GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null && | |
cfd781ea DS |
155 | fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" && |
156 | test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt && | |
157 | test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt && | |
28cb5e66 | 158 | test_path_is_missing .git/refs/remotes && |
cfd781ea DS |
159 | git log prefetch/remotes/remote1/one && |
160 | git log prefetch/remotes/remote2/two && | |
28cb5e66 | 161 | git fetch --all && |
cfd781ea DS |
162 | test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one && |
163 | test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two && | |
96eaffeb DS |
164 | |
165 | test_cmp_config refs/prefetch/ log.excludedecoration && | |
166 | git log --oneline --decorate --all >log && | |
32f67888 DS |
167 | ! grep "prefetch" log && |
168 | ||
169 | test_when_finished git config --unset remote.remote1.skipFetchAll && | |
170 | git config remote.remote1.skipFetchAll true && | |
171 | GIT_TRACE2_EVENT="$(pwd)/skip-remote1.txt" git maintenance run --task=prefetch 2>/dev/null && | |
172 | test_subcommand ! git fetch remote1 $fetchargs <skip-remote1.txt && | |
173 | test_subcommand git fetch remote2 $fetchargs <skip-remote1.txt | |
96eaffeb DS |
174 | ' |
175 | ||
176 | test_expect_success 'prefetch and existing log.excludeDecoration values' ' | |
177 | git config --unset-all log.excludeDecoration && | |
178 | git config log.excludeDecoration refs/remotes/remote1/ && | |
179 | git maintenance run --task=prefetch && | |
180 | ||
181 | git config --get-all log.excludeDecoration >out && | |
182 | grep refs/remotes/remote1/ out && | |
183 | grep refs/prefetch/ out && | |
184 | ||
185 | git log --oneline --decorate --all >log && | |
186 | ! grep "prefetch" log && | |
187 | ! grep "remote1" log && | |
188 | grep "remote2" log && | |
189 | ||
190 | # a second run does not change the config | |
191 | git maintenance run --task=prefetch && | |
192 | git log --oneline --decorate --all >log2 && | |
193 | test_cmp log log2 | |
28cb5e66 DS |
194 | ' |
195 | ||
252cfb7c DS |
196 | test_expect_success 'loose-objects task' ' |
197 | # Repack everything so we know the state of the object dir | |
198 | git repack -adk && | |
199 | ||
200 | # Hack to stop maintenance from running during "git commit" | |
201 | echo in use >.git/objects/maintenance.lock && | |
202 | ||
203 | # Assuming that "git commit" creates at least one loose object | |
204 | test_commit create-loose-object && | |
205 | rm .git/objects/maintenance.lock && | |
206 | ||
207 | ls .git/objects >obj-dir-before && | |
208 | test_file_not_empty obj-dir-before && | |
209 | ls .git/objects/pack/*.pack >packs-before && | |
210 | test_line_count = 1 packs-before && | |
211 | ||
212 | # The first run creates a pack-file | |
213 | # but does not delete loose objects. | |
214 | git maintenance run --task=loose-objects && | |
215 | ls .git/objects >obj-dir-between && | |
216 | test_cmp obj-dir-before obj-dir-between && | |
217 | ls .git/objects/pack/*.pack >packs-between && | |
218 | test_line_count = 2 packs-between && | |
219 | ls .git/objects/pack/loose-*.pack >loose-packs && | |
220 | test_line_count = 1 loose-packs && | |
221 | ||
222 | # The second run deletes loose objects | |
223 | # but does not create a pack-file. | |
224 | git maintenance run --task=loose-objects && | |
225 | ls .git/objects >obj-dir-after && | |
226 | cat >expect <<-\EOF && | |
227 | info | |
228 | pack | |
229 | EOF | |
230 | test_cmp expect obj-dir-after && | |
231 | ls .git/objects/pack/*.pack >packs-after && | |
232 | test_cmp packs-between packs-after | |
233 | ' | |
234 | ||
3e220e60 DS |
235 | test_expect_success 'maintenance.loose-objects.auto' ' |
236 | git repack -adk && | |
237 | GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \ | |
238 | git -c maintenance.loose-objects.auto=1 maintenance \ | |
239 | run --auto --task=loose-objects 2>/dev/null && | |
240 | test_subcommand ! git prune-packed --quiet <trace-lo1.txt && | |
241 | printf data-A | git hash-object -t blob --stdin -w && | |
242 | GIT_TRACE2_EVENT="$(pwd)/trace-loA" \ | |
243 | git -c maintenance.loose-objects.auto=2 \ | |
244 | maintenance run --auto --task=loose-objects 2>/dev/null && | |
245 | test_subcommand ! git prune-packed --quiet <trace-loA && | |
246 | printf data-B | git hash-object -t blob --stdin -w && | |
247 | GIT_TRACE2_EVENT="$(pwd)/trace-loB" \ | |
248 | git -c maintenance.loose-objects.auto=2 \ | |
249 | maintenance run --auto --task=loose-objects 2>/dev/null && | |
250 | test_subcommand git prune-packed --quiet <trace-loB && | |
251 | GIT_TRACE2_EVENT="$(pwd)/trace-loC" \ | |
252 | git -c maintenance.loose-objects.auto=2 \ | |
253 | maintenance run --auto --task=loose-objects 2>/dev/null && | |
254 | test_subcommand git prune-packed --quiet <trace-loC | |
255 | ' | |
256 | ||
52fe41ff DS |
257 | test_expect_success 'incremental-repack task' ' |
258 | packDir=.git/objects/pack && | |
259 | for i in $(test_seq 1 5) | |
260 | do | |
261 | test_commit $i || return 1 | |
262 | done && | |
263 | ||
264 | # Create three disjoint pack-files with size BIG, small, small. | |
265 | echo HEAD~2 | git pack-objects --revs $packDir/test-1 && | |
266 | test_tick && | |
267 | git pack-objects --revs $packDir/test-2 <<-\EOF && | |
268 | HEAD~1 | |
269 | ^HEAD~2 | |
270 | EOF | |
271 | test_tick && | |
272 | git pack-objects --revs $packDir/test-3 <<-\EOF && | |
273 | HEAD | |
274 | ^HEAD~1 | |
275 | EOF | |
3cf5f221 DS |
276 | |
277 | # Delete refs that have not been repacked in these packs. | |
278 | git for-each-ref --format="delete %(refname)" \ | |
b4724242 | 279 | refs/prefetch refs/tags refs/remotes >refs && |
3cf5f221 DS |
280 | git update-ref --stdin <refs && |
281 | ||
282 | # Replace the object directory with this pack layout. | |
52fe41ff DS |
283 | rm -f $packDir/pack-* && |
284 | rm -f $packDir/loose-* && | |
285 | ls $packDir/*.pack >packs-before && | |
286 | test_line_count = 3 packs-before && | |
287 | ||
b4724242 JK |
288 | # make sure we do not have any broken refs that were |
289 | # missed in the deletion above | |
290 | git for-each-ref && | |
291 | ||
52fe41ff DS |
292 | # the job repacks the two into a new pack, but does not |
293 | # delete the old ones. | |
294 | git maintenance run --task=incremental-repack && | |
295 | ls $packDir/*.pack >packs-between && | |
296 | test_line_count = 4 packs-between && | |
297 | ||
298 | # the job deletes the two old packs, and does not write | |
a13e3d0e DS |
299 | # a new one because the batch size is not high enough to |
300 | # pack the largest pack-file. | |
52fe41ff DS |
301 | git maintenance run --task=incremental-repack && |
302 | ls .git/objects/pack/*.pack >packs-after && | |
a13e3d0e DS |
303 | test_line_count = 2 packs-after |
304 | ' | |
305 | ||
306 | test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' | |
a0c5ccc1 JK |
307 | test_config core.compression 0 && |
308 | ||
a13e3d0e DS |
309 | for i in $(test_seq 1 5) |
310 | do | |
311 | test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || | |
312 | return 1 | |
313 | done && | |
314 | git add big && | |
a0c5ccc1 | 315 | git commit -qm "Add big file (1)" && |
a13e3d0e DS |
316 | |
317 | # ensure any possible loose objects are in a pack-file | |
318 | git maintenance run --task=loose-objects && | |
319 | ||
320 | rm big && | |
321 | for i in $(test_seq 6 10) | |
322 | do | |
323 | test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || | |
324 | return 1 | |
325 | done && | |
326 | git add big && | |
a0c5ccc1 | 327 | git commit -qm "Add big file (2)" && |
a13e3d0e DS |
328 | |
329 | # ensure any possible loose objects are in a pack-file | |
330 | git maintenance run --task=loose-objects && | |
331 | ||
332 | # Now run the incremental-repack task and check the batch-size | |
333 | GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \ | |
334 | --task=incremental-repack 2>/dev/null && | |
335 | test_subcommand git multi-pack-index repack \ | |
336 | --no-progress --batch-size=2147483647 <run-2g.txt | |
52fe41ff DS |
337 | ' |
338 | ||
e841a79a DS |
339 | test_expect_success 'maintenance.incremental-repack.auto' ' |
340 | git repack -adk && | |
341 | git config core.multiPackIndex true && | |
342 | git multi-pack-index write && | |
343 | GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \ | |
344 | -c maintenance.incremental-repack.auto=1 \ | |
345 | maintenance run --auto --task=incremental-repack 2>/dev/null && | |
346 | test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt && | |
347 | test_commit A && | |
348 | git pack-objects --revs .git/objects/pack/pack <<-\EOF && | |
349 | HEAD | |
350 | ^HEAD~1 | |
351 | EOF | |
352 | GIT_TRACE2_EVENT=$(pwd)/trace-A git \ | |
353 | -c maintenance.incremental-repack.auto=2 \ | |
354 | maintenance run --auto --task=incremental-repack 2>/dev/null && | |
355 | test_subcommand ! git multi-pack-index write --no-progress <trace-A && | |
356 | test_commit B && | |
357 | git pack-objects --revs .git/objects/pack/pack <<-\EOF && | |
358 | HEAD | |
359 | ^HEAD~1 | |
360 | EOF | |
361 | GIT_TRACE2_EVENT=$(pwd)/trace-B git \ | |
362 | -c maintenance.incremental-repack.auto=2 \ | |
363 | maintenance run --auto --task=incremental-repack 2>/dev/null && | |
364 | test_subcommand git multi-pack-index write --no-progress <trace-B | |
365 | ' | |
366 | ||
41abfe15 DS |
367 | test_expect_success 'pack-refs task' ' |
368 | for n in $(test_seq 1 5) | |
369 | do | |
370 | git branch -f to-pack/$n HEAD || return 1 | |
371 | done && | |
372 | GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \ | |
373 | git maintenance run --task=pack-refs && | |
41abfe15 DS |
374 | test_subcommand git pack-refs --all --prune <pack-refs.txt |
375 | ' | |
376 | ||
b08ff1fe DS |
377 | test_expect_success '--auto and --schedule incompatible' ' |
378 | test_must_fail git maintenance run --auto --schedule=daily 2>err && | |
379 | test_i18ngrep "at most one" err | |
380 | ' | |
381 | ||
382 | test_expect_success 'invalid --schedule value' ' | |
383 | test_must_fail git maintenance run --schedule=annually 2>err && | |
384 | test_i18ngrep "unrecognized --schedule" err | |
385 | ' | |
386 | ||
387 | test_expect_success '--schedule inheritance weekly -> daily -> hourly' ' | |
388 | git config maintenance.loose-objects.enabled true && | |
389 | git config maintenance.loose-objects.schedule hourly && | |
390 | git config maintenance.commit-graph.enabled true && | |
391 | git config maintenance.commit-graph.schedule daily && | |
392 | git config maintenance.incremental-repack.enabled true && | |
393 | git config maintenance.incremental-repack.schedule weekly && | |
394 | ||
395 | GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \ | |
396 | git maintenance run --schedule=hourly 2>/dev/null && | |
397 | test_subcommand git prune-packed --quiet <hourly.txt && | |
398 | test_subcommand ! git commit-graph write --split --reachable \ | |
399 | --no-progress <hourly.txt && | |
400 | test_subcommand ! git multi-pack-index write --no-progress <hourly.txt && | |
401 | ||
402 | GIT_TRACE2_EVENT="$(pwd)/daily.txt" \ | |
403 | git maintenance run --schedule=daily 2>/dev/null && | |
404 | test_subcommand git prune-packed --quiet <daily.txt && | |
405 | test_subcommand git commit-graph write --split --reachable \ | |
406 | --no-progress <daily.txt && | |
407 | test_subcommand ! git multi-pack-index write --no-progress <daily.txt && | |
408 | ||
409 | GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \ | |
410 | git maintenance run --schedule=weekly 2>/dev/null && | |
411 | test_subcommand git prune-packed --quiet <weekly.txt && | |
412 | test_subcommand git commit-graph write --split --reachable \ | |
413 | --no-progress <weekly.txt && | |
414 | test_subcommand git multi-pack-index write --no-progress <weekly.txt | |
415 | ' | |
416 | ||
a4cb1a23 DS |
417 | test_expect_success 'maintenance.strategy inheritance' ' |
418 | for task in commit-graph loose-objects incremental-repack | |
419 | do | |
420 | git config --unset maintenance.$task.schedule || return 1 | |
421 | done && | |
422 | ||
423 | test_when_finished git config --unset maintenance.strategy && | |
424 | git config maintenance.strategy incremental && | |
425 | ||
426 | GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \ | |
427 | git maintenance run --schedule=hourly --quiet && | |
428 | GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \ | |
429 | git maintenance run --schedule=daily --quiet && | |
acc1c4d5 DS |
430 | GIT_TRACE2_EVENT="$(pwd)/incremental-weekly.txt" \ |
431 | git maintenance run --schedule=weekly --quiet && | |
a4cb1a23 DS |
432 | |
433 | test_subcommand git commit-graph write --split --reachable \ | |
434 | --no-progress <incremental-hourly.txt && | |
435 | test_subcommand ! git prune-packed --quiet <incremental-hourly.txt && | |
436 | test_subcommand ! git multi-pack-index write --no-progress \ | |
437 | <incremental-hourly.txt && | |
acc1c4d5 DS |
438 | test_subcommand ! git pack-refs --all --prune \ |
439 | <incremental-hourly.txt && | |
a4cb1a23 DS |
440 | |
441 | test_subcommand git commit-graph write --split --reachable \ | |
442 | --no-progress <incremental-daily.txt && | |
443 | test_subcommand git prune-packed --quiet <incremental-daily.txt && | |
444 | test_subcommand git multi-pack-index write --no-progress \ | |
445 | <incremental-daily.txt && | |
acc1c4d5 DS |
446 | test_subcommand ! git pack-refs --all --prune \ |
447 | <incremental-daily.txt && | |
448 | ||
449 | test_subcommand git commit-graph write --split --reachable \ | |
450 | --no-progress <incremental-weekly.txt && | |
451 | test_subcommand git prune-packed --quiet <incremental-weekly.txt && | |
452 | test_subcommand git multi-pack-index write --no-progress \ | |
453 | <incremental-weekly.txt && | |
454 | test_subcommand git pack-refs --all --prune \ | |
455 | <incremental-weekly.txt && | |
a4cb1a23 DS |
456 | |
457 | # Modify defaults | |
458 | git config maintenance.commit-graph.schedule daily && | |
459 | git config maintenance.loose-objects.schedule hourly && | |
460 | git config maintenance.incremental-repack.enabled false && | |
461 | ||
462 | GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \ | |
463 | git maintenance run --schedule=hourly --quiet && | |
464 | GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \ | |
465 | git maintenance run --schedule=daily --quiet && | |
466 | ||
467 | test_subcommand ! git commit-graph write --split --reachable \ | |
468 | --no-progress <modified-hourly.txt && | |
469 | test_subcommand git prune-packed --quiet <modified-hourly.txt && | |
470 | test_subcommand ! git multi-pack-index write --no-progress \ | |
471 | <modified-hourly.txt && | |
472 | ||
473 | test_subcommand git commit-graph write --split --reachable \ | |
474 | --no-progress <modified-daily.txt && | |
475 | test_subcommand git prune-packed --quiet <modified-daily.txt && | |
476 | test_subcommand ! git multi-pack-index write --no-progress \ | |
477 | <modified-daily.txt | |
478 | ' | |
479 | ||
0c18b700 DS |
480 | test_expect_success 'register and unregister' ' |
481 | test_when_finished git config --global --unset-all maintenance.repo && | |
482 | git config --global --add maintenance.repo /existing1 && | |
483 | git config --global --add maintenance.repo /existing2 && | |
484 | git config --global --get-all maintenance.repo >before && | |
61f7a383 | 485 | |
0c18b700 | 486 | git maintenance register && |
61f7a383 DS |
487 | test_cmp_config false maintenance.auto && |
488 | git config --global --get-all maintenance.repo >between && | |
489 | cp before expect && | |
490 | pwd >>expect && | |
491 | test_cmp expect between && | |
492 | ||
0c18b700 DS |
493 | git maintenance unregister && |
494 | git config --global --get-all maintenance.repo >actual && | |
495 | test_cmp before actual | |
496 | ' | |
497 | ||
483a6d9b DS |
498 | test_expect_success !MINGW 'register and unregister with regex metacharacters' ' |
499 | META="a+b*c" && | |
500 | git init "$META" && | |
501 | git -C "$META" maintenance register && | |
502 | git config --get-all --show-origin maintenance.repo && | |
503 | git config --get-all --global --fixed-value \ | |
504 | maintenance.repo "$(pwd)/$META" && | |
505 | git -C "$META" maintenance unregister && | |
506 | test_must_fail git config --get-all --global --fixed-value \ | |
507 | maintenance.repo "$(pwd)/$META" | |
508 | ' | |
509 | ||
eba1ba9d LH |
510 | test_expect_success 'start --scheduler=<scheduler>' ' |
511 | test_expect_code 129 git maintenance start --scheduler=foo 2>err && | |
512 | test_i18ngrep "unrecognized --scheduler argument" err && | |
513 | ||
514 | test_expect_code 129 git maintenance start --no-scheduler 2>err && | |
515 | test_i18ngrep "unknown option" err && | |
516 | ||
517 | test_expect_code 128 \ | |
518 | env GIT_TEST_MAINT_SCHEDULER="launchctl:true,schtasks:true" \ | |
519 | git maintenance start --scheduler=crontab 2>err && | |
520 | test_i18ngrep "fatal: crontab scheduler is not available" err | |
521 | ' | |
522 | ||
2fec604f | 523 | test_expect_success 'start from empty cron table' ' |
eba1ba9d | 524 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && |
2fec604f DS |
525 | |
526 | # start registers the repo | |
610a3fc9 | 527 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
2fec604f DS |
528 | |
529 | grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt && | |
530 | grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt && | |
531 | grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt | |
532 | ' | |
533 | ||
534 | test_expect_success 'stop from existing schedule' ' | |
31345d55 | 535 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
2fec604f DS |
536 | |
537 | # stop does not unregister the repo | |
610a3fc9 | 538 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
2fec604f DS |
539 | |
540 | # Operation is idempotent | |
31345d55 | 541 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
2fec604f DS |
542 | test_must_be_empty cron.txt |
543 | ' | |
544 | ||
545 | test_expect_success 'start preserves existing schedule' ' | |
546 | echo "Important information!" >cron.txt && | |
eba1ba9d | 547 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start --scheduler=crontab && |
2fec604f DS |
548 | grep "Important information!" cron.txt |
549 | ' | |
550 | ||
a52df25a MÅ |
551 | test_expect_success 'magic markers are correct' ' |
552 | grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual && | |
553 | cat >expect <<-\EOF && | |
554 | # BEGIN GIT MAINTENANCE SCHEDULE | |
555 | # END GIT MAINTENANCE SCHEDULE | |
556 | EOF | |
557 | test_cmp actual expect | |
558 | ' | |
559 | ||
66dc0a36 MÅ |
560 | test_expect_success 'stop preserves surrounding schedule' ' |
561 | echo "Crucial information!" >>cron.txt && | |
b2ace187 | 562 | GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop && |
66dc0a36 MÅ |
563 | grep "Important information!" cron.txt && |
564 | grep "Crucial information!" cron.txt | |
565 | ' | |
566 | ||
2afe7e35 DS |
567 | test_expect_success 'start and stop macOS maintenance' ' |
568 | # ensure $HOME can be compared against hook arguments on all platforms | |
569 | pfx=$(cd "$HOME" && pwd) && | |
570 | ||
571 | write_script print-args <<-\EOF && | |
572 | echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args | |
573 | EOF | |
574 | ||
575 | rm -f args && | |
eba1ba9d | 576 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
2afe7e35 DS |
577 | |
578 | # start registers the repo | |
b2ace187 | 579 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
2afe7e35 DS |
580 | |
581 | ls "$HOME/Library/LaunchAgents" >actual && | |
582 | cat >expect <<-\EOF && | |
583 | org.git-scm.git.daily.plist | |
584 | org.git-scm.git.hourly.plist | |
585 | org.git-scm.git.weekly.plist | |
586 | EOF | |
587 | test_cmp expect actual && | |
588 | ||
589 | rm -f expect && | |
590 | for frequency in hourly daily weekly | |
591 | do | |
592 | PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && | |
593 | test_xmllint "$PLIST" && | |
594 | grep schedule=$frequency "$PLIST" && | |
595 | echo "bootout gui/[UID] $PLIST" >>expect && | |
596 | echo "bootstrap gui/[UID] $PLIST" >>expect || return 1 | |
597 | done && | |
598 | test_cmp expect args && | |
599 | ||
600 | rm -f args && | |
601 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop && | |
602 | ||
603 | # stop does not unregister the repo | |
b2ace187 | 604 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
2afe7e35 DS |
605 | |
606 | printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ | |
607 | hourly daily weekly >expect && | |
608 | test_cmp expect args && | |
609 | ls "$HOME/Library/LaunchAgents" >actual && | |
610 | test_line_count = 0 actual | |
a16eb6b1 DS |
611 | ' |
612 | ||
613 | test_expect_success 'use launchctl list to prevent extra work' ' | |
614 | # ensure we are registered | |
ed8794ef | 615 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
a16eb6b1 DS |
616 | |
617 | # do it again on a fresh args file | |
618 | rm -f args && | |
ed8794ef | 619 | GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start --scheduler=launchctl && |
a16eb6b1 DS |
620 | |
621 | ls "$HOME/Library/LaunchAgents" >actual && | |
622 | cat >expect <<-\EOF && | |
623 | list org.git-scm.git.hourly | |
624 | list org.git-scm.git.daily | |
625 | list org.git-scm.git.weekly | |
626 | EOF | |
627 | test_cmp expect args | |
2afe7e35 DS |
628 | ' |
629 | ||
3797a0a7 DS |
630 | test_expect_success 'start and stop Windows maintenance' ' |
631 | write_script print-args <<-\EOF && | |
632 | echo $* >>args | |
633 | while test $# -gt 0 | |
634 | do | |
635 | case "$1" in | |
636 | /xml) shift; xmlfile=$1; break ;; | |
637 | *) shift ;; | |
638 | esac | |
639 | done | |
640 | test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml" | |
641 | EOF | |
642 | ||
643 | rm -f args && | |
eba1ba9d | 644 | GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start --scheduler=schtasks && |
3797a0a7 DS |
645 | |
646 | # start registers the repo | |
b2ace187 | 647 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
3797a0a7 DS |
648 | |
649 | for frequency in hourly daily weekly | |
650 | do | |
651 | grep "/create /tn Git Maintenance ($frequency) /f /xml" args && | |
652 | file=$(ls .git/schedule_${frequency}*.xml) && | |
653 | test_xmllint "$file" || return 1 | |
654 | done && | |
655 | ||
656 | rm -f args && | |
657 | GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop && | |
658 | ||
659 | # stop does not unregister the repo | |
b2ace187 | 660 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && |
3797a0a7 DS |
661 | |
662 | printf "/delete /tn Git Maintenance (%s) /f\n" \ | |
663 | hourly daily weekly >expect && | |
664 | test_cmp expect args | |
665 | ' | |
666 | ||
b681b191 LH |
667 | test_expect_success 'start and stop Linux/systemd maintenance' ' |
668 | write_script print-args <<-\EOF && | |
669 | printf "%s\n" "$*" >>args | |
670 | EOF | |
671 | ||
672 | XDG_CONFIG_HOME="$PWD" && | |
673 | export XDG_CONFIG_HOME && | |
674 | rm -f args && | |
675 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance start --scheduler=systemd-timer && | |
676 | ||
677 | # start registers the repo | |
678 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && | |
679 | ||
680 | test_systemd_analyze_verify "systemd/user/git-maintenance@.service" && | |
681 | ||
682 | printf -- "--user enable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && | |
683 | test_cmp expect args && | |
684 | ||
685 | rm -f args && | |
686 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args" git maintenance stop && | |
687 | ||
688 | # stop does not unregister the repo | |
689 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && | |
690 | ||
691 | test_path_is_missing "systemd/user/git-maintenance@.timer" && | |
692 | test_path_is_missing "systemd/user/git-maintenance@.service" && | |
693 | ||
694 | printf -- "--user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && | |
695 | test_cmp expect args | |
696 | ' | |
697 | ||
eba1ba9d LH |
698 | test_expect_success 'start and stop when several schedulers are available' ' |
699 | write_script print-args <<-\EOF && | |
700 | printf "%s\n" "$*" | sed "s:gui/[0-9][0-9]*:gui/[UID]:; s:\(schtasks /create .* /xml\).*:\1:;" >>args | |
701 | EOF | |
702 | ||
703 | rm -f args && | |
b681b191 LH |
704 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=systemd-timer && |
705 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ | |
eba1ba9d | 706 | hourly daily weekly >expect && |
b681b191 LH |
707 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ |
708 | hourly daily weekly >>expect && | |
709 | printf -- "systemctl --user enable --now git-maintenance@%s.timer\n" hourly daily weekly >>expect && | |
710 | test_cmp expect args && | |
711 | ||
712 | rm -f args && | |
713 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=launchctl && | |
714 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && | |
715 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ | |
716 | hourly daily weekly >>expect && | |
eba1ba9d LH |
717 | for frequency in hourly daily weekly |
718 | do | |
719 | PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" && | |
720 | echo "launchctl bootout gui/[UID] $PLIST" >>expect && | |
721 | echo "launchctl bootstrap gui/[UID] $PLIST" >>expect || return 1 | |
722 | done && | |
723 | test_cmp expect args && | |
724 | ||
725 | rm -f args && | |
b681b191 LH |
726 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance start --scheduler=schtasks && |
727 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && | |
eba1ba9d | 728 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
b681b191 | 729 | hourly daily weekly >>expect && |
eba1ba9d LH |
730 | printf "schtasks /create /tn Git Maintenance (%s) /f /xml\n" \ |
731 | hourly daily weekly >>expect && | |
732 | test_cmp expect args && | |
733 | ||
734 | rm -f args && | |
b681b191 LH |
735 | GIT_TEST_MAINT_SCHEDULER="systemctl:./print-args systemctl,launchctl:./print-args launchctl,schtasks:./print-args schtasks" git maintenance stop && |
736 | printf -- "systemctl --user disable --now git-maintenance@%s.timer\n" hourly daily weekly >expect && | |
eba1ba9d | 737 | printf "launchctl bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \ |
b681b191 | 738 | hourly daily weekly >>expect && |
eba1ba9d LH |
739 | printf "schtasks /delete /tn Git Maintenance (%s) /f\n" \ |
740 | hourly daily weekly >>expect && | |
741 | test_cmp expect args | |
742 | ' | |
743 | ||
61f7a383 DS |
744 | test_expect_success 'register preserves existing strategy' ' |
745 | git config maintenance.strategy none && | |
746 | git maintenance register && | |
747 | test_config maintenance.strategy none && | |
748 | git config --unset maintenance.strategy && | |
749 | git maintenance register && | |
750 | test_config maintenance.strategy incremental | |
751 | ' | |
752 | ||
0a1f2d05 | 753 | test_expect_success 'fails when running outside of a repository' ' |
e72f7def RS |
754 | nongit test_must_fail git maintenance run && |
755 | nongit test_must_fail git maintenance stop && | |
756 | nongit test_must_fail git maintenance start && | |
757 | nongit test_must_fail git maintenance register && | |
758 | nongit test_must_fail git maintenance unregister | |
759 | ' | |
760 | ||
26c79743 ES |
761 | test_expect_success 'register and unregister bare repo' ' |
762 | test_when_finished "git config --global --unset-all maintenance.repo || :" && | |
763 | test_might_fail git config --global --unset-all maintenance.repo && | |
764 | git init --bare barerepo && | |
765 | ( | |
766 | cd barerepo && | |
767 | git maintenance register && | |
768 | git config --get --global --fixed-value maintenance.repo "$(pwd)" && | |
769 | git maintenance unregister && | |
770 | test_must_fail git config --global --get-all maintenance.repo | |
771 | ) | |
772 | ' | |
773 | ||
2057d750 | 774 | test_done |