remote-hg: ensure remote rebasing works
[git/gitweb.git] / contrib / remote-helpers / test-hg.sh
blobaf27a0f65fae51771740bc5a31671c8a976f8a1d
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 -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 check () {
25 cd $1 &&
26 git log --format='%s' -1 &&
27 git symbolic-ref HEAD
28 ) > actual &&
30 echo $2 &&
31 echo "refs/heads/$3"
32 ) > expected &&
33 test_cmp expected actual
36 setup () {
38 echo "[ui]"
39 echo "username = H G Wells <wells@example.com>"
40 echo "[extensions]"
41 echo "mq ="
42 ) >> "$HOME"/.hgrc
45 setup
47 test_expect_success 'cloning' '
48 test_when_finished "rm -rf gitrepo*" &&
51 hg init hgrepo &&
52 cd hgrepo &&
53 echo zero > content &&
54 hg add content &&
55 hg commit -m zero
56 ) &&
58 git clone "hg::hgrepo" gitrepo &&
59 check gitrepo zero master
62 test_expect_success 'cloning with branches' '
63 test_when_finished "rm -rf gitrepo*" &&
66 cd hgrepo &&
67 hg branch next &&
68 echo next > content &&
69 hg commit -m next
70 ) &&
72 git clone "hg::hgrepo" gitrepo &&
73 check gitrepo next next &&
75 (cd hgrepo && hg checkout default) &&
77 git clone "hg::hgrepo" gitrepo2 &&
78 check gitrepo2 zero master
81 test_expect_success 'cloning with bookmarks' '
82 test_when_finished "rm -rf gitrepo*" &&
85 cd hgrepo &&
86 hg bookmark feature-a &&
87 echo feature-a > content &&
88 hg commit -m feature-a
89 ) &&
91 git clone "hg::hgrepo" gitrepo &&
92 check gitrepo feature-a feature-a
95 test_expect_success 'cloning with detached head' '
96 test_when_finished "rm -rf gitrepo*" &&
99 cd hgrepo &&
100 hg update -r 0
101 ) &&
103 git clone "hg::hgrepo" gitrepo &&
104 check gitrepo zero master
107 test_expect_success 'update bookmark' '
108 test_when_finished "rm -rf gitrepo*" &&
111 cd hgrepo &&
112 hg bookmark devel
113 ) &&
116 git clone "hg::hgrepo" gitrepo &&
117 cd gitrepo &&
118 git checkout --quiet devel &&
119 echo devel > content &&
120 git commit -a -m devel &&
121 git push --quiet
122 ) &&
124 hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
127 # cleanup previous stuff
128 rm -rf hgrepo
130 author_test () {
131 echo $1 >> content &&
132 hg commit -u "$2" -m "add $1" &&
133 echo "$3" >> ../expected
136 test_expect_success 'authors' '
137 test_when_finished "rm -rf hgrepo gitrepo" &&
140 hg init hgrepo &&
141 cd hgrepo &&
143 touch content &&
144 hg add content &&
146 > ../expected &&
147 author_test alpha "" "H G Wells <wells@example.com>" &&
148 author_test beta "test" "test <unknown>" &&
149 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
150 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
151 author_test delta "name<test@example.com>" "name <test@example.com>" &&
152 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
153 author_test zeta " test " "test <unknown>" &&
154 author_test eta "test < test@example.com >" "test <test@example.com>" &&
155 author_test theta "test >test@example.com>" "test <test@example.com>" &&
156 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
157 author_test kappa "test@example.com" "Unknown <test@example.com>"
158 ) &&
160 git clone "hg::hgrepo" gitrepo &&
161 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
163 test_cmp expected actual
166 test_expect_success 'strip' '
167 test_when_finished "rm -rf hgrepo gitrepo" &&
170 hg init hgrepo &&
171 cd hgrepo &&
173 echo one >> content &&
174 hg add content &&
175 hg commit -m one &&
177 echo two >> content &&
178 hg commit -m two
179 ) &&
181 git clone "hg::hgrepo" gitrepo &&
184 cd hgrepo &&
185 hg strip 1 &&
187 echo three >> content &&
188 hg commit -m three &&
190 echo four >> content &&
191 hg commit -m four
192 ) &&
195 cd gitrepo &&
196 git fetch &&
197 git log --format="%s" origin/master > ../actual
198 ) &&
200 hg -R hgrepo log --template "{desc}\n" > expected &&
201 test_cmp actual expected
204 test_done