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
'cloning' '
110 test_when_finished "rm -rf gitrepo*" &&
115 echo zero >content &&
120 git clone "hg::hgrepo" gitrepo &&
121 check gitrepo HEAD zero
124 test_expect_success
'cloning with branches' '
125 test_when_finished "rm -rf gitrepo*" &&
130 echo next >content &&
134 git clone "hg::hgrepo" gitrepo &&
135 check gitrepo origin/branches/next next
138 test_expect_success
'cloning with bookmarks' '
139 test_when_finished "rm -rf gitrepo*" &&
143 hg checkout default &&
144 hg bookmark feature-a &&
145 echo feature-a >content &&
146 hg commit -m feature-a
149 git clone "hg::hgrepo" gitrepo &&
150 check gitrepo origin/feature-a feature-a
153 test_expect_success
'update bookmark' '
154 test_when_finished "rm -rf gitrepo*" &&
162 git clone "hg::hgrepo" gitrepo &&
164 git checkout --quiet devel &&
165 echo devel >content &&
166 git commit -a -m devel &&
170 check_bookmark hgrepo devel devel
173 test_expect_success
'new bookmark' '
174 test_when_finished "rm -rf gitrepo*" &&
177 git clone "hg::hgrepo" gitrepo &&
179 git checkout --quiet -b feature-b &&
180 echo feature-b >content &&
181 git commit -a -m feature-b &&
182 git push --quiet origin feature-b
185 check_bookmark hgrepo feature-b feature-b
188 # cleanup previous stuff
193 hg commit
-u "$2" -m "add $1" &&
194 echo "$3" >>..
/expected
197 test_expect_success
'authors' '
198 test_when_finished "rm -rf hgrepo gitrepo" &&
208 author_test alpha "" "H G Wells <wells@example.com>" &&
209 author_test beta "beta" "beta <unknown>" &&
210 author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
211 author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
212 author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
213 author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
214 author_test eta " eta " "eta <unknown>" &&
215 author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
216 author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
217 author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
218 author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
219 author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
222 git clone "hg::hgrepo" gitrepo &&
223 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
225 test_cmp expected actual
228 test_expect_success
'strip' '
229 test_when_finished "rm -rf hgrepo gitrepo" &&
235 echo one >>content &&
239 echo two >>content &&
243 git clone "hg::hgrepo" gitrepo &&
249 echo three >>content &&
250 hg commit -m three &&
252 echo four >>content &&
259 git log --format="%s" origin/master >../actual
262 hg -R hgrepo log --template "{desc}\n" >expected &&
263 test_cmp actual expected
266 test_expect_success
'remote push with master bookmark' '
267 test_when_finished "rm -rf hgrepo gitrepo*" &&
272 echo zero >content &&
275 hg bookmark master &&
281 git clone "hg::hgrepo" gitrepo &&
284 git commit -a -m two &&
288 check_branch hgrepo default two
292 changeset
: 0:6e2126489d3d
294 user
: A U Thor
<author@example.com
>
295 date: Mon Jan
01 00:00:00 2007 +0230
300 test_expect_success
'remote push from master branch' '
301 test_when_finished "rm -rf hgrepo gitrepo*" &&
308 git remote add origin "hg::../hgrepo" &&
311 git commit -a -m one &&
312 git push origin master
315 hg -R hgrepo log >actual &&
317 test_cmp expected actual &&
319 check_branch hgrepo default one
322 GIT_REMOTE_HG_TEST_REMOTE
=1
323 export GIT_REMOTE_HG_TEST_REMOTE
325 test_expect_success
'remote cloning' '
326 test_when_finished "rm -rf gitrepo*" &&
331 echo zero >content &&
336 git clone "hg::hgrepo" gitrepo &&
337 check gitrepo HEAD zero
340 test_expect_success
'moving remote clone' '
341 test_when_finished "rm -rf gitrepo*" &&
344 git clone "hg::hgrepo" gitrepo &&
345 mv gitrepo gitrepo2 &&
351 test_expect_success
'remote update bookmark' '
352 test_when_finished "rm -rf gitrepo*" &&
360 git clone "hg::hgrepo" gitrepo &&
362 git checkout --quiet devel &&
363 echo devel >content &&
364 git commit -a -m devel &&
368 check_bookmark hgrepo devel devel
371 test_expect_success
'remote new bookmark' '
372 test_when_finished "rm -rf gitrepo*" &&
375 git clone "hg::hgrepo" gitrepo &&
377 git checkout --quiet -b feature-b &&
378 echo feature-b >content &&
379 git commit -a -m feature-b &&
380 git push --quiet origin feature-b
383 check_bookmark hgrepo feature-b feature-b
386 test_expect_success
'remote push diverged' '
387 test_when_finished "rm -rf gitrepo*" &&
389 git clone "hg::hgrepo" gitrepo &&
393 hg checkout default &&
394 echo bump >content &&
400 echo diverge >content &&
401 git commit -a -m diverged &&
403 master:non-fast-forward
407 check_branch hgrepo default bump
410 test_expect_success
'remote update bookmark diverge' '
411 test_when_finished "rm -rf gitrepo*" &&
419 git clone "hg::hgrepo" gitrepo &&
423 echo "bump bookmark" >content &&
424 hg commit -m "bump bookmark"
429 git checkout --quiet diverge &&
430 echo diverge >content &&
431 git commit -a -m diverge &&
437 check_bookmark hgrepo diverge "bump bookmark"
440 test_expect_success
'remote new bookmark multiple branch head' '
441 test_when_finished "rm -rf gitrepo*" &&
444 git clone "hg::hgrepo" gitrepo &&
446 git checkout --quiet -b feature-c HEAD^ &&
447 echo feature-c >content &&
448 git commit -a -m feature-c &&
449 git push --quiet origin feature-c
452 check_bookmark hgrepo feature-c feature-c
455 # cleanup previous stuff
458 test_expect_success
'fetch special filenames' '
459 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
468 echo test >> "æ rø" &&
470 echo test >> "ø~?" &&
472 hg commit -m add-utf-8 &&
473 echo test >> "æ rø" &&
474 hg commit -m test-utf-8 &&
476 hg mv "æ rø" "ø~?" &&
477 hg commit -m hg-mv-utf-8
481 git clone "hg::hgrepo" gitrepo &&
483 git -c core.quotepath=false ls-files > ../actual
485 echo "ø~?" > expected &&
486 test_cmp expected actual
489 test_expect_success
'push special filenames' '
490 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
492 mkdir -p tmp && cd tmp &&
501 echo one >> content &&
507 git clone "hg::hgrepo" gitrepo &&
510 echo test >> "æ rø" &&
512 git commit -m utf-8 &&
519 hg manifest > ../actual
522 printf "content\næ rø\n" > expected &&
523 test_cmp expected actual
530 echo zero
>content
&&
533 hg bookmark bad_bmark1
&&
536 hg bookmark bad_bmark2
&&
537 hg bookmark good_bmark
&&
538 hg bookmark
-i good_bmark
&&
539 hg
-q branch good_branch
&&
540 echo "good branch" >content
&&
541 hg commit
-m "good branch" &&
542 hg
-q branch bad_branch
&&
543 echo "bad branch" >content
&&
544 hg commit
-m "bad branch"
547 git clone
"hg::hgrepo" gitrepo
&&
552 git commit
-q -a -m two
&&
554 git checkout
-q good_bmark
&&
555 echo three
>content
&&
556 git commit
-q -a -m three
&&
558 git checkout
-q bad_bmark1
&&
559 git
reset --hard HEAD^
&&
560 echo four
>content
&&
561 git commit
-q -a -m four
&&
563 git checkout
-q bad_bmark2
&&
564 git
reset --hard HEAD^
&&
565 echo five
>content
&&
566 git commit
-q -a -m five
&&
568 git checkout
-q -b new_bmark master
&&
570 git commit
-q -a -m six
&&
572 git checkout
-q branches
/good_branch
&&
573 echo seven
>content
&&
574 git commit
-q -a -m seven
&&
575 echo eight
>content
&&
576 git commit
-q -a -m eight
&&
578 git checkout
-q branches
/bad_branch
&&
579 git
reset --hard HEAD^
&&
580 echo nine
>content
&&
581 git commit
-q -a -m nine
&&
583 git checkout
-q -b branches
/new_branch master
&&
585 git commit
-q -a -m ten
589 test_expect_success
'remote big push' '
590 test_when_finished "rm -rf hgrepo gitrepo*" &&
597 check_push 1 --all <<-\EOF
602 branches/new_branch:new
603 bad_bmark1:non-fast-forward
604 bad_bmark2:non-fast-forward
605 branches/bad_branch:non-fast-forward
609 check_branch hgrepo default one &&
610 check_branch hgrepo good_branch "good branch" &&
611 check_branch hgrepo bad_branch "bad branch" &&
612 check_branch hgrepo new_branch '' &&
613 check_bookmark hgrepo good_bmark one &&
614 check_bookmark hgrepo bad_bmark1 one &&
615 check_bookmark hgrepo bad_bmark2 one &&
616 check_bookmark hgrepo new_bmark ''
619 test_expect_success
'remote big push fetch first' '
620 test_when_finished "rm -rf hgrepo gitrepo*" &&
625 echo zero >content &&
628 hg bookmark bad_bmark &&
629 hg bookmark good_bmark &&
630 hg bookmark -i good_bmark &&
631 hg -q branch good_branch &&
632 echo "good branch" >content &&
633 hg commit -m "good branch" &&
634 hg -q branch bad_branch &&
635 echo "bad branch" >content &&
636 hg commit -m "bad branch"
639 git clone "hg::hgrepo" gitrepo &&
643 hg bookmark -f bad_bmark &&
644 echo update_bmark >content &&
645 hg commit -m "update bmark"
651 git commit -q -a -m two &&
653 git checkout -q good_bmark &&
654 echo three >content &&
655 git commit -q -a -m three &&
657 git checkout -q bad_bmark &&
658 echo four >content &&
659 git commit -q -a -m four &&
661 git checkout -q branches/bad_branch &&
662 echo five >content &&
663 git commit -q -a -m five &&
665 check_push 1 --all <<-\EOF &&
668 bad_bmark:fetch-first
669 branches/bad_branch:festch-first
674 check_push 1 --all <<-\EOF
677 bad_bmark:non-fast-forward
678 branches/bad_branch:non-fast-forward
683 test_expect_failure
'remote big push force' '
684 test_when_finished "rm -rf hgrepo gitrepo*" &&
691 check_push 0 --force --all <<-\EOF
696 branches/new_branch:new
697 bad_bmark1:forced-update
698 bad_bmark2:forced-update
699 branches/bad_branch:forced-update
703 check_branch hgrepo default six &&
704 check_branch hgrepo good_branch eight &&
705 check_branch hgrepo bad_branch nine &&
706 check_branch hgrepo new_branch ten &&
707 check_bookmark hgrepo good_bmark three &&
708 check_bookmark hgrepo bad_bmark1 four &&
709 check_bookmark hgrepo bad_bmark2 five &&
710 check_bookmark hgrepo new_bmark six
713 test_expect_failure
'remote big push dry-run' '
714 test_when_finished "rm -rf hgrepo gitrepo*" &&
721 check_push 1 --dry-run --all <<-\EOF &&
726 branches/new_branch:new
727 bad_bmark1:non-fast-forward
728 bad_bmark2:non-fast-forward
729 branches/bad_branch:non-fast-forward
732 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
737 branches/new_branch:new
741 check_branch hgrepo default one &&
742 check_branch hgrepo good_branch "good branch" &&
743 check_branch hgrepo bad_branch "bad branch" &&
744 check_branch hgrepo new_branch '' &&
745 check_bookmark hgrepo good_bmark one &&
746 check_bookmark hgrepo bad_bmark1 one &&
747 check_bookmark hgrepo bad_bmark2 one &&
748 check_bookmark hgrepo new_bmark ''
751 test_expect_success
'remote double failed push' '
752 test_when_finished "rm -rf hgrepo gitrepo*" &&
757 echo zero >content &&
765 git clone "hg::hgrepo" gitrepo &&
767 git reset --hard HEAD^ &&
769 git commit -a -m two &&
770 test_expect_code 1 git push &&
771 test_expect_code 1 git push