Merge branch 'ps/reflog-list' into HEAD
[alt-git.git] / t / t5801-remote-helpers.sh
blob4e0a77f9859b392b06edd9f3696e804271d6f225
1 #!/bin/sh
3 # Copyright (c) 2010 Sverre Rabbelier
6 test_description='Test remote-helper import and export commands'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY"/lib-gpg.sh
14 PATH="$TEST_DIRECTORY/t5801:$PATH"
16 compare_refs() {
17 fail= &&
18 if test "x$1" = 'x!'
19 then
20 fail='!' &&
21 shift
22 fi &&
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' '
29 git init server &&
30 (cd server &&
31 echo content >file &&
32 git add file &&
33 git commit -m one)
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' '
42 (cd server &&
43 echo content >>file &&
44 git commit -a -m two)
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' '
53 (cd local &&
54 echo content >>file &&
55 git commit -a -m three &&
56 git push) &&
57 compare_refs local HEAD server HEAD
60 test_expect_success 'fetch new branch' '
61 (cd server &&
62 git reset --hard &&
63 git checkout -b new &&
64 echo content >>file &&
65 git commit -a -m five
66 ) &&
67 (cd local &&
68 git fetch origin new
69 ) &&
70 compare_refs server HEAD local FETCH_HEAD
73 test_expect_success 'fetch multiple branches' '
74 (cd local &&
75 git fetch
76 ) &&
77 compare_refs server main local refs/remotes/origin/main &&
78 compare_refs server new local refs/remotes/origin/new
81 test_expect_success 'push when remote has extra refs' '
82 (cd local &&
83 git reset --hard origin/main &&
84 echo content >>file &&
85 git commit -a -m six &&
86 git push
87 ) &&
88 compare_refs local main server main
91 test_expect_success 'push new branch by name' '
92 (cd local &&
93 git checkout -b new-name &&
94 echo content >>file &&
95 git commit -a -m seven &&
96 git push origin new-name
97 ) &&
98 compare_refs local HEAD server refs/heads/new-name
101 test_expect_success 'push new branch with old:new refspec' '
102 (cd local &&
103 git push origin new-name:new-refspec
104 ) &&
105 compare_refs local HEAD server refs/heads/new-refspec
108 test_expect_success 'push new branch with HEAD:new refspec' '
109 (cd local &&
110 git checkout new-name &&
111 git push origin HEAD:new-refspec-2
112 ) &&
113 compare_refs local HEAD server refs/heads/new-refspec-2
116 test_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
124 test_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
137 test_expect_success 'cloning without refspec' '
138 GIT_REMOTE_TESTGIT_NOREFSPEC=1 \
139 git clone "testgit::${PWD}/server" local2 2>error &&
140 test_grep "this remote helper should implement refspec capability" error &&
141 compare_refs local2 HEAD server HEAD
144 test_expect_success 'pulling without refspecs' '
145 (cd local2 &&
146 git reset --hard &&
147 GIT_REMOTE_TESTGIT_NOREFSPEC=1 git pull 2>../error) &&
148 test_grep "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)" &&
154 (cd local2 &&
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_grep "remote-helper doesn.t support push; refspec needed" error
163 test_expect_success 'pulling without marks' '
164 (cd local2 &&
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)" &&
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
178 test_expect_success 'push all with existing object' '
179 (cd local &&
180 git branch dup2 main &&
181 git push origin --all
182 ) &&
183 compare_refs local dup2 server dup2
186 test_expect_success 'push ref with existing object' '
187 (cd local &&
188 git branch dup main &&
189 git push origin dup
190 ) &&
191 compare_refs local dup server dup
194 test_expect_success GPG 'push signed tag' '
195 (cd local &&
196 git checkout main &&
197 git tag -s -m signed-tag signed-tag &&
198 git push origin signed-tag
199 ) &&
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' '
205 (cd local &&
206 git checkout main &&
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
213 test_expect_success 'push update refs' '
214 (cd local &&
215 git checkout -b update main &&
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' '
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
236 test_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 &&
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
249 clean_mark () {
250 cut -f 2 -d ' ' "$1" |
251 git cat-file --batch-check |
252 grep commit |
253 sort >$(basename "$1")
256 test_expect_success 'proper failure checks for fetching' '
257 (cd local &&
258 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
259 test_grep -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" &&
265 (cd local &&
266 git checkout -b crash main &&
267 echo crash >>file &&
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' '
277 (cd local &&
278 git checkout -b new_branch main &&
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
290 test_expect_success 'fetch HEAD' '
291 (cd server &&
292 git checkout main &&
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
302 test_expect_success 'fetch url' '
303 (cd server &&
304 git checkout main &&
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
314 test_expect_success 'fetch tag' '
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
324 test_done