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
; then
14 skip_all
='skipping remote-hg tests; python not available'
18 if ! python
-c 'import mercurial'; then
19 skip_all
='skipping remote-hg tests; mercurial not available'
25 git
--git-dir=$1/.git log
--format='%s' -1 $2 > actual
26 test_cmp expected actual
32 hg
-R $1 log
-r $2 --template '{desc}\n' > actual
&&
33 test_cmp expected actual
35 hg
-R $1 branches
> out
&&
43 hg
-R $1 log
-r "bookmark('$2')" --template '{desc}\n' > actual
&&
44 test_cmp expected actual
46 hg
-R $1 bookmarks
> out
&&
52 local expected_ret
=$1 ret
=0 ref_ret
=0 IFS
=':'
55 git push origin
"$@" 2> error
59 while read branch kind
63 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret
=1
66 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret
=1
69 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret
=1
72 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret
=1
75 let 'ref_ret' && echo "match for '$branch' failed" && break
78 if let 'expected_ret != ret || ref_ret'
89 echo "username = H G Wells <wells@example.com>"
94 GIT_AUTHOR_DATE
="2007-01-01 00:00:00 +0230" &&
95 GIT_COMMITTER_DATE
="$GIT_AUTHOR_DATE" &&
96 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
101 test_expect_success
'cloning' '
102 test_when_finished "rm -rf gitrepo*" &&
107 echo zero > content &&
112 git clone "hg::hgrepo" gitrepo &&
113 check gitrepo HEAD zero
116 test_expect_success
'cloning with branches' '
117 test_when_finished "rm -rf gitrepo*" &&
122 echo next > content &&
126 git clone "hg::hgrepo" gitrepo &&
127 check gitrepo origin/branches/next next
130 test_expect_success
'cloning with bookmarks' '
131 test_when_finished "rm -rf gitrepo*" &&
135 hg checkout default &&
136 hg bookmark feature-a &&
137 echo feature-a > content &&
138 hg commit -m feature-a
141 git clone "hg::hgrepo" gitrepo &&
142 check gitrepo origin/feature-a feature-a
145 test_expect_success
'update bookmark' '
146 test_when_finished "rm -rf gitrepo*" &&
154 git clone "hg::hgrepo" gitrepo &&
156 git checkout --quiet devel &&
157 echo devel > content &&
158 git commit -a -m devel &&
162 check_bookmark hgrepo devel devel
165 test_expect_success
'new bookmark' '
166 test_when_finished "rm -rf gitrepo*" &&
169 git clone "hg::hgrepo" gitrepo &&
171 git checkout --quiet -b feature-b &&
172 echo feature-b > content &&
173 git commit -a -m feature-b &&
174 git push --quiet origin feature-b
177 check_bookmark hgrepo feature-b feature-b
180 # cleanup previous stuff
184 echo $1 >> content
&&
185 hg commit
-u "$2" -m "add $1" &&
186 echo "$3" >> ..
/expected
189 test_expect_success
'authors' '
190 test_when_finished "rm -rf hgrepo gitrepo" &&
200 author_test alpha "" "H G Wells <wells@example.com>" &&
201 author_test beta "test" "test <unknown>" &&
202 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
203 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
204 author_test delta "name<test@example.com>" "name <test@example.com>" &&
205 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
206 author_test zeta " test " "test <unknown>" &&
207 author_test eta "test < test@example.com >" "test <test@example.com>" &&
208 author_test theta "test >test@example.com>" "test <test@example.com>" &&
209 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
210 author_test kappa "test@example.com" "Unknown <test@example.com>"
213 git clone "hg::hgrepo" gitrepo &&
214 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
216 test_cmp expected actual
219 test_expect_success
'strip' '
220 test_when_finished "rm -rf hgrepo gitrepo" &&
226 echo one >> content &&
230 echo two >> content &&
234 git clone "hg::hgrepo" gitrepo &&
240 echo three >> content &&
241 hg commit -m three &&
243 echo four >> content &&
250 git log --format="%s" origin/master > ../actual
253 hg -R hgrepo log --template "{desc}\n" > expected &&
254 test_cmp actual expected
257 test_expect_success
'remote push with master bookmark' '
258 test_when_finished "rm -rf hgrepo gitrepo*" &&
263 echo zero > content &&
266 hg bookmark master &&
267 echo one > content &&
272 git clone "hg::hgrepo" gitrepo &&
274 echo two > content &&
275 git commit -a -m two &&
279 check_branch hgrepo default two
283 changeset: 0:6e2126489d3d
285 user: A U Thor <author@example.com>
286 date: Mon Jan 01 00:00:00 2007 +0230
291 test_expect_success
'remote push from master branch' '
292 test_when_finished "rm -rf hgrepo gitrepo*" &&
299 git remote add origin "hg::../hgrepo" &&
300 echo one > content &&
302 git commit -a -m one &&
303 git push origin master
306 hg -R hgrepo log > actual &&
308 test_cmp expected actual &&
310 check_branch hgrepo default one
313 GIT_REMOTE_HG_TEST_REMOTE
=1
314 export GIT_REMOTE_HG_TEST_REMOTE
316 test_expect_success
'remote cloning' '
317 test_when_finished "rm -rf gitrepo*" &&
322 echo zero > content &&
327 git clone "hg::hgrepo" gitrepo &&
328 check gitrepo HEAD zero
331 test_expect_success
'remote update bookmark' '
332 test_when_finished "rm -rf gitrepo*" &&
340 git clone "hg::hgrepo" gitrepo &&
342 git checkout --quiet devel &&
343 echo devel > content &&
344 git commit -a -m devel &&
348 check_bookmark hgrepo devel devel
351 test_expect_success
'remote new bookmark' '
352 test_when_finished "rm -rf gitrepo*" &&
355 git clone "hg::hgrepo" gitrepo &&
357 git checkout --quiet -b feature-b &&
358 echo feature-b > content &&
359 git commit -a -m feature-b &&
360 git push --quiet origin feature-b
363 check_bookmark hgrepo feature-b feature-b
366 test_expect_success
'remote push diverged' '
367 test_when_finished "rm -rf gitrepo*" &&
369 git clone "hg::hgrepo" gitrepo &&
373 hg checkout default &&
374 echo bump > content &&
380 echo diverge > content &&
381 git commit -a -m diverged &&
383 master:non-fast-forward
387 check_branch hgrepo default bump
390 test_expect_success
'remote update bookmark diverge' '
391 test_when_finished "rm -rf gitrepo*" &&
399 git clone "hg::hgrepo" gitrepo &&
403 echo "bump bookmark" > content &&
404 hg commit -m "bump bookmark"
409 git checkout --quiet diverge &&
410 echo diverge > content &&
411 git commit -a -m diverge &&
417 check_bookmark hgrepo diverge "bump bookmark"
420 test_expect_success
'remote new bookmark multiple branch head' '
421 test_when_finished "rm -rf gitrepo*" &&
424 git clone "hg::hgrepo" gitrepo &&
426 git checkout --quiet -b feature-c HEAD^ &&
427 echo feature-c > content &&
428 git commit -a -m feature-c &&
429 git push --quiet origin feature-c
432 check_bookmark hgrepo feature-c feature-c
435 # cleanup previous stuff
442 echo zero
> content
&&
445 hg bookmark bad_bmark1
&&
446 echo one
> content
&&
448 hg bookmark bad_bmark2
&&
449 hg bookmark good_bmark
&&
450 hg bookmark
-i good_bmark
&&
451 hg
-q branch good_branch
&&
452 echo "good branch" > content
&&
453 hg commit
-m "good branch" &&
454 hg
-q branch bad_branch
&&
455 echo "bad branch" > content
&&
456 hg commit
-m "bad branch"
459 git clone
"hg::hgrepo" gitrepo
&&
463 echo two
> content
&&
464 git commit
-q -a -m two
&&
466 git checkout
-q good_bmark
&&
467 echo three
> content
&&
468 git commit
-q -a -m three
&&
470 git checkout
-q bad_bmark1
&&
471 git
reset --hard HEAD^
&&
472 echo four
> content
&&
473 git commit
-q -a -m four
&&
475 git checkout
-q bad_bmark2
&&
476 git
reset --hard HEAD^
&&
477 echo five
> content
&&
478 git commit
-q -a -m five
&&
480 git checkout
-q -b new_bmark master
&&
481 echo six
> content
&&
482 git commit
-q -a -m six
&&
484 git checkout
-q branches
/good_branch
&&
485 echo seven
> content
&&
486 git commit
-q -a -m seven
&&
487 echo eight
> content
&&
488 git commit
-q -a -m eight
&&
490 git checkout
-q branches
/bad_branch
&&
491 git
reset --hard HEAD^
&&
492 echo nine
> content
&&
493 git commit
-q -a -m nine
&&
495 git checkout
-q -b branches
/new_branch master
&&
496 echo ten
> content
&&
497 git commit
-q -a -m ten
501 test_expect_success
'remote big push' '
502 test_when_finished "rm -rf hgrepo gitrepo*" &&
509 check_push 1 --all <<-EOF
514 branches/new_branch:new
515 bad_bmark1:non-fast-forward
516 bad_bmark2:non-fast-forward
517 branches/bad_branch:non-fast-forward
521 check_branch hgrepo default one &&
522 check_branch hgrepo good_branch "good branch" &&
523 check_branch hgrepo bad_branch "bad branch" &&
524 check_branch hgrepo new_branch '' &&
525 check_bookmark hgrepo good_bmark one &&
526 check_bookmark hgrepo bad_bmark1 one &&
527 check_bookmark hgrepo bad_bmark2 one &&
528 check_bookmark hgrepo new_bmark ''
531 test_expect_success
'remote big push fetch first' '
532 test_when_finished "rm -rf hgrepo gitrepo*" &&
537 echo zero > content &&
540 hg bookmark bad_bmark &&
541 hg bookmark good_bmark &&
542 hg bookmark -i good_bmark &&
543 hg -q branch good_branch &&
544 echo "good branch" > content &&
545 hg commit -m "good branch" &&
546 hg -q branch bad_branch &&
547 echo "bad branch" > content &&
548 hg commit -m "bad branch"
551 git clone "hg::hgrepo" gitrepo &&
555 hg bookmark -f bad_bmark &&
556 echo update_bmark > content &&
557 hg commit -m "update bmark"
562 echo two > content &&
563 git commit -q -a -m two &&
565 git checkout -q good_bmark &&
566 echo three > content &&
567 git commit -q -a -m three &&
569 git checkout -q bad_bmark &&
570 echo four > content &&
571 git commit -q -a -m four &&
573 git checkout -q branches/bad_branch &&
574 echo five > content &&
575 git commit -q -a -m five &&
577 check_push 1 --all <<-EOF
582 bad_bmark:fetch-first
583 branches/bad_branch:festch-first
588 check_push 1 --all <<-EOF
591 bad_bmark:non-fast-forward
592 branches/bad_branch:non-fast-forward
597 test_expect_failure
'remote big push dry-run' '
598 test_when_finished "rm -rf hgrepo gitrepo*" &&
605 check_push 0 --dry-run --all <<-EOF
610 branches/new_branch:new
611 bad_bmark1:non-fast-forward
612 bad_bmark2:non-fast-forward
613 branches/bad_branch:non-fast-forward
616 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-EOF
621 branches/new_branch:new
625 check_branch hgrepo default one &&
626 check_branch hgrepo good_branch "good branch" &&
627 check_branch hgrepo bad_branch "bad branch" &&
628 check_branch hgrepo new_branch '' &&
629 check_bookmark hgrepo good_bmark one &&
630 check_bookmark hgrepo bad_bmark1 one &&
631 check_bookmark hgrepo bad_bmark2 one &&
632 check_bookmark hgrepo new_bmark ''
635 test_expect_success
'remote double failed push' '
636 test_when_finished "rm -rf hgrepo gitrepo*" &&
641 echo zero > content &&
644 echo one > content &&
649 git clone "hg::hgrepo" gitrepo &&
651 git reset --hard HEAD^ &&
652 echo two > content &&
653 git commit -a -m two &&
654 test_expect_code 1 git push &&
655 test_expect_code 1 git push