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
13 .
"$TEST_DIRECTORY"/lib-gpg.sh
15 PATH
="$TEST_DIRECTORY/t5801:$PATH"
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' '
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' '
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 &&
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' '
67 echo content >>file &&
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' '
78 echo content >>file &&
79 git commit -a -m three &&
81 compare_refs local HEAD server HEAD
84 test_expect_success
'fetch new branch' '
87 git checkout -b new &&
88 echo content >>file &&
94 compare_refs server HEAD local FETCH_HEAD
97 test_expect_success
'fetch multiple branches' '
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' '
107 git reset --hard origin/main &&
108 echo content >>file &&
109 git commit -a -m six &&
112 compare_refs local main server main
115 test_expect_success
'push new branch by name' '
117 git checkout -b new-name &&
118 echo content >>file &&
119 git commit -a -m seven &&
120 git push origin new-name
122 compare_refs local HEAD server refs/heads/new-name
125 test_expect_success
'push new branch with old:new refspec' '
127 git push origin new-name:new-refspec
129 compare_refs local HEAD server refs/heads/new-refspec
132 test_expect_success
'push new branch with HEAD:new refspec' '
134 git checkout new-name &&
135 git push origin HEAD:new-refspec-2
137 compare_refs local HEAD server refs/heads/new-refspec-2
140 test_expect_success
'push delete branch' '
142 git push origin :new-name
144 test_must_fail git --git-dir="server/.git" \
145 rev-parse --verify refs/heads/new-name
148 test_expect_success
'forced push' '
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
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' '
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)" &&
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' '
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)" &&
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' '
204 git branch dup2 main &&
205 git push origin --all
207 compare_refs local dup2 server dup2
210 test_expect_success
'push ref with existing object' '
212 git branch dup main &&
215 compare_refs local dup server dup
218 test_expect_success GPG
'push signed tag' '
221 git tag -s -m signed-tag signed-tag &&
222 git push origin signed-tag
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' '
231 git tag -s -m signed-tag signed-tag-2 &&
232 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
234 compare_refs local signed-tag-2 server signed-tag-2
237 test_expect_success
'push update refs' '
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' '
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' '
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
274 cut
-f 2 -d ' ' "$1" |
275 git cat-file
--batch-check |
277 sort >$
(basename "$1")
280 test_expect_success
'proper failure checks for fetching' '
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" &&
290 git checkout -b crash main &&
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' '
302 git checkout -b new_branch main &&
304 git commit -a -m new &&
305 git push origin new_branch &&
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' '
318 git commit -a -m more
321 git fetch origin HEAD
323 compare_refs server HEAD local FETCH_HEAD
326 test_expect_success
'fetch url' '
330 git commit -a -m more
333 git fetch "testgit::${PWD}/../server"
335 compare_refs server HEAD local FETCH_HEAD
338 test_expect_success
'fetch tag' '
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 &&
354 env PATH="$PWD:$PATH" \
355 git clone broken://example.com/foo.git 2>stderr &&