remote-hg: add bidirectional tests

Base commands from hg-git tests: https://bitbucket.org/durin42/hg-git/src Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Jeff King <peff@peff.net>

Felipe Contreras committed Nov 4, 2012 at 03:13 UTC 74954ee8aa0530a4c1ccaeaa5f8def71ef6b68bd
1 file changed +243
contrib/remote-helpers/test-hg-bidi.sh new
+243
@@ -0,0 +1,243 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2012 Felipe Contreras
4 +#
5 +# Base commands from hg-git tests:
6 +# https://bitbucket.org/durin42/hg-git/src
7 +#
8 +
9 +test_description='Test biridectionality of remote-hg'
10 +
11 +. ./test-lib.sh
12 +
13 +if ! test_have_prereq PYTHON; then
14 + skip_all='skipping remote-hg tests; python not available'
15 + test_done
16 +fi
17 +
18 +if ! "$PYTHON_PATH" -c 'import mercurial'; then
19 + skip_all='skipping remote-hg tests; mercurial not available'
20 + test_done
21 +fi
22 +
23 +# clone to a git repo
24 +git_clone () {
25 + hg -R $1 bookmark -f -r tip master &&
26 + git clone -q "hg::$PWD/$1" $2
27 +}
28 +
29 +# clone to an hg repo
30 +hg_clone () {
31 + (
32 + hg init $2 &&
33 + cd $1 &&
34 + git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
35 + ) &&
36 +
37 + (cd $2 && hg -q update)
38 +}
39 +
40 +# push an hg repo
41 +hg_push () {
42 + (
43 + cd $2
44 + old=$(git symbolic-ref --short HEAD)
45 + git checkout -q -b tmp &&
46 + git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
47 + git checkout -q $old &&
48 + git branch -q -D tmp 2> /dev/null || true
49 + )
50 +}
51 +
52 +hg_log () {
53 + hg -R $1 log --graph --debug | grep -v 'tag: *default/'
54 +}
55 +
56 +setup () {
57 + (
58 + echo "[ui]"
59 + echo "username = A U Thor <author@example.com>"
60 + echo "[defaults]"
61 + echo "backout = -d \"0 0\""
62 + echo "commit = -d \"0 0\""
63 + echo "debugrawcommit = -d \"0 0\""
64 + echo "tag = -d \"0 0\""
65 + ) >> "$HOME"/.hgrc &&
66 + git config --global remote-hg.hg-git-compat true
67 +
68 + export HGEDITOR=/usr/bin/true
69 +
70 + export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
71 + export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
72 +}
73 +
74 +setup
75 +
76 +test_expect_success 'encoding' '
77 + mkdir -p tmp && cd tmp &&
78 + test_when_finished "cd .. && rm -rf tmp" &&
79 +
80 + (
81 + git init -q gitrepo &&
82 + cd gitrepo &&
83 +
84 + echo alpha > alpha &&
85 + git add alpha &&
86 + git commit -m "add älphà" &&
87 +
88 + export GIT_AUTHOR_NAME="tést èncödîng" &&
89 + echo beta > beta &&
90 + git add beta &&
91 + git commit -m "add beta" &&
92 +
93 + echo gamma > gamma &&
94 + git add gamma &&
95 + git commit -m "add gämmâ" &&
96 +
97 + : TODO git config i18n.commitencoding latin-1 &&
98 + echo delta > delta &&
99 + git add delta &&
100 + git commit -m "add déltà"
101 + ) &&
102 +
103 + hg_clone gitrepo hgrepo &&
104 + git_clone hgrepo gitrepo2 &&
105 + hg_clone gitrepo2 hgrepo2 &&
106 +
107 + HGENCODING=utf-8 hg_log hgrepo > expected &&
108 + HGENCODING=utf-8 hg_log hgrepo2 > actual &&
109 +
110 + test_cmp expected actual
111 +'
112 +
113 +test_expect_success 'file removal' '
114 + mkdir -p tmp && cd tmp &&
115 + test_when_finished "cd .. && rm -rf tmp" &&
116 +
117 + (
118 + git init -q gitrepo &&
119 + cd gitrepo &&
120 + echo alpha > alpha &&
121 + git add alpha &&
122 + git commit -m "add alpha" &&
123 + echo beta > beta &&
124 + git add beta &&
125 + git commit -m "add beta"
126 + mkdir foo &&
127 + echo blah > foo/bar &&
128 + git add foo &&
129 + git commit -m "add foo" &&
130 + git rm alpha &&
131 + git commit -m "remove alpha" &&
132 + git rm foo/bar &&
133 + git commit -m "remove foo/bar"
134 + ) &&
135 +
136 + hg_clone gitrepo hgrepo &&
137 + git_clone hgrepo gitrepo2 &&
138 + hg_clone gitrepo2 hgrepo2 &&
139 +
140 + hg_log hgrepo > expected &&
141 + hg_log hgrepo2 > actual &&
142 +
143 + test_cmp expected actual
144 +'
145 +
146 +test_expect_success 'git tags' '
147 + mkdir -p tmp && cd tmp &&
148 + test_when_finished "cd .. && rm -rf tmp" &&
149 +
150 + (
151 + git init -q gitrepo &&
152 + cd gitrepo &&
153 + git config receive.denyCurrentBranch ignore &&
154 + echo alpha > alpha &&
155 + git add alpha &&
156 + git commit -m "add alpha" &&
157 + git tag alpha &&
158 +
159 + echo beta > beta &&
160 + git add beta &&
161 + git commit -m "add beta" &&
162 + git tag -a -m "added tag beta" beta
163 + ) &&
164 +
165 + hg_clone gitrepo hgrepo &&
166 + git_clone hgrepo gitrepo2 &&
167 + hg_clone gitrepo2 hgrepo2 &&
168 +
169 + hg_log hgrepo > expected &&
170 + hg_log hgrepo2 > actual &&
171 +
172 + test_cmp expected actual
173 +'
174 +
175 +test_expect_success 'hg branch' '
176 + mkdir -p tmp && cd tmp &&
177 + test_when_finished "cd .. && rm -rf tmp" &&
178 +
179 + (
180 + git init -q gitrepo &&
181 + cd gitrepo &&
182 +
183 + echo alpha > alpha &&
184 + git add alpha &&
185 + git commit -q -m "add alpha" &&
186 + git checkout -q -b not-master
187 + ) &&
188 +
189 + (
190 + hg_clone gitrepo hgrepo &&
191 +
192 + cd hgrepo &&
193 + hg -q co master &&
194 + hg mv alpha beta &&
195 + hg -q commit -m "rename alpha to beta" &&
196 + hg branch gamma | grep -v "permanent and global" &&
197 + hg -q commit -m "started branch gamma"
198 + ) &&
199 +
200 + hg_push hgrepo gitrepo &&
201 + hg_clone gitrepo hgrepo2 &&
202 +
203 + : TODO, avoid "master" bookmark &&
204 + (cd hgrepo2 && hg checkout gamma) &&
205 +
206 + hg_log hgrepo > expected &&
207 + hg_log hgrepo2 > actual &&
208 +
209 + test_cmp expected actual
210 +'
211 +
212 +test_expect_success 'hg tags' '
213 + mkdir -p tmp && cd tmp &&
214 + test_when_finished "cd .. && rm -rf tmp" &&
215 +
216 + (
217 + git init -q gitrepo &&
218 + cd gitrepo &&
219 +
220 + echo alpha > alpha &&
221 + git add alpha &&
222 + git commit -m "add alpha" &&
223 + git checkout -q -b not-master
224 + ) &&
225 +
226 + (
227 + hg_clone gitrepo hgrepo &&
228 +
229 + cd hgrepo &&
230 + hg co master &&
231 + hg tag alpha
232 + ) &&
233 +
234 + hg_push hgrepo gitrepo &&
235 + hg_clone gitrepo hgrepo2 &&
236 +
237 + hg_log hgrepo > expected &&
238 + hg_log hgrepo2 > actual &&
239 +
240 + test_cmp expected actual
241 +'
242 +
243 +test_done