remote-hg: add test for failed double push
[alt-git.git] / contrib / remote-helpers / test-hg.sh
blobcbaac51c27c92ffc74ab7340c02153a08ff9b70f
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
9 test_description='Test remote-hg'
11 . ./test-lib.sh
13 if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
18 if ! python -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 check () {
24 echo $3 > expected &&
25 git --git-dir=$1/.git log --format='%s' -1 $2 > actual
26 test_cmp expected actual
29 check_branch () {
30 if [ -n "$3" ]; then
31 echo $3 > expected &&
32 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
33 test_cmp expected actual
34 else
35 hg -R $1 branches > out &&
36 ! grep $2 out
40 check_bookmark () {
41 if [ -n "$3" ]; then
42 echo $3 > expected &&
43 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
44 test_cmp expected actual
45 else
46 hg -R $1 bookmarks > out &&
47 ! grep $2 out
51 setup () {
53 echo "[ui]"
54 echo "username = H G Wells <wells@example.com>"
55 echo "[extensions]"
56 echo "mq ="
57 ) >> "$HOME"/.hgrc &&
59 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
60 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
61 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
64 setup
66 test_expect_success 'cloning' '
67 test_when_finished "rm -rf gitrepo*" &&
70 hg init hgrepo &&
71 cd hgrepo &&
72 echo zero > content &&
73 hg add content &&
74 hg commit -m zero
75 ) &&
77 git clone "hg::hgrepo" gitrepo &&
78 check gitrepo HEAD zero
81 test_expect_success 'cloning with branches' '
82 test_when_finished "rm -rf gitrepo*" &&
85 cd hgrepo &&
86 hg branch next &&
87 echo next > content &&
88 hg commit -m next
89 ) &&
91 git clone "hg::hgrepo" gitrepo &&
92 check gitrepo origin/branches/next next
95 test_expect_success 'cloning with bookmarks' '
96 test_when_finished "rm -rf gitrepo*" &&
99 cd hgrepo &&
100 hg checkout default &&
101 hg bookmark feature-a &&
102 echo feature-a > content &&
103 hg commit -m feature-a
104 ) &&
106 git clone "hg::hgrepo" gitrepo &&
107 check gitrepo origin/feature-a feature-a
110 test_expect_success 'update bookmark' '
111 test_when_finished "rm -rf gitrepo*" &&
114 cd hgrepo &&
115 hg bookmark devel
116 ) &&
119 git clone "hg::hgrepo" gitrepo &&
120 cd gitrepo &&
121 git checkout --quiet devel &&
122 echo devel > content &&
123 git commit -a -m devel &&
124 git push --quiet
125 ) &&
127 check_bookmark hgrepo devel devel
130 test_expect_success 'new bookmark' '
131 test_when_finished "rm -rf gitrepo*" &&
134 git clone "hg::hgrepo" gitrepo &&
135 cd gitrepo &&
136 git checkout --quiet -b feature-b &&
137 echo feature-b > content &&
138 git commit -a -m feature-b &&
139 git push --quiet origin feature-b
140 ) &&
142 check_bookmark hgrepo feature-b feature-b
145 # cleanup previous stuff
146 rm -rf hgrepo
148 author_test () {
149 echo $1 >> content &&
150 hg commit -u "$2" -m "add $1" &&
151 echo "$3" >> ../expected
154 test_expect_success 'authors' '
155 test_when_finished "rm -rf hgrepo gitrepo" &&
158 hg init hgrepo &&
159 cd hgrepo &&
161 touch content &&
162 hg add content &&
164 > ../expected &&
165 author_test alpha "" "H G Wells <wells@example.com>" &&
166 author_test beta "test" "test <unknown>" &&
167 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
168 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
169 author_test delta "name<test@example.com>" "name <test@example.com>" &&
170 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
171 author_test zeta " test " "test <unknown>" &&
172 author_test eta "test < test@example.com >" "test <test@example.com>" &&
173 author_test theta "test >test@example.com>" "test <test@example.com>" &&
174 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
175 author_test kappa "test@example.com" "Unknown <test@example.com>"
176 ) &&
178 git clone "hg::hgrepo" gitrepo &&
179 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
181 test_cmp expected actual
184 test_expect_success 'strip' '
185 test_when_finished "rm -rf hgrepo gitrepo" &&
188 hg init hgrepo &&
189 cd hgrepo &&
191 echo one >> content &&
192 hg add content &&
193 hg commit -m one &&
195 echo two >> content &&
196 hg commit -m two
197 ) &&
199 git clone "hg::hgrepo" gitrepo &&
202 cd hgrepo &&
203 hg strip 1 &&
205 echo three >> content &&
206 hg commit -m three &&
208 echo four >> content &&
209 hg commit -m four
210 ) &&
213 cd gitrepo &&
214 git fetch &&
215 git log --format="%s" origin/master > ../actual
216 ) &&
218 hg -R hgrepo log --template "{desc}\n" > expected &&
219 test_cmp actual expected
222 test_expect_success 'remote push with master bookmark' '
223 test_when_finished "rm -rf hgrepo gitrepo*" &&
226 hg init hgrepo &&
227 cd hgrepo &&
228 echo zero > content &&
229 hg add content &&
230 hg commit -m zero &&
231 hg bookmark master &&
232 echo one > content &&
233 hg commit -m one
234 ) &&
237 git clone "hg::hgrepo" gitrepo &&
238 cd gitrepo &&
239 echo two > content &&
240 git commit -a -m two &&
241 git push
242 ) &&
244 check_branch hgrepo default two
247 cat > expected <<EOF
248 changeset: 0:6e2126489d3d
249 tag: tip
250 user: A U Thor <author@example.com>
251 date: Mon Jan 01 00:00:00 2007 +0230
252 summary: one
256 test_expect_success 'remote push from master branch' '
257 test_when_finished "rm -rf hgrepo gitrepo*" &&
259 hg init hgrepo &&
262 git init gitrepo &&
263 cd gitrepo &&
264 git remote add origin "hg::../hgrepo" &&
265 echo one > content &&
266 git add content &&
267 git commit -a -m one &&
268 git push origin master
269 ) &&
271 hg -R hgrepo log > actual &&
272 cat actual &&
273 test_cmp expected actual &&
275 check_branch hgrepo default one
278 GIT_REMOTE_HG_TEST_REMOTE=1
279 export GIT_REMOTE_HG_TEST_REMOTE
281 test_expect_success 'remote cloning' '
282 test_when_finished "rm -rf gitrepo*" &&
285 hg init hgrepo &&
286 cd hgrepo &&
287 echo zero > content &&
288 hg add content &&
289 hg commit -m zero
290 ) &&
292 git clone "hg::hgrepo" gitrepo &&
293 check gitrepo HEAD zero
296 test_expect_success 'remote update bookmark' '
297 test_when_finished "rm -rf gitrepo*" &&
300 cd hgrepo &&
301 hg bookmark devel
302 ) &&
305 git clone "hg::hgrepo" gitrepo &&
306 cd gitrepo &&
307 git checkout --quiet devel &&
308 echo devel > content &&
309 git commit -a -m devel &&
310 git push --quiet
311 ) &&
313 check_bookmark hgrepo devel devel
316 test_expect_success 'remote new bookmark' '
317 test_when_finished "rm -rf gitrepo*" &&
320 git clone "hg::hgrepo" gitrepo &&
321 cd gitrepo &&
322 git checkout --quiet -b feature-b &&
323 echo feature-b > content &&
324 git commit -a -m feature-b &&
325 git push --quiet origin feature-b
326 ) &&
328 check_bookmark hgrepo feature-b feature-b
331 test_expect_failure 'remote push diverged' '
332 test_when_finished "rm -rf gitrepo*" &&
334 git clone "hg::hgrepo" gitrepo &&
337 cd hgrepo &&
338 hg checkout default &&
339 echo bump > content &&
340 hg commit -m bump
341 ) &&
344 cd gitrepo &&
345 echo diverge > content &&
346 git commit -a -m diverged &&
347 test_expect_code 1 git push 2> error &&
348 grep "^ ! \[rejected\] *master -> master (non-fast-forward)$" error
349 ) &&
351 check_branch hgrepo default bump
354 test_expect_failure 'remote update bookmark diverge' '
355 test_when_finished "rm -rf gitrepo*" &&
358 cd hgrepo &&
359 hg checkout tip^ &&
360 hg bookmark diverge
361 ) &&
363 git clone "hg::hgrepo" gitrepo &&
366 cd hgrepo &&
367 echo "bump bookmark" > content &&
368 hg commit -m "bump bookmark"
369 ) &&
372 cd gitrepo &&
373 git checkout --quiet diverge &&
374 echo diverge > content &&
375 git commit -a -m diverge &&
376 test_expect_code 1 git push 2> error &&
377 grep "^ ! \[rejected\] *diverge -> diverge (non-fast-forward)$" error
378 ) &&
380 check_bookmark hgrepo diverge "bump bookmark"
383 test_expect_failure 'remote new bookmark multiple branch head' '
384 test_when_finished "rm -rf gitrepo*" &&
387 git clone "hg::hgrepo" gitrepo &&
388 cd gitrepo &&
389 git checkout --quiet -b feature-c HEAD^ &&
390 echo feature-c > content &&
391 git commit -a -m feature-c &&
392 git push --quiet origin feature-c
393 ) &&
395 check_bookmark hgrepo feature-c feature-c
398 # cleanup previous stuff
399 rm -rf hgrepo
401 test_expect_failure 'remote big push' '
402 test_when_finished "rm -rf hgrepo gitrepo*" &&
405 hg init hgrepo &&
406 cd hgrepo &&
407 echo zero > content &&
408 hg add content &&
409 hg commit -m zero &&
410 hg bookmark bad_bmark1 &&
411 echo one > content &&
412 hg commit -m one &&
413 hg bookmark bad_bmark2 &&
414 hg bookmark good_bmark &&
415 hg bookmark -i good_bmark &&
416 hg -q branch good_branch &&
417 echo "good branch" > content &&
418 hg commit -m "good branch" &&
419 hg -q branch bad_branch &&
420 echo "bad branch" > content &&
421 hg commit -m "bad branch"
422 ) &&
424 git clone "hg::hgrepo" gitrepo &&
427 cd gitrepo &&
428 echo two > content &&
429 git commit -q -a -m two &&
431 git checkout -q good_bmark &&
432 echo three > content &&
433 git commit -q -a -m three &&
435 git checkout -q bad_bmark1 &&
436 git reset --hard HEAD^ &&
437 echo four > content &&
438 git commit -q -a -m four &&
440 git checkout -q bad_bmark2 &&
441 git reset --hard HEAD^ &&
442 echo five > content &&
443 git commit -q -a -m five &&
445 git checkout -q -b new_bmark master &&
446 echo six > content &&
447 git commit -q -a -m six &&
449 git checkout -q branches/good_branch &&
450 echo seven > content &&
451 git commit -q -a -m seven &&
452 echo eight > content &&
453 git commit -q -a -m eight &&
455 git checkout -q branches/bad_branch &&
456 git reset --hard HEAD^ &&
457 echo nine > content &&
458 git commit -q -a -m nine &&
460 git checkout -q -b branches/new_branch master &&
461 echo ten > content &&
462 git commit -q -a -m ten &&
464 test_expect_code 1 git push origin master \
465 good_bmark bad_bmark1 bad_bmark2 new_bmark \
466 branches/good_branch branches/bad_branch \
467 branches/new_branch 2> error &&
469 grep "^ [a-f0-9]*\.\.[a-f0-9]* *master -> master$" error &&
470 grep "^ [a-f0-9]*\.\.[a-f0-9]* *good_bmark -> good_bmark$" error &&
471 grep "^ \* \[new branch\] *new_bmark -> new_bmark$" error &&
472 grep "^ ! \[rejected\] *bad_bmark2 -> bad_bmark2 (non-fast-forward)$" error &&
473 grep "^ ! \[rejected\] *bad_bmark1 -> bad_bmark1 (non-fast-forward)$" error &&
474 grep "^ [a-f0-9]*\.\.[a-f0-9]* *branches/good_branch -> branches/good_branch$" error &&
475 grep "^ ! \[rejected\] *branches/bad_branch -> branches/bad_branch (non-fast-forward)$" error &&
476 grep "^ \* \[new branch\] *branches/new_branch -> branches/new_branch$" error
477 ) &&
479 check_branch hgrepo default one &&
480 check_branch hgrepo good_branch "good branch" &&
481 check_branch hgrepo bad_branch "bad branch" &&
482 check_branch hgrepo new_branch '' &&
483 check_bookmark hgrepo good_bmark one &&
484 check_bookmark hgrepo bad_bmark1 one &&
485 check_bookmark hgrepo bad_bmark2 one &&
486 check_bookmark hgrepo new_bmark ''
489 test_expect_failure 'remote double failed push' '
490 test_when_finished "rm -rf hgrepo gitrepo*" &&
493 hg init hgrepo &&
494 cd hgrepo &&
495 echo zero > content &&
496 hg add content &&
497 hg commit -m zero &&
498 echo one > content &&
499 hg commit -m one
500 ) &&
503 git clone "hg::hgrepo" gitrepo &&
504 cd gitrepo &&
505 git reset --hard HEAD^ &&
506 echo two > content &&
507 git commit -a -m two &&
508 test_expect_code 1 git push &&
509 test_expect_code 1 git push
513 test_done