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 -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON
16 skip_all='skipping remote-hg tests; python not available'
20 if ! python -c 'import mercurial'
22 skip_all='skipping remote-hg tests; mercurial not available'
28 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
29 test_cmp expected actual
36 hg -R $1 log -r $2 --template '{desc}\n' >actual &&
37 test_cmp expected actual
39 hg -R $1 branches >out &&
48 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' >actual &&
49 test_cmp expected actual
51 hg -R $1 bookmarks >out &&
57 expected_ret=$1 ret=0 ref_ret=0
60 git push origin "$@" 2>error
64 while IFS=':' read branch kind
68 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
71 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
74 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
77 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
80 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
83 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
86 if test $expected_ret -ne $ret || test $ref_ret -ne 0
97 echo "username = H G Wells <wells@example.com>"
102 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
103 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
104 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
109 test_expect_success 'setup' '
113 echo zero >content &&
119 test_expect_success 'cloning' '
120 test_when_finished "rm -rf gitrepo*" &&
121 git clone "hg::hgrepo" gitrepo &&
122 check gitrepo HEAD zero
125 test_expect_success 'cloning with branches' '
126 test_when_finished "rm -rf gitrepo*" &&
131 echo next >content &&
135 git clone "hg::hgrepo" gitrepo &&
136 check gitrepo origin/branches/next next
139 test_expect_success 'cloning with bookmarks' '
140 test_when_finished "rm -rf gitrepo*" &&
144 hg checkout default &&
145 hg bookmark feature-a &&
146 echo feature-a >content &&
147 hg commit -m feature-a
150 git clone "hg::hgrepo" gitrepo &&
151 check gitrepo origin/feature-a feature-a
154 test_expect_success 'update bookmark' '
155 test_when_finished "rm -rf gitrepo*" &&
163 git clone "hg::hgrepo" gitrepo &&
165 git checkout --quiet devel &&
166 echo devel >content &&
167 git commit -a -m devel &&
171 check_bookmark hgrepo devel devel
174 test_expect_success 'new bookmark' '
175 test_when_finished "rm -rf gitrepo*" &&
178 git clone "hg::hgrepo" gitrepo &&
180 git checkout --quiet -b feature-b &&
181 echo feature-b >content &&
182 git commit -a -m feature-b &&
183 git push --quiet origin feature-b
186 check_bookmark hgrepo feature-b feature-b
189 # cleanup previous stuff
194 hg commit -u "$2" -m "add $1" &&
195 echo "$3" >>../expected
198 test_expect_success 'authors' '
199 test_when_finished "rm -rf hgrepo gitrepo" &&
209 author_test alpha "" "H G Wells <wells@example.com>" &&
210 author_test beta "beta" "beta <unknown>" &&
211 author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
212 author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
213 author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
214 author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
215 author_test eta " eta " "eta <unknown>" &&
216 author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
217 author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
218 author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
219 author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
220 author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
223 git clone "hg::hgrepo" gitrepo &&
224 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
226 test_cmp expected actual
229 test_expect_success 'strip' '
230 test_when_finished "rm -rf hgrepo gitrepo" &&
236 echo one >>content &&
240 echo two >>content &&
244 git clone "hg::hgrepo" gitrepo &&
250 echo three >>content &&
251 hg commit -m three &&
253 echo four >>content &&
260 git log --format="%s" origin/master >../actual
263 hg -R hgrepo log --template "{desc}\n" >expected &&
264 test_cmp actual expected
267 test_expect_success 'remote push with master bookmark' '
268 test_when_finished "rm -rf hgrepo gitrepo*" &&
273 echo zero >content &&
276 hg bookmark master &&
282 git clone "hg::hgrepo" gitrepo &&
285 git commit -a -m two &&
289 check_branch hgrepo default two
293 changeset: 0:6e2126489d3d
295 user: A U Thor <author@example.com>
296 date: Mon Jan 01 00:00:00 2007 +0230
301 test_expect_success 'remote push from master branch' '
302 test_when_finished "rm -rf hgrepo gitrepo*" &&
309 git remote add origin "hg::../hgrepo" &&
312 git commit -a -m one &&
313 git push origin master
316 hg -R hgrepo log >actual &&
318 test_cmp expected actual &&
320 check_branch hgrepo default one
323 GIT_REMOTE_HG_TEST_REMOTE=1
324 export GIT_REMOTE_HG_TEST_REMOTE
326 test_expect_success 'remote cloning' '
327 test_when_finished "rm -rf gitrepo*" &&
332 echo zero >content &&
337 git clone "hg::hgrepo" gitrepo &&
338 check gitrepo HEAD zero
341 test_expect_success 'moving remote clone' '
342 test_when_finished "rm -rf gitrepo*" &&
345 git clone "hg::hgrepo" gitrepo &&
346 mv gitrepo gitrepo2 &&
352 test_expect_success 'remote update bookmark' '
353 test_when_finished "rm -rf gitrepo*" &&
361 git clone "hg::hgrepo" gitrepo &&
363 git checkout --quiet devel &&
364 echo devel >content &&
365 git commit -a -m devel &&
369 check_bookmark hgrepo devel devel
372 test_expect_success 'remote new bookmark' '
373 test_when_finished "rm -rf gitrepo*" &&
376 git clone "hg::hgrepo" gitrepo &&
378 git checkout --quiet -b feature-b &&
379 echo feature-b >content &&
380 git commit -a -m feature-b &&
381 git push --quiet origin feature-b
384 check_bookmark hgrepo feature-b feature-b
387 test_expect_success 'remote push diverged' '
388 test_when_finished "rm -rf gitrepo*" &&
390 git clone "hg::hgrepo" gitrepo &&
394 hg checkout default &&
395 echo bump >content &&
401 echo diverge >content &&
402 git commit -a -m diverged &&
404 master:non-fast-forward
408 check_branch hgrepo default bump
411 test_expect_success 'remote update bookmark diverge' '
412 test_when_finished "rm -rf gitrepo*" &&
420 git clone "hg::hgrepo" gitrepo &&
424 echo "bump bookmark" >content &&
425 hg commit -m "bump bookmark"
430 git checkout --quiet diverge &&
431 echo diverge >content &&
432 git commit -a -m diverge &&
438 check_bookmark hgrepo diverge "bump bookmark"
441 test_expect_success 'remote new bookmark multiple branch head' '
442 test_when_finished "rm -rf gitrepo*" &&
445 git clone "hg::hgrepo" gitrepo &&
447 git checkout --quiet -b feature-c HEAD^ &&
448 echo feature-c >content &&
449 git commit -a -m feature-c &&
450 git push --quiet origin feature-c
453 check_bookmark hgrepo feature-c feature-c
456 # cleanup previous stuff
459 test_expect_success 'fetch special filenames' '
460 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
469 echo test >> "æ rø" &&
471 echo test >> "ø~?" &&
473 hg commit -m add-utf-8 &&
474 echo test >> "æ rø" &&
475 hg commit -m test-utf-8 &&
477 hg mv "æ rø" "ø~?" &&
478 hg commit -m hg-mv-utf-8
482 git clone "hg::hgrepo" gitrepo &&
484 git -c core.quotepath=false ls-files > ../actual
486 echo "ø~?" > expected &&
487 test_cmp expected actual
490 test_expect_success 'push special filenames' '
491 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
493 mkdir -p tmp && cd tmp &&
502 echo one >> content &&
508 git clone "hg::hgrepo" gitrepo &&
511 echo test >> "æ rø" &&
513 git commit -m utf-8 &&
520 hg manifest > ../actual
523 printf "content\næ rø\n" > expected &&
524 test_cmp expected actual
531 echo zero >content &&
534 hg bookmark bad_bmark1 &&
537 hg bookmark bad_bmark2 &&
538 hg bookmark good_bmark &&
539 hg bookmark -i good_bmark &&
540 hg -q branch good_branch &&
541 echo "good branch" >content &&
542 hg commit -m "good branch" &&
543 hg -q branch bad_branch &&
544 echo "bad branch" >content &&
545 hg commit -m "bad branch"
548 git clone "hg::hgrepo" gitrepo &&
553 git commit -q -a -m two &&
555 git checkout -q good_bmark &&
556 echo three >content &&
557 git commit -q -a -m three &&
559 git checkout -q bad_bmark1 &&
560 git reset --hard HEAD^ &&
561 echo four >content &&
562 git commit -q -a -m four &&
564 git checkout -q bad_bmark2 &&
565 git reset --hard HEAD^ &&
566 echo five >content &&
567 git commit -q -a -m five &&
569 git checkout -q -b new_bmark master &&
571 git commit -q -a -m six &&
573 git checkout -q branches/good_branch &&
574 echo seven >content &&
575 git commit -q -a -m seven &&
576 echo eight >content &&
577 git commit -q -a -m eight &&
579 git checkout -q branches/bad_branch &&
580 git reset --hard HEAD^ &&
581 echo nine >content &&
582 git commit -q -a -m nine &&
584 git checkout -q -b branches/new_branch master &&
586 git commit -q -a -m ten
590 test_expect_success 'remote big push' '
591 test_when_finished "rm -rf hgrepo gitrepo*" &&
598 check_push 1 --all <<-\EOF
603 branches/new_branch:new
604 bad_bmark1:non-fast-forward
605 bad_bmark2:non-fast-forward
606 branches/bad_branch:non-fast-forward
610 check_branch hgrepo default one &&
611 check_branch hgrepo good_branch "good branch" &&
612 check_branch hgrepo bad_branch "bad branch" &&
613 check_branch hgrepo new_branch '' &&
614 check_bookmark hgrepo good_bmark one &&
615 check_bookmark hgrepo bad_bmark1 one &&
616 check_bookmark hgrepo bad_bmark2 one &&
617 check_bookmark hgrepo new_bmark ''
620 test_expect_success 'remote big push fetch first' '
621 test_when_finished "rm -rf hgrepo gitrepo*" &&
626 echo zero >content &&
629 hg bookmark bad_bmark &&
630 hg bookmark good_bmark &&
631 hg bookmark -i good_bmark &&
632 hg -q branch good_branch &&
633 echo "good branch" >content &&
634 hg commit -m "good branch" &&
635 hg -q branch bad_branch &&
636 echo "bad branch" >content &&
637 hg commit -m "bad branch"
640 git clone "hg::hgrepo" gitrepo &&
644 hg bookmark -f bad_bmark &&
645 echo update_bmark >content &&
646 hg commit -m "update bmark"
652 git commit -q -a -m two &&
654 git checkout -q good_bmark &&
655 echo three >content &&
656 git commit -q -a -m three &&
658 git checkout -q bad_bmark &&
659 echo four >content &&
660 git commit -q -a -m four &&
662 git checkout -q branches/bad_branch &&
663 echo five >content &&
664 git commit -q -a -m five &&
666 check_push 1 --all <<-\EOF &&
669 bad_bmark:fetch-first
670 branches/bad_branch:festch-first
675 check_push 1 --all <<-\EOF
678 bad_bmark:non-fast-forward
679 branches/bad_branch:non-fast-forward
684 test_expect_failure 'remote big push force' '
685 test_when_finished "rm -rf hgrepo gitrepo*" &&
692 check_push 0 --force --all <<-\EOF
697 branches/new_branch:new
698 bad_bmark1:forced-update
699 bad_bmark2:forced-update
700 branches/bad_branch:forced-update
704 check_branch hgrepo default six &&
705 check_branch hgrepo good_branch eight &&
706 check_branch hgrepo bad_branch nine &&
707 check_branch hgrepo new_branch ten &&
708 check_bookmark hgrepo good_bmark three &&
709 check_bookmark hgrepo bad_bmark1 four &&
710 check_bookmark hgrepo bad_bmark2 five &&
711 check_bookmark hgrepo new_bmark six
714 test_expect_failure 'remote big push dry-run' '
715 test_when_finished "rm -rf hgrepo gitrepo*" &&
722 check_push 1 --dry-run --all <<-\EOF &&
727 branches/new_branch:new
728 bad_bmark1:non-fast-forward
729 bad_bmark2:non-fast-forward
730 branches/bad_branch:non-fast-forward
733 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
738 branches/new_branch:new
742 check_branch hgrepo default one &&
743 check_branch hgrepo good_branch "good branch" &&
744 check_branch hgrepo bad_branch "bad branch" &&
745 check_branch hgrepo new_branch '' &&
746 check_bookmark hgrepo good_bmark one &&
747 check_bookmark hgrepo bad_bmark1 one &&
748 check_bookmark hgrepo bad_bmark2 one &&
749 check_bookmark hgrepo new_bmark ''
752 test_expect_success 'remote double failed push' '
753 test_when_finished "rm -rf hgrepo gitrepo*" &&
758 echo zero >content &&
766 git clone "hg::hgrepo" gitrepo &&
768 git reset --hard HEAD^ &&
770 git commit -a -m two &&
771 test_expect_code 1 git push &&
772 test_expect_code 1 git push