]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9210-scalar.sh
clone: allow "--bare" with "-o"
[thirdparty/git.git] / t / t9210-scalar.sh
1 #!/bin/sh
2
3 test_description='test the `scalar` command'
4
5 . ./test-lib.sh
6
7 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
8 export GIT_TEST_MAINT_SCHEDULER
9
10 test_expect_success 'scalar shows a usage' '
11 test_expect_code 129 scalar -h
12 '
13
14 test_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
34 test_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
54 test_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
77 test_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
87 test_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
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
105 '
106
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
120 '
121
122 test_expect_success 'set up repository to clone' '
123 test_commit first &&
124 test_commit second &&
125 test_commit third &&
126 git switch -c parallel first &&
127 mkdir -p 1/2 &&
128 test_commit 1/2/3 &&
129 git config uploadPack.allowFilter true &&
130 git config uploadPack.allowAnySHA1InWant true
131 '
132
133 test_expect_success 'scalar clone' '
134 second=$(git rev-parse --verify second:second.t) &&
135 scalar clone "file://$(pwd)" cloned --single-branch &&
136 (
137 cd cloned/src &&
138
139 git config --get --global --fixed-value maintenance.repo \
140 "$(pwd)" &&
141
142 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
143 echo "refs/remotes/origin/parallel" >expect &&
144 test_cmp expect actual &&
145
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
152 )
153 '
154
155 test_expect_success 'scalar reconfigure' '
156 git init one/src &&
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)"
164 '
165
166 test_expect_success 'scalar delete without enlistment shows a usage' '
167 test_expect_code 129 scalar delete
168 '
169
170 test_expect_success 'scalar delete with enlistment' '
171 scalar delete cloned &&
172 test_path_is_missing cloned
173 '
174
175 test_expect_success 'scalar supports -c/-C' '
176 test_when_finished "scalar delete sub" &&
177 git init 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)"
181 '
182
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
186 '
187
188 SQ="'"
189 test_expect_success UNZIP 'scalar diagnose' '
190 scalar clone "file://$(pwd)" cloned --single-branch &&
191 git repack &&
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
208 '
209
210 test_done