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 "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret
=1
72 let 'ref_ret' && echo "match for '$branch' failed" && break
75 if let 'expected_ret != ret || ref_ret'
86 echo "username = H G Wells <wells@example.com>"
91 GIT_AUTHOR_DATE
="2007-01-01 00:00:00 +0230" &&
92 GIT_COMMITTER_DATE
="$GIT_AUTHOR_DATE" &&
93 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
98 test_expect_success
'cloning' '
99 test_when_finished "rm -rf gitrepo*" &&
104 echo zero > content &&
109 git clone "hg::hgrepo" gitrepo &&
110 check gitrepo HEAD zero
113 test_expect_success
'cloning with branches' '
114 test_when_finished "rm -rf gitrepo*" &&
119 echo next > content &&
123 git clone "hg::hgrepo" gitrepo &&
124 check gitrepo origin/branches/next next
127 test_expect_success
'cloning with bookmarks' '
128 test_when_finished "rm -rf gitrepo*" &&
132 hg checkout default &&
133 hg bookmark feature-a &&
134 echo feature-a > content &&
135 hg commit -m feature-a
138 git clone "hg::hgrepo" gitrepo &&
139 check gitrepo origin/feature-a feature-a
142 test_expect_success
'update bookmark' '
143 test_when_finished "rm -rf gitrepo*" &&
151 git clone "hg::hgrepo" gitrepo &&
153 git checkout --quiet devel &&
154 echo devel > content &&
155 git commit -a -m devel &&
159 check_bookmark hgrepo devel devel
162 test_expect_success
'new bookmark' '
163 test_when_finished "rm -rf gitrepo*" &&
166 git clone "hg::hgrepo" gitrepo &&
168 git checkout --quiet -b feature-b &&
169 echo feature-b > content &&
170 git commit -a -m feature-b &&
171 git push --quiet origin feature-b
174 check_bookmark hgrepo feature-b feature-b
177 # cleanup previous stuff
181 echo $1 >> content
&&
182 hg commit
-u "$2" -m "add $1" &&
183 echo "$3" >> ..
/expected
186 test_expect_success
'authors' '
187 test_when_finished "rm -rf hgrepo gitrepo" &&
197 author_test alpha "" "H G Wells <wells@example.com>" &&
198 author_test beta "test" "test <unknown>" &&
199 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
200 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
201 author_test delta "name<test@example.com>" "name <test@example.com>" &&
202 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
203 author_test zeta " test " "test <unknown>" &&
204 author_test eta "test < test@example.com >" "test <test@example.com>" &&
205 author_test theta "test >test@example.com>" "test <test@example.com>" &&
206 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
207 author_test kappa "test@example.com" "Unknown <test@example.com>"
210 git clone "hg::hgrepo" gitrepo &&
211 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
213 test_cmp expected actual
216 test_expect_success
'strip' '
217 test_when_finished "rm -rf hgrepo gitrepo" &&
223 echo one >> content &&
227 echo two >> content &&
231 git clone "hg::hgrepo" gitrepo &&
237 echo three >> content &&
238 hg commit -m three &&
240 echo four >> content &&
247 git log --format="%s" origin/master > ../actual
250 hg -R hgrepo log --template "{desc}\n" > expected &&
251 test_cmp actual expected
254 test_expect_success
'remote push with master bookmark' '
255 test_when_finished "rm -rf hgrepo gitrepo*" &&
260 echo zero > content &&
263 hg bookmark master &&
264 echo one > content &&
269 git clone "hg::hgrepo" gitrepo &&
271 echo two > content &&
272 git commit -a -m two &&
276 check_branch hgrepo default two
280 changeset: 0:6e2126489d3d
282 user: A U Thor <author@example.com>
283 date: Mon Jan 01 00:00:00 2007 +0230
288 test_expect_success
'remote push from master branch' '
289 test_when_finished "rm -rf hgrepo gitrepo*" &&
296 git remote add origin "hg::../hgrepo" &&
297 echo one > content &&
299 git commit -a -m one &&
300 git push origin master
303 hg -R hgrepo log > actual &&
305 test_cmp expected actual &&
307 check_branch hgrepo default one
310 GIT_REMOTE_HG_TEST_REMOTE
=1
311 export GIT_REMOTE_HG_TEST_REMOTE
313 test_expect_success
'remote cloning' '
314 test_when_finished "rm -rf gitrepo*" &&
319 echo zero > content &&
324 git clone "hg::hgrepo" gitrepo &&
325 check gitrepo HEAD zero
328 test_expect_success
'remote update bookmark' '
329 test_when_finished "rm -rf gitrepo*" &&
337 git clone "hg::hgrepo" gitrepo &&
339 git checkout --quiet devel &&
340 echo devel > content &&
341 git commit -a -m devel &&
345 check_bookmark hgrepo devel devel
348 test_expect_success
'remote new bookmark' '
349 test_when_finished "rm -rf gitrepo*" &&
352 git clone "hg::hgrepo" gitrepo &&
354 git checkout --quiet -b feature-b &&
355 echo feature-b > content &&
356 git commit -a -m feature-b &&
357 git push --quiet origin feature-b
360 check_bookmark hgrepo feature-b feature-b
363 test_expect_success
'remote push diverged' '
364 test_when_finished "rm -rf gitrepo*" &&
366 git clone "hg::hgrepo" gitrepo &&
370 hg checkout default &&
371 echo bump > content &&
377 echo diverge > content &&
378 git commit -a -m diverged &&
380 master:non-fast-forward
384 check_branch hgrepo default bump
387 test_expect_success
'remote update bookmark diverge' '
388 test_when_finished "rm -rf gitrepo*" &&
396 git clone "hg::hgrepo" gitrepo &&
400 echo "bump bookmark" > content &&
401 hg commit -m "bump bookmark"
406 git checkout --quiet diverge &&
407 echo diverge > content &&
408 git commit -a -m diverge &&
410 diverge:non-fast-forward
414 check_bookmark hgrepo diverge "bump bookmark"
417 test_expect_success
'remote new bookmark multiple branch head' '
418 test_when_finished "rm -rf gitrepo*" &&
421 git clone "hg::hgrepo" gitrepo &&
423 git checkout --quiet -b feature-c HEAD^ &&
424 echo feature-c > content &&
425 git commit -a -m feature-c &&
426 git push --quiet origin feature-c
429 check_bookmark hgrepo feature-c feature-c
432 # cleanup previous stuff
439 echo zero
> content
&&
442 hg bookmark bad_bmark1
&&
443 echo one
> content
&&
445 hg bookmark bad_bmark2
&&
446 hg bookmark good_bmark
&&
447 hg bookmark
-i good_bmark
&&
448 hg
-q branch good_branch
&&
449 echo "good branch" > content
&&
450 hg commit
-m "good branch" &&
451 hg
-q branch bad_branch
&&
452 echo "bad branch" > content
&&
453 hg commit
-m "bad branch"
456 git clone
"hg::hgrepo" gitrepo
&&
460 echo two
> content
&&
461 git commit
-q -a -m two
&&
463 git checkout
-q good_bmark
&&
464 echo three
> content
&&
465 git commit
-q -a -m three
&&
467 git checkout
-q bad_bmark1
&&
468 git
reset --hard HEAD^
&&
469 echo four
> content
&&
470 git commit
-q -a -m four
&&
472 git checkout
-q bad_bmark2
&&
473 git
reset --hard HEAD^
&&
474 echo five
> content
&&
475 git commit
-q -a -m five
&&
477 git checkout
-q -b new_bmark master
&&
478 echo six
> content
&&
479 git commit
-q -a -m six
&&
481 git checkout
-q branches
/good_branch
&&
482 echo seven
> content
&&
483 git commit
-q -a -m seven
&&
484 echo eight
> content
&&
485 git commit
-q -a -m eight
&&
487 git checkout
-q branches
/bad_branch
&&
488 git
reset --hard HEAD^
&&
489 echo nine
> content
&&
490 git commit
-q -a -m nine
&&
492 git checkout
-q -b branches
/new_branch master
&&
493 echo ten
> content
&&
494 git commit
-q -a -m ten
498 test_expect_success
'remote big push' '
499 test_when_finished "rm -rf hgrepo gitrepo*" &&
506 check_push 1 --all <<-EOF
511 branches/new_branch:new
512 bad_bmark1:non-fast-forward
513 bad_bmark2:non-fast-forward
514 branches/bad_branch:non-fast-forward
518 check_branch hgrepo default one &&
519 check_branch hgrepo good_branch "good branch" &&
520 check_branch hgrepo bad_branch "bad branch" &&
521 check_branch hgrepo new_branch '' &&
522 check_bookmark hgrepo good_bmark one &&
523 check_bookmark hgrepo bad_bmark1 one &&
524 check_bookmark hgrepo bad_bmark2 one &&
525 check_bookmark hgrepo new_bmark ''
528 test_expect_success
'remote double failed push' '
529 test_when_finished "rm -rf hgrepo gitrepo*" &&
534 echo zero > content &&
537 echo one > content &&
542 git clone "hg::hgrepo" gitrepo &&
544 git reset --hard HEAD^ &&
545 echo two > content &&
546 git commit -a -m two &&
547 test_expect_code 1 git push &&
548 test_expect_code 1 git push