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 -z "$TEST_DIRECTORY" && TEST_DIRECTORY="$PWD/.."
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON; then
15 skip_all='skipping remote-hg tests; python not available'
19 if ! "$PYTHON_PATH" -c 'import mercurial'; then
20 skip_all='skipping remote-hg tests; mercurial not available'
26 git --git-dir=$1/.git log --format='%s' -1 $2 > actual
27 test_cmp expected actual
33 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
34 test_cmp expected actual
36 hg -R $1 branches > out &&
44 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
45 test_cmp expected actual
47 hg -R $1 bookmarks > out &&
53 local expected_ret=$1 ret=0 ref_ret=0 IFS=':'
56 git push origin "$@" 2> error
60 while read branch kind
64 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
67 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
70 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
73 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
76 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
79 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
82 if test $expected_ret -ne $ret -o $ref_ret -ne 0
93 echo "username = H G Wells <wells@example.com>"
98 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
99 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
100 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
105 test_expect_success 'cloning' '
106 test_when_finished "rm -rf gitrepo*" &&
111 echo zero > content &&
116 git clone "hg::hgrepo" gitrepo &&
117 check gitrepo HEAD zero
120 test_expect_success 'cloning with branches' '
121 test_when_finished "rm -rf gitrepo*" &&
126 echo next > content &&
130 git clone "hg::hgrepo" gitrepo &&
131 check gitrepo origin/branches/next next
134 test_expect_success 'cloning with bookmarks' '
135 test_when_finished "rm -rf gitrepo*" &&
139 hg checkout default &&
140 hg bookmark feature-a &&
141 echo feature-a > content &&
142 hg commit -m feature-a
145 git clone "hg::hgrepo" gitrepo &&
146 check gitrepo origin/feature-a feature-a
149 test_expect_success 'update bookmark' '
150 test_when_finished "rm -rf gitrepo*" &&
158 git clone "hg::hgrepo" gitrepo &&
160 git checkout --quiet devel &&
161 echo devel > content &&
162 git commit -a -m devel &&
166 check_bookmark hgrepo devel devel
169 test_expect_success 'new bookmark' '
170 test_when_finished "rm -rf gitrepo*" &&
173 git clone "hg::hgrepo" gitrepo &&
175 git checkout --quiet -b feature-b &&
176 echo feature-b > content &&
177 git commit -a -m feature-b &&
178 git push --quiet origin feature-b
181 check_bookmark hgrepo feature-b feature-b
184 # cleanup previous stuff
188 echo $1 >> content &&
189 hg commit -u "$2" -m "add $1" &&
190 echo "$3" >> ../expected
193 test_expect_success 'authors' '
194 test_when_finished "rm -rf hgrepo gitrepo" &&
204 author_test alpha "" "H G Wells <wells@example.com>" &&
205 author_test beta "test" "test <unknown>" &&
206 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
207 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
208 author_test delta "name<test@example.com>" "name <test@example.com>" &&
209 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
210 author_test zeta " test " "test <unknown>" &&
211 author_test eta "test < test@example.com >" "test <test@example.com>" &&
212 author_test theta "test >test@example.com>" "test <test@example.com>" &&
213 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
214 author_test kappa "test@example.com" "Unknown <test@example.com>"
217 git clone "hg::hgrepo" gitrepo &&
218 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
220 test_cmp expected actual
223 test_expect_success 'strip' '
224 test_when_finished "rm -rf hgrepo gitrepo" &&
230 echo one >> content &&
234 echo two >> content &&
238 git clone "hg::hgrepo" gitrepo &&
244 echo three >> content &&
245 hg commit -m three &&
247 echo four >> content &&
254 git log --format="%s" origin/master > ../actual
257 hg -R hgrepo log --template "{desc}\n" > expected &&
258 test_cmp actual expected
261 test_expect_success 'remote push with master bookmark' '
262 test_when_finished "rm -rf hgrepo gitrepo*" &&
267 echo zero > content &&
270 hg bookmark master &&
271 echo one > content &&
276 git clone "hg::hgrepo" gitrepo &&
278 echo two > content &&
279 git commit -a -m two &&
283 check_branch hgrepo default two
287 changeset: 0:6e2126489d3d
289 user: A U Thor <author@example.com>
290 date: Mon Jan 01 00:00:00 2007 +0230
295 test_expect_success 'remote push from master branch' '
296 test_when_finished "rm -rf hgrepo gitrepo*" &&
303 git remote add origin "hg::../hgrepo" &&
304 echo one > content &&
306 git commit -a -m one &&
307 git push origin master
310 hg -R hgrepo log > actual &&
312 test_cmp expected actual &&
314 check_branch hgrepo default one
317 GIT_REMOTE_HG_TEST_REMOTE=1
318 export GIT_REMOTE_HG_TEST_REMOTE
320 test_expect_success 'remote cloning' '
321 test_when_finished "rm -rf gitrepo*" &&
326 echo zero > content &&
331 git clone "hg::hgrepo" gitrepo &&
332 check gitrepo HEAD zero
335 test_expect_success 'remote update bookmark' '
336 test_when_finished "rm -rf gitrepo*" &&
344 git clone "hg::hgrepo" gitrepo &&
346 git checkout --quiet devel &&
347 echo devel > content &&
348 git commit -a -m devel &&
352 check_bookmark hgrepo devel devel
355 test_expect_success 'remote new bookmark' '
356 test_when_finished "rm -rf gitrepo*" &&
359 git clone "hg::hgrepo" gitrepo &&
361 git checkout --quiet -b feature-b &&
362 echo feature-b > content &&
363 git commit -a -m feature-b &&
364 git push --quiet origin feature-b
367 check_bookmark hgrepo feature-b feature-b
370 test_expect_success 'remote push diverged' '
371 test_when_finished "rm -rf gitrepo*" &&
373 git clone "hg::hgrepo" gitrepo &&
377 hg checkout default &&
378 echo bump > content &&
384 echo diverge > content &&
385 git commit -a -m diverged &&
387 master:non-fast-forward
391 check_branch hgrepo default bump
394 test_expect_success 'remote update bookmark diverge' '
395 test_when_finished "rm -rf gitrepo*" &&
403 git clone "hg::hgrepo" gitrepo &&
407 echo "bump bookmark" > content &&
408 hg commit -m "bump bookmark"
413 git checkout --quiet diverge &&
414 echo diverge > content &&
415 git commit -a -m diverge &&
421 check_bookmark hgrepo diverge "bump bookmark"
424 test_expect_success 'remote new bookmark multiple branch head' '
425 test_when_finished "rm -rf gitrepo*" &&
428 git clone "hg::hgrepo" gitrepo &&
430 git checkout --quiet -b feature-c HEAD^ &&
431 echo feature-c > content &&
432 git commit -a -m feature-c &&
433 git push --quiet origin feature-c
436 check_bookmark hgrepo feature-c feature-c
439 # cleanup previous stuff
442 test_expect_success 'fetch special filenames' '
443 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
452 echo test >> "æ rø" &&
454 echo test >> "ø~?" &&
456 hg commit -m add-utf-8 &&
457 echo test >> "æ rø" &&
458 hg commit -m test-utf-8 &&
460 hg mv "æ rø" "ø~?" &&
461 hg commit -m hg-mv-utf-8
465 git clone "hg::hgrepo" gitrepo &&
467 git -c core.quotepath=false ls-files > ../actual
469 echo "ø~?" > expected &&
470 test_cmp expected actual
473 test_expect_success 'push special filenames' '
474 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
476 mkdir -p tmp && cd tmp &&
485 echo one >> content &&
491 git clone "hg::hgrepo" gitrepo &&
494 echo test >> "æ rø" &&
496 git commit -m utf-8 &&
503 hg manifest > ../actual
506 printf "content\næ rø\n" > expected &&
507 test_cmp expected actual
514 echo zero > content &&
517 hg bookmark bad_bmark1 &&
518 echo one > content &&
520 hg bookmark bad_bmark2 &&
521 hg bookmark good_bmark &&
522 hg bookmark -i good_bmark &&
523 hg -q branch good_branch &&
524 echo "good branch" > content &&
525 hg commit -m "good branch" &&
526 hg -q branch bad_branch &&
527 echo "bad branch" > content &&
528 hg commit -m "bad branch"
531 git clone "hg::hgrepo" gitrepo &&
535 echo two > content &&
536 git commit -q -a -m two &&
538 git checkout -q good_bmark &&
539 echo three > content &&
540 git commit -q -a -m three &&
542 git checkout -q bad_bmark1 &&
543 git reset --hard HEAD^ &&
544 echo four > content &&
545 git commit -q -a -m four &&
547 git checkout -q bad_bmark2 &&
548 git reset --hard HEAD^ &&
549 echo five > content &&
550 git commit -q -a -m five &&
552 git checkout -q -b new_bmark master &&
553 echo six > content &&
554 git commit -q -a -m six &&
556 git checkout -q branches/good_branch &&
557 echo seven > content &&
558 git commit -q -a -m seven &&
559 echo eight > content &&
560 git commit -q -a -m eight &&
562 git checkout -q branches/bad_branch &&
563 git reset --hard HEAD^ &&
564 echo nine > content &&
565 git commit -q -a -m nine &&
567 git checkout -q -b branches/new_branch master &&
568 echo ten > content &&
569 git commit -q -a -m ten
573 test_expect_success 'remote big push' '
574 test_when_finished "rm -rf hgrepo gitrepo*" &&
581 check_push 1 --all <<-EOF
586 branches/new_branch:new
587 bad_bmark1:non-fast-forward
588 bad_bmark2:non-fast-forward
589 branches/bad_branch:non-fast-forward
593 check_branch hgrepo default one &&
594 check_branch hgrepo good_branch "good branch" &&
595 check_branch hgrepo bad_branch "bad branch" &&
596 check_branch hgrepo new_branch '' &&
597 check_bookmark hgrepo good_bmark one &&
598 check_bookmark hgrepo bad_bmark1 one &&
599 check_bookmark hgrepo bad_bmark2 one &&
600 check_bookmark hgrepo new_bmark ''
603 test_expect_success 'remote big push fetch first' '
604 test_when_finished "rm -rf hgrepo gitrepo*" &&
609 echo zero > content &&
612 hg bookmark bad_bmark &&
613 hg bookmark good_bmark &&
614 hg bookmark -i good_bmark &&
615 hg -q branch good_branch &&
616 echo "good branch" > content &&
617 hg commit -m "good branch" &&
618 hg -q branch bad_branch &&
619 echo "bad branch" > content &&
620 hg commit -m "bad branch"
623 git clone "hg::hgrepo" gitrepo &&
627 hg bookmark -f bad_bmark &&
628 echo update_bmark > content &&
629 hg commit -m "update bmark"
634 echo two > content &&
635 git commit -q -a -m two &&
637 git checkout -q good_bmark &&
638 echo three > content &&
639 git commit -q -a -m three &&
641 git checkout -q bad_bmark &&
642 echo four > content &&
643 git commit -q -a -m four &&
645 git checkout -q branches/bad_branch &&
646 echo five > content &&
647 git commit -q -a -m five &&
649 check_push 1 --all <<-EOF &&
652 bad_bmark:fetch-first
653 branches/bad_branch:festch-first
658 check_push 1 --all <<-EOF
661 bad_bmark:non-fast-forward
662 branches/bad_branch:non-fast-forward
667 test_expect_success 'remote big push force' '
668 test_when_finished "rm -rf hgrepo gitrepo*" &&
675 check_push 0 --force --all <<-EOF
680 branches/new_branch:new
681 bad_bmark1:forced-update
682 bad_bmark2:forced-update
683 branches/bad_branch:forced-update
687 check_branch hgrepo default six &&
688 check_branch hgrepo good_branch eight &&
689 check_branch hgrepo bad_branch nine &&
690 check_branch hgrepo new_branch ten &&
691 check_bookmark hgrepo good_bmark three &&
692 check_bookmark hgrepo bad_bmark1 four &&
693 check_bookmark hgrepo bad_bmark2 five &&
694 check_bookmark hgrepo new_bmark six
697 test_expect_success 'remote big push dry-run' '
698 test_when_finished "rm -rf hgrepo gitrepo*" &&
705 check_push 1 --dry-run --all <<-EOF &&
710 branches/new_branch:new
711 bad_bmark1:non-fast-forward
712 bad_bmark2:non-fast-forward
713 branches/bad_branch:non-fast-forward
716 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-EOF
721 branches/new_branch:new
725 check_branch hgrepo default one &&
726 check_branch hgrepo good_branch "good branch" &&
727 check_branch hgrepo bad_branch "bad branch" &&
728 check_branch hgrepo new_branch '' &&
729 check_bookmark hgrepo good_bmark one &&
730 check_bookmark hgrepo bad_bmark1 one &&
731 check_bookmark hgrepo bad_bmark2 one &&
732 check_bookmark hgrepo new_bmark ''
735 test_expect_success 'remote double failed push' '
736 test_when_finished "rm -rf hgrepo gitrepo*" &&
741 echo zero > content &&
744 echo one > content &&
749 git clone "hg::hgrepo" gitrepo &&
751 git reset --hard HEAD^ &&
752 echo two > content &&
753 git commit -a -m two &&
754 test_expect_code 1 git push &&
755 test_expect_code 1 git push