3 test_description
='test the `scalar` command'
5 TEST_PASSES_SANITIZE_LEAK
=true
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 &&
23 scalar register ${enlistment_root} &&
25 grep "$(pwd)/${enlistment_root}/src\$" out &&
27 # Delete (including enlistment root)
28 scalar delete $enlistment_root &&
29 test_path_is_missing $enlistment_root &&
31 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
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 &&
43 scalar register ${enlistment_root}/src &&
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 &&
51 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
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} &&
63 scalar register ${enlistment_root} &&
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 &&
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
78 test_expect_success
'scalar repo search respects GIT_CEILING_DIRECTORIES' '
79 test_when_finished rm -rf test &&
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 &&
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' '
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' '
135 test_commit second &&
137 git switch -c parallel first &&
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 &&
150 git config --get --global --fixed-value maintenance.repo \
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 \
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 &&
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' '
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" &&
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
215 scalar reconfigure --all &&
219 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
223 test_expect_success
'scalar reconfigure --all with detached HEADs' '
224 repos="two three four" &&
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
235 scalar reconfigure --all &&
239 test true = "$(git -C $num/src config core.preloadIndex)" || return 1
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 &&
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" &&
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
280 test_expect_success UNZIP
'scalar diagnose' '
281 scalar clone "file://$(pwd)" cloned --single-branch &&
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