The eleventh batch
[git/gitster.git] / t / t9210-scalar.sh
bloba30b2c9f7055eb85d70c896faa5d78b5c0dd8f16
1 #!/bin/sh
3 test_description='test the `scalar` command'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
9 export GIT_TEST_MAINT_SCHEDULER
11 test_expect_success 'scalar shows a usage' '
12 test_expect_code 129 scalar -h
15 test_expect_success 'scalar invoked on enlistment root' '
16 test_when_finished rm -rf test src deeper &&
18 for enlistment_root in test src deeper/test
20 git init ${enlistment_root}/src &&
22 # Register
23 scalar register ${enlistment_root} &&
24 scalar list >out &&
25 grep "$(pwd)/${enlistment_root}/src\$" out &&
27 # Delete (including enlistment root)
28 scalar delete $enlistment_root &&
29 test_path_is_missing $enlistment_root &&
30 scalar list >out &&
31 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
32 done
35 test_expect_success 'scalar invoked on enlistment src repo' '
36 test_when_finished rm -rf test src deeper &&
38 for enlistment_root in test src deeper/test
40 git init ${enlistment_root}/src &&
42 # Register
43 scalar register ${enlistment_root}/src &&
44 scalar list >out &&
45 grep "$(pwd)/${enlistment_root}/src\$" out &&
47 # Delete (will not include enlistment root)
48 scalar delete ${enlistment_root}/src &&
49 test_path_is_dir $enlistment_root &&
50 scalar list >out &&
51 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
52 done
55 test_expect_success 'scalar invoked when enlistment root and repo are the same' '
56 test_when_finished rm -rf test src deeper &&
58 for enlistment_root in test src deeper/test
60 git init ${enlistment_root} &&
62 # Register
63 scalar register ${enlistment_root} &&
64 scalar list >out &&
65 grep "$(pwd)/${enlistment_root}\$" out &&
67 # Delete (will not include enlistment root)
68 scalar delete ${enlistment_root} &&
69 test_path_is_missing $enlistment_root &&
70 scalar list >out &&
71 ! grep "^$(pwd)/${enlistment_root}\$" out &&
73 # Make sure we did not accidentally delete the trash dir
74 test_path_is_dir "$TRASH_DIRECTORY" || return 1
75 done
78 test_expect_success 'scalar repo search respects GIT_CEILING_DIRECTORIES' '
79 test_when_finished rm -rf test &&
81 git init test/src &&
82 mkdir -p test/src/deep &&
83 GIT_CEILING_DIRECTORIES="$(pwd)/test/src" &&
84 ! scalar register test/src/deep 2>err &&
85 grep "not a git repository" err
88 test_expect_success 'scalar enlistments need a worktree' '
89 test_when_finished rm -rf bare test &&
91 git init --bare bare/src &&
92 ! scalar register bare/src 2>err &&
93 grep "Scalar enlistments require a worktree" err &&
95 git init test/src &&
96 ! scalar register test/src/.git 2>err &&
97 grep "Scalar enlistments require a worktree" err
100 test_expect_success FSMONITOR_DAEMON 'scalar register starts fsmon daemon' '
101 git init test/src &&
102 test_must_fail git -C test/src fsmonitor--daemon status &&
103 scalar register test/src &&
104 git -C test/src fsmonitor--daemon status &&
105 test_cmp_config -C test/src true core.fsmonitor
108 test_expect_success 'scalar register warns when background maintenance fails' '
109 git init register-repo &&
110 GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
111 scalar register register-repo 2>err &&
112 grep "could not turn on maintenance" err
115 test_expect_success 'scalar unregister' '
116 git init vanish/src &&
117 scalar register vanish/src &&
118 git config --get --global --fixed-value \
119 maintenance.repo "$(pwd)/vanish/src" &&
120 scalar list >scalar.repos &&
121 grep -F "$(pwd)/vanish/src" scalar.repos &&
122 rm -rf vanish/src/.git &&
123 scalar unregister vanish &&
124 test_must_fail git config --get --global --fixed-value \
125 maintenance.repo "$(pwd)/vanish/src" &&
126 scalar list >scalar.repos &&
127 ! grep -F "$(pwd)/vanish/src" scalar.repos &&
129 # scalar unregister should be idempotent
130 scalar unregister vanish
133 test_expect_success 'set up repository to clone' '
134 test_commit first &&
135 test_commit second &&
136 test_commit third &&
137 git switch -c parallel first &&
138 mkdir -p 1/2 &&
139 test_commit 1/2/3 &&
140 git config uploadPack.allowFilter true &&
141 git config uploadPack.allowAnySHA1InWant true
144 test_expect_success 'scalar clone' '
145 second=$(git rev-parse --verify second:second.t) &&
146 scalar clone "file://$(pwd)" cloned --single-branch &&
148 cd cloned/src &&
150 git config --get --global --fixed-value maintenance.repo \
151 "$(pwd)" &&
153 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
154 echo "refs/remotes/origin/parallel" >expect &&
155 test_cmp expect actual &&
157 test_path_is_missing 1/2 &&
159 # This relies on the fact that the presence of "--missing"
160 # on the command line forces lazy fetching off before
161 # "$second^{blob}" gets parsed. Without "^{blob}", a
162 # bare object name "$second" is taken into the queue and
163 # the command may not fail with a fixed "rev-list --missing".
164 test_must_fail git rev-list --missing=print "$second^{blob}" -- &&
166 git rev-list $second &&
167 git cat-file blob $second >actual &&
168 echo "second" >expect &&
169 test_cmp expect actual
173 test_expect_success 'scalar clone --no-... opts' '
174 # Note: redirect stderr always to avoid having a verbose test
175 # run result in a difference in the --[no-]progress option.
176 GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \
177 --no-tags --no-src \
178 "file://$(pwd)" no-opts --single-branch 2>/dev/null &&
180 test_subcommand git fetch --quiet --no-progress \
181 origin --no-tags <no-opt-trace &&
183 cd no-opts &&
185 test_cmp_config --no-tags remote.origin.tagopt &&
186 git for-each-ref --format="%(refname)" refs/tags/ >tags &&
187 test_line_count = 0 tags
191 test_expect_success 'scalar reconfigure' '
192 git init one/src &&
193 scalar register one &&
194 git -C one/src config core.preloadIndex false &&
195 scalar reconfigure one &&
196 test true = "$(git -C one/src config core.preloadIndex)" &&
197 git -C one/src config core.preloadIndex false &&
198 rm one/src/cron.txt &&
199 GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
200 test_path_is_file one/src/cron.txt &&
201 test true = "$(git -C one/src config core.preloadIndex)" &&
202 test_subcommand git maintenance start <reconfigure
205 test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
206 repos="two three four" &&
207 for num in $repos
209 git init $num/src &&
210 scalar register $num/src &&
211 git -C $num/src config includeif."onbranch:foo".path something &&
212 git -C $num/src config core.preloadIndex false || return 1
213 done &&
215 scalar reconfigure --all &&
217 for num in $repos
219 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
220 done
223 test_expect_success 'scalar reconfigure --all with detached HEADs' '
224 repos="two three four" &&
225 for num in $repos
227 rm -rf $num/src &&
228 git init $num/src &&
229 scalar register $num/src &&
230 git -C $num/src config core.preloadIndex false &&
231 test_commit -C $num/src initial &&
232 git -C $num/src switch --detach HEAD || return 1
233 done &&
235 scalar reconfigure --all &&
237 for num in $repos
239 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
240 done
243 test_expect_success '`reconfigure -a` removes stale config entries' '
244 git init stale/src &&
245 scalar register stale &&
246 scalar list >scalar.repos &&
247 grep stale scalar.repos &&
249 grep -v stale scalar.repos >expect &&
251 rm -rf stale &&
252 scalar reconfigure -a &&
253 scalar list >scalar.repos &&
254 test_cmp expect scalar.repos
257 test_expect_success 'scalar delete without enlistment shows a usage' '
258 test_expect_code 129 scalar delete
261 test_expect_success 'scalar delete with enlistment' '
262 scalar delete cloned &&
263 test_path_is_missing cloned
266 test_expect_success 'scalar supports -c/-C' '
267 test_when_finished "scalar delete sub" &&
268 git init sub &&
269 scalar -C sub -c status.aheadBehind=bogus register &&
270 test -z "$(git -C sub config --local status.aheadBehind)" &&
271 test true = "$(git -C sub config core.preloadIndex)"
274 test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
275 ! scalar run config cloned 2>err &&
276 grep "cloned. does not exist" err
279 SQ="'"
280 test_expect_success UNZIP 'scalar diagnose' '
281 scalar clone "file://$(pwd)" cloned --single-branch &&
282 git repack &&
283 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
284 test_commit -C cloned/src loose &&
285 scalar diagnose cloned >out 2>err &&
286 grep "Available space" out &&
287 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
288 zip_path=$(cat zip_path) &&
289 test -n "$zip_path" &&
290 "$GIT_UNZIP" -v "$zip_path" &&
291 folder=${zip_path%.zip} &&
292 test_path_is_missing "$folder" &&
293 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
294 test_file_not_empty out &&
295 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
296 grep "$(pwd)/.git/objects" out &&
297 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
298 grep "^Total: [1-9]" out
301 test_done