3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description
='Test remote-helper import and export commands'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
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
'create new commit on remote' '
43 echo content >>file &&
47 test_expect_success
'pulling from local repo' '
48 (cd local && git pull) &&
49 test_cmp server/file local/file
52 test_expect_success
'pushing to local repo' '
54 echo content >>file &&
55 git commit -a -m three &&
57 compare_refs local HEAD server HEAD
60 test_expect_success
'fetch new branch' '
63 git checkout -b new &&
64 echo content >>file &&
70 compare_refs server HEAD local FETCH_HEAD
73 test_expect_success
'fetch multiple branches' '
77 compare_refs server master local refs/remotes/origin/master &&
78 compare_refs server new local refs/remotes/origin/new
81 test_expect_success
'push when remote has extra refs' '
83 git reset --hard origin/master &&
84 echo content >>file &&
85 git commit -a -m six &&
88 compare_refs local master server master
91 test_expect_success
'push new branch by name' '
93 git checkout -b new-name &&
94 echo content >>file &&
95 git commit -a -m seven &&
96 git push origin new-name
98 compare_refs local HEAD server refs/heads/new-name
101 test_expect_success
'push new branch with old:new refspec' '
103 git push origin new-name:new-refspec
105 compare_refs local HEAD server refs/heads/new-refspec
108 test_expect_success
'push new branch with HEAD:new refspec' '
110 git checkout new-name &&
111 git push origin HEAD:new-refspec-2
113 compare_refs local HEAD server refs/heads/new-refspec-2
116 test_expect_success
'push delete branch' '
118 git push origin :new-name
120 test_must_fail git --git-dir="server/.git" \
121 rev-parse --verify refs/heads/new-name
124 test_expect_success
'forced push' '
126 git checkout -b force-test &&
127 echo content >> file &&
128 git commit -a -m eight &&
129 git push origin force-test &&
130 echo content >> file &&
131 git commit -a --amend -m eight-modified &&
132 git push --force origin force-test
134 compare_refs local refs/heads/force-test server refs/heads/force-test
137 test_expect_success
'cloning without refspec' '
138 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
139 git clone "testgit::${PWD}/server" local2 2>error &&
140 test_i18ngrep "this remote helper should implement refspec capability" error &&
141 compare_refs local2 HEAD server HEAD
144 test_expect_success
'pulling without refspecs' '
147 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
148 test_i18ngrep "this remote helper should implement refspec capability" error &&
149 compare_refs local2 HEAD server HEAD
152 test_expect_success
'pushing without refspecs' '
153 test_when_finished "(cd local2 && git reset --hard origin)" &&
155 echo content >>file &&
156 git commit -a -m ten &&
157 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
158 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
159 test_must_fail git push 2>../error) &&
160 test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
163 test_expect_success
'pulling without marks' '
165 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
166 compare_refs local2 HEAD server HEAD
169 test_expect_failure
'pushing without marks' '
170 test_when_finished "(cd local2 && git reset --hard origin)" &&
172 echo content >>file &&
173 git commit -a -m twelve &&
174 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
175 compare_refs local2 HEAD server HEAD
178 test_expect_success
'push all with existing object' '
180 git branch dup2 master &&
181 git push origin --all
183 compare_refs local dup2 server dup2
186 test_expect_success
'push ref with existing object' '
188 git branch dup master &&
191 compare_refs local dup server dup
194 test_expect_success GPG
'push signed tag' '
196 git checkout master &&
197 git tag -s -m signed-tag signed-tag &&
198 git push origin signed-tag
200 compare_refs local signed-tag^{} server signed-tag^{} &&
201 compare_refs ! local signed-tag server signed-tag
204 test_expect_success GPG
'push signed tag with signed-tags capability' '
206 git checkout master &&
207 git tag -s -m signed-tag signed-tag-2 &&
208 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
210 compare_refs local signed-tag-2 server signed-tag-2
213 test_expect_success
'push update refs' '
215 git checkout -b update master &&
216 echo update >>file &&
217 git commit -a -m update &&
218 git push origin update &&
219 git rev-parse --verify remotes/origin/update >expect &&
220 git rev-parse --verify testgit/origin/heads/update >actual &&
221 test_cmp expect actual
225 test_expect_success
'push update refs disabled by no-private-update' '
227 echo more-update >>file &&
228 git commit -a -m more-update &&
229 git rev-parse --verify testgit/origin/heads/update >expect &&
230 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
231 git rev-parse --verify testgit/origin/heads/update >actual &&
232 test_cmp expect actual
236 test_expect_success
'push update refs failure' '
238 git checkout update &&
239 echo "update fail" >>file &&
240 git commit -a -m "update fail" &&
241 git rev-parse --verify testgit/origin/heads/update >expect &&
242 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
243 git push origin update &&
244 git rev-parse --verify testgit/origin/heads/update >actual &&
245 test_cmp expect actual
250 cut
-f 2 -d ' ' "$1" |
251 git cat-file
--batch-check |
253 sort >$
(basename "$1")
256 test_expect_success
'proper failure checks for fetching' '
258 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
259 test_i18ngrep -q "error while running fast-import" error
263 test_expect_success
'proper failure checks for pushing' '
264 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
266 git checkout -b crash master &&
268 git commit -a -m crash &&
269 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
270 clean_mark ".git/testgit/origin/git.marks" &&
271 clean_mark ".git/testgit/origin/testgit.marks" &&
272 test_cmp git.marks testgit.marks
276 test_expect_success
'push messages' '
278 git checkout -b new_branch master &&
280 git commit -a -m new &&
281 git push origin new_branch &&
284 git commit -a -m new &&
285 git push origin new_branch 2> msg &&
286 ! grep "\[new branch\]" msg
290 test_expect_success
'fetch HEAD' '
292 git checkout master &&
294 git commit -a -m more
297 git fetch origin HEAD
299 compare_refs server HEAD local FETCH_HEAD
302 test_expect_success
'fetch url' '
304 git checkout master &&
306 git commit -a -m more
309 git fetch "testgit::${PWD}/../server"
311 compare_refs server HEAD local FETCH_HEAD
314 test_expect_success
'fetch tag' '
321 compare_refs local v1.0 server v1.0