]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5801-remote-helpers.sh
Start the 2.46 cycle
[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
95cf2c01 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
fc407f98 11. ./test-lib.sh
b8bd826f 12. "$TEST_DIRECTORY"/lib-gpg.sh
fc407f98 13
5afb2ce4
JS
14PATH="$TEST_DIRECTORY/t5801:$PATH"
15
fc407f98 16compare_refs() {
ec8f87b8
DL
17 fail= &&
18 if test "x$1" = 'x!'
19 then
20 fail='!' &&
21 shift
22 fi &&
fc407f98
FC
23 git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
24 git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
ec8f87b8 25 eval $fail test_cmp expect actual
fc407f98
FC
26}
27
28test_expect_success 'setup repository' '
3808b851
FC
29 git init server &&
30 (cd server &&
fc407f98
FC
31 echo content >file &&
32 git add file &&
3808b851 33 git commit -m one)
fc407f98
FC
34'
35
36test_expect_success 'cloning from local repo' '
3808b851
FC
37 git clone "testgit::${PWD}/server" local &&
38 test_cmp server/file local/file
fc407f98
FC
39'
40
fc407f98 41test_expect_success 'create new commit on remote' '
3808b851 42 (cd server &&
fc407f98 43 echo content >>file &&
3808b851 44 git commit -a -m two)
fc407f98
FC
45'
46
47test_expect_success 'pulling from local repo' '
3808b851
FC
48 (cd local && git pull) &&
49 test_cmp server/file local/file
fc407f98
FC
50'
51
fc407f98 52test_expect_success 'pushing to local repo' '
3808b851 53 (cd local &&
fc407f98
FC
54 echo content >>file &&
55 git commit -a -m three &&
56 git push) &&
3808b851 57 compare_refs local HEAD server HEAD
fc407f98
FC
58'
59
fc407f98 60test_expect_success 'fetch new branch' '
3808b851
FC
61 (cd server &&
62 git reset --hard &&
fc407f98
FC
63 git checkout -b new &&
64 echo content >>file &&
3808b851 65 git commit -a -m five
fc407f98 66 ) &&
3808b851 67 (cd local &&
fc407f98
FC
68 git fetch origin new
69 ) &&
3808b851 70 compare_refs server HEAD local FETCH_HEAD
fc407f98
FC
71'
72
73test_expect_success 'fetch multiple branches' '
3808b851 74 (cd local &&
fc407f98
FC
75 git fetch
76 ) &&
95cf2c01 77 compare_refs server main local refs/remotes/origin/main &&
3808b851 78 compare_refs server new local refs/remotes/origin/new
fc407f98
FC
79'
80
81test_expect_success 'push when remote has extra refs' '
3808b851 82 (cd local &&
95cf2c01 83 git reset --hard origin/main &&
fc407f98
FC
84 echo content >>file &&
85 git commit -a -m six &&
86 git push
87 ) &&
95cf2c01 88 compare_refs local main server main
fc407f98
FC
89'
90
91test_expect_success 'push new branch by name' '
3808b851 92 (cd local &&
fc407f98
FC
93 git checkout -b new-name &&
94 echo content >>file &&
95 git commit -a -m seven &&
96 git push origin new-name
97 ) &&
3808b851 98 compare_refs local HEAD server refs/heads/new-name
fc407f98
FC
99'
100
d98c8153 101test_expect_success 'push new branch with old:new refspec' '
3808b851 102 (cd local &&
fc407f98
FC
103 git push origin new-name:new-refspec
104 ) &&
3808b851 105 compare_refs local HEAD server refs/heads/new-refspec
fc407f98
FC
106'
107
9193f742
FC
108test_expect_success 'push new branch with HEAD:new refspec' '
109 (cd local &&
51b85471 110 git checkout new-name &&
9193f742
FC
111 git push origin HEAD:new-refspec-2
112 ) &&
113 compare_refs local HEAD server refs/heads/new-refspec-2
114'
115
f3d03763
FC
116test_expect_success 'push delete branch' '
117 (cd local &&
118 git push origin :new-name
119 ) &&
120 test_must_fail git --git-dir="server/.git" \
121 rev-parse --verify refs/heads/new-name
122'
123
510fa6f5
FC
124test_expect_success 'forced push' '
125 (cd local &&
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
133 ) &&
134 compare_refs local refs/heads/force-test server refs/heads/force-test
135'
136
ee10fbf9 137test_expect_success 'cloning without refspec' '
6e17fb34 138 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
a93b4a09 139 git clone "testgit::${PWD}/server" local2 2>error &&
6789275d 140 test_grep "this remote helper should implement refspec capability" error &&
ee10fbf9
FC
141 compare_refs local2 HEAD server HEAD
142'
143
144test_expect_success 'pulling without refspecs' '
145 (cd local2 &&
146 git reset --hard &&
6e17fb34 147 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
6789275d 148 test_grep "this remote helper should implement refspec capability" error &&
ee10fbf9
FC
149 compare_refs local2 HEAD server HEAD
150'
151
21610d82 152test_expect_success 'pushing without refspecs' '
ee10fbf9
FC
153 test_when_finished "(cd local2 && git reset --hard origin)" &&
154 (cd local2 &&
155 echo content >>file &&
156 git commit -a -m ten &&
6e17fb34
FC
157 GIT_REMOTE_TESTGIT_NOREFSPEC=1 &&
158 export GIT_REMOTE_TESTGIT_NOREFSPEC &&
1afe6e40 159 test_must_fail git push 2>../error) &&
6789275d 160 test_grep "remote-helper doesn.t support push; refspec needed" error
ee10fbf9
FC
161'
162
163test_expect_success 'pulling without marks' '
164 (cd local2 &&
165 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
166 compare_refs local2 HEAD server HEAD
167'
168
169test_expect_failure 'pushing without marks' '
170 test_when_finished "(cd local2 && git reset --hard origin)" &&
171 (cd local2 &&
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
176'
177
49266e8a
FC
178test_expect_success 'push all with existing object' '
179 (cd local &&
95cf2c01 180 git branch dup2 main &&
49266e8a
FC
181 git push origin --all
182 ) &&
183 compare_refs local dup2 server dup2
184'
185
f28e7c90
FC
186test_expect_success 'push ref with existing object' '
187 (cd local &&
95cf2c01 188 git branch dup main &&
f28e7c90
FC
189 git push origin dup
190 ) &&
191 compare_refs local dup server dup
192'
193
b8bd826f
JK
194test_expect_success GPG 'push signed tag' '
195 (cd local &&
95cf2c01 196 git checkout main &&
b8bd826f
JK
197 git tag -s -m signed-tag signed-tag &&
198 git push origin signed-tag
199 ) &&
0d957a4d 200 compare_refs local signed-tag^{} server signed-tag^{} &&
ec8f87b8 201 compare_refs ! local signed-tag server signed-tag
0d957a4d
JK
202'
203
204test_expect_success GPG 'push signed tag with signed-tags capability' '
205 (cd local &&
95cf2c01 206 git checkout main &&
0d957a4d
JK
207 git tag -s -m signed-tag signed-tag-2 &&
208 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
209 ) &&
210 compare_refs local signed-tag-2 server signed-tag-2
b8bd826f
JK
211'
212
664059fb
FC
213test_expect_success 'push update refs' '
214 (cd local &&
95cf2c01 215 git checkout -b update main &&
664059fb
FC
216 echo update >>file &&
217 git commit -a -m update &&
d6ae7b2d 218 git push origin update &&
664059fb
FC
219 git rev-parse --verify remotes/origin/update >expect &&
220 git rev-parse --verify testgit/origin/heads/update >actual &&
221 test_cmp expect actual
222 )
223'
224
597b831a
MM
225test_expect_success 'push update refs disabled by no-private-update' '
226 (cd local &&
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
233 )
234'
235
126aac5c
FC
236test_expect_success 'push update refs failure' '
237 (cd local &&
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 &&
b2c851a8
JH
242 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
243 git push origin update &&
126aac5c
FC
244 git rev-parse --verify testgit/origin/heads/update >actual &&
245 test_cmp expect actual
246 )
247'
248
b2c851a8
JH
249clean_mark () {
250 cut -f 2 -d ' ' "$1" |
251 git cat-file --batch-check |
252 grep commit |
253 sort >$(basename "$1")
254}
255
81d340d4 256test_expect_success 'proper failure checks for fetching' '
b2c851a8
JH
257 (cd local &&
258 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
6789275d 259 test_grep -q "error while running fast-import" error
81d340d4
FC
260 )
261'
262
263test_expect_success 'proper failure checks for pushing' '
c545bc62 264 test_when_finished "rm -rf local/git.marks local/testgit.marks" &&
512477b1 265 (cd local &&
95cf2c01 266 git checkout -b crash main &&
b2c851a8
JH
267 echo crash >>file &&
268 git commit -a -m crash &&
269 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
c545bc62
JK
270 clean_mark ".git/testgit/origin/git.marks" &&
271 clean_mark ".git/testgit/origin/testgit.marks" &&
272 test_cmp git.marks testgit.marks
81d340d4
FC
273 )
274'
275
b056620f
FC
276test_expect_success 'push messages' '
277 (cd local &&
95cf2c01 278 git checkout -b new_branch main &&
b056620f
FC
279 echo new >>file &&
280 git commit -a -m new &&
281 git push origin new_branch &&
282 git fetch origin &&
283 echo new >>file &&
284 git commit -a -m new &&
285 git push origin new_branch 2> msg &&
286 ! grep "\[new branch\]" msg
287 )
288'
289
33cae542
MH
290test_expect_success 'fetch HEAD' '
291 (cd server &&
95cf2c01 292 git checkout main &&
33cae542
MH
293 echo more >>file &&
294 git commit -a -m more
295 ) &&
296 (cd local &&
297 git fetch origin HEAD
298 ) &&
299 compare_refs server HEAD local FETCH_HEAD
300'
301
302test_expect_success 'fetch url' '
303 (cd server &&
95cf2c01 304 git checkout main &&
33cae542
MH
305 echo more >>file &&
306 git commit -a -m more
307 ) &&
308 (cd local &&
309 git fetch "testgit::${PWD}/../server"
310 ) &&
311 compare_refs server HEAD local FETCH_HEAD
312'
313
f80d9223 314test_expect_success 'fetch tag' '
8144f09c
FC
315 (cd server &&
316 git tag v1.0
317 ) &&
318 (cd local &&
319 git fetch
320 ) &&
321 compare_refs local v1.0 server v1.0
322'
323
fc407f98 324test_done