debian: new upstream release candidate
[git/debian.git] / t / t5801-remote-helpers.sh
blob0f04b6cddb723316b0edf1135086405a09e4205b
1 #!/bin/sh
3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-gpg.sh
11 PATH="$TEST_DIRECTORY/t5801:$PATH"
13 compare_refs() {
14 fail= &&
15 if test "x$1" = 'x!'
16 then
17 fail='!' &&
18 shift
19 fi &&
20 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
21 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
22 eval $fail test_cmp expect actual
25 test_expect_success 'setup repository' '
26 git init server &&
27 (cd server &&
28 echo content >file &&
29 git add file &&
30 git commit -m one)
33 test_expect_success 'cloning from local repo' '
34 git clone "testgit::${PWD}/server" local &&
35 test_cmp server/file local/file
38 test_expect_success 'create new commit on remote' '
39 (cd server &&
40 echo content >>file &&
41 git commit -a -m two)
44 test_expect_success 'pulling from local repo' '
45 (cd local && git pull) &&
46 test_cmp server/file local/file
49 test_expect_success 'pushing to local repo' '
50 (cd local &&
51 echo content >>file &&
52 git commit -a -m three &&
53 git push) &&
54 compare_refs local HEAD server HEAD
57 test_expect_success 'fetch new branch' '
58 (cd server &&
59 git reset --hard &&
60 git checkout -b new &&
61 echo content >>file &&
62 git commit -a -m five
63 ) &&
64 (cd local &&
65 git fetch origin new
66 ) &&
67 compare_refs server HEAD local FETCH_HEAD
70 test_expect_success 'fetch multiple branches' '
71 (cd local &&
72 git fetch
73 ) &&
74 compare_refs server master local refs/remotes/origin/master &&
75 compare_refs server new local refs/remotes/origin/new
78 test_expect_success 'push when remote has extra refs' '
79 (cd local &&
80 git reset --hard origin/master &&
81 echo content >>file &&
82 git commit -a -m six &&
83 git push
84 ) &&
85 compare_refs local master server master
88 test_expect_success 'push new branch by name' '
89 (cd local &&
90 git checkout -b new-name &&
91 echo content >>file &&
92 git commit -a -m seven &&
93 git push origin new-name
94 ) &&
95 compare_refs local HEAD server refs/heads/new-name
98 test_expect_success 'push new branch with old:new refspec' '
99 (cd local &&
100 git push origin new-name:new-refspec
101 ) &&
102 compare_refs local HEAD server refs/heads/new-refspec
105 test_expect_success 'push new branch with HEAD:new refspec' '
106 (cd local &&
107 git checkout new-name &&
108 git push origin HEAD:new-refspec-2
109 ) &&
110 compare_refs local HEAD server refs/heads/new-refspec-2
113 test_expect_success 'push delete branch' '
114 (cd local &&
115 git push origin :new-name
116 ) &&
117 test_must_fail git --git-dir="server/.git" \
118 rev-parse --verify refs/heads/new-name
121 test_expect_success 'forced push' '
122 (cd local &&
123 git checkout -b force-test &&
124 echo content >> file &&
125 git commit -a -m eight &&
126 git push origin force-test &&
127 echo content >> file &&
128 git commit -a --amend -m eight-modified &&
129 git push --force origin force-test
130 ) &&
131 compare_refs local refs/heads/force-test server refs/heads/force-test
134 test_expect_success 'cloning without refspec' '
135 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
136 git clone "testgit::${PWD}/server" local2 2>error &&
137 test_i18ngrep "this remote helper should implement refspec capability" error &&
138 compare_refs local2 HEAD server HEAD
141 test_expect_success 'pulling without refspecs' '
142 (cd local2 &&
143 git reset --hard &&
144 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
145 test_i18ngrep "this remote helper should implement refspec capability" error &&
146 compare_refs local2 HEAD server HEAD
149 test_expect_success 'pushing without refspecs' '
150 test_when_finished "(cd local2 && git reset --hard origin)" &&
151 (cd local2 &&
152 echo content >>file &&
153 git commit -a -m ten &&
154 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
155 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
156 test_must_fail git push 2>../error) &&
157 test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
160 test_expect_success 'pulling without marks' '
161 (cd local2 &&
162 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
163 compare_refs local2 HEAD server HEAD
166 test_expect_failure 'pushing without marks' '
167 test_when_finished "(cd local2 && git reset --hard origin)" &&
168 (cd local2 &&
169 echo content >>file &&
170 git commit -a -m twelve &&
171 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
172 compare_refs local2 HEAD server HEAD
175 test_expect_success 'push all with existing object' '
176 (cd local &&
177 git branch dup2 master &&
178 git push origin --all
179 ) &&
180 compare_refs local dup2 server dup2
183 test_expect_success 'push ref with existing object' '
184 (cd local &&
185 git branch dup master &&
186 git push origin dup
187 ) &&
188 compare_refs local dup server dup
191 test_expect_success GPG 'push signed tag' '
192 (cd local &&
193 git checkout master &&
194 git tag -s -m signed-tag signed-tag &&
195 git push origin signed-tag
196 ) &&
197 compare_refs local signed-tag^{} server signed-tag^{} &&
198 compare_refs ! local signed-tag server signed-tag
201 test_expect_success GPG 'push signed tag with signed-tags capability' '
202 (cd local &&
203 git checkout master &&
204 git tag -s -m signed-tag signed-tag-2 &&
205 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
206 ) &&
207 compare_refs local signed-tag-2 server signed-tag-2
210 test_expect_success 'push update refs' '
211 (cd local &&
212 git checkout -b update master &&
213 echo update >>file &&
214 git commit -a -m update &&
215 git push origin update &&
216 git rev-parse --verify remotes/origin/update >expect &&
217 git rev-parse --verify testgit/origin/heads/update >actual &&
218 test_cmp expect actual
222 test_expect_success 'push update refs disabled by no-private-update' '
223 (cd local &&
224 echo more-update >>file &&
225 git commit -a -m more-update &&
226 git rev-parse --verify testgit/origin/heads/update >expect &&
227 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
228 git rev-parse --verify testgit/origin/heads/update >actual &&
229 test_cmp expect actual
233 test_expect_success 'push update refs failure' '
234 (cd local &&
235 git checkout update &&
236 echo "update fail" >>file &&
237 git commit -a -m "update fail" &&
238 git rev-parse --verify testgit/origin/heads/update >expect &&
239 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
240 git push origin update &&
241 git rev-parse --verify testgit/origin/heads/update >actual &&
242 test_cmp expect actual
246 clean_mark () {
247 cut -f 2 -d ' ' "$1" |
248 git cat-file --batch-check |
249 grep commit |
250 sort >$(basename "$1")
253 test_expect_success 'proper failure checks for fetching' '
254 (cd local &&
255 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
256 test_i18ngrep -q "error while running fast-import" error
260 test_expect_success 'proper failure checks for pushing' '
261 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
262 (cd local &&
263 git checkout -b crash master &&
264 echo crash >>file &&
265 git commit -a -m crash &&
266 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
267 clean_mark ".git/testgit/origin/git.marks" &&
268 clean_mark ".git/testgit/origin/testgit.marks" &&
269 test_cmp git.marks testgit.marks
273 test_expect_success 'push messages' '
274 (cd local &&
275 git checkout -b new_branch master &&
276 echo new >>file &&
277 git commit -a -m new &&
278 git push origin new_branch &&
279 git fetch origin &&
280 echo new >>file &&
281 git commit -a -m new &&
282 git push origin new_branch 2> msg &&
283 ! grep "\[new branch\]" msg
287 test_expect_success 'fetch HEAD' '
288 (cd server &&
289 git checkout master &&
290 echo more >>file &&
291 git commit -a -m more
292 ) &&
293 (cd local &&
294 git fetch origin HEAD
295 ) &&
296 compare_refs server HEAD local FETCH_HEAD
299 test_expect_success 'fetch url' '
300 (cd server &&
301 git checkout master &&
302 echo more >>file &&
303 git commit -a -m more
304 ) &&
305 (cd local &&
306 git fetch "testgit::${PWD}/../server"
307 ) &&
308 compare_refs server HEAD local FETCH_HEAD
311 test_expect_success 'fetch tag' '
312 (cd server &&
313 git tag v1.0
314 ) &&
315 (cd local &&
316 git fetch
317 ) &&
318 compare_refs local v1.0 server v1.0
321 test_done