]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9210-scalar.sh
Merge branch 'ds/scalar-reconfigure-all-fix'
[thirdparty/git.git] / t / t9210-scalar.sh
CommitLineData
9187659f
JS
1#!/bin/sh
2
3test_description='test the `scalar` command'
4
7b5c93c6 5. ./test-lib.sh
9187659f 6
7b5c93c6 7GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
546f822d
JS
8export GIT_TEST_MAINT_SCHEDULER
9
9187659f
JS
10test_expect_success 'scalar shows a usage' '
11 test_expect_code 129 scalar -h
12'
13
65f6a9eb
VD
14test_expect_success 'scalar invoked on enlistment root' '
15 test_when_finished rm -rf test src deeper &&
16
17 for enlistment_root in test src deeper/test
18 do
19 git init ${enlistment_root}/src &&
20
21 # Register
22 scalar register ${enlistment_root} &&
23 scalar list >out &&
24 grep "$(pwd)/${enlistment_root}/src\$" out &&
25
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
32'
33
34test_expect_success 'scalar invoked on enlistment src repo' '
35 test_when_finished rm -rf test src deeper &&
36
37 for enlistment_root in test src deeper/test
38 do
39 git init ${enlistment_root}/src &&
40
41 # Register
42 scalar register ${enlistment_root}/src &&
43 scalar list >out &&
44 grep "$(pwd)/${enlistment_root}/src\$" out &&
45
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
52'
53
54test_expect_success 'scalar invoked when enlistment root and repo are the same' '
55 test_when_finished rm -rf test src deeper &&
56
57 for enlistment_root in test src deeper/test
58 do
59 git init ${enlistment_root} &&
60
61 # Register
62 scalar register ${enlistment_root} &&
63 scalar list >out &&
64 grep "$(pwd)/${enlistment_root}\$" out &&
65
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 &&
71
72 # Make sure we did not accidentally delete the trash dir
73 test_path_is_dir "$TRASH_DIRECTORY" || return 1
74 done
75'
76
77test_expect_success 'scalar repo search respects GIT_CEILING_DIRECTORIES' '
78 test_when_finished rm -rf test &&
79
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
85'
86
87test_expect_success 'scalar enlistments need a worktree' '
88 test_when_finished rm -rf bare test &&
89
90 git init --bare bare/src &&
91 ! scalar register bare/src 2>err &&
92 grep "Scalar enlistments require a worktree" err &&
93
94 git init test/src &&
95 ! scalar register test/src/.git 2>err &&
96 grep "Scalar enlistments require a worktree" err
97'
98
3f1917dc
MJC
99test_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
105'
106
dea63088 107test_expect_success 'scalar register warns when background maintenance fails' '
eeea9ae1
DS
108 git init register-repo &&
109 GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
dea63088 110 scalar register register-repo 2>err &&
eeea9ae1
DS
111 grep "could not turn on maintenance" err
112'
113
f5f0842d
JS
114test_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 &&
d871b6c6
DS
126 ! grep -F "$(pwd)/vanish/src" scalar.repos &&
127
128 # scalar unregister should be idempotent
129 scalar unregister vanish
f5f0842d
JS
130'
131
546f822d
JS
132test_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
141'
142
143test_expect_success 'scalar clone' '
144 second=$(git rev-parse --verify second:second.t) &&
4368e40b 145 scalar clone "file://$(pwd)" cloned --single-branch &&
546f822d
JS
146 (
147 cd cloned/src &&
148
149 git config --get --global --fixed-value maintenance.repo \
150 "$(pwd)" &&
151
4368e40b
JS
152 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
153 echo "refs/remotes/origin/parallel" >expect &&
154 test_cmp expect actual &&
155
546f822d 156 test_path_is_missing 1/2 &&
75389e27
JH
157
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}" -- &&
164
546f822d
JS
165 git rev-list $second &&
166 git cat-file blob $second >actual &&
167 echo "second" >expect &&
168 test_cmp expect actual
169 )
170'
171
cb59d55e
JS
172test_expect_success 'scalar reconfigure' '
173 git init one/src &&
174 scalar register one &&
175 git -C one/src config core.preloadIndex false &&
176 scalar reconfigure one &&
45826760
JS
177 test true = "$(git -C one/src config core.preloadIndex)" &&
178 git -C one/src config core.preloadIndex false &&
179 scalar reconfigure -a &&
cb59d55e
JS
180 test true = "$(git -C one/src config core.preloadIndex)"
181'
182
b64b0df9
DS
183test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
184 repos="two three four" &&
185 for num in $repos
186 do
187 git init $num/src &&
188 scalar register $num/src &&
189 git -C $num/src config includeif."onbranch:foo".path something &&
190 git -C $num/src config core.preloadIndex false || return 1
191 done &&
192
193 scalar reconfigure --all &&
194
195 for num in $repos
196 do
197 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
198 done
199'
200
201 test_expect_success 'scalar reconfigure --all with detached HEADs' '
202 repos="two three four" &&
203 for num in $repos
204 do
205 rm -rf $num/src &&
206 git init $num/src &&
207 scalar register $num/src &&
208 git -C $num/src config core.preloadIndex false &&
209 test_commit -C $num/src initial &&
210 git -C $num/src switch --detach HEAD || return 1
211 done &&
212
213 scalar reconfigure --all &&
214
215 for num in $repos
216 do
217 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
218 done
219'
220
c90db53d
JS
221test_expect_success '`reconfigure -a` removes stale config entries' '
222 git init stale/src &&
223 scalar register stale &&
224 scalar list >scalar.repos &&
225 grep stale scalar.repos &&
a90085b6
JS
226
227 grep -v stale scalar.repos >expect &&
228
c90db53d
JS
229 rm -rf stale &&
230 scalar reconfigure -a &&
231 scalar list >scalar.repos &&
a90085b6 232 test_cmp expect scalar.repos
c90db53d
JS
233'
234
d85ada7c
MJC
235test_expect_success 'scalar delete without enlistment shows a usage' '
236 test_expect_code 129 scalar delete
237'
238
239test_expect_success 'scalar delete with enlistment' '
240 scalar delete cloned &&
241 test_path_is_missing cloned
242'
243
2ae8eb5d
JS
244test_expect_success 'scalar supports -c/-C' '
245 test_when_finished "scalar delete sub" &&
246 git init sub &&
247 scalar -C sub -c status.aheadBehind=bogus register &&
248 test -z "$(git -C sub config --local status.aheadBehind)" &&
249 test true = "$(git -C sub config core.preloadIndex)"
250'
251
b4485574
JS
252test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
253 ! scalar run config cloned 2>err &&
254 grep "cloned. does not exist" err
255'
256
aa5c79a3
JS
257SQ="'"
258test_expect_success UNZIP 'scalar diagnose' '
259 scalar clone "file://$(pwd)" cloned --single-branch &&
93e804b2
MJC
260 git repack &&
261 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
15d8adcc 262 test_commit -C cloned/src loose &&
aa5c79a3 263 scalar diagnose cloned >out 2>err &&
0ed5b13f 264 grep "Available space" out &&
aa5c79a3
JS
265 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
266 zip_path=$(cat zip_path) &&
267 test -n "$zip_path" &&
81ad5513 268 "$GIT_UNZIP" -v "$zip_path" &&
aa5c79a3
JS
269 folder=${zip_path%.zip} &&
270 test_path_is_missing "$folder" &&
81ad5513 271 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
93e804b2 272 test_file_not_empty out &&
81ad5513 273 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
15d8adcc 274 grep "$(pwd)/.git/objects" out &&
81ad5513 275 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
15d8adcc 276 grep "^Total: [1-9]" out
aa5c79a3
JS
277'
278
9187659f 279test_done