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'
13 if ! test_have_prereq PYTHON
15 skip_all
='skipping remote-hg tests; python not available'
19 if ! python
-c 'import mercurial'
21 skip_all
='skipping remote-hg tests; mercurial not available'
27 git
--git-dir=$1/.git log
--format='%s' -1 $2 >actual
28 test_cmp expected actual
35 hg
-R $1 log
-r $2 --template '{desc}\n' >actual
&&
36 test_cmp expected actual
38 hg
-R $1 branches
>out
&&
47 hg
-R $1 log
-r "bookmark('$2')" --template '{desc}\n' >actual
&&
48 test_cmp expected actual
50 hg
-R $1 bookmarks
>out
&&
56 local expected_ret
=$1 ret
=0 ref_ret
=0 IFS
=':'
59 git push origin
"$@" 2>error
63 while read branch kind
67 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret
=1
70 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret
=1
73 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret
=1
76 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret
=1
79 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret
=1
82 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
85 if test $expected_ret -ne $ret -o $ref_ret -ne 0
96 echo "username = H G Wells <wells@example.com>"
101 GIT_AUTHOR_DATE
="2007-01-01 00:00:00 +0230" &&
102 GIT_COMMITTER_DATE
="$GIT_AUTHOR_DATE" &&
103 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
108 test_expect_success
'cloning' '
109 test_when_finished "rm -rf gitrepo*" &&
114 echo zero >content &&
119 git clone "hg::hgrepo" gitrepo &&
120 check gitrepo HEAD zero
123 test_expect_success
'cloning with branches' '
124 test_when_finished "rm -rf gitrepo*" &&
129 echo next >content &&
133 git clone "hg::hgrepo" gitrepo &&
134 check gitrepo origin/branches/next next
137 test_expect_success
'cloning with bookmarks' '
138 test_when_finished "rm -rf gitrepo*" &&
142 hg checkout default &&
143 hg bookmark feature-a &&
144 echo feature-a >content &&
145 hg commit -m feature-a
148 git clone "hg::hgrepo" gitrepo &&
149 check gitrepo origin/feature-a feature-a
152 test_expect_success
'update bookmark' '
153 test_when_finished "rm -rf gitrepo*" &&
161 git clone "hg::hgrepo" gitrepo &&
163 git checkout --quiet devel &&
164 echo devel >content &&
165 git commit -a -m devel &&
169 check_bookmark hgrepo devel devel
172 test_expect_success
'new bookmark' '
173 test_when_finished "rm -rf gitrepo*" &&
176 git clone "hg::hgrepo" gitrepo &&
178 git checkout --quiet -b feature-b &&
179 echo feature-b >content &&
180 git commit -a -m feature-b &&
181 git push --quiet origin feature-b
184 check_bookmark hgrepo feature-b feature-b
187 # cleanup previous stuff
192 hg commit
-u "$2" -m "add $1" &&
193 echo "$3" >>..
/expected
196 test_expect_success
'authors' '
197 test_when_finished "rm -rf hgrepo gitrepo" &&
207 author_test alpha "" "H G Wells <wells@example.com>" &&
208 author_test beta "test" "test <unknown>" &&
209 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
210 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
211 author_test delta "name<test@example.com>" "name <test@example.com>" &&
212 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
213 author_test zeta " test " "test <unknown>" &&
214 author_test eta "test < test@example.com >" "test <test@example.com>" &&
215 author_test theta "test >test@example.com>" "test <test@example.com>" &&
216 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
217 author_test kappa "test@example.com" "Unknown <test@example.com>"
220 git clone "hg::hgrepo" gitrepo &&
221 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
223 test_cmp expected actual
226 test_expect_success
'strip' '
227 test_when_finished "rm -rf hgrepo gitrepo" &&
233 echo one >>content &&
237 echo two >>content &&
241 git clone "hg::hgrepo" gitrepo &&
247 echo three >>content &&
248 hg commit -m three &&
250 echo four >>content &&
257 git log --format="%s" origin/master >../actual
260 hg -R hgrepo log --template "{desc}\n" >expected &&
261 test_cmp actual expected
264 test_expect_success
'remote push with master bookmark' '
265 test_when_finished "rm -rf hgrepo gitrepo*" &&
270 echo zero >content &&
273 hg bookmark master &&
279 git clone "hg::hgrepo" gitrepo &&
282 git commit -a -m two &&
286 check_branch hgrepo default two
290 changeset
: 0:6e2126489d3d
292 user
: A U Thor
<author@example.com
>
293 date: Mon Jan
01 00:00:00 2007 +0230
298 test_expect_success
'remote push from master branch' '
299 test_when_finished "rm -rf hgrepo gitrepo*" &&
306 git remote add origin "hg::../hgrepo" &&
309 git commit -a -m one &&
310 git push origin master
313 hg -R hgrepo log >actual &&
315 test_cmp expected actual &&
317 check_branch hgrepo default one
320 GIT_REMOTE_HG_TEST_REMOTE
=1
321 export GIT_REMOTE_HG_TEST_REMOTE
323 test_expect_success
'remote cloning' '
324 test_when_finished "rm -rf gitrepo*" &&
329 echo zero >content &&
334 git clone "hg::hgrepo" gitrepo &&
335 check gitrepo HEAD zero
338 test_expect_success
'remote update bookmark' '
339 test_when_finished "rm -rf gitrepo*" &&
347 git clone "hg::hgrepo" gitrepo &&
349 git checkout --quiet devel &&
350 echo devel >content &&
351 git commit -a -m devel &&
355 check_bookmark hgrepo devel devel
358 test_expect_success
'remote new bookmark' '
359 test_when_finished "rm -rf gitrepo*" &&
362 git clone "hg::hgrepo" gitrepo &&
364 git checkout --quiet -b feature-b &&
365 echo feature-b >content &&
366 git commit -a -m feature-b &&
367 git push --quiet origin feature-b
370 check_bookmark hgrepo feature-b feature-b
373 test_expect_success
'remote push diverged' '
374 test_when_finished "rm -rf gitrepo*" &&
376 git clone "hg::hgrepo" gitrepo &&
380 hg checkout default &&
381 echo bump >content &&
387 echo diverge >content &&
388 git commit -a -m diverged &&
390 master:non-fast-forward
394 check_branch hgrepo default bump
397 test_expect_success
'remote update bookmark diverge' '
398 test_when_finished "rm -rf gitrepo*" &&
406 git clone "hg::hgrepo" gitrepo &&
410 echo "bump bookmark" >content &&
411 hg commit -m "bump bookmark"
416 git checkout --quiet diverge &&
417 echo diverge >content &&
418 git commit -a -m diverge &&
424 check_bookmark hgrepo diverge "bump bookmark"
427 test_expect_success
'remote new bookmark multiple branch head' '
428 test_when_finished "rm -rf gitrepo*" &&
431 git clone "hg::hgrepo" gitrepo &&
433 git checkout --quiet -b feature-c HEAD^ &&
434 echo feature-c >content &&
435 git commit -a -m feature-c &&
436 git push --quiet origin feature-c
439 check_bookmark hgrepo feature-c feature-c
442 # cleanup previous stuff
449 echo zero
>content
&&
452 hg bookmark bad_bmark1
&&
455 hg bookmark bad_bmark2
&&
456 hg bookmark good_bmark
&&
457 hg bookmark
-i good_bmark
&&
458 hg
-q branch good_branch
&&
459 echo "good branch" >content
&&
460 hg commit
-m "good branch" &&
461 hg
-q branch bad_branch
&&
462 echo "bad branch" >content
&&
463 hg commit
-m "bad branch"
466 git clone
"hg::hgrepo" gitrepo
&&
471 git commit
-q -a -m two
&&
473 git checkout
-q good_bmark
&&
474 echo three
>content
&&
475 git commit
-q -a -m three
&&
477 git checkout
-q bad_bmark1
&&
478 git
reset --hard HEAD^
&&
479 echo four
>content
&&
480 git commit
-q -a -m four
&&
482 git checkout
-q bad_bmark2
&&
483 git
reset --hard HEAD^
&&
484 echo five
>content
&&
485 git commit
-q -a -m five
&&
487 git checkout
-q -b new_bmark master
&&
489 git commit
-q -a -m six
&&
491 git checkout
-q branches
/good_branch
&&
492 echo seven
>content
&&
493 git commit
-q -a -m seven
&&
494 echo eight
>content
&&
495 git commit
-q -a -m eight
&&
497 git checkout
-q branches
/bad_branch
&&
498 git
reset --hard HEAD^
&&
499 echo nine
>content
&&
500 git commit
-q -a -m nine
&&
502 git checkout
-q -b branches
/new_branch master
&&
504 git commit
-q -a -m ten
508 test_expect_success
'remote big push' '
509 test_when_finished "rm -rf hgrepo gitrepo*" &&
516 check_push 1 --all <<-\EOF
521 branches/new_branch:new
522 bad_bmark1:non-fast-forward
523 bad_bmark2:non-fast-forward
524 branches/bad_branch:non-fast-forward
528 check_branch hgrepo default one &&
529 check_branch hgrepo good_branch "good branch" &&
530 check_branch hgrepo bad_branch "bad branch" &&
531 check_branch hgrepo new_branch '' &&
532 check_bookmark hgrepo good_bmark one &&
533 check_bookmark hgrepo bad_bmark1 one &&
534 check_bookmark hgrepo bad_bmark2 one &&
535 check_bookmark hgrepo new_bmark ''
538 test_expect_success
'remote big push fetch first' '
539 test_when_finished "rm -rf hgrepo gitrepo*" &&
544 echo zero >content &&
547 hg bookmark bad_bmark &&
548 hg bookmark good_bmark &&
549 hg bookmark -i good_bmark &&
550 hg -q branch good_branch &&
551 echo "good branch" >content &&
552 hg commit -m "good branch" &&
553 hg -q branch bad_branch &&
554 echo "bad branch" >content &&
555 hg commit -m "bad branch"
558 git clone "hg::hgrepo" gitrepo &&
562 hg bookmark -f bad_bmark &&
563 echo update_bmark >content &&
564 hg commit -m "update bmark"
570 git commit -q -a -m two &&
572 git checkout -q good_bmark &&
573 echo three >content &&
574 git commit -q -a -m three &&
576 git checkout -q bad_bmark &&
577 echo four >content &&
578 git commit -q -a -m four &&
580 git checkout -q branches/bad_branch &&
581 echo five >content &&
582 git commit -q -a -m five &&
584 check_push 1 --all <<-\EOF &&
587 bad_bmark:fetch-first
588 branches/bad_branch:festch-first
593 check_push 1 --all <<-\EOF
596 bad_bmark:non-fast-forward
597 branches/bad_branch:non-fast-forward
602 test_expect_failure
'remote big push force' '
603 test_when_finished "rm -rf hgrepo gitrepo*" &&
610 check_push 0 --force --all <<-\EOF
615 branches/new_branch:new
616 bad_bmark1:forced-update
617 bad_bmark2:forced-update
618 branches/bad_branch:forced-update
622 check_branch hgrepo default six &&
623 check_branch hgrepo good_branch eight &&
624 check_branch hgrepo bad_branch nine &&
625 check_branch hgrepo new_branch ten &&
626 check_bookmark hgrepo good_bmark three &&
627 check_bookmark hgrepo bad_bmark1 four &&
628 check_bookmark hgrepo bad_bmark2 five &&
629 check_bookmark hgrepo new_bmark six
632 test_expect_failure
'remote big push dry-run' '
633 test_when_finished "rm -rf hgrepo gitrepo*" &&
640 check_push 1 --dry-run --all <<-\EOF &&
645 branches/new_branch:new
646 bad_bmark1:non-fast-forward
647 bad_bmark2:non-fast-forward
648 branches/bad_branch:non-fast-forward
651 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
656 branches/new_branch:new
660 check_branch hgrepo default one &&
661 check_branch hgrepo good_branch "good branch" &&
662 check_branch hgrepo bad_branch "bad branch" &&
663 check_branch hgrepo new_branch '' &&
664 check_bookmark hgrepo good_bmark one &&
665 check_bookmark hgrepo bad_bmark1 one &&
666 check_bookmark hgrepo bad_bmark2 one &&
667 check_bookmark hgrepo new_bmark ''
670 test_expect_success
'remote double failed push' '
671 test_when_finished "rm -rf hgrepo gitrepo*" &&
676 echo zero >content &&
684 git clone "hg::hgrepo" gitrepo &&
686 git reset --hard HEAD^ &&
688 git commit -a -m two &&
689 test_expect_code 1 git push &&
690 test_expect_code 1 git push