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 -o $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 "test" "test <unknown>" &&
210 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
211 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
212 author_test delta "name<test@example.com>" "name <test@example.com>" &&
213 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
214 author_test zeta " test " "test <unknown>" &&
215 author_test eta "test < test@example.com >" "test <test@example.com>" &&
216 author_test theta "test >test@example.com>" "test <test@example.com>" &&
217 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
218 author_test kappa "test@example.com" "Unknown <test@example.com>"
221 git clone "hg::hgrepo" gitrepo &&
222 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
224 test_cmp expected actual
227 test_expect_success
'strip' '
228 test_when_finished "rm -rf hgrepo gitrepo" &&
234 echo one >>content &&
238 echo two >>content &&
242 git clone "hg::hgrepo" gitrepo &&
248 echo three >>content &&
249 hg commit -m three &&
251 echo four >>content &&
258 git log --format="%s" origin/master >../actual
261 hg -R hgrepo log --template "{desc}\n" >expected &&
262 test_cmp actual expected
265 test_expect_success
'remote push with master bookmark' '
266 test_when_finished "rm -rf hgrepo gitrepo*" &&
271 echo zero >content &&
274 hg bookmark master &&
280 git clone "hg::hgrepo" gitrepo &&
283 git commit -a -m two &&
287 check_branch hgrepo default two
291 changeset
: 0:6e2126489d3d
293 user
: A U Thor
<author@example.com
>
294 date: Mon Jan
01 00:00:00 2007 +0230
299 test_expect_success
'remote push from master branch' '
300 test_when_finished "rm -rf hgrepo gitrepo*" &&
307 git remote add origin "hg::../hgrepo" &&
310 git commit -a -m one &&
311 git push origin master
314 hg -R hgrepo log >actual &&
316 test_cmp expected actual &&
318 check_branch hgrepo default one
321 GIT_REMOTE_HG_TEST_REMOTE
=1
322 export GIT_REMOTE_HG_TEST_REMOTE
324 test_expect_success
'remote cloning' '
325 test_when_finished "rm -rf gitrepo*" &&
330 echo zero >content &&
335 git clone "hg::hgrepo" gitrepo &&
336 check gitrepo HEAD zero
339 test_expect_success
'remote update bookmark' '
340 test_when_finished "rm -rf gitrepo*" &&
348 git clone "hg::hgrepo" gitrepo &&
350 git checkout --quiet devel &&
351 echo devel >content &&
352 git commit -a -m devel &&
356 check_bookmark hgrepo devel devel
359 test_expect_success
'remote new bookmark' '
360 test_when_finished "rm -rf gitrepo*" &&
363 git clone "hg::hgrepo" gitrepo &&
365 git checkout --quiet -b feature-b &&
366 echo feature-b >content &&
367 git commit -a -m feature-b &&
368 git push --quiet origin feature-b
371 check_bookmark hgrepo feature-b feature-b
374 test_expect_success
'remote push diverged' '
375 test_when_finished "rm -rf gitrepo*" &&
377 git clone "hg::hgrepo" gitrepo &&
381 hg checkout default &&
382 echo bump >content &&
388 echo diverge >content &&
389 git commit -a -m diverged &&
391 master:non-fast-forward
395 check_branch hgrepo default bump
398 test_expect_success
'remote update bookmark diverge' '
399 test_when_finished "rm -rf gitrepo*" &&
407 git clone "hg::hgrepo" gitrepo &&
411 echo "bump bookmark" >content &&
412 hg commit -m "bump bookmark"
417 git checkout --quiet diverge &&
418 echo diverge >content &&
419 git commit -a -m diverge &&
425 check_bookmark hgrepo diverge "bump bookmark"
428 test_expect_success
'remote new bookmark multiple branch head' '
429 test_when_finished "rm -rf gitrepo*" &&
432 git clone "hg::hgrepo" gitrepo &&
434 git checkout --quiet -b feature-c HEAD^ &&
435 echo feature-c >content &&
436 git commit -a -m feature-c &&
437 git push --quiet origin feature-c
440 check_bookmark hgrepo feature-c feature-c
443 # cleanup previous stuff
450 echo zero
>content
&&
453 hg bookmark bad_bmark1
&&
456 hg bookmark bad_bmark2
&&
457 hg bookmark good_bmark
&&
458 hg bookmark
-i good_bmark
&&
459 hg
-q branch good_branch
&&
460 echo "good branch" >content
&&
461 hg commit
-m "good branch" &&
462 hg
-q branch bad_branch
&&
463 echo "bad branch" >content
&&
464 hg commit
-m "bad branch"
467 git clone
"hg::hgrepo" gitrepo
&&
472 git commit
-q -a -m two
&&
474 git checkout
-q good_bmark
&&
475 echo three
>content
&&
476 git commit
-q -a -m three
&&
478 git checkout
-q bad_bmark1
&&
479 git
reset --hard HEAD^
&&
480 echo four
>content
&&
481 git commit
-q -a -m four
&&
483 git checkout
-q bad_bmark2
&&
484 git
reset --hard HEAD^
&&
485 echo five
>content
&&
486 git commit
-q -a -m five
&&
488 git checkout
-q -b new_bmark master
&&
490 git commit
-q -a -m six
&&
492 git checkout
-q branches
/good_branch
&&
493 echo seven
>content
&&
494 git commit
-q -a -m seven
&&
495 echo eight
>content
&&
496 git commit
-q -a -m eight
&&
498 git checkout
-q branches
/bad_branch
&&
499 git
reset --hard HEAD^
&&
500 echo nine
>content
&&
501 git commit
-q -a -m nine
&&
503 git checkout
-q -b branches
/new_branch master
&&
505 git commit
-q -a -m ten
509 test_expect_success
'remote big push' '
510 test_when_finished "rm -rf hgrepo gitrepo*" &&
517 check_push 1 --all <<-\EOF
522 branches/new_branch:new
523 bad_bmark1:non-fast-forward
524 bad_bmark2:non-fast-forward
525 branches/bad_branch:non-fast-forward
529 check_branch hgrepo default one &&
530 check_branch hgrepo good_branch "good branch" &&
531 check_branch hgrepo bad_branch "bad branch" &&
532 check_branch hgrepo new_branch '' &&
533 check_bookmark hgrepo good_bmark one &&
534 check_bookmark hgrepo bad_bmark1 one &&
535 check_bookmark hgrepo bad_bmark2 one &&
536 check_bookmark hgrepo new_bmark ''
539 test_expect_success
'remote big push fetch first' '
540 test_when_finished "rm -rf hgrepo gitrepo*" &&
545 echo zero >content &&
548 hg bookmark bad_bmark &&
549 hg bookmark good_bmark &&
550 hg bookmark -i good_bmark &&
551 hg -q branch good_branch &&
552 echo "good branch" >content &&
553 hg commit -m "good branch" &&
554 hg -q branch bad_branch &&
555 echo "bad branch" >content &&
556 hg commit -m "bad branch"
559 git clone "hg::hgrepo" gitrepo &&
563 hg bookmark -f bad_bmark &&
564 echo update_bmark >content &&
565 hg commit -m "update bmark"
571 git commit -q -a -m two &&
573 git checkout -q good_bmark &&
574 echo three >content &&
575 git commit -q -a -m three &&
577 git checkout -q bad_bmark &&
578 echo four >content &&
579 git commit -q -a -m four &&
581 git checkout -q branches/bad_branch &&
582 echo five >content &&
583 git commit -q -a -m five &&
585 check_push 1 --all <<-\EOF &&
588 bad_bmark:fetch-first
589 branches/bad_branch:festch-first
594 check_push 1 --all <<-\EOF
597 bad_bmark:non-fast-forward
598 branches/bad_branch:non-fast-forward
603 test_expect_failure
'remote big push force' '
604 test_when_finished "rm -rf hgrepo gitrepo*" &&
611 check_push 0 --force --all <<-\EOF
616 branches/new_branch:new
617 bad_bmark1:forced-update
618 bad_bmark2:forced-update
619 branches/bad_branch:forced-update
623 check_branch hgrepo default six &&
624 check_branch hgrepo good_branch eight &&
625 check_branch hgrepo bad_branch nine &&
626 check_branch hgrepo new_branch ten &&
627 check_bookmark hgrepo good_bmark three &&
628 check_bookmark hgrepo bad_bmark1 four &&
629 check_bookmark hgrepo bad_bmark2 five &&
630 check_bookmark hgrepo new_bmark six
633 test_expect_failure
'remote big push dry-run' '
634 test_when_finished "rm -rf hgrepo gitrepo*" &&
641 check_push 1 --dry-run --all <<-\EOF &&
646 branches/new_branch:new
647 bad_bmark1:non-fast-forward
648 bad_bmark2:non-fast-forward
649 branches/bad_branch:non-fast-forward
652 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
657 branches/new_branch:new
661 check_branch hgrepo default one &&
662 check_branch hgrepo good_branch "good branch" &&
663 check_branch hgrepo bad_branch "bad branch" &&
664 check_branch hgrepo new_branch '' &&
665 check_bookmark hgrepo good_bmark one &&
666 check_bookmark hgrepo bad_bmark1 one &&
667 check_bookmark hgrepo bad_bmark2 one &&
668 check_bookmark hgrepo new_bmark ''
671 test_expect_success
'remote double failed push' '
672 test_when_finished "rm -rf hgrepo gitrepo*" &&
677 echo zero >content &&
685 git clone "hg::hgrepo" gitrepo &&
687 git reset --hard HEAD^ &&
689 git commit -a -m two &&
690 test_expect_code 1 git push &&
691 test_expect_code 1 git push