Revert "Merge branch 'jc/graduate-remote-hg-bzr' (early part)"
[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
90test_expect_failure '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
510fa6f5
FC
97test_expect_success 'forced push' '
98 (cd local &&
99 git checkout -b force-test &&
100 echo content >> file &&
101 git commit -a -m eight &&
102 git push origin force-test &&
103 echo content >> file &&
104 git commit -a --amend -m eight-modified &&
105 git push --force origin force-test
106 ) &&
107 compare_refs local refs/heads/force-test server refs/heads/force-test
108'
109
ee10fbf9
FC
110test_expect_success 'cloning without refspec' '
111 GIT_REMOTE_TESTGIT_REFSPEC="" \
a93b4a09
FC
112 git clone "testgit::${PWD}/server" local2 2>error &&
113 grep "This remote helper should implement refspec capability" error &&
ee10fbf9
FC
114 compare_refs local2 HEAD server HEAD
115'
116
117test_expect_success 'pulling without refspecs' '
118 (cd local2 &&
119 git reset --hard &&
a93b4a09
FC
120 GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
121 grep "This remote helper should implement refspec capability" error &&
ee10fbf9
FC
122 compare_refs local2 HEAD server HEAD
123'
124
21610d82 125test_expect_success 'pushing without refspecs' '
ee10fbf9
FC
126 test_when_finished "(cd local2 && git reset --hard origin)" &&
127 (cd local2 &&
128 echo content >>file &&
129 git commit -a -m ten &&
1afe6e40
JH
130 GIT_REMOTE_TESTGIT_REFSPEC="" &&
131 export GIT_REMOTE_TESTGIT_REFSPEC &&
132 test_must_fail git push 2>../error) &&
21610d82 133 grep "remote-helper doesn.t support push; refspec needed" error
ee10fbf9
FC
134'
135
136test_expect_success 'pulling without marks' '
137 (cd local2 &&
138 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
139 compare_refs local2 HEAD server HEAD
140'
141
142test_expect_failure 'pushing without marks' '
143 test_when_finished "(cd local2 && git reset --hard origin)" &&
144 (cd local2 &&
145 echo content >>file &&
146 git commit -a -m twelve &&
147 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
148 compare_refs local2 HEAD server HEAD
149'
150
49266e8a
FC
151test_expect_success 'push all with existing object' '
152 (cd local &&
153 git branch dup2 master &&
154 git push origin --all
155 ) &&
156 compare_refs local dup2 server dup2
157'
158
f28e7c90
FC
159test_expect_success 'push ref with existing object' '
160 (cd local &&
161 git branch dup master &&
162 git push origin dup
163 ) &&
164 compare_refs local dup server dup
165'
166
b8bd826f
JK
167test_expect_success GPG 'push signed tag' '
168 (cd local &&
169 git checkout master &&
170 git tag -s -m signed-tag signed-tag &&
171 git push origin signed-tag
172 ) &&
0d957a4d
JK
173 compare_refs local signed-tag^{} server signed-tag^{} &&
174 test_must_fail compare_refs local signed-tag server signed-tag
175'
176
177test_expect_success GPG 'push signed tag with signed-tags capability' '
178 (cd local &&
179 git checkout master &&
180 git tag -s -m signed-tag signed-tag-2 &&
181 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
182 ) &&
183 compare_refs local signed-tag-2 server signed-tag-2
b8bd826f
JK
184'
185
664059fb
FC
186test_expect_success 'push update refs' '
187 (cd local &&
188 git checkout -b update master &&
189 echo update >>file &&
190 git commit -a -m update &&
d6ae7b2d 191 git push origin update &&
664059fb
FC
192 git rev-parse --verify remotes/origin/update >expect &&
193 git rev-parse --verify testgit/origin/heads/update >actual &&
194 test_cmp expect actual
195 )
196'
197
597b831a
MM
198test_expect_success 'push update refs disabled by no-private-update' '
199 (cd local &&
200 echo more-update >>file &&
201 git commit -a -m more-update &&
202 git rev-parse --verify testgit/origin/heads/update >expect &&
203 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
204 git rev-parse --verify testgit/origin/heads/update >actual &&
205 test_cmp expect actual
206 )
207'
208
126aac5c
FC
209test_expect_success 'push update refs failure' '
210 (cd local &&
211 git checkout update &&
212 echo "update fail" >>file &&
213 git commit -a -m "update fail" &&
214 git rev-parse --verify testgit/origin/heads/update >expect &&
b2c851a8
JH
215 test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \
216 git push origin update &&
126aac5c
FC
217 git rev-parse --verify testgit/origin/heads/update >actual &&
218 test_cmp expect actual
219 )
220'
221
b2c851a8
JH
222clean_mark () {
223 cut -f 2 -d ' ' "$1" |
224 git cat-file --batch-check |
225 grep commit |
226 sort >$(basename "$1")
227}
228
229cmp_marks () {
230 test_when_finished "rm -rf git.marks testgit.marks" &&
231 clean_mark ".git/testgit/$1/git.marks" &&
232 clean_mark ".git/testgit/$1/testgit.marks" &&
233 test_cmp git.marks testgit.marks
234}
235
81d340d4 236test_expect_success 'proper failure checks for fetching' '
b2c851a8
JH
237 (cd local &&
238 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
81d340d4
FC
239 cat error &&
240 grep -q "Error while running fast-import" error
241 )
242'
243
244test_expect_success 'proper failure checks for pushing' '
512477b1 245 (cd local &&
b2c851a8
JH
246 git checkout -b crash master &&
247 echo crash >>file &&
248 git commit -a -m crash &&
249 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all &&
250 cmp_marks origin
81d340d4
FC
251 )
252'
253
b056620f
FC
254test_expect_success 'push messages' '
255 (cd local &&
256 git checkout -b new_branch master &&
257 echo new >>file &&
258 git commit -a -m new &&
259 git push origin new_branch &&
260 git fetch origin &&
261 echo new >>file &&
262 git commit -a -m new &&
263 git push origin new_branch 2> msg &&
264 ! grep "\[new branch\]" msg
265 )
266'
267
fc407f98 268test_done