]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5801-remote-helpers.sh
Merge branch 'dl/checkout-p-merge-base'
[thirdparty/git.git] / t / t5801-remote-helpers.sh
CommitLineData
fc407f98
FC
1#!/bin/sh
2#
3# Copyright (c) 2010 Sverre Rabbelier
4#
5
6test_description='Test remote-helper import and export commands'
7
8. ./test-lib.sh
b8bd826f 9. "$TEST_DIRECTORY"/lib-gpg.sh
fc407f98 10
5afb2ce4
JS
11PATH="$TEST_DIRECTORY/t5801:$PATH"
12
fc407f98 13compare_refs() {
ec8f87b8
DL
14 fail= &&
15 if test "x$1" = 'x!'
16 then
17 fail='!' &&
18 shift
19 fi &&
fc407f98
FC
20 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
21 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
ec8f87b8 22 eval $fail test_cmp expect actual
fc407f98
FC
23}
24
25test_expect_success 'setup repository' '
3808b851
FC
26 git init server &&
27 (cd server &&
fc407f98
FC
28 echo content >file &&
29 git add file &&
3808b851 30 git commit -m one)
fc407f98
FC
31'
32
33test_expect_success 'cloning from local repo' '
3808b851
FC
34 git clone "testgit::${PWD}/server" local &&
35 test_cmp server/file local/file
fc407f98
FC
36'
37
fc407f98 38test_expect_success 'create new commit on remote' '
3808b851 39 (cd server &&
fc407f98 40 echo content >>file &&
3808b851 41 git commit -a -m two)
fc407f98
FC
42'
43
44test_expect_success 'pulling from local repo' '
3808b851
FC
45 (cd local && git pull) &&
46 test_cmp server/file local/file
fc407f98
FC
47'
48
fc407f98 49test_expect_success 'pushing to local repo' '
3808b851 50 (cd local &&
fc407f98
FC
51 echo content >>file &&
52 git commit -a -m three &&
53 git push) &&
3808b851 54 compare_refs local HEAD server HEAD
fc407f98
FC
55'
56
fc407f98 57test_expect_success 'fetch new branch' '
3808b851
FC
58 (cd server &&
59 git reset --hard &&
fc407f98
FC
60 git checkout -b new &&
61 echo content >>file &&
3808b851 62 git commit -a -m five
fc407f98 63 ) &&
3808b851 64 (cd local &&
fc407f98
FC
65 git fetch origin new
66 ) &&
3808b851 67 compare_refs server HEAD local FETCH_HEAD
fc407f98
FC
68'
69
70test_expect_success 'fetch multiple branches' '
3808b851 71 (cd local &&
fc407f98
FC
72 git fetch
73 ) &&
3808b851
FC
74 compare_refs server master local refs/remotes/origin/master &&
75 compare_refs server new local refs/remotes/origin/new
fc407f98
FC
76'
77
78test_expect_success 'push when remote has extra refs' '
3808b851 79 (cd local &&
984f3768 80 git reset --hard origin/master &&
fc407f98
FC
81 echo content >>file &&
82 git commit -a -m six &&
83 git push
84 ) &&
3808b851 85 compare_refs local master server master
fc407f98
FC
86'
87
88test_expect_success 'push new branch by name' '
3808b851 89 (cd local &&
fc407f98
FC
90 git checkout -b new-name &&
91 echo content >>file &&
92 git commit -a -m seven &&
93 git push origin new-name
94 ) &&
3808b851 95 compare_refs local HEAD server refs/heads/new-name
fc407f98
FC
96'
97
d98c8153 98test_expect_success 'push new branch with old:new refspec' '
3808b851 99 (cd local &&
fc407f98
FC
100 git push origin new-name:new-refspec
101 ) &&
3808b851 102 compare_refs local HEAD server refs/heads/new-refspec
fc407f98
FC
103'
104
9193f742
FC
105test_expect_success 'push new branch with HEAD:new refspec' '
106 (cd local &&
51b85471 107 git checkout new-name &&
9193f742
FC
108 git push origin HEAD:new-refspec-2
109 ) &&
110 compare_refs local HEAD server refs/heads/new-refspec-2
111'
112
f3d03763
FC
113test_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
119'
120
510fa6f5
FC
121test_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
132'
133
ee10fbf9 134test_expect_success 'cloning without refspec' '
6e17fb34 135 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
a93b4a09 136 git clone "testgit::${PWD}/server" local2 2>error &&
6b5b309f 137 test_i18ngrep "this remote helper should implement refspec capability" error &&
ee10fbf9
FC
138 compare_refs local2 HEAD server HEAD
139'
140
141test_expect_success 'pulling without refspecs' '
142 (cd local2 &&
143 git reset --hard &&
6e17fb34 144 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
6b5b309f 145 test_i18ngrep "this remote helper should implement refspec capability" error &&
ee10fbf9
FC
146 compare_refs local2 HEAD server HEAD
147'
148
21610d82 149test_expect_success 'pushing without refspecs' '
ee10fbf9
FC
150 test_when_finished "(cd local2 && git reset --hard origin)" &&
151 (cd local2 &&
152 echo content >>file &&
153 git commit -a -m ten &&
6e17fb34
FC
154 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
155 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
1afe6e40 156 test_must_fail git push 2>../error) &&
6b5b309f 157 test_i18ngrep "remote-helper doesn.t support push; refspec needed" error
ee10fbf9
FC
158'
159
160test_expect_success 'pulling without marks' '
161 (cd local2 &&
162 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
163 compare_refs local2 HEAD server HEAD
164'
165
166test_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
173'
174
49266e8a
FC
175test_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
181'
182
f28e7c90
FC
183test_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
189'
190
b8bd826f
JK
191test_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 ) &&
0d957a4d 197 compare_refs local signed-tag^{} server signed-tag^{} &&
ec8f87b8 198 compare_refs ! local signed-tag server signed-tag
0d957a4d
JK
199'
200
201test_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
b8bd826f
JK
208'
209
664059fb
FC
210test_expect_success 'push update refs' '
211 (cd local &&
212 git checkout -b update master &&
213 echo update >>file &&
214 git commit -a -m update &&
d6ae7b2d 215 git push origin update &&
664059fb
FC
216 git rev-parse --verify remotes/origin/update >expect &&
217 git rev-parse --verify testgit/origin/heads/update >actual &&
218 test_cmp expect actual
219 )
220'
221
597b831a
MM
222test_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
230 )
231'
232
126aac5c
FC
233test_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 &&
b2c851a8
JH
239 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
240 git push origin update &&
126aac5c
FC
241 git rev-parse --verify testgit/origin/heads/update >actual &&
242 test_cmp expect actual
243 )
244'
245
b2c851a8
JH
246clean_mark () {
247 cut -f 2 -d ' ' "$1" |
248 git cat-file --batch-check |
249 grep commit |
250 sort >$(basename "$1")
251}
252
81d340d4 253test_expect_success 'proper failure checks for fetching' '
b2c851a8
JH
254 (cd local &&
255 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
6b5b309f 256 test_i18ngrep -q "error while running fast-import" error
81d340d4
FC
257 )
258'
259
260test_expect_success 'proper failure checks for pushing' '
c545bc62 261 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
512477b1 262 (cd local &&
b2c851a8
JH
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 &&
c545bc62
JK
267 clean_mark ".git/testgit/origin/git.marks" &&
268 clean_mark ".git/testgit/origin/testgit.marks" &&
269 test_cmp git.marks testgit.marks
81d340d4
FC
270 )
271'
272
b056620f
FC
273test_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
284 )
285'
286
33cae542
MH
287test_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
297'
298
299test_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
309'
310
f80d9223 311test_expect_success 'fetch tag' '
8144f09c
FC
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
319'
320
fc407f98 321test_done