transport-helper: fix leaking import/export marks
[git/gitster.git] / t / t5801-remote-helpers.sh
blobd4882288a30ca056c83201b3f1ce9d29fbd07014
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_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY"/lib-gpg.sh
15 PATH="$TEST_DIRECTORY/t5801:$PATH"
17 compare_refs() {
18 fail= &&
19 if test "x$1" = 'x!'
20 then
21 fail='!' &&
22 shift
23 fi &&
24 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
25 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
26 eval $fail test_cmp expect actual
29 test_expect_success 'setup repository' '
30 git init server &&
31 (cd server &&
32 echo content >file &&
33 git add file &&
34 git commit -m one)
37 test_expect_success 'cloning from local repo' '
38 git clone "testgit::${PWD}/server" local &&
39 test_cmp server/file local/file
42 test_expect_success 'clone with remote.*.vcs config' '
43 GIT_TRACE=$PWD/vcs-clone.trace \
44 git clone --no-local -c remote.origin.vcs=testgit "$PWD/server" vcs-clone &&
45 test_grep remote-testgit vcs-clone.trace
48 test_expect_success 'fetch with configured remote.*.vcs' '
49 git init vcs-fetch &&
50 git -C vcs-fetch config remote.origin.vcs testgit &&
51 git -C vcs-fetch config remote.origin.url "$PWD/server" &&
52 GIT_TRACE=$PWD/vcs-fetch.trace \
53 git -C vcs-fetch fetch origin &&
54 test_grep remote-testgit vcs-fetch.trace
57 test_expect_success 'vcs remote with no url' '
58 NOURL_UPSTREAM=$PWD/server &&
59 export NOURL_UPSTREAM &&
60 git init vcs-nourl &&
61 git -C vcs-nourl config remote.origin.vcs nourl &&
62 git -C vcs-nourl fetch origin
65 test_expect_success 'create new commit on remote' '
66 (cd server &&
67 echo content >>file &&
68 git commit -a -m two)
71 test_expect_success 'pulling from local repo' '
72 (cd local && git pull) &&
73 test_cmp server/file local/file
76 test_expect_success 'pushing to local repo' '
77 (cd local &&
78 echo content >>file &&
79 git commit -a -m three &&
80 git push) &&
81 compare_refs local HEAD server HEAD
84 test_expect_success 'fetch new branch' '
85 (cd server &&
86 git reset --hard &&
87 git checkout -b new &&
88 echo content >>file &&
89 git commit -a -m five
90 ) &&
91 (cd local &&
92 git fetch origin new
93 ) &&
94 compare_refs server HEAD local FETCH_HEAD
97 test_expect_success 'fetch multiple branches' '
98 (cd local &&
99 git fetch
100 ) &&
101 compare_refs server main local refs/remotes/origin/main &&
102 compare_refs server new local refs/remotes/origin/new
105 test_expect_success 'push when remote has extra refs' '
106 (cd local &&
107 git reset --hard origin/main &&
108 echo content >>file &&
109 git commit -a -m six &&
110 git push
111 ) &&
112 compare_refs local main server main
115 test_expect_success 'push new branch by name' '
116 (cd local &&
117 git checkout -b new-name &&
118 echo content >>file &&
119 git commit -a -m seven &&
120 git push origin new-name
121 ) &&
122 compare_refs local HEAD server refs/heads/new-name
125 test_expect_success 'push new branch with old:new refspec' '
126 (cd local &&
127 git push origin new-name:new-refspec
128 ) &&
129 compare_refs local HEAD server refs/heads/new-refspec
132 test_expect_success 'push new branch with HEAD:new refspec' '
133 (cd local &&
134 git checkout new-name &&
135 git push origin HEAD:new-refspec-2
136 ) &&
137 compare_refs local HEAD server refs/heads/new-refspec-2
140 test_expect_success 'push delete branch' '
141 (cd local &&
142 git push origin :new-name
143 ) &&
144 test_must_fail git --git-dir="server/.git" \
145 rev-parse --verify refs/heads/new-name
148 test_expect_success 'forced push' '
149 (cd local &&
150 git checkout -b force-test &&
151 echo content >> file &&
152 git commit -a -m eight &&
153 git push origin force-test &&
154 echo content >> file &&
155 git commit -a --amend -m eight-modified &&
156 git push --force origin force-test
157 ) &&
158 compare_refs local refs/heads/force-test server refs/heads/force-test
161 test_expect_success 'cloning without refspec' '
162 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
163 git clone "testgit::${PWD}/server" local2 2>error &&
164 test_grep "this remote helper should implement refspec capability" error &&
165 compare_refs local2 HEAD server HEAD
168 test_expect_success 'pulling without refspecs' '
169 (cd local2 &&
170 git reset --hard &&
171 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
172 test_grep "this remote helper should implement refspec capability" error &&
173 compare_refs local2 HEAD server HEAD
176 test_expect_success 'pushing without refspecs' '
177 test_when_finished "(cd local2 && git reset --hard origin)" &&
178 (cd local2 &&
179 echo content >>file &&
180 git commit -a -m ten &&
181 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
182 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
183 test_must_fail git push 2>../error) &&
184 test_grep "remote-helper doesn.t support push; refspec needed" error
187 test_expect_success 'pulling without marks' '
188 (cd local2 &&
189 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
190 compare_refs local2 HEAD server HEAD
193 test_expect_failure 'pushing without marks' '
194 test_when_finished "(cd local2 && git reset --hard origin)" &&
195 (cd local2 &&
196 echo content >>file &&
197 git commit -a -m twelve &&
198 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
199 compare_refs local2 HEAD server HEAD
202 test_expect_success 'push all with existing object' '
203 (cd local &&
204 git branch dup2 main &&
205 git push origin --all
206 ) &&
207 compare_refs local dup2 server dup2
210 test_expect_success 'push ref with existing object' '
211 (cd local &&
212 git branch dup main &&
213 git push origin dup
214 ) &&
215 compare_refs local dup server dup
218 test_expect_success GPG 'push signed tag' '
219 (cd local &&
220 git checkout main &&
221 git tag -s -m signed-tag signed-tag &&
222 git push origin signed-tag
223 ) &&
224 compare_refs local signed-tag^{} server signed-tag^{} &&
225 compare_refs ! local signed-tag server signed-tag
228 test_expect_success GPG 'push signed tag with signed-tags capability' '
229 (cd local &&
230 git checkout main &&
231 git tag -s -m signed-tag signed-tag-2 &&
232 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
233 ) &&
234 compare_refs local signed-tag-2 server signed-tag-2
237 test_expect_success 'push update refs' '
238 (cd local &&
239 git checkout -b update main &&
240 echo update >>file &&
241 git commit -a -m update &&
242 git push origin update &&
243 git rev-parse --verify remotes/origin/update >expect &&
244 git rev-parse --verify testgit/origin/heads/update >actual &&
245 test_cmp expect actual
249 test_expect_success 'push update refs disabled by no-private-update' '
250 (cd local &&
251 echo more-update >>file &&
252 git commit -a -m more-update &&
253 git rev-parse --verify testgit/origin/heads/update >expect &&
254 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
255 git rev-parse --verify testgit/origin/heads/update >actual &&
256 test_cmp expect actual
260 test_expect_success 'push update refs failure' '
261 (cd local &&
262 git checkout update &&
263 echo "update fail" >>file &&
264 git commit -a -m "update fail" &&
265 git rev-parse --verify testgit/origin/heads/update >expect &&
266 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
267 git push origin update &&
268 git rev-parse --verify testgit/origin/heads/update >actual &&
269 test_cmp expect actual
273 clean_mark () {
274 cut -f 2 -d ' ' "$1" |
275 git cat-file --batch-check |
276 grep commit |
277 sort >$(basename "$1")
280 test_expect_success 'proper failure checks for fetching' '
281 (cd local &&
282 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
283 test_grep -q "error while running fast-import" error
287 test_expect_success 'proper failure checks for pushing' '
288 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
289 (cd local &&
290 git checkout -b crash main &&
291 echo crash >>file &&
292 git commit -a -m crash &&
293 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
294 clean_mark ".git/testgit/origin/git.marks" &&
295 clean_mark ".git/testgit/origin/testgit.marks" &&
296 test_cmp git.marks testgit.marks
300 test_expect_success 'push messages' '
301 (cd local &&
302 git checkout -b new_branch main &&
303 echo new >>file &&
304 git commit -a -m new &&
305 git push origin new_branch &&
306 git fetch origin &&
307 echo new >>file &&
308 git commit -a -m new &&
309 git push origin new_branch 2> msg &&
310 ! grep "\[new branch\]" msg
314 test_expect_success 'fetch HEAD' '
315 (cd server &&
316 git checkout main &&
317 echo more >>file &&
318 git commit -a -m more
319 ) &&
320 (cd local &&
321 git fetch origin HEAD
322 ) &&
323 compare_refs server HEAD local FETCH_HEAD
326 test_expect_success 'fetch url' '
327 (cd server &&
328 git checkout main &&
329 echo more >>file &&
330 git commit -a -m more
331 ) &&
332 (cd local &&
333 git fetch "testgit::${PWD}/../server"
334 ) &&
335 compare_refs server HEAD local FETCH_HEAD
338 test_expect_success 'fetch tag' '
339 (cd server &&
340 git tag v1.0
341 ) &&
342 (cd local &&
343 git fetch
344 ) &&
345 compare_refs local v1.0 server v1.0
348 test_expect_success 'totally broken helper reports failure message' '
349 write_script git-remote-broken <<-\EOF &&
350 read cap_cmd
351 exit 1
353 test_must_fail \
354 env PATH="$PWD:$PATH" \
355 git clone broken://example.com/foo.git 2>stderr &&
356 grep aborted stderr
359 test_done