remote-hg: tests: fix hg merge
[alt-git.git] / contrib / remote-helpers / test-hg-hg-git.sh
blobe0dbebf0500c6ebfdc465eb5422adf8c95d7a32e
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 -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 if ! python -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 git clone -q "hg::$PWD/$1" $2
33 # clone to an hg repo with git
34 hg_clone_git () {
36 hg init $2 &&
37 hg -R $2 bookmark -i master &&
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 -i -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 >log &&
82 grep -v 'tag: *default/' log
85 git_log () {
86 git --git-dir=$1/.git fast-export --branches
89 setup () {
91 echo "[ui]"
92 echo "username = A U Thor <author@example.com>"
93 echo "[defaults]"
94 echo "backout = -d \"0 0\""
95 echo "commit = -d \"0 0\""
96 echo "debugrawcommit = -d \"0 0\""
97 echo "tag = -d \"0 0\""
98 echo "[extensions]"
99 echo "hgext.bookmarks ="
100 echo "hggit ="
101 echo "graphlog ="
102 ) >> "$HOME"/.hgrc &&
103 git config --global receive.denycurrentbranch warn
104 git config --global remote-hg.hg-git-compat true
105 git config --global remote-hg.track-branches false
107 HGEDITOR=true
108 HGMERGE=true
110 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
111 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
112 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
115 setup
117 test_expect_success 'executable bit' '
118 mkdir -p tmp && cd tmp &&
119 test_when_finished "cd .. && rm -rf tmp" &&
122 git init -q gitrepo &&
123 cd gitrepo &&
124 echo alpha > alpha &&
125 chmod 0644 alpha &&
126 git add alpha &&
127 git commit -m "add alpha" &&
128 chmod 0755 alpha &&
129 git add alpha &&
130 git commit -m "set executable bit" &&
131 chmod 0644 alpha &&
132 git add alpha &&
133 git commit -m "clear executable bit"
134 ) &&
136 for x in hg git; do
138 hg_clone_$x gitrepo hgrepo-$x &&
139 cd hgrepo-$x &&
140 hg_log . &&
141 hg manifest -r 1 -v &&
142 hg manifest -v
143 ) > output-$x &&
145 git_clone_$x hgrepo-$x gitrepo2-$x &&
146 git_log gitrepo2-$x > log-$x
147 done &&
149 test_cmp output-hg output-git &&
150 test_cmp log-hg log-git
153 test_expect_success 'symlink' '
154 mkdir -p tmp && cd tmp &&
155 test_when_finished "cd .. && rm -rf tmp" &&
158 git init -q gitrepo &&
159 cd gitrepo &&
160 echo alpha > alpha &&
161 git add alpha &&
162 git commit -m "add alpha" &&
163 ln -s alpha beta &&
164 git add beta &&
165 git commit -m "add beta"
166 ) &&
168 for x in hg git; do
170 hg_clone_$x gitrepo hgrepo-$x &&
171 cd hgrepo-$x &&
172 hg_log . &&
173 hg manifest -v
174 ) > output-$x &&
176 git_clone_$x hgrepo-$x gitrepo2-$x &&
177 git_log gitrepo2-$x > log-$x
178 done &&
180 test_cmp output-hg output-git &&
181 test_cmp log-hg log-git
184 test_expect_success 'merge conflict 1' '
185 mkdir -p tmp && cd tmp &&
186 test_when_finished "cd .. && rm -rf tmp" &&
189 hg init hgrepo1 &&
190 cd hgrepo1 &&
191 echo A > afile &&
192 hg add afile &&
193 hg ci -m "origin" &&
195 echo B > afile &&
196 hg ci -m "A->B" &&
198 hg up -r0 &&
199 echo C > afile &&
200 hg ci -m "A->C" &&
202 hg merge -r1 &&
203 echo C > afile &&
204 hg resolve -m afile &&
205 hg ci -m "merge to C"
206 ) &&
208 for x in hg git; do
209 git_clone_$x hgrepo1 gitrepo-$x &&
210 hg_clone_$x gitrepo-$x hgrepo2-$x &&
211 hg_log hgrepo2-$x > hg-log-$x &&
212 git_log gitrepo-$x > git-log-$x
213 done &&
215 test_cmp hg-log-hg hg-log-git &&
216 test_cmp git-log-hg git-log-git
219 test_expect_success 'merge conflict 2' '
220 mkdir -p tmp && cd tmp &&
221 test_when_finished "cd .. && rm -rf tmp" &&
224 hg init hgrepo1 &&
225 cd hgrepo1 &&
226 echo A > afile &&
227 hg add afile &&
228 hg ci -m "origin" &&
230 echo B > afile &&
231 hg ci -m "A->B" &&
233 hg up -r0 &&
234 echo C > afile &&
235 hg ci -m "A->C" &&
237 hg merge -r1 || true &&
238 echo B > afile &&
239 hg resolve -m afile &&
240 hg ci -m "merge to B"
241 ) &&
243 for x in hg git; do
244 git_clone_$x hgrepo1 gitrepo-$x &&
245 hg_clone_$x gitrepo-$x hgrepo2-$x &&
246 hg_log hgrepo2-$x > hg-log-$x &&
247 git_log gitrepo-$x > git-log-$x
248 done &&
250 test_cmp hg-log-hg hg-log-git &&
251 test_cmp git-log-hg git-log-git
254 test_expect_success 'converged merge' '
255 mkdir -p tmp && cd tmp &&
256 test_when_finished "cd .. && rm -rf tmp" &&
259 hg init hgrepo1 &&
260 cd hgrepo1 &&
261 echo A > afile &&
262 hg add afile &&
263 hg ci -m "origin" &&
265 echo B > afile &&
266 hg ci -m "A->B" &&
268 echo C > afile &&
269 hg ci -m "B->C" &&
271 hg up -r0 &&
272 echo C > afile &&
273 hg ci -m "A->C" &&
275 hg merge -r2 || true &&
276 hg ci -m "merge"
277 ) &&
279 for x in hg git; do
280 git_clone_$x hgrepo1 gitrepo-$x &&
281 hg_clone_$x gitrepo-$x hgrepo2-$x &&
282 hg_log hgrepo2-$x > hg-log-$x &&
283 git_log gitrepo-$x > git-log-$x
284 done &&
286 test_cmp hg-log-hg hg-log-git &&
287 test_cmp git-log-hg git-log-git
290 test_expect_success 'encoding' '
291 mkdir -p tmp && cd tmp &&
292 test_when_finished "cd .. && rm -rf tmp" &&
295 git init -q gitrepo &&
296 cd gitrepo &&
298 echo alpha > alpha &&
299 git add alpha &&
300 git commit -m "add älphà" &&
302 GIT_AUTHOR_NAME="tést èncödîng" &&
303 export GIT_AUTHOR_NAME &&
304 echo beta > beta &&
305 git add beta &&
306 git commit -m "add beta" &&
308 echo gamma > gamma &&
309 git add gamma &&
310 git commit -m "add gämmâ" &&
312 : TODO git config i18n.commitencoding latin-1 &&
313 echo delta > delta &&
314 git add delta &&
315 git commit -m "add déltà"
316 ) &&
318 for x in hg git; do
319 hg_clone_$x gitrepo hgrepo-$x &&
320 git_clone_$x hgrepo-$x gitrepo2-$x &&
322 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
323 git_log gitrepo2-$x > git-log-$x
324 done &&
326 test_cmp hg-log-hg hg-log-git &&
327 test_cmp git-log-hg git-log-git
330 test_expect_success 'file removal' '
331 mkdir -p tmp && cd tmp &&
332 test_when_finished "cd .. && rm -rf tmp" &&
335 git init -q gitrepo &&
336 cd gitrepo &&
337 echo alpha > alpha &&
338 git add alpha &&
339 git commit -m "add alpha" &&
340 echo beta > beta &&
341 git add beta &&
342 git commit -m "add beta"
343 mkdir foo &&
344 echo blah > foo/bar &&
345 git add foo &&
346 git commit -m "add foo" &&
347 git rm alpha &&
348 git commit -m "remove alpha" &&
349 git rm foo/bar &&
350 git commit -m "remove foo/bar"
351 ) &&
353 for x in hg git; do
355 hg_clone_$x gitrepo hgrepo-$x &&
356 cd hgrepo-$x &&
357 hg_log . &&
358 hg manifest -r 3 &&
359 hg manifest
360 ) > output-$x &&
362 git_clone_$x hgrepo-$x gitrepo2-$x &&
363 git_log gitrepo2-$x > log-$x
364 done &&
366 test_cmp output-hg output-git &&
367 test_cmp log-hg log-git
370 test_expect_success 'git tags' '
371 mkdir -p tmp && cd tmp &&
372 test_when_finished "cd .. && rm -rf tmp" &&
375 git init -q gitrepo &&
376 cd gitrepo &&
377 git config receive.denyCurrentBranch ignore &&
378 echo alpha > alpha &&
379 git add alpha &&
380 git commit -m "add alpha" &&
381 git tag alpha &&
383 echo beta > beta &&
384 git add beta &&
385 git commit -m "add beta" &&
386 git tag -a -m "added tag beta" beta
387 ) &&
389 for x in hg git; do
390 hg_clone_$x gitrepo hgrepo-$x &&
391 hg_log hgrepo-$x > log-$x
392 done &&
394 test_cmp log-hg log-git
397 test_expect_success 'hg author' '
398 mkdir -p tmp && cd tmp &&
399 test_when_finished "cd .. && rm -rf tmp" &&
401 for x in hg git; do
403 git init -q gitrepo-$x &&
404 cd gitrepo-$x &&
406 echo alpha > alpha &&
407 git add alpha &&
408 git commit -m "add alpha" &&
409 git checkout -q -b not-master
410 ) &&
413 hg_clone_$x gitrepo-$x hgrepo-$x &&
414 cd hgrepo-$x &&
416 hg co master &&
417 echo beta > beta &&
418 hg add beta &&
419 hg commit -u "test" -m "add beta" &&
421 echo gamma >> beta &&
422 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
424 echo gamma > gamma &&
425 hg add gamma &&
426 hg commit -u "<test@example.com>" -m "add gamma" &&
428 echo delta > delta &&
429 hg add delta &&
430 hg commit -u "name<test@example.com>" -m "add delta" &&
432 echo epsilon > epsilon &&
433 hg add epsilon &&
434 hg commit -u "name <test@example.com" -m "add epsilon" &&
436 echo zeta > zeta &&
437 hg add zeta &&
438 hg commit -u " test " -m "add zeta" &&
440 echo eta > eta &&
441 hg add eta &&
442 hg commit -u "test < test@example.com >" -m "add eta" &&
444 echo theta > theta &&
445 hg add theta &&
446 hg commit -u "test >test@example.com>" -m "add theta" &&
448 echo iota > iota &&
449 hg add iota &&
450 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
451 ) &&
453 hg_push_$x hgrepo-$x gitrepo-$x &&
454 hg_clone_$x gitrepo-$x hgrepo2-$x &&
456 hg_log hgrepo2-$x > hg-log-$x &&
457 git_log gitrepo-$x > git-log-$x
458 done &&
460 test_cmp hg-log-hg hg-log-git &&
461 test_cmp git-log-hg git-log-git
464 test_expect_success 'hg branch' '
465 mkdir -p tmp && cd tmp &&
466 test_when_finished "cd .. && rm -rf tmp" &&
468 for x in hg git; do
470 git init -q gitrepo-$x &&
471 cd gitrepo-$x &&
473 echo alpha > alpha &&
474 git add alpha &&
475 git commit -q -m "add alpha" &&
476 git checkout -q -b not-master
477 ) &&
480 hg_clone_$x gitrepo-$x hgrepo-$x &&
482 cd hgrepo-$x &&
483 hg -q co master &&
484 hg mv alpha beta &&
485 hg -q commit -m "rename alpha to beta" &&
486 hg branch gamma | grep -v "permanent and global" &&
487 hg -q commit -m "started branch gamma"
488 ) &&
490 hg_push_$x hgrepo-$x gitrepo-$x &&
491 hg_clone_$x gitrepo-$x hgrepo2-$x &&
493 hg_log hgrepo2-$x > hg-log-$x &&
494 git_log gitrepo-$x > git-log-$x
495 done &&
497 test_cmp hg-log-hg hg-log-git &&
498 test_cmp git-log-hg git-log-git
501 test_expect_success 'hg tags' '
502 mkdir -p tmp && cd tmp &&
503 test_when_finished "cd .. && rm -rf tmp" &&
505 for x in hg git; do
507 git init -q gitrepo-$x &&
508 cd gitrepo-$x &&
510 echo alpha > alpha &&
511 git add alpha &&
512 git commit -m "add alpha" &&
513 git checkout -q -b not-master
514 ) &&
517 hg_clone_$x gitrepo-$x hgrepo-$x &&
519 cd hgrepo-$x &&
520 hg co master &&
521 hg tag alpha
522 ) &&
524 hg_push_$x hgrepo-$x gitrepo-$x &&
525 hg_clone_$x gitrepo-$x hgrepo2-$x &&
528 git --git-dir=gitrepo-$x/.git tag -l &&
529 hg_log hgrepo2-$x &&
530 cat hgrepo2-$x/.hgtags
531 ) > output-$x
532 done &&
534 test_cmp output-hg output-git
537 test_done