3 test_description='git maintenance builtin'
7 GIT_TEST_COMMIT_GRAPH=0
8 GIT_TEST_MULTI_PACK_INDEX=0
10 test_expect_success 'help text' '
11 test_expect_code 129 git maintenance -h 2>err &&
12 test_i18ngrep "usage: git maintenance run" err &&
13 test_expect_code 128 git maintenance barf 2>err &&
14 test_i18ngrep "invalid subcommand: barf" err &&
15 test_expect_code 129 git maintenance 2>err &&
16 test_i18ngrep "usage: git maintenance" err
19 test_expect_success 'run [--auto|--quiet]' '
20 GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
21 git maintenance run 2>/dev/null &&
22 GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
23 git maintenance run --auto 2>/dev/null &&
24 GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
25 git maintenance run --no-quiet 2>/dev/null &&
26 test_subcommand git gc --quiet <run-no-auto.txt &&
27 test_subcommand ! git gc --auto --quiet <run-auto.txt &&
28 test_subcommand git gc --no-quiet <run-no-quiet.txt
31 test_expect_success 'maintenance.<task>.enabled' '
32 git config maintenance.gc.enabled false &&
33 git config maintenance.commit-graph.enabled true &&
34 GIT_TRACE2_EVENT="$(pwd)/run-config.txt" git maintenance run 2>err &&
35 test_subcommand ! git gc --quiet <run-config.txt &&
36 test_subcommand git commit-graph write --split --reachable --no-progress <run-config.txt
39 test_expect_success 'run --task=<task>' '
40 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
41 git maintenance run --task=commit-graph 2>/dev/null &&
42 GIT_TRACE2_EVENT="$(pwd)/run-gc.txt" \
43 git maintenance run --task=gc 2>/dev/null &&
44 GIT_TRACE2_EVENT="$(pwd)/run-commit-graph.txt" \
45 git maintenance run --task=commit-graph 2>/dev/null &&
46 GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
47 git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
48 test_subcommand ! git gc --quiet <run-commit-graph.txt &&
49 test_subcommand git gc --quiet <run-gc.txt &&
50 test_subcommand git gc --quiet <run-both.txt &&
51 test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
52 test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
53 test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
56 test_expect_success 'run --task=bogus' '
57 test_must_fail git maintenance run --task=bogus 2>err &&
58 test_i18ngrep "is not a valid task" err
61 test_expect_success 'run --task duplicate' '
62 test_must_fail git maintenance run --task=gc --task=gc 2>err &&
63 test_i18ngrep "cannot be selected multiple times" err
66 test_expect_success 'run --task=prefetch with no remotes' '
67 git maintenance run --task=prefetch 2>err &&
68 test_must_be_empty err
71 test_expect_success 'prefetch multiple remotes' '
74 git remote add remote1 "file://$(pwd)/clone1" &&
75 git remote add remote2 "file://$(pwd)/clone2" &&
76 git -C clone1 switch -c one &&
77 git -C clone2 switch -c two &&
78 test_commit -C clone1 one &&
79 test_commit -C clone2 two &&
80 GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
81 fetchargs="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" &&
82 test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* <run-prefetch.txt &&
83 test_subcommand git fetch remote2 $fetchargs +refs/heads/\\*:refs/prefetch/remote2/\\* <run-prefetch.txt &&
84 test_path_is_missing .git/refs/remotes &&
85 git log prefetch/remote1/one &&
86 git log prefetch/remote2/two &&
88 test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one &&
89 test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two
92 test_expect_success 'loose-objects task' '
93 # Repack everything so we know the state of the object dir
96 # Hack to stop maintenance from running during "git commit"
97 echo in use >.git/objects/maintenance.lock &&
99 # Assuming that "git commit" creates at least one loose object
100 test_commit create-loose-object &&
101 rm .git/objects/maintenance.lock &&
103 ls .git/objects >obj-dir-before &&
104 test_file_not_empty obj-dir-before &&
105 ls .git/objects/pack/*.pack >packs-before &&
106 test_line_count = 1 packs-before &&
108 # The first run creates a pack-file
109 # but does not delete loose objects.
110 git maintenance run --task=loose-objects &&
111 ls .git/objects >obj-dir-between &&
112 test_cmp obj-dir-before obj-dir-between &&
113 ls .git/objects/pack/*.pack >packs-between &&
114 test_line_count = 2 packs-between &&
115 ls .git/objects/pack/loose-*.pack >loose-packs &&
116 test_line_count = 1 loose-packs &&
118 # The second run deletes loose objects
119 # but does not create a pack-file.
120 git maintenance run --task=loose-objects &&
121 ls .git/objects >obj-dir-after &&
122 cat >expect <<-\EOF &&
126 test_cmp expect obj-dir-after &&
127 ls .git/objects/pack/*.pack >packs-after &&
128 test_cmp packs-between packs-after
131 test_expect_success 'maintenance.loose-objects.auto' '
133 GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
134 git -c maintenance.loose-objects.auto=1 maintenance \
135 run --auto --task=loose-objects 2>/dev/null &&
136 test_subcommand ! git prune-packed --quiet <trace-lo1.txt &&
137 printf data-A | git hash-object -t blob --stdin -w &&
138 GIT_TRACE2_EVENT="$(pwd)/trace-loA" \
139 git -c maintenance.loose-objects.auto=2 \
140 maintenance run --auto --task=loose-objects 2>/dev/null &&
141 test_subcommand ! git prune-packed --quiet <trace-loA &&
142 printf data-B | git hash-object -t blob --stdin -w &&
143 GIT_TRACE2_EVENT="$(pwd)/trace-loB" \
144 git -c maintenance.loose-objects.auto=2 \
145 maintenance run --auto --task=loose-objects 2>/dev/null &&
146 test_subcommand git prune-packed --quiet <trace-loB &&
147 GIT_TRACE2_EVENT="$(pwd)/trace-loC" \
148 git -c maintenance.loose-objects.auto=2 \
149 maintenance run --auto --task=loose-objects 2>/dev/null &&
150 test_subcommand git prune-packed --quiet <trace-loC
153 test_expect_success 'incremental-repack task' '
154 packDir=.git/objects/pack &&
155 for i in $(test_seq 1 5)
157 test_commit $i || return 1
160 # Create three disjoint pack-files with size BIG, small, small.
161 echo HEAD~2 | git pack-objects --revs $packDir/test-1 &&
163 git pack-objects --revs $packDir/test-2 <<-\EOF &&
168 git pack-objects --revs $packDir/test-3 <<-\EOF &&
172 rm -f $packDir/pack-* &&
173 rm -f $packDir/loose-* &&
174 ls $packDir/*.pack >packs-before &&
175 test_line_count = 3 packs-before &&
177 # the job repacks the two into a new pack, but does not
178 # delete the old ones.
179 git maintenance run --task=incremental-repack &&
180 ls $packDir/*.pack >packs-between &&
181 test_line_count = 4 packs-between &&
183 # the job deletes the two old packs, and does not write
184 # a new one because the batch size is not high enough to
185 # pack the largest pack-file.
186 git maintenance run --task=incremental-repack &&
187 ls .git/objects/pack/*.pack >packs-after &&
188 test_line_count = 2 packs-after
191 test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
192 for i in $(test_seq 1 5)
194 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
198 git commit -m "Add big file (1)" &&
200 # ensure any possible loose objects are in a pack-file
201 git maintenance run --task=loose-objects &&
204 for i in $(test_seq 6 10)
206 test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
210 git commit -m "Add big file (2)" &&
212 # ensure any possible loose objects are in a pack-file
213 git maintenance run --task=loose-objects &&
215 # Now run the incremental-repack task and check the batch-size
216 GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \
217 --task=incremental-repack 2>/dev/null &&
218 test_subcommand git multi-pack-index repack \
219 --no-progress --batch-size=2147483647 <run-2g.txt
222 test_expect_success 'maintenance.incremental-repack.auto' '
224 git config core.multiPackIndex true &&
225 git multi-pack-index write &&
226 GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
227 -c maintenance.incremental-repack.auto=1 \
228 maintenance run --auto --task=incremental-repack 2>/dev/null &&
229 test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
231 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
235 GIT_TRACE2_EVENT=$(pwd)/trace-A git \
236 -c maintenance.incremental-repack.auto=2 \
237 maintenance run --auto --task=incremental-repack 2>/dev/null &&
238 test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
240 git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
244 GIT_TRACE2_EVENT=$(pwd)/trace-B git \
245 -c maintenance.incremental-repack.auto=2 \
246 maintenance run --auto --task=incremental-repack 2>/dev/null &&
247 test_subcommand git multi-pack-index write --no-progress <trace-B