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
9. "$TEST_DIRECTORY"/lib-gpg.sh
10
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' '
18 git init server &&
19 (cd server &&
20 echo content >file &&
21 git add file &&
22 git commit -m one)
23'
24
25test_expect_success 'cloning from local repo' '
26 git clone "testgit::${PWD}/server" local &&
27 test_cmp server/file local/file
28'
29
30test_expect_success 'create new commit on remote' '
31 (cd server &&
32 echo content >>file &&
33 git commit -a -m two)
34'
35
36test_expect_success 'pulling from local repo' '
37 (cd local && git pull) &&
38 test_cmp server/file local/file
39'
40
41test_expect_success 'pushing to local repo' '
42 (cd local &&
43 echo content >>file &&
44 git commit -a -m three &&
45 git push) &&
46 compare_refs local HEAD server HEAD
47'
48
49test_expect_success 'fetch new branch' '
50 (cd server &&
51 git reset --hard &&
52 git checkout -b new &&
53 echo content >>file &&
54 git commit -a -m five
55 ) &&
56 (cd local &&
57 git fetch origin new
58 ) &&
59 compare_refs server HEAD local FETCH_HEAD
60'
61
62test_expect_success 'fetch multiple branches' '
63 (cd local &&
64 git fetch
65 ) &&
66 compare_refs server master local refs/remotes/origin/master &&
67 compare_refs server new local refs/remotes/origin/new
68'
69
70test_expect_success 'push when remote has extra refs' '
71 (cd local &&
72 git reset --hard origin/master &&
73 echo content >>file &&
74 git commit -a -m six &&
75 git push
76 ) &&
77 compare_refs local master server master
78'
79
80test_expect_success 'push new branch by name' '
81 (cd local &&
82 git checkout -b new-name &&
83 echo content >>file &&
84 git commit -a -m seven &&
85 git push origin new-name
86 ) &&
87 compare_refs local HEAD server refs/heads/new-name
88'
89
90test_expect_success 'push new branch with old:new refspec' '
91 (cd local &&
92 git push origin new-name:new-refspec
93 ) &&
94 compare_refs local HEAD server refs/heads/new-refspec
95'
96
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
105test_expect_success 'forced push' '
106 (cd local &&
107 git checkout -b force-test &&
108 echo content >> file &&
109 git commit -a -m eight &&
110 git push origin force-test &&
111 echo content >> file &&
112 git commit -a --amend -m eight-modified &&
113 git push --force origin force-test
114 ) &&
115 compare_refs local refs/heads/force-test server refs/heads/force-test
116'
117
118test_expect_success 'cloning without refspec' '
119 GIT_REMOTE_TESTGIT_REFSPEC="" \
120 git clone "testgit::${PWD}/server" local2 2>error &&
121 grep "This remote helper should implement refspec capability" error &&
122 compare_refs local2 HEAD server HEAD
123'
124
125test_expect_success 'pulling without refspecs' '
126 (cd local2 &&
127 git reset --hard &&
128 GIT_REMOTE_TESTGIT_REFSPEC="" git pull 2>../error) &&
129 grep "This remote helper should implement refspec capability" error &&
130 compare_refs local2 HEAD server HEAD
131'
132
133test_expect_success 'pushing without refspecs' '
134 test_when_finished "(cd local2 && git reset --hard origin)" &&
135 (cd local2 &&
136 echo content >>file &&
137 git commit -a -m ten &&
138 GIT_REMOTE_TESTGIT_REFSPEC="" &&
139 export GIT_REMOTE_TESTGIT_REFSPEC &&
140 test_must_fail git push 2>../error) &&
141 grep "remote-helper doesn.t support push; refspec needed" error
142'
143
144test_expect_success 'pulling without marks' '
145 (cd local2 &&
146 GIT_REMOTE_TESTGIT_NO_MARKS=1 git pull) &&
147 compare_refs local2 HEAD server HEAD
148'
149
150test_expect_failure 'pushing without marks' '
151 test_when_finished "(cd local2 && git reset --hard origin)" &&
152 (cd local2 &&
153 echo content >>file &&
154 git commit -a -m twelve &&
155 GIT_REMOTE_TESTGIT_NO_MARKS=1 git push) &&
156 compare_refs local2 HEAD server HEAD
157'
158
159test_expect_success 'push all with existing object' '
160 (cd local &&
161 git branch dup2 master &&
162 git push origin --all
163 ) &&
164 compare_refs local dup2 server dup2
165'
166
167test_expect_success 'push ref with existing object' '
168 (cd local &&
169 git branch dup master &&
170 git push origin dup
171 ) &&
172 compare_refs local dup server dup
173'
174
175test_expect_success GPG 'push signed tag' '
176 (cd local &&
177 git checkout master &&
178 git tag -s -m signed-tag signed-tag &&
179 git push origin signed-tag
180 ) &&
181 compare_refs local signed-tag^{} server signed-tag^{} &&
182 test_must_fail compare_refs local signed-tag server signed-tag
183'
184
185test_expect_success GPG 'push signed tag with signed-tags capability' '
186 (cd local &&
187 git checkout master &&
188 git tag -s -m signed-tag signed-tag-2 &&
189 GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
190 ) &&
191 compare_refs local signed-tag-2 server signed-tag-2
192'
193
194test_expect_success 'push update refs' '
195 (cd local &&
196 git checkout -b update master &&
197 echo update >>file &&
198 git commit -a -m update &&
199 git push origin update &&
200 git rev-parse --verify remotes/origin/update >expect &&
201 git rev-parse --verify testgit/origin/heads/update >actual &&
202 test_cmp expect actual
203 )
204'
205
206test_expect_success 'push update refs disabled by no-private-update' '
207 (cd local &&
208 echo more-update >>file &&
209 git commit -a -m more-update &&
210 git rev-parse --verify testgit/origin/heads/update >expect &&
211 GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
212 git rev-parse --verify testgit/origin/heads/update >actual &&
213 test_cmp expect actual
214 )
215'
216
217test_expect_success 'push update refs failure' '
218 (cd local &&
219 git checkout update &&
220 echo "update fail" >>file &&
221 git commit -a -m "update fail" &&
222 git rev-parse --verify testgit/origin/heads/update >expect &&
223 GIT_REMOTE_TESTGIT_PUSH_ERROR="non-fast forward" &&
224 export GIT_REMOTE_TESTGIT_PUSH_ERROR &&
225 test_expect_code 1 git push origin update &&
226 git rev-parse --verify testgit/origin/heads/update >actual &&
227 test_cmp expect actual
228 )
229'
230
231test_expect_success 'proper failure checks for fetching' '
232 (GIT_REMOTE_TESTGIT_FAILURE=1 &&
233 export GIT_REMOTE_TESTGIT_FAILURE &&
234 cd local &&
235 test_must_fail git fetch 2> error &&
236 cat error &&
237 grep -q "Error while running fast-import" error
238 )
239'
240
241test_expect_success 'proper failure checks for pushing' '
242 (cd local &&
243 test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all
244 )
245'
246
247test_expect_success 'push messages' '
248 (cd local &&
249 git checkout -b new_branch master &&
250 echo new >>file &&
251 git commit -a -m new &&
252 git push origin new_branch &&
253 git fetch origin &&
254 echo new >>file &&
255 git commit -a -m new &&
256 git push origin new_branch 2> msg &&
257 ! grep "\[new branch\]" msg
258 )
259'
260
261test_done