sequencer.c: fix overflow & segfault in parse_strategy_opts()
[git.git] / t / t9210-scalar.sh
blob25f500cf682a33787e0809bf5e7b513fd9282e4c
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 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 &&
121 # scalar unregister should be idempotent
122 scalar unregister vanish
125 test_expect_success 'set up repository to clone' '
126 test_commit first &&
127 test_commit second &&
128 test_commit third &&
129 git switch -c parallel first &&
130 mkdir -p 1/2 &&
131 test_commit 1/2/3 &&
132 git config uploadPack.allowFilter true &&
133 git config uploadPack.allowAnySHA1InWant true
136 test_expect_success 'scalar clone' '
137 second=$(git rev-parse --verify second:second.t) &&
138 scalar clone "file://$(pwd)" cloned --single-branch &&
140 cd cloned/src &&
142 git config --get --global --fixed-value maintenance.repo \
143 "$(pwd)" &&
145 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
146 echo "refs/remotes/origin/parallel" >expect &&
147 test_cmp expect actual &&
149 test_path_is_missing 1/2 &&
150 test_must_fail git rev-list --missing=print $second &&
151 git rev-list $second &&
152 git cat-file blob $second >actual &&
153 echo "second" >expect &&
154 test_cmp expect actual
158 test_expect_success 'scalar reconfigure' '
159 git init one/src &&
160 scalar register one &&
161 git -C one/src config core.preloadIndex false &&
162 scalar reconfigure one &&
163 test true = "$(git -C one/src config core.preloadIndex)" &&
164 git -C one/src config core.preloadIndex false &&
165 scalar reconfigure -a &&
166 test true = "$(git -C one/src config core.preloadIndex)"
169 test_expect_success '`reconfigure -a` removes stale config entries' '
170 git init stale/src &&
171 scalar register stale &&
172 scalar list >scalar.repos &&
173 grep stale scalar.repos &&
175 grep -v stale scalar.repos >expect &&
177 rm -rf stale &&
178 scalar reconfigure -a &&
179 scalar list >scalar.repos &&
180 test_cmp expect scalar.repos
183 test_expect_success 'scalar delete without enlistment shows a usage' '
184 test_expect_code 129 scalar delete
187 test_expect_success 'scalar delete with enlistment' '
188 scalar delete cloned &&
189 test_path_is_missing cloned
192 test_expect_success 'scalar supports -c/-C' '
193 test_when_finished "scalar delete sub" &&
194 git init sub &&
195 scalar -C sub -c status.aheadBehind=bogus register &&
196 test -z "$(git -C sub config --local status.aheadBehind)" &&
197 test true = "$(git -C sub config core.preloadIndex)"
200 test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
201 ! scalar run config cloned 2>err &&
202 grep "cloned. does not exist" err
205 SQ="'"
206 test_expect_success UNZIP 'scalar diagnose' '
207 scalar clone "file://$(pwd)" cloned --single-branch &&
208 git repack &&
209 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
210 test_commit -C cloned/src loose &&
211 scalar diagnose cloned >out 2>err &&
212 grep "Available space" out &&
213 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
214 zip_path=$(cat zip_path) &&
215 test -n "$zip_path" &&
216 "$GIT_UNZIP" -v "$zip_path" &&
217 folder=${zip_path%.zip} &&
218 test_path_is_missing "$folder" &&
219 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
220 test_file_not_empty out &&
221 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
222 grep "$(pwd)/.git/objects" out &&
223 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
224 grep "^Total: [1-9]" out
227 test_done