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
&&
54 echo "username = H G Wells <wells@example.com>"
59 GIT_AUTHOR_DATE
="2007-01-01 00:00:00 +0230" &&
60 GIT_COMMITTER_DATE
="$GIT_AUTHOR_DATE" &&
61 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
66 test_expect_success
'cloning' '
67 test_when_finished "rm -rf gitrepo*" &&
72 echo zero > content &&
77 git clone "hg::hgrepo" gitrepo &&
78 check gitrepo HEAD zero
81 test_expect_success
'cloning with branches' '
82 test_when_finished "rm -rf gitrepo*" &&
87 echo next > content &&
91 git clone "hg::hgrepo" gitrepo &&
92 check gitrepo origin/branches/next next
95 test_expect_success
'cloning with bookmarks' '
96 test_when_finished "rm -rf gitrepo*" &&
100 hg checkout default &&
101 hg bookmark feature-a &&
102 echo feature-a > content &&
103 hg commit -m feature-a
106 git clone "hg::hgrepo" gitrepo &&
107 check gitrepo origin/feature-a feature-a
110 test_expect_success
'update bookmark' '
111 test_when_finished "rm -rf gitrepo*" &&
119 git clone "hg::hgrepo" gitrepo &&
121 git checkout --quiet devel &&
122 echo devel > content &&
123 git commit -a -m devel &&
127 check_bookmark hgrepo devel devel
130 test_expect_success
'new bookmark' '
131 test_when_finished "rm -rf gitrepo*" &&
134 git clone "hg::hgrepo" gitrepo &&
136 git checkout --quiet -b feature-b &&
137 echo feature-b > content &&
138 git commit -a -m feature-b &&
139 git push --quiet origin feature-b
142 check_bookmark hgrepo feature-b feature-b
145 # cleanup previous stuff
149 echo $1 >> content
&&
150 hg commit
-u "$2" -m "add $1" &&
151 echo "$3" >> ..
/expected
154 test_expect_success
'authors' '
155 test_when_finished "rm -rf hgrepo gitrepo" &&
165 author_test alpha "" "H G Wells <wells@example.com>" &&
166 author_test beta "test" "test <unknown>" &&
167 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
168 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
169 author_test delta "name<test@example.com>" "name <test@example.com>" &&
170 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
171 author_test zeta " test " "test <unknown>" &&
172 author_test eta "test < test@example.com >" "test <test@example.com>" &&
173 author_test theta "test >test@example.com>" "test <test@example.com>" &&
174 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
175 author_test kappa "test@example.com" "Unknown <test@example.com>"
178 git clone "hg::hgrepo" gitrepo &&
179 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
181 test_cmp expected actual
184 test_expect_success
'strip' '
185 test_when_finished "rm -rf hgrepo gitrepo" &&
191 echo one >> content &&
195 echo two >> content &&
199 git clone "hg::hgrepo" gitrepo &&
205 echo three >> content &&
206 hg commit -m three &&
208 echo four >> content &&
215 git log --format="%s" origin/master > ../actual
218 hg -R hgrepo log --template "{desc}\n" > expected &&
219 test_cmp actual expected
222 test_expect_success
'remote push with master bookmark' '
223 test_when_finished "rm -rf hgrepo gitrepo*" &&
228 echo zero > content &&
231 hg bookmark master &&
232 echo one > content &&
237 git clone "hg::hgrepo" gitrepo &&
239 echo two > content &&
240 git commit -a -m two &&
244 check_branch hgrepo default two
248 changeset: 0:6e2126489d3d
250 user: A U Thor <author@example.com>
251 date: Mon Jan 01 00:00:00 2007 +0230
256 test_expect_success
'remote push from master branch' '
257 test_when_finished "rm -rf hgrepo gitrepo*" &&
264 git remote add origin "hg::../hgrepo" &&
265 echo one > content &&
267 git commit -a -m one &&
268 git push origin master
271 hg -R hgrepo log > actual &&
273 test_cmp expected actual &&
275 check_branch hgrepo default one
278 GIT_REMOTE_HG_TEST_REMOTE
=1
279 export GIT_REMOTE_HG_TEST_REMOTE
281 test_expect_success
'remote cloning' '
282 test_when_finished "rm -rf gitrepo*" &&
287 echo zero > content &&
292 git clone "hg::hgrepo" gitrepo &&
293 check gitrepo HEAD zero
296 test_expect_success
'remote update bookmark' '
297 test_when_finished "rm -rf gitrepo*" &&
305 git clone "hg::hgrepo" gitrepo &&
307 git checkout --quiet devel &&
308 echo devel > content &&
309 git commit -a -m devel &&
313 check_bookmark hgrepo devel devel
316 test_expect_success
'remote new bookmark' '
317 test_when_finished "rm -rf gitrepo*" &&
320 git clone "hg::hgrepo" gitrepo &&
322 git checkout --quiet -b feature-b &&
323 echo feature-b > content &&
324 git commit -a -m feature-b &&
325 git push --quiet origin feature-b
328 check_bookmark hgrepo feature-b feature-b
331 test_expect_success
'remote push diverged' '
332 test_when_finished "rm -rf gitrepo*" &&
334 git clone "hg::hgrepo" gitrepo &&
338 hg checkout default &&
339 echo bump > content &&
345 echo diverge > content &&
346 git commit -a -m diverged &&
347 test_expect_code 1 git push 2> error &&
348 grep "^ ! \[rejected\] *master -> master (non-fast-forward)$" error
351 check_branch hgrepo default bump
354 test_expect_success
'remote update bookmark diverge' '
355 test_when_finished "rm -rf gitrepo*" &&
363 git clone "hg::hgrepo" gitrepo &&
367 echo "bump bookmark" > content &&
368 hg commit -m "bump bookmark"
373 git checkout --quiet diverge &&
374 echo diverge > content &&
375 git commit -a -m diverge &&
376 test_expect_code 1 git push 2> error &&
377 grep "^ ! \[rejected\] *diverge -> diverge (non-fast-forward)$" error
380 check_bookmark hgrepo diverge "bump bookmark"
383 test_expect_failure
'remote new bookmark multiple branch head' '
384 test_when_finished "rm -rf gitrepo*" &&
387 git clone "hg::hgrepo" gitrepo &&
389 git checkout --quiet -b feature-c HEAD^ &&
390 echo feature-c > content &&
391 git commit -a -m feature-c &&
392 git push --quiet origin feature-c
395 check_bookmark hgrepo feature-c feature-c
398 # cleanup previous stuff
401 test_expect_success
'remote big push' '
402 test_when_finished "rm -rf hgrepo gitrepo*" &&
407 echo zero > content &&
410 hg bookmark bad_bmark1 &&
411 echo one > content &&
413 hg bookmark bad_bmark2 &&
414 hg bookmark good_bmark &&
415 hg bookmark -i good_bmark &&
416 hg -q branch good_branch &&
417 echo "good branch" > content &&
418 hg commit -m "good branch" &&
419 hg -q branch bad_branch &&
420 echo "bad branch" > content &&
421 hg commit -m "bad branch"
424 git clone "hg::hgrepo" gitrepo &&
428 echo two > content &&
429 git commit -q -a -m two &&
431 git checkout -q good_bmark &&
432 echo three > content &&
433 git commit -q -a -m three &&
435 git checkout -q bad_bmark1 &&
436 git reset --hard HEAD^ &&
437 echo four > content &&
438 git commit -q -a -m four &&
440 git checkout -q bad_bmark2 &&
441 git reset --hard HEAD^ &&
442 echo five > content &&
443 git commit -q -a -m five &&
445 git checkout -q -b new_bmark master &&
446 echo six > content &&
447 git commit -q -a -m six &&
449 git checkout -q branches/good_branch &&
450 echo seven > content &&
451 git commit -q -a -m seven &&
452 echo eight > content &&
453 git commit -q -a -m eight &&
455 git checkout -q branches/bad_branch &&
456 git reset --hard HEAD^ &&
457 echo nine > content &&
458 git commit -q -a -m nine &&
460 git checkout -q -b branches/new_branch master &&
461 echo ten > content &&
462 git commit -q -a -m ten &&
464 test_expect_code 1 git push origin master \
465 good_bmark bad_bmark1 bad_bmark2 new_bmark \
466 branches/good_branch branches/bad_branch \
467 branches/new_branch 2> error &&
469 grep "^ [a-f0-9]*\.\.[a-f0-9]* *master -> master$" error &&
470 grep "^ [a-f0-9]*\.\.[a-f0-9]* *good_bmark -> good_bmark$" error &&
471 grep "^ \* \[new branch\] *new_bmark -> new_bmark$" error &&
472 grep "^ ! \[rejected\] *bad_bmark2 -> bad_bmark2 (non-fast-forward)$" error &&
473 grep "^ ! \[rejected\] *bad_bmark1 -> bad_bmark1 (non-fast-forward)$" error &&
474 grep "^ [a-f0-9]*\.\.[a-f0-9]* *branches/good_branch -> branches/good_branch$" error &&
475 grep "^ ! \[rejected\] *branches/bad_branch -> branches/bad_branch (non-fast-forward)$" error &&
476 grep "^ \* \[new branch\] *branches/new_branch -> branches/new_branch$" error
479 check_branch hgrepo default one &&
480 check_branch hgrepo good_branch "good branch" &&
481 check_branch hgrepo bad_branch "bad branch" &&
482 check_branch hgrepo new_branch '' &&
483 check_bookmark hgrepo good_bmark one &&
484 check_bookmark hgrepo bad_bmark1 one &&
485 check_bookmark hgrepo bad_bmark2 one &&
486 check_bookmark hgrepo new_bmark ''
489 test_expect_failure
'remote double failed push' '
490 test_when_finished "rm -rf hgrepo gitrepo*" &&
495 echo zero > content &&
498 echo one > content &&
503 git clone "hg::hgrepo" gitrepo &&
505 git reset --hard HEAD^ &&
506 echo two > content &&
507 git commit -a -m two &&
508 test_expect_code 1 git push &&
509 test_expect_code 1 git push