remote-hg: add basic tests
[alt-git.git] / contrib / remote-helpers / test-hg.sh
blob40e6e3c0630f761eb96ed194ccb2dc7648097c7f
1 #!/bin/sh
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-lib.sh
13 if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
18 if ! "$PYTHON_PATH" -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 check () {
24 (cd $1 &&
25 git log --format='%s' -1 &&
26 git symbolic-ref HEAD) > actual &&
27 (echo $2 &&
28 echo "refs/heads/$3") > expected &&
29 test_cmp expected actual
32 test_expect_success 'cloning' '
33 test_when_finished "rm -rf gitrepo*" &&
36 hg init hgrepo &&
37 cd hgrepo &&
38 echo zero > content &&
39 hg add content &&
40 hg commit -m zero
41 ) &&
43 git clone "hg::$PWD/hgrepo" gitrepo &&
44 check gitrepo zero master
47 test_expect_success 'cloning with branches' '
48 test_when_finished "rm -rf gitrepo*" &&
51 cd hgrepo &&
52 hg branch next &&
53 echo next > content &&
54 hg commit -m next
55 ) &&
57 git clone "hg::$PWD/hgrepo" gitrepo &&
58 check gitrepo next next &&
60 (cd hgrepo && hg checkout default) &&
62 git clone "hg::$PWD/hgrepo" gitrepo2 &&
63 check gitrepo2 zero master
66 test_expect_success 'cloning with bookmarks' '
67 test_when_finished "rm -rf gitrepo*" &&
70 cd hgrepo &&
71 hg bookmark feature-a &&
72 echo feature-a > content &&
73 hg commit -m feature-a
74 ) &&
76 git clone "hg::$PWD/hgrepo" gitrepo &&
77 check gitrepo feature-a feature-a
80 test_expect_success 'cloning with detached head' '
81 test_when_finished "rm -rf gitrepo*" &&
84 cd hgrepo &&
85 hg update -r 0
86 ) &&
88 git clone "hg::$PWD/hgrepo" gitrepo &&
89 check gitrepo zero master
92 test_expect_success 'update bookmark' '
93 test_when_finished "rm -rf gitrepo*" &&
96 cd hgrepo &&
97 hg bookmark devel
98 ) &&
101 git clone "hg::$PWD/hgrepo" gitrepo &&
102 cd gitrepo &&
103 git checkout devel &&
104 echo devel > content &&
105 git commit -a -m devel &&
106 git push
107 ) &&
109 hg -R hgrepo bookmarks | grep "devel\s\+3:"
112 test_done