Git 2.46-rc0
[git/gitster.git] / t / t5801-remote-helpers.sh
blob20f43f7b7d3e21c589483f17f9103f12629c3529
1 #!/bin/sh
3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY"/lib-gpg.sh
14 PATH="$TEST_DIRECTORY/t5801:$PATH"
16 compare_refs() {
17 fail= &&
18 if test "x$1" = 'x!'
19 then
20 fail='!' &&
21 shift
22 fi &&
23 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
24 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
25 eval $fail test_cmp expect actual
28 test_expect_success 'setup repository' '
29 git init server &&
30 (cd server &&
31 echo content >file &&
32 git add file &&
33 git commit -m one)
36 test_expect_success 'cloning from local repo' '
37 git clone "testgit::${PWD}/server" local &&
38 test_cmp server/file local/file
41 test_expect_success 'clone with remote.*.vcs config' '
42 GIT_TRACE=$PWD/vcs-clone.trace \
43 git clone --no-local -c remote.origin.vcs=testgit "$PWD/server" vcs-clone &&
44 test_grep remote-testgit vcs-clone.trace
47 test_expect_success 'fetch with configured remote.*.vcs' '
48 git init vcs-fetch &&
49 git -C vcs-fetch config remote.origin.vcs testgit &&
50 git -C vcs-fetch config remote.origin.url "$PWD/server" &&
51 GIT_TRACE=$PWD/vcs-fetch.trace \
52 git -C vcs-fetch fetch origin &&
53 test_grep remote-testgit vcs-fetch.trace
56 test_expect_success 'vcs remote with no url' '
57 NOURL_UPSTREAM=$PWD/server &&
58 export NOURL_UPSTREAM &&
59 git init vcs-nourl &&
60 git -C vcs-nourl config remote.origin.vcs nourl &&
61 git -C vcs-nourl fetch origin
64 test_expect_success 'create new commit on remote' '
65 (cd server &&
66 echo content >>file &&
67 git commit -a -m two)
70 test_expect_success 'pulling from local repo' '
71 (cd local && git pull) &&
72 test_cmp server/file local/file
75 test_expect_success 'pushing to local repo' '
76 (cd local &&
77 echo content >>file &&
78 git commit -a -m three &&
79 git push) &&
80 compare_refs local HEAD server HEAD
83 test_expect_success 'fetch new branch' '
84 (cd server &&
85 git reset --hard &&
86 git checkout -b new &&
87 echo content >>file &&
88 git commit -a -m five
89 ) &&
90 (cd local &&
91 git fetch origin new
92 ) &&
93 compare_refs server HEAD local FETCH_HEAD
96 test_expect_success 'fetch multiple branches' '
97 (cd local &&
98 git fetch
99 ) &&
100 compare_refs server main local refs/remotes/origin/main &&
101 compare_refs server new local refs/remotes/origin/new
104 test_expect_success 'push when remote has extra refs' '
105 (cd local &&
106 git reset --hard origin/main &&
107 echo content >>file &&
108 git commit -a -m six &&
109 git push
110 ) &&
111 compare_refs local main server main
114 test_expect_success 'push new branch by name' '
115 (cd local &&
116 git checkout -b new-name &&
117 echo content >>file &&
118 git commit -a -m seven &&
119 git push origin new-name
120 ) &&
121 compare_refs local HEAD server refs/heads/new-name
124 test_expect_success 'push new branch with old:new refspec' '
125 (cd local &&
126 git push origin new-name:new-refspec
127 ) &&
128 compare_refs local HEAD server refs/heads/new-refspec
131 test_expect_success 'push new branch with HEAD:new refspec' '
132 (cd local &&
133 git checkout new-name &&
134 git push origin HEAD:new-refspec-2
135 ) &&
136 compare_refs local HEAD server refs/heads/new-refspec-2
139 test_expect_success 'push delete branch' '
140 (cd local &&
141 git push origin :new-name
142 ) &&
143 test_must_fail git --git-dir="server/.git" \
144 rev-parse --verify refs/heads/new-name
147 test_expect_success 'forced push' '
148 (cd local &&
149 git checkout -b force-test &&
150 echo content >> file &&
151 git commit -a -m eight &&
152 git push origin force-test &&
153 echo content >> file &&
154 git commit -a --amend -m eight-modified &&
155 git push --force origin force-test
156 ) &&
157 compare_refs local refs/heads/force-test server refs/heads/force-test
160 test_expect_success 'cloning without refspec' '
161 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
162 git clone "testgit::${PWD}/server" local2 2>error &&
163 test_grep "this remote helper should implement refspec capability" error &&
164 compare_refs local2 HEAD server HEAD
167 test_expect_success 'pulling without refspecs' '
168 (cd local2 &&
169 git reset --hard &&
170 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
171 test_grep "this remote helper should implement refspec capability" error &&
172 compare_refs local2 HEAD server HEAD
175 test_expect_success 'pushing without refspecs' '
176 test_when_finished "(cd local2 && git reset --hard origin)" &&
177 (cd local2 &&
178 echo content >>file &&
179 git commit -a -m ten &&
180 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
181 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
182 test_must_fail git push 2>../error) &&
183 test_grep "remote-helper doesn.t support push; refspec needed" error
186 test_expect_success 'pulling without marks' '
187 (cd local2 &&
188 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
189 compare_refs local2 HEAD server HEAD
192 test_expect_failure 'pushing without marks' '
193 test_when_finished "(cd local2 && git reset --hard origin)" &&
194 (cd local2 &&
195 echo content >>file &&
196 git commit -a -m twelve &&
197 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
198 compare_refs local2 HEAD server HEAD
201 test_expect_success 'push all with existing object' '
202 (cd local &&
203 git branch dup2 main &&
204 git push origin --all
205 ) &&
206 compare_refs local dup2 server dup2
209 test_expect_success 'push ref with existing object' '
210 (cd local &&
211 git branch dup main &&
212 git push origin dup
213 ) &&
214 compare_refs local dup server dup
217 test_expect_success GPG 'push signed tag' '
218 (cd local &&
219 git checkout main &&
220 git tag -s -m signed-tag signed-tag &&
221 git push origin signed-tag
222 ) &&
223 compare_refs local signed-tag^{} server signed-tag^{} &&
224 compare_refs ! local signed-tag server signed-tag
227 test_expect_success GPG 'push signed tag with signed-tags capability' '
228 (cd local &&
229 git checkout main &&
230 git tag -s -m signed-tag signed-tag-2 &&
231 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
232 ) &&
233 compare_refs local signed-tag-2 server signed-tag-2
236 test_expect_success 'push update refs' '
237 (cd local &&
238 git checkout -b update main &&
239 echo update >>file &&
240 git commit -a -m update &&
241 git push origin update &&
242 git rev-parse --verify remotes/origin/update >expect &&
243 git rev-parse --verify testgit/origin/heads/update >actual &&
244 test_cmp expect actual
248 test_expect_success 'push update refs disabled by no-private-update' '
249 (cd local &&
250 echo more-update >>file &&
251 git commit -a -m more-update &&
252 git rev-parse --verify testgit/origin/heads/update >expect &&
253 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
254 git rev-parse --verify testgit/origin/heads/update >actual &&
255 test_cmp expect actual
259 test_expect_success 'push update refs failure' '
260 (cd local &&
261 git checkout update &&
262 echo "update fail" >>file &&
263 git commit -a -m "update fail" &&
264 git rev-parse --verify testgit/origin/heads/update >expect &&
265 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
266 git push origin update &&
267 git rev-parse --verify testgit/origin/heads/update >actual &&
268 test_cmp expect actual
272 clean_mark () {
273 cut -f 2 -d ' ' "$1" |
274 git cat-file --batch-check |
275 grep commit |
276 sort >$(basename "$1")
279 test_expect_success 'proper failure checks for fetching' '
280 (cd local &&
281 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
282 test_grep -q "error while running fast-import" error
286 test_expect_success 'proper failure checks for pushing' '
287 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
288 (cd local &&
289 git checkout -b crash main &&
290 echo crash >>file &&
291 git commit -a -m crash &&
292 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
293 clean_mark ".git/testgit/origin/git.marks" &&
294 clean_mark ".git/testgit/origin/testgit.marks" &&
295 test_cmp git.marks testgit.marks
299 test_expect_success 'push messages' '
300 (cd local &&
301 git checkout -b new_branch main &&
302 echo new >>file &&
303 git commit -a -m new &&
304 git push origin new_branch &&
305 git fetch origin &&
306 echo new >>file &&
307 git commit -a -m new &&
308 git push origin new_branch 2> msg &&
309 ! grep "\[new branch\]" msg
313 test_expect_success 'fetch HEAD' '
314 (cd server &&
315 git checkout main &&
316 echo more >>file &&
317 git commit -a -m more
318 ) &&
319 (cd local &&
320 git fetch origin HEAD
321 ) &&
322 compare_refs server HEAD local FETCH_HEAD
325 test_expect_success 'fetch url' '
326 (cd server &&
327 git checkout main &&
328 echo more >>file &&
329 git commit -a -m more
330 ) &&
331 (cd local &&
332 git fetch "testgit::${PWD}/../server"
333 ) &&
334 compare_refs server HEAD local FETCH_HEAD
337 test_expect_success 'fetch tag' '
338 (cd server &&
339 git tag v1.0
340 ) &&
341 (cd local &&
342 git fetch
343 ) &&
344 compare_refs local v1.0 server v1.0
347 test_done