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} (forced update)$" error || ref_ret
=1
75 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret
=1
78 let 'ref_ret' && echo "match for '$branch' failed" && break
81 if let 'expected_ret != ret || ref_ret'
92 echo "username = H G Wells <wells@example.com>"
97 GIT_AUTHOR_DATE
="2007-01-01 00:00:00 +0230" &&
98 GIT_COMMITTER_DATE
="$GIT_AUTHOR_DATE" &&
99 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
104 test_expect_success
'cloning' '
105 test_when_finished "rm -rf gitrepo*" &&
110 echo zero > content &&
115 git clone "hg::hgrepo" gitrepo &&
116 check gitrepo HEAD zero
119 test_expect_success
'cloning with branches' '
120 test_when_finished "rm -rf gitrepo*" &&
125 echo next > content &&
129 git clone "hg::hgrepo" gitrepo &&
130 check gitrepo origin/branches/next next
133 test_expect_success
'cloning with bookmarks' '
134 test_when_finished "rm -rf gitrepo*" &&
138 hg checkout default &&
139 hg bookmark feature-a &&
140 echo feature-a > content &&
141 hg commit -m feature-a
144 git clone "hg::hgrepo" gitrepo &&
145 check gitrepo origin/feature-a feature-a
148 test_expect_success
'update bookmark' '
149 test_when_finished "rm -rf gitrepo*" &&
157 git clone "hg::hgrepo" gitrepo &&
159 git checkout --quiet devel &&
160 echo devel > content &&
161 git commit -a -m devel &&
165 check_bookmark hgrepo devel devel
168 test_expect_success
'new bookmark' '
169 test_when_finished "rm -rf gitrepo*" &&
172 git clone "hg::hgrepo" gitrepo &&
174 git checkout --quiet -b feature-b &&
175 echo feature-b > content &&
176 git commit -a -m feature-b &&
177 git push --quiet origin feature-b
180 check_bookmark hgrepo feature-b feature-b
183 # cleanup previous stuff
187 echo $1 >> content
&&
188 hg commit
-u "$2" -m "add $1" &&
189 echo "$3" >> ..
/expected
192 test_expect_success
'authors' '
193 test_when_finished "rm -rf hgrepo gitrepo" &&
203 author_test alpha "" "H G Wells <wells@example.com>" &&
204 author_test beta "test" "test <unknown>" &&
205 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
206 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
207 author_test delta "name<test@example.com>" "name <test@example.com>" &&
208 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
209 author_test zeta " test " "test <unknown>" &&
210 author_test eta "test < test@example.com >" "test <test@example.com>" &&
211 author_test theta "test >test@example.com>" "test <test@example.com>" &&
212 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
213 author_test kappa "test@example.com" "Unknown <test@example.com>"
216 git clone "hg::hgrepo" gitrepo &&
217 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
219 test_cmp expected actual
222 test_expect_success
'strip' '
223 test_when_finished "rm -rf hgrepo gitrepo" &&
229 echo one >> content &&
233 echo two >> content &&
237 git clone "hg::hgrepo" gitrepo &&
243 echo three >> content &&
244 hg commit -m three &&
246 echo four >> content &&
253 git log --format="%s" origin/master > ../actual
256 hg -R hgrepo log --template "{desc}\n" > expected &&
257 test_cmp actual expected
260 test_expect_success
'remote push with master bookmark' '
261 test_when_finished "rm -rf hgrepo gitrepo*" &&
266 echo zero > content &&
269 hg bookmark master &&
270 echo one > content &&
275 git clone "hg::hgrepo" gitrepo &&
277 echo two > content &&
278 git commit -a -m two &&
282 check_branch hgrepo default two
286 changeset: 0:6e2126489d3d
288 user: A U Thor <author@example.com>
289 date: Mon Jan 01 00:00:00 2007 +0230
294 test_expect_success
'remote push from master branch' '
295 test_when_finished "rm -rf hgrepo gitrepo*" &&
302 git remote add origin "hg::../hgrepo" &&
303 echo one > content &&
305 git commit -a -m one &&
306 git push origin master
309 hg -R hgrepo log > actual &&
311 test_cmp expected actual &&
313 check_branch hgrepo default one
316 GIT_REMOTE_HG_TEST_REMOTE
=1
317 export GIT_REMOTE_HG_TEST_REMOTE
319 test_expect_success
'remote cloning' '
320 test_when_finished "rm -rf gitrepo*" &&
325 echo zero > content &&
330 git clone "hg::hgrepo" gitrepo &&
331 check gitrepo HEAD zero
334 test_expect_success
'remote update bookmark' '
335 test_when_finished "rm -rf gitrepo*" &&
343 git clone "hg::hgrepo" gitrepo &&
345 git checkout --quiet devel &&
346 echo devel > content &&
347 git commit -a -m devel &&
351 check_bookmark hgrepo devel devel
354 test_expect_success
'remote new bookmark' '
355 test_when_finished "rm -rf gitrepo*" &&
358 git clone "hg::hgrepo" gitrepo &&
360 git checkout --quiet -b feature-b &&
361 echo feature-b > content &&
362 git commit -a -m feature-b &&
363 git push --quiet origin feature-b
366 check_bookmark hgrepo feature-b feature-b
369 test_expect_success
'remote push diverged' '
370 test_when_finished "rm -rf gitrepo*" &&
372 git clone "hg::hgrepo" gitrepo &&
376 hg checkout default &&
377 echo bump > content &&
383 echo diverge > content &&
384 git commit -a -m diverged &&
386 master:non-fast-forward
390 check_branch hgrepo default bump
393 test_expect_success
'remote update bookmark diverge' '
394 test_when_finished "rm -rf gitrepo*" &&
402 git clone "hg::hgrepo" gitrepo &&
406 echo "bump bookmark" > content &&
407 hg commit -m "bump bookmark"
412 git checkout --quiet diverge &&
413 echo diverge > content &&
414 git commit -a -m diverge &&
420 check_bookmark hgrepo diverge "bump bookmark"
423 test_expect_success
'remote new bookmark multiple branch head' '
424 test_when_finished "rm -rf gitrepo*" &&
427 git clone "hg::hgrepo" gitrepo &&
429 git checkout --quiet -b feature-c HEAD^ &&
430 echo feature-c > content &&
431 git commit -a -m feature-c &&
432 git push --quiet origin feature-c
435 check_bookmark hgrepo feature-c feature-c
438 # cleanup previous stuff
445 echo zero
> content
&&
448 hg bookmark bad_bmark1
&&
449 echo one
> content
&&
451 hg bookmark bad_bmark2
&&
452 hg bookmark good_bmark
&&
453 hg bookmark
-i good_bmark
&&
454 hg
-q branch good_branch
&&
455 echo "good branch" > content
&&
456 hg commit
-m "good branch" &&
457 hg
-q branch bad_branch
&&
458 echo "bad branch" > content
&&
459 hg commit
-m "bad branch"
462 git clone
"hg::hgrepo" gitrepo
&&
466 echo two
> content
&&
467 git commit
-q -a -m two
&&
469 git checkout
-q good_bmark
&&
470 echo three
> content
&&
471 git commit
-q -a -m three
&&
473 git checkout
-q bad_bmark1
&&
474 git
reset --hard HEAD^
&&
475 echo four
> content
&&
476 git commit
-q -a -m four
&&
478 git checkout
-q bad_bmark2
&&
479 git
reset --hard HEAD^
&&
480 echo five
> content
&&
481 git commit
-q -a -m five
&&
483 git checkout
-q -b new_bmark master
&&
484 echo six
> content
&&
485 git commit
-q -a -m six
&&
487 git checkout
-q branches
/good_branch
&&
488 echo seven
> content
&&
489 git commit
-q -a -m seven
&&
490 echo eight
> content
&&
491 git commit
-q -a -m eight
&&
493 git checkout
-q branches
/bad_branch
&&
494 git
reset --hard HEAD^
&&
495 echo nine
> content
&&
496 git commit
-q -a -m nine
&&
498 git checkout
-q -b branches
/new_branch master
&&
499 echo ten
> content
&&
500 git commit
-q -a -m ten
504 test_expect_success
'remote big push' '
505 test_when_finished "rm -rf hgrepo gitrepo*" &&
512 check_push 1 --all <<-EOF
517 branches/new_branch:new
518 bad_bmark1:non-fast-forward
519 bad_bmark2:non-fast-forward
520 branches/bad_branch:non-fast-forward
524 check_branch hgrepo default one &&
525 check_branch hgrepo good_branch "good branch" &&
526 check_branch hgrepo bad_branch "bad branch" &&
527 check_branch hgrepo new_branch '' &&
528 check_bookmark hgrepo good_bmark one &&
529 check_bookmark hgrepo bad_bmark1 one &&
530 check_bookmark hgrepo bad_bmark2 one &&
531 check_bookmark hgrepo new_bmark ''
534 test_expect_success
'remote big push fetch first' '
535 test_when_finished "rm -rf hgrepo gitrepo*" &&
540 echo zero > content &&
543 hg bookmark bad_bmark &&
544 hg bookmark good_bmark &&
545 hg bookmark -i good_bmark &&
546 hg -q branch good_branch &&
547 echo "good branch" > content &&
548 hg commit -m "good branch" &&
549 hg -q branch bad_branch &&
550 echo "bad branch" > content &&
551 hg commit -m "bad branch"
554 git clone "hg::hgrepo" gitrepo &&
558 hg bookmark -f bad_bmark &&
559 echo update_bmark > content &&
560 hg commit -m "update bmark"
565 echo two > content &&
566 git commit -q -a -m two &&
568 git checkout -q good_bmark &&
569 echo three > content &&
570 git commit -q -a -m three &&
572 git checkout -q bad_bmark &&
573 echo four > content &&
574 git commit -q -a -m four &&
576 git checkout -q branches/bad_branch &&
577 echo five > content &&
578 git commit -q -a -m five &&
580 check_push 1 --all <<-EOF
585 bad_bmark:fetch-first
586 branches/bad_branch:festch-first
591 check_push 1 --all <<-EOF
594 bad_bmark:non-fast-forward
595 branches/bad_branch:non-fast-forward
600 test_expect_failure
'remote big push force' '
601 test_when_finished "rm -rf hgrepo gitrepo*" &&
608 check_push 0 --force --all <<-EOF
613 branches/new_branch:new
614 bad_bmark1:forced-update
615 bad_bmark2:forced-update
616 branches/bad_branch:forced-update
620 check_branch hgrepo default six &&
621 check_branch hgrepo good_branch eight &&
622 check_branch hgrepo bad_branch nine &&
623 check_branch hgrepo new_branch ten &&
624 check_bookmark hgrepo good_bmark three &&
625 check_bookmark hgrepo bad_bmark1 four &&
626 check_bookmark hgrepo bad_bmark2 five &&
627 check_bookmark hgrepo new_bmark six
630 test_expect_failure
'remote big push dry-run' '
631 test_when_finished "rm -rf hgrepo gitrepo*" &&
638 check_push 0 --dry-run --all <<-EOF
643 branches/new_branch:new
644 bad_bmark1:non-fast-forward
645 bad_bmark2:non-fast-forward
646 branches/bad_branch:non-fast-forward
649 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-EOF
654 branches/new_branch:new
658 check_branch hgrepo default one &&
659 check_branch hgrepo good_branch "good branch" &&
660 check_branch hgrepo bad_branch "bad branch" &&
661 check_branch hgrepo new_branch '' &&
662 check_bookmark hgrepo good_bmark one &&
663 check_bookmark hgrepo bad_bmark1 one &&
664 check_bookmark hgrepo bad_bmark2 one &&
665 check_bookmark hgrepo new_bmark ''
668 test_expect_success
'remote double failed push' '
669 test_when_finished "rm -rf hgrepo gitrepo*" &&
674 echo zero > content &&
677 echo one > content &&
682 git clone "hg::hgrepo" gitrepo &&
684 git reset --hard HEAD^ &&
685 echo two > content &&
686 git commit -a -m two &&
687 test_expect_code 1 git push &&
688 test_expect_code 1 git push