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