3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description
='Test remote-helper import and export commands'
9 .
"$TEST_DIRECTORY"/lib-gpg.sh
11 PATH
="$TEST_DIRECTORY/t5801:$PATH"
14 git
--git-dir="$1/.git" rev-parse
--verify $2 >expect
&&
15 git
--git-dir="$3/.git" rev-parse
--verify $4 >actual
&&
16 test_cmp expect actual
19 test_expect_success
'setup repository' '
27 test_expect_success
'cloning from local repo' '
28 git clone "testgit::${PWD}/server" local &&
29 test_cmp server/file local/file
32 test_expect_success
'create new commit on remote' '
34 echo content >>file &&
38 test_expect_success
'pulling from local repo' '
39 (cd local && git pull) &&
40 test_cmp server/file local/file
43 test_expect_success
'pushing to local repo' '
45 echo content >>file &&
46 git commit -a -m three &&
48 compare_refs local HEAD server HEAD
51 test_expect_success
'fetch new branch' '
54 git checkout -b new &&
55 echo content >>file &&
61 compare_refs server HEAD local FETCH_HEAD
64 test_expect_success
'fetch multiple branches' '
68 compare_refs server master local refs/remotes/origin/master &&
69 compare_refs server new local refs/remotes/origin/new
72 test_expect_success
'push when remote has extra refs' '
74 git reset --hard origin/master &&
75 echo content >>file &&
76 git commit -a -m six &&
79 compare_refs local master server master
82 test_expect_success
'push new branch by name' '
84 git checkout -b new-name &&
85 echo content >>file &&
86 git commit -a -m seven &&
87 git push origin new-name
89 compare_refs local HEAD server refs/heads/new-name
92 test_expect_success
'push new branch with old:new refspec' '
94 git push origin new-name:new-refspec
96 compare_refs local HEAD server refs/heads/new-refspec
99 test_expect_success
'push new branch with HEAD:new refspec' '
101 git checkout new-name &&
102 git push origin HEAD:new-refspec-2
104 compare_refs local HEAD server refs/heads/new-refspec-2
107 test_expect_success
'push delete branch' '
109 git push origin :new-name
111 test_must_fail git --git-dir="server/.git" \
112 rev-parse --verify refs/heads/new-name
115 test_expect_success
'forced push' '
117 git checkout -b force-test &&
118 echo content >> file &&
119 git commit -a -m eight &&
120 git push origin force-test &&
121 echo content >> file &&
122 git commit -a --amend -m eight-modified &&
123 git push --force origin force-test
125 compare_refs local refs/heads/force-test server refs/heads/force-test
128 test_expect_success
'cloning without refspec' '
129 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
130 git clone "testgit::${PWD}/server" local2 2>error &&
131 test_i18ngrep "this remote helper should implement refspec capability" error &&
132 compare_refs local2 HEAD server HEAD
135 test_expect_success
'pulling without refspecs' '
138 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
139 test_i18ngrep "this remote helper should implement refspec capability" error &&
140 compare_refs local2 HEAD server HEAD
143 test_expect_success
'pushing without refspecs' '
144 test_when_finished "(cd local2 && git reset --hard origin)" &&
146 echo content >>file &&
147 git commit -a -m ten &&
148 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
149 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
150 test_must_fail git push 2>../error) &&
151 test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
154 test_expect_success
'pulling without marks' '
156 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
157 compare_refs local2 HEAD server HEAD
160 test_expect_failure
'pushing without marks' '
161 test_when_finished "(cd local2 && git reset --hard origin)" &&
163 echo content >>file &&
164 git commit -a -m twelve &&
165 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
166 compare_refs local2 HEAD server HEAD
169 test_expect_success
'push all with existing object' '
171 git branch dup2 master &&
172 git push origin --all
174 compare_refs local dup2 server dup2
177 test_expect_success
'push ref with existing object' '
179 git branch dup master &&
182 compare_refs local dup server dup
185 test_expect_success GPG
'push signed tag' '
187 git checkout master &&
188 git tag -s -m signed-tag signed-tag &&
189 git push origin signed-tag
191 compare_refs local signed-tag^{} server signed-tag^{} &&
192 test_must_fail compare_refs local signed-tag server signed-tag
195 test_expect_success GPG
'push signed tag with signed-tags capability' '
197 git checkout master &&
198 git tag -s -m signed-tag signed-tag-2 &&
199 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
201 compare_refs local signed-tag-2 server signed-tag-2
204 test_expect_success
'push update refs' '
206 git checkout -b update master &&
207 echo update >>file &&
208 git commit -a -m update &&
209 git push origin update &&
210 git rev-parse --verify remotes/origin/update >expect &&
211 git rev-parse --verify testgit/origin/heads/update >actual &&
212 test_cmp expect actual
216 test_expect_success
'push update refs disabled by no-private-update' '
218 echo more-update >>file &&
219 git commit -a -m more-update &&
220 git rev-parse --verify testgit/origin/heads/update >expect &&
221 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
222 git rev-parse --verify testgit/origin/heads/update >actual &&
223 test_cmp expect actual
227 test_expect_success
'push update refs failure' '
229 git checkout update &&
230 echo "update fail" >>file &&
231 git commit -a -m "update fail" &&
232 git rev-parse --verify testgit/origin/heads/update >expect &&
233 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
234 git push origin update &&
235 git rev-parse --verify testgit/origin/heads/update >actual &&
236 test_cmp expect actual
241 cut
-f 2 -d ' ' "$1" |
242 git cat-file
--batch-check |
244 sort >$
(basename "$1")
247 test_expect_success
'proper failure checks for fetching' '
249 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
250 test_i18ngrep -q "error while running fast-import" error
254 test_expect_success
'proper failure checks for pushing' '
255 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
257 git checkout -b crash master &&
259 git commit -a -m crash &&
260 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
261 clean_mark ".git/testgit/origin/git.marks" &&
262 clean_mark ".git/testgit/origin/testgit.marks" &&
263 test_cmp git.marks testgit.marks
267 test_expect_success
'push messages' '
269 git checkout -b new_branch master &&
271 git commit -a -m new &&
272 git push origin new_branch &&
275 git commit -a -m new &&
276 git push origin new_branch 2> msg &&
277 ! grep "\[new branch\]" msg
281 test_expect_success
'fetch HEAD' '
283 git checkout master &&
285 git commit -a -m more
288 git fetch origin HEAD
290 compare_refs server HEAD local FETCH_HEAD
293 test_expect_success
'fetch url' '
295 git checkout master &&
297 git commit -a -m more
300 git fetch "testgit::${PWD}/../server"
302 compare_refs server HEAD local FETCH_HEAD
305 test_expect_success
'fetch tag' '
312 compare_refs local v1.0 server v1.0