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