Makefile: Replace merge-file.h with merge-blobs.h in LIB_H
[git/mingw.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob3e76d9fb60bff8b25f5b2751c6e11cfabb6c9dc6
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 output compared to hg-git'
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 if ! "$PYTHON_PATH" -c 'import hggit'; then
24 skip_all='skipping remote-hg tests; hg-git not available'
25 test_done
28 # clone to a git repo with git
29 git_clone_git () {
30 hg -R $1 bookmark -f -r tip master &&
31 git clone -q "hg::$PWD/$1" $2
34 # clone to an hg repo with git
35 hg_clone_git () {
37 hg init $2 &&
38 cd $1 &&
39 git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
40 ) &&
42 (cd $2 && hg -q update)
45 # clone to a git repo with hg
46 git_clone_hg () {
48 git init -q $2 &&
49 cd $1 &&
50 hg bookmark -f -r tip master &&
51 hg -q push -r master ../$2 || true
55 # clone to an hg repo with hg
56 hg_clone_hg () {
57 hg -q clone $1 $2
60 # push an hg repo with git
61 hg_push_git () {
63 cd $2
64 old=$(git symbolic-ref --short HEAD)
65 git checkout -q -b tmp &&
66 git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
67 git checkout -q $old &&
68 git branch -q -D tmp 2> /dev/null || true
72 # push an hg git repo with hg
73 hg_push_hg () {
75 cd $1 &&
76 hg -q push ../$2 || true
80 hg_log () {
81 hg -R $1 log --graph --debug | grep -v 'tag: *default/'
84 git_log () {
85 git --git-dir=$1/.git fast-export --branches
88 setup () {
90 echo "[ui]"
91 echo "username = A U Thor <author@example.com>"
92 echo "[defaults]"
93 echo "backout = -d \"0 0\""
94 echo "commit = -d \"0 0\""
95 echo "debugrawcommit = -d \"0 0\""
96 echo "tag = -d \"0 0\""
97 echo "[extensions]"
98 echo "hgext.bookmarks ="
99 echo "hggit ="
100 ) >> "$HOME"/.hgrc &&
101 git config --global receive.denycurrentbranch warn
102 git config --global remote-hg.hg-git-compat true
104 export HGEDITOR=/usr/bin/true
106 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
107 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
110 setup
112 test_expect_success 'merge conflict 1' '
113 mkdir -p tmp && cd tmp &&
114 test_when_finished "cd .. && rm -rf tmp" &&
117 hg init hgrepo1 &&
118 cd hgrepo1 &&
119 echo A > afile &&
120 hg add afile &&
121 hg ci -m "origin" &&
123 echo B > afile &&
124 hg ci -m "A->B" &&
126 hg up -r0 &&
127 echo C > afile &&
128 hg ci -m "A->C" &&
130 hg merge -r1 || true &&
131 echo C > afile &&
132 hg resolve -m afile &&
133 hg ci -m "merge to C"
134 ) &&
136 for x in hg git; do
137 git_clone_$x hgrepo1 gitrepo-$x &&
138 hg_clone_$x gitrepo-$x hgrepo2-$x &&
139 hg_log hgrepo2-$x > hg-log-$x &&
140 git_log gitrepo-$x > git-log-$x
141 done &&
143 test_cmp hg-log-hg hg-log-git &&
144 test_cmp git-log-hg git-log-git
147 test_expect_success 'merge conflict 2' '
148 mkdir -p tmp && cd tmp &&
149 test_when_finished "cd .. && rm -rf tmp" &&
152 hg init hgrepo1 &&
153 cd hgrepo1 &&
154 echo A > afile &&
155 hg add afile &&
156 hg ci -m "origin" &&
158 echo B > afile &&
159 hg ci -m "A->B" &&
161 hg up -r0 &&
162 echo C > afile &&
163 hg ci -m "A->C" &&
165 hg merge -r1 || true &&
166 echo B > afile &&
167 hg resolve -m afile &&
168 hg ci -m "merge to B"
169 ) &&
171 for x in hg git; do
172 git_clone_$x hgrepo1 gitrepo-$x &&
173 hg_clone_$x gitrepo-$x hgrepo2-$x &&
174 hg_log hgrepo2-$x > hg-log-$x &&
175 git_log gitrepo-$x > git-log-$x
176 done &&
178 test_cmp hg-log-hg hg-log-git &&
179 test_cmp git-log-hg git-log-git
182 test_expect_success 'converged merge' '
183 mkdir -p tmp && cd tmp &&
184 test_when_finished "cd .. && rm -rf tmp" &&
187 hg init hgrepo1 &&
188 cd hgrepo1 &&
189 echo A > afile &&
190 hg add afile &&
191 hg ci -m "origin" &&
193 echo B > afile &&
194 hg ci -m "A->B" &&
196 echo C > afile &&
197 hg ci -m "B->C" &&
199 hg up -r0 &&
200 echo C > afile &&
201 hg ci -m "A->C" &&
203 hg merge -r2 || true &&
204 hg ci -m "merge"
205 ) &&
207 for x in hg git; do
208 git_clone_$x hgrepo1 gitrepo-$x &&
209 hg_clone_$x gitrepo-$x hgrepo2-$x &&
210 hg_log hgrepo2-$x > hg-log-$x &&
211 git_log gitrepo-$x > git-log-$x
212 done &&
214 test_cmp hg-log-hg hg-log-git &&
215 test_cmp git-log-hg git-log-git
218 test_expect_success 'encoding' '
219 mkdir -p tmp && cd tmp &&
220 test_when_finished "cd .. && rm -rf tmp" &&
223 git init -q gitrepo &&
224 cd gitrepo &&
226 echo alpha > alpha &&
227 git add alpha &&
228 git commit -m "add älphà" &&
230 export GIT_AUTHOR_NAME="tést èncödîng" &&
231 echo beta > beta &&
232 git add beta &&
233 git commit -m "add beta" &&
235 echo gamma > gamma &&
236 git add gamma &&
237 git commit -m "add gämmâ" &&
239 : TODO git config i18n.commitencoding latin-1 &&
240 echo delta > delta &&
241 git add delta &&
242 git commit -m "add déltà"
243 ) &&
245 for x in hg git; do
246 hg_clone_$x gitrepo hgrepo-$x &&
247 git_clone_$x hgrepo-$x gitrepo2-$x &&
249 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
250 git_log gitrepo2-$x > git-log-$x
251 done &&
253 test_cmp hg-log-hg hg-log-git &&
254 test_cmp git-log-hg git-log-git
257 test_expect_success 'file removal' '
258 mkdir -p tmp && cd tmp &&
259 test_when_finished "cd .. && rm -rf tmp" &&
262 git init -q gitrepo &&
263 cd gitrepo &&
264 echo alpha > alpha &&
265 git add alpha &&
266 git commit -m "add alpha" &&
267 echo beta > beta &&
268 git add beta &&
269 git commit -m "add beta"
270 mkdir foo &&
271 echo blah > foo/bar &&
272 git add foo &&
273 git commit -m "add foo" &&
274 git rm alpha &&
275 git commit -m "remove alpha" &&
276 git rm foo/bar &&
277 git commit -m "remove foo/bar"
278 ) &&
280 for x in hg git; do
282 hg_clone_$x gitrepo hgrepo-$x &&
283 cd hgrepo-$x &&
284 hg_log . &&
285 hg manifest -r 3 &&
286 hg manifest
287 ) > output-$x &&
289 git_clone_$x hgrepo-$x gitrepo2-$x &&
290 git_log gitrepo2-$x > log-$x
291 done &&
293 test_cmp output-hg output-git &&
294 test_cmp log-hg log-git
297 test_expect_success 'git tags' '
298 mkdir -p tmp && cd tmp &&
299 test_when_finished "cd .. && rm -rf tmp" &&
302 git init -q gitrepo &&
303 cd gitrepo &&
304 git config receive.denyCurrentBranch ignore &&
305 echo alpha > alpha &&
306 git add alpha &&
307 git commit -m "add alpha" &&
308 git tag alpha &&
310 echo beta > beta &&
311 git add beta &&
312 git commit -m "add beta" &&
313 git tag -a -m "added tag beta" beta
314 ) &&
316 for x in hg git; do
317 hg_clone_$x gitrepo hgrepo-$x &&
318 hg_log hgrepo-$x > log-$x
319 done &&
321 test_cmp log-hg log-git
324 test_expect_success 'hg author' '
325 mkdir -p tmp && cd tmp &&
326 test_when_finished "cd .. && rm -rf tmp" &&
328 for x in hg git; do
330 git init -q gitrepo-$x &&
331 cd gitrepo-$x &&
333 echo alpha > alpha &&
334 git add alpha &&
335 git commit -m "add alpha" &&
336 git checkout -q -b not-master
337 ) &&
340 hg_clone_$x gitrepo-$x hgrepo-$x &&
341 cd hgrepo-$x &&
343 hg co master &&
344 echo beta > beta &&
345 hg add beta &&
346 hg commit -u "test" -m "add beta" &&
348 echo gamma >> beta &&
349 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
351 echo gamma > gamma &&
352 hg add gamma &&
353 hg commit -u "<test@example.com>" -m "add gamma" &&
355 echo delta > delta &&
356 hg add delta &&
357 hg commit -u "name<test@example.com>" -m "add delta" &&
359 echo epsilon > epsilon &&
360 hg add epsilon &&
361 hg commit -u "name <test@example.com" -m "add epsilon" &&
363 echo zeta > zeta &&
364 hg add zeta &&
365 hg commit -u " test " -m "add zeta" &&
367 echo eta > eta &&
368 hg add eta &&
369 hg commit -u "test < test@example.com >" -m "add eta" &&
371 echo theta > theta &&
372 hg add theta &&
373 hg commit -u "test >test@example.com>" -m "add theta" &&
375 echo iota > iota &&
376 hg add iota &&
377 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
378 ) &&
380 hg_push_$x hgrepo-$x gitrepo-$x &&
381 hg_clone_$x gitrepo-$x hgrepo2-$x &&
383 hg_log hgrepo2-$x > hg-log-$x &&
384 git_log gitrepo-$x > git-log-$x
385 done &&
387 test_cmp git-log-hg git-log-git &&
389 test_cmp hg-log-hg hg-log-git &&
390 test_cmp git-log-hg git-log-git
393 test_expect_success 'hg branch' '
394 mkdir -p tmp && cd tmp &&
395 test_when_finished "cd .. && rm -rf tmp" &&
397 for x in hg git; do
399 git init -q gitrepo-$x &&
400 cd gitrepo-$x &&
402 echo alpha > alpha &&
403 git add alpha &&
404 git commit -q -m "add alpha" &&
405 git checkout -q -b not-master
406 ) &&
409 hg_clone_$x gitrepo-$x hgrepo-$x &&
411 cd hgrepo-$x &&
412 hg -q co master &&
413 hg mv alpha beta &&
414 hg -q commit -m "rename alpha to beta" &&
415 hg branch gamma | grep -v "permanent and global" &&
416 hg -q commit -m "started branch gamma"
417 ) &&
419 hg_push_$x hgrepo-$x gitrepo-$x &&
420 hg_clone_$x gitrepo-$x hgrepo2-$x &&
422 hg_log hgrepo2-$x > hg-log-$x &&
423 git_log gitrepo-$x > git-log-$x
424 done &&
426 test_cmp hg-log-hg hg-log-git &&
427 test_cmp git-log-hg git-log-git
430 test_expect_success 'hg tags' '
431 mkdir -p tmp && cd tmp &&
432 test_when_finished "cd .. && rm -rf tmp" &&
434 for x in hg git; do
436 git init -q gitrepo-$x &&
437 cd gitrepo-$x &&
439 echo alpha > alpha &&
440 git add alpha &&
441 git commit -m "add alpha" &&
442 git checkout -q -b not-master
443 ) &&
446 hg_clone_$x gitrepo-$x hgrepo-$x &&
448 cd hgrepo-$x &&
449 hg co master &&
450 hg tag alpha
451 ) &&
453 hg_push_$x hgrepo-$x gitrepo-$x &&
454 hg_clone_$x gitrepo-$x hgrepo2-$x &&
457 git --git-dir=gitrepo-$x/.git tag -l &&
458 hg_log hgrepo2-$x &&
459 cat hgrepo2-$x/.hgtags
460 ) > output-$x
461 done &&
463 test_cmp output-hg output-git
466 test_done