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
12 .
"$TEST_DIRECTORY"/lib-gpg.sh
14 PATH
="$TEST_DIRECTORY/t5801:$PATH"
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' '
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' '
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 &&
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' '
66 echo content >>file &&
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' '
77 echo content >>file &&
78 git commit -a -m three &&
80 compare_refs local HEAD server HEAD
83 test_expect_success
'fetch new branch' '
86 git checkout -b new &&
87 echo content >>file &&
93 compare_refs server HEAD local FETCH_HEAD
96 test_expect_success
'fetch multiple branches' '
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' '
106 git reset --hard origin/main &&
107 echo content >>file &&
108 git commit -a -m six &&
111 compare_refs local main server main
114 test_expect_success
'push new branch by name' '
116 git checkout -b new-name &&
117 echo content >>file &&
118 git commit -a -m seven &&
119 git push origin new-name
121 compare_refs local HEAD server refs/heads/new-name
124 test_expect_success
'push new branch with old:new refspec' '
126 git push origin new-name:new-refspec
128 compare_refs local HEAD server refs/heads/new-refspec
131 test_expect_success
'push new branch with HEAD:new refspec' '
133 git checkout new-name &&
134 git push origin HEAD:new-refspec-2
136 compare_refs local HEAD server refs/heads/new-refspec-2
139 test_expect_success
'push delete branch' '
141 git push origin :new-name
143 test_must_fail git --git-dir="server/.git" \
144 rev-parse --verify refs/heads/new-name
147 test_expect_success
'forced push' '
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
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' '
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)" &&
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' '
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)" &&
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' '
203 git branch dup2 main &&
204 git push origin --all
206 compare_refs local dup2 server dup2
209 test_expect_success
'push ref with existing object' '
211 git branch dup main &&
214 compare_refs local dup server dup
217 test_expect_success GPG
'push signed tag' '
220 git tag -s -m signed-tag signed-tag &&
221 git push origin signed-tag
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' '
230 git tag -s -m signed-tag signed-tag-2 &&
231 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
233 compare_refs local signed-tag-2 server signed-tag-2
236 test_expect_success
'push update refs' '
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' '
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' '
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
273 cut
-f 2 -d ' ' "$1" |
274 git cat-file
--batch-check |
276 sort >$
(basename "$1")
279 test_expect_success
'proper failure checks for fetching' '
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" &&
289 git checkout -b crash main &&
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' '
301 git checkout -b new_branch main &&
303 git commit -a -m new &&
304 git push origin new_branch &&
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' '
317 git commit -a -m more
320 git fetch origin HEAD
322 compare_refs server HEAD local FETCH_HEAD
325 test_expect_success
'fetch url' '
329 git commit -a -m more
332 git fetch "testgit::${PWD}/../server"
334 compare_refs server HEAD local FETCH_HEAD
337 test_expect_success
'fetch tag' '
344 compare_refs local v1.0 server v1.0