Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t9210-scalar.sh
blob027235d61aa35e9ff3110b72d50ce012e72327dd
1 #!/bin/sh
3 test_description='test the `scalar` command'
5 . ./test-lib.sh
7 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
8 export GIT_TEST_MAINT_SCHEDULER
10 test_expect_success 'scalar shows a usage' '
11 test_expect_code 129 scalar -h
14 test_expect_success 'scalar invoked on enlistment root' '
15 test_when_finished rm -rf test src deeper &&
17 for enlistment_root in test src deeper/test
19 git init ${enlistment_root}/src &&
21 # Register
22 scalar register ${enlistment_root} &&
23 scalar list >out &&
24 grep "$(pwd)/${enlistment_root}/src\$" out &&
26 # Delete (including enlistment root)
27 scalar delete $enlistment_root &&
28 test_path_is_missing $enlistment_root &&
29 scalar list >out &&
30 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
31 done
34 test_expect_success 'scalar invoked on enlistment src repo' '
35 test_when_finished rm -rf test src deeper &&
37 for enlistment_root in test src deeper/test
39 git init ${enlistment_root}/src &&
41 # Register
42 scalar register ${enlistment_root}/src &&
43 scalar list >out &&
44 grep "$(pwd)/${enlistment_root}/src\$" out &&
46 # Delete (will not include enlistment root)
47 scalar delete ${enlistment_root}/src &&
48 test_path_is_dir $enlistment_root &&
49 scalar list >out &&
50 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
51 done
54 test_expect_success 'scalar invoked when enlistment root and repo are the same' '
55 test_when_finished rm -rf test src deeper &&
57 for enlistment_root in test src deeper/test
59 git init ${enlistment_root} &&
61 # Register
62 scalar register ${enlistment_root} &&
63 scalar list >out &&
64 grep "$(pwd)/${enlistment_root}\$" out &&
66 # Delete (will not include enlistment root)
67 scalar delete ${enlistment_root} &&
68 test_path_is_missing $enlistment_root &&
69 scalar list >out &&
70 ! grep "^$(pwd)/${enlistment_root}\$" out &&
72 # Make sure we did not accidentally delete the trash dir
73 test_path_is_dir "$TRASH_DIRECTORY" || return 1
74 done
77 test_expect_success 'scalar repo search respects GIT_CEILING_DIRECTORIES' '
78 test_when_finished rm -rf test &&
80 git init test/src &&
81 mkdir -p test/src/deep &&
82 GIT_CEILING_DIRECTORIES="$(pwd)/test/src" &&
83 ! scalar register test/src/deep 2>err &&
84 grep "not a git repository" err
87 test_expect_success 'scalar enlistments need a worktree' '
88 test_when_finished rm -rf bare test &&
90 git init --bare bare/src &&
91 ! scalar register bare/src 2>err &&
92 grep "Scalar enlistments require a worktree" err &&
94 git init test/src &&
95 ! scalar register test/src/.git 2>err &&
96 grep "Scalar enlistments require a worktree" err
99 test_expect_success FSMONITOR_DAEMON 'scalar register starts fsmon daemon' '
100 git init test/src &&
101 test_must_fail git -C test/src fsmonitor--daemon status &&
102 scalar register test/src &&
103 git -C test/src fsmonitor--daemon status &&
104 test_cmp_config -C test/src true core.fsmonitor
107 test_expect_success 'scalar register warns when background maintenance fails' '
108 git init register-repo &&
109 GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
110 scalar register register-repo 2>err &&
111 grep "could not turn on maintenance" err
114 test_expect_success 'scalar unregister' '
115 git init vanish/src &&
116 scalar register vanish/src &&
117 git config --get --global --fixed-value \
118 maintenance.repo "$(pwd)/vanish/src" &&
119 scalar list >scalar.repos &&
120 grep -F "$(pwd)/vanish/src" scalar.repos &&
121 rm -rf vanish/src/.git &&
122 scalar unregister vanish &&
123 test_must_fail git config --get --global --fixed-value \
124 maintenance.repo "$(pwd)/vanish/src" &&
125 scalar list >scalar.repos &&
126 ! grep -F "$(pwd)/vanish/src" scalar.repos &&
128 # scalar unregister should be idempotent
129 scalar unregister vanish
132 test_expect_success 'set up repository to clone' '
133 test_commit first &&
134 test_commit second &&
135 test_commit third &&
136 git switch -c parallel first &&
137 mkdir -p 1/2 &&
138 test_commit 1/2/3 &&
139 git config uploadPack.allowFilter true &&
140 git config uploadPack.allowAnySHA1InWant true
143 test_expect_success 'scalar clone' '
144 second=$(git rev-parse --verify second:second.t) &&
145 scalar clone "file://$(pwd)" cloned --single-branch &&
147 cd cloned/src &&
149 git config --get --global --fixed-value maintenance.repo \
150 "$(pwd)" &&
152 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
153 echo "refs/remotes/origin/parallel" >expect &&
154 test_cmp expect actual &&
156 test_path_is_missing 1/2 &&
158 # This relies on the fact that the presence of "--missing"
159 # on the command line forces lazy fetching off before
160 # "$second^{blob}" gets parsed. Without "^{blob}", a
161 # bare object name "$second" is taken into the queue and
162 # the command may not fail with a fixed "rev-list --missing".
163 test_must_fail git rev-list --missing=print "$second^{blob}" -- &&
165 git rev-list $second &&
166 git cat-file blob $second >actual &&
167 echo "second" >expect &&
168 test_cmp expect actual
172 test_expect_success 'scalar clone --no-... opts' '
173 # Note: redirect stderr always to avoid having a verbose test
174 # run result in a difference in the --[no-]progress option.
175 GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \
176 --no-tags --no-src \
177 "file://$(pwd)" no-opts --single-branch 2>/dev/null &&
179 test_subcommand git fetch --quiet --no-progress \
180 origin --no-tags <no-opt-trace &&
182 cd no-opts &&
184 test_cmp_config --no-tags remote.origin.tagopt &&
185 git for-each-ref --format="%(refname)" refs/tags/ >tags &&
186 test_line_count = 0 tags
190 test_expect_success 'scalar reconfigure' '
191 git init one/src &&
192 scalar register one &&
193 git -C one/src config core.preloadIndex false &&
194 scalar reconfigure one &&
195 test true = "$(git -C one/src config core.preloadIndex)" &&
196 git -C one/src config core.preloadIndex false &&
197 rm one/src/cron.txt &&
198 GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
199 test_path_is_file one/src/cron.txt &&
200 test true = "$(git -C one/src config core.preloadIndex)" &&
201 test_subcommand git maintenance start <reconfigure
204 test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
205 repos="two three four" &&
206 for num in $repos
208 git init $num/src &&
209 scalar register $num/src &&
210 git -C $num/src config includeif."onbranch:foo".path something &&
211 git -C $num/src config core.preloadIndex false || return 1
212 done &&
214 scalar reconfigure --all &&
216 for num in $repos
218 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
219 done
222 test_expect_success 'scalar reconfigure --all with detached HEADs' '
223 repos="two three four" &&
224 for num in $repos
226 rm -rf $num/src &&
227 git init $num/src &&
228 scalar register $num/src &&
229 git -C $num/src config core.preloadIndex false &&
230 test_commit -C $num/src initial &&
231 git -C $num/src switch --detach HEAD || return 1
232 done &&
234 scalar reconfigure --all &&
236 for num in $repos
238 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
239 done
242 test_expect_success '`reconfigure -a` removes stale config entries' '
243 git init stale/src &&
244 scalar register stale &&
245 scalar list >scalar.repos &&
246 grep stale scalar.repos &&
248 grep -v stale scalar.repos >expect &&
250 rm -rf stale &&
251 scalar reconfigure -a &&
252 scalar list >scalar.repos &&
253 test_cmp expect scalar.repos
256 test_expect_success 'scalar delete without enlistment shows a usage' '
257 test_expect_code 129 scalar delete
260 test_expect_success 'scalar delete with enlistment' '
261 scalar delete cloned &&
262 test_path_is_missing cloned
265 test_expect_success 'scalar supports -c/-C' '
266 test_when_finished "scalar delete sub" &&
267 git init sub &&
268 scalar -C sub -c status.aheadBehind=bogus register &&
269 test -z "$(git -C sub config --local status.aheadBehind)" &&
270 test true = "$(git -C sub config core.preloadIndex)"
273 test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
274 ! scalar run config cloned 2>err &&
275 grep "cloned. does not exist" err
278 SQ="'"
279 test_expect_success UNZIP 'scalar diagnose' '
280 scalar clone "file://$(pwd)" cloned --single-branch &&
281 git repack &&
282 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
283 test_commit -C cloned/src loose &&
284 scalar diagnose cloned >out 2>err &&
285 grep "Available space" out &&
286 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
287 zip_path=$(cat zip_path) &&
288 test -n "$zip_path" &&
289 "$GIT_UNZIP" -v "$zip_path" &&
290 folder=${zip_path%.zip} &&
291 test_path_is_missing "$folder" &&
292 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
293 test_file_not_empty out &&
294 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
295 grep "$(pwd)/.git/objects" out &&
296 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
297 grep "^Total: [1-9]" out
300 test_done