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