3 test_description
='test the `scalar` command'
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 &&
22 scalar register ${enlistment_root} &&
24 grep "$(pwd)/${enlistment_root}/src\$" out &&
26 # Delete (including enlistment root)
27 scalar delete $enlistment_root &&
28 test_path_is_missing $enlistment_root &&
30 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
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 &&
42 scalar register ${enlistment_root}/src &&
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 &&
50 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
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} &&
62 scalar register ${enlistment_root} &&
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 &&
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
77 test_expect_success
'scalar repo search respects GIT_CEILING_DIRECTORIES' '
78 test_when_finished rm -rf test &&
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 &&
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' '
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 unregister' '
108 git init vanish/src &&
109 scalar register vanish/src &&
110 git config --get --global --fixed-value \
111 maintenance.repo "$(pwd)/vanish/src" &&
112 scalar list >scalar.repos &&
113 grep -F "$(pwd)/vanish/src" scalar.repos &&
114 rm -rf vanish/src/.git &&
115 scalar unregister vanish &&
116 test_must_fail git config --get --global --fixed-value \
117 maintenance.repo "$(pwd)/vanish/src" &&
118 scalar list >scalar.repos &&
119 ! grep -F "$(pwd)/vanish/src" scalar.repos
122 test_expect_success
'set up repository to clone' '
124 test_commit second &&
126 git switch -c parallel first &&
129 git config uploadPack.allowFilter true &&
130 git config uploadPack.allowAnySHA1InWant true
133 test_expect_success
'scalar clone' '
134 second=$(git rev-parse --verify second:second.t) &&
135 scalar clone "file://$(pwd)" cloned --single-branch &&
139 git config --get --global --fixed-value maintenance.repo \
142 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
143 echo "refs/remotes/origin/parallel" >expect &&
144 test_cmp expect actual &&
146 test_path_is_missing 1/2 &&
147 test_must_fail git rev-list --missing=print $second &&
148 git rev-list $second &&
149 git cat-file blob $second >actual &&
150 echo "second" >expect &&
151 test_cmp expect actual
155 test_expect_success
'scalar reconfigure' '
157 scalar register one &&
158 git -C one/src config core.preloadIndex false &&
159 scalar reconfigure one &&
160 test true = "$(git -C one/src config core.preloadIndex)" &&
161 git -C one/src config core.preloadIndex false &&
162 scalar reconfigure -a &&
163 test true = "$(git -C one/src config core.preloadIndex)"
166 test_expect_success
'scalar delete without enlistment shows a usage' '
167 test_expect_code 129 scalar delete
170 test_expect_success
'scalar delete with enlistment' '
171 scalar delete cloned &&
172 test_path_is_missing cloned
175 test_expect_success
'scalar supports -c/-C' '
176 test_when_finished "scalar delete sub" &&
178 scalar -C sub -c status.aheadBehind=bogus register &&
179 test -z "$(git -C sub config --local status.aheadBehind)" &&
180 test true = "$(git -C sub config core.preloadIndex)"
183 test_expect_success
'`scalar [...] <dir>` errors out when dir is missing' '
184 ! scalar run config cloned 2>err &&
185 grep "cloned. does not exist" err
189 test_expect_success UNZIP
'scalar diagnose' '
190 scalar clone "file://$(pwd)" cloned --single-branch &&
192 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
193 test_commit -C cloned/src loose &&
194 scalar diagnose cloned >out 2>err &&
195 grep "Available space" out &&
196 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
197 zip_path=$(cat zip_path) &&
198 test -n "$zip_path" &&
199 "$GIT_UNZIP" -v "$zip_path" &&
200 folder=${zip_path%.zip} &&
201 test_path_is_missing "$folder" &&
202 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
203 test_file_not_empty out &&
204 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
205 grep "$(pwd)/.git/objects" out &&
206 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
207 grep "^Total: [1-9]" out