pretty: share code between format_decoration and show_decorations
[git/mingw.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob3f253b7de75a6fa44c4cff3b2e1f53f9feffcf5d
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 'executable bit' '
113 mkdir -p tmp && cd tmp &&
114 test_when_finished "cd .. && rm -rf tmp" &&
117 git init -q gitrepo &&
118 cd gitrepo &&
119 echo alpha > alpha &&
120 chmod 0644 alpha &&
121 git add alpha &&
122 git commit -m "add alpha" &&
123 chmod 0755 alpha &&
124 git add alpha &&
125 git commit -m "set executable bit" &&
126 chmod 0644 alpha &&
127 git add alpha &&
128 git commit -m "clear executable bit"
129 ) &&
131 for x in hg git; do
133 hg_clone_$x gitrepo hgrepo-$x &&
134 cd hgrepo-$x &&
135 hg_log . &&
136 hg manifest -r 1 -v &&
137 hg manifest -v
138 ) > output-$x &&
140 git_clone_$x hgrepo-$x gitrepo2-$x &&
141 git_log gitrepo2-$x > log-$x
142 done &&
144 test_cmp output-hg output-git &&
145 test_cmp log-hg log-git
148 test_expect_success 'symlink' '
149 mkdir -p tmp && cd tmp &&
150 test_when_finished "cd .. && rm -rf tmp" &&
153 git init -q gitrepo &&
154 cd gitrepo &&
155 echo alpha > alpha &&
156 git add alpha &&
157 git commit -m "add alpha" &&
158 ln -s alpha beta &&
159 git add beta &&
160 git commit -m "add beta"
161 ) &&
163 for x in hg git; do
165 hg_clone_$x gitrepo hgrepo-$x &&
166 cd hgrepo-$x &&
167 hg_log . &&
168 hg manifest -v
169 ) > output-$x &&
171 git_clone_$x hgrepo-$x gitrepo2-$x &&
172 git_log gitrepo2-$x > log-$x
173 done &&
175 test_cmp output-hg output-git &&
176 test_cmp log-hg log-git
179 test_expect_success 'merge conflict 1' '
180 mkdir -p tmp && cd tmp &&
181 test_when_finished "cd .. && rm -rf tmp" &&
184 hg init hgrepo1 &&
185 cd hgrepo1 &&
186 echo A > afile &&
187 hg add afile &&
188 hg ci -m "origin" &&
190 echo B > afile &&
191 hg ci -m "A->B" &&
193 hg up -r0 &&
194 echo C > afile &&
195 hg ci -m "A->C" &&
197 hg merge -r1 || true &&
198 echo C > afile &&
199 hg resolve -m afile &&
200 hg ci -m "merge to C"
201 ) &&
203 for x in hg git; do
204 git_clone_$x hgrepo1 gitrepo-$x &&
205 hg_clone_$x gitrepo-$x hgrepo2-$x &&
206 hg_log hgrepo2-$x > hg-log-$x &&
207 git_log gitrepo-$x > git-log-$x
208 done &&
210 test_cmp hg-log-hg hg-log-git &&
211 test_cmp git-log-hg git-log-git
214 test_expect_success 'merge conflict 2' '
215 mkdir -p tmp && cd tmp &&
216 test_when_finished "cd .. && rm -rf tmp" &&
219 hg init hgrepo1 &&
220 cd hgrepo1 &&
221 echo A > afile &&
222 hg add afile &&
223 hg ci -m "origin" &&
225 echo B > afile &&
226 hg ci -m "A->B" &&
228 hg up -r0 &&
229 echo C > afile &&
230 hg ci -m "A->C" &&
232 hg merge -r1 || true &&
233 echo B > afile &&
234 hg resolve -m afile &&
235 hg ci -m "merge to B"
236 ) &&
238 for x in hg git; do
239 git_clone_$x hgrepo1 gitrepo-$x &&
240 hg_clone_$x gitrepo-$x hgrepo2-$x &&
241 hg_log hgrepo2-$x > hg-log-$x &&
242 git_log gitrepo-$x > git-log-$x
243 done &&
245 test_cmp hg-log-hg hg-log-git &&
246 test_cmp git-log-hg git-log-git
249 test_expect_success 'converged merge' '
250 mkdir -p tmp && cd tmp &&
251 test_when_finished "cd .. && rm -rf tmp" &&
254 hg init hgrepo1 &&
255 cd hgrepo1 &&
256 echo A > afile &&
257 hg add afile &&
258 hg ci -m "origin" &&
260 echo B > afile &&
261 hg ci -m "A->B" &&
263 echo C > afile &&
264 hg ci -m "B->C" &&
266 hg up -r0 &&
267 echo C > afile &&
268 hg ci -m "A->C" &&
270 hg merge -r2 || true &&
271 hg ci -m "merge"
272 ) &&
274 for x in hg git; do
275 git_clone_$x hgrepo1 gitrepo-$x &&
276 hg_clone_$x gitrepo-$x hgrepo2-$x &&
277 hg_log hgrepo2-$x > hg-log-$x &&
278 git_log gitrepo-$x > git-log-$x
279 done &&
281 test_cmp hg-log-hg hg-log-git &&
282 test_cmp git-log-hg git-log-git
285 test_expect_success 'encoding' '
286 mkdir -p tmp && cd tmp &&
287 test_when_finished "cd .. && rm -rf tmp" &&
290 git init -q gitrepo &&
291 cd gitrepo &&
293 echo alpha > alpha &&
294 git add alpha &&
295 git commit -m "add älphà" &&
297 export GIT_AUTHOR_NAME="tést èncödîng" &&
298 echo beta > beta &&
299 git add beta &&
300 git commit -m "add beta" &&
302 echo gamma > gamma &&
303 git add gamma &&
304 git commit -m "add gämmâ" &&
306 : TODO git config i18n.commitencoding latin-1 &&
307 echo delta > delta &&
308 git add delta &&
309 git commit -m "add déltà"
310 ) &&
312 for x in hg git; do
313 hg_clone_$x gitrepo hgrepo-$x &&
314 git_clone_$x hgrepo-$x gitrepo2-$x &&
316 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
317 git_log gitrepo2-$x > git-log-$x
318 done &&
320 test_cmp hg-log-hg hg-log-git &&
321 test_cmp git-log-hg git-log-git
324 test_expect_success 'file removal' '
325 mkdir -p tmp && cd tmp &&
326 test_when_finished "cd .. && rm -rf tmp" &&
329 git init -q gitrepo &&
330 cd gitrepo &&
331 echo alpha > alpha &&
332 git add alpha &&
333 git commit -m "add alpha" &&
334 echo beta > beta &&
335 git add beta &&
336 git commit -m "add beta"
337 mkdir foo &&
338 echo blah > foo/bar &&
339 git add foo &&
340 git commit -m "add foo" &&
341 git rm alpha &&
342 git commit -m "remove alpha" &&
343 git rm foo/bar &&
344 git commit -m "remove foo/bar"
345 ) &&
347 for x in hg git; do
349 hg_clone_$x gitrepo hgrepo-$x &&
350 cd hgrepo-$x &&
351 hg_log . &&
352 hg manifest -r 3 &&
353 hg manifest
354 ) > output-$x &&
356 git_clone_$x hgrepo-$x gitrepo2-$x &&
357 git_log gitrepo2-$x > log-$x
358 done &&
360 test_cmp output-hg output-git &&
361 test_cmp log-hg log-git
364 test_expect_success 'git tags' '
365 mkdir -p tmp && cd tmp &&
366 test_when_finished "cd .. && rm -rf tmp" &&
369 git init -q gitrepo &&
370 cd gitrepo &&
371 git config receive.denyCurrentBranch ignore &&
372 echo alpha > alpha &&
373 git add alpha &&
374 git commit -m "add alpha" &&
375 git tag alpha &&
377 echo beta > beta &&
378 git add beta &&
379 git commit -m "add beta" &&
380 git tag -a -m "added tag beta" beta
381 ) &&
383 for x in hg git; do
384 hg_clone_$x gitrepo hgrepo-$x &&
385 hg_log hgrepo-$x > log-$x
386 done &&
388 test_cmp log-hg log-git
391 test_expect_success 'hg author' '
392 mkdir -p tmp && cd tmp &&
393 test_when_finished "cd .. && rm -rf tmp" &&
395 for x in hg git; do
397 git init -q gitrepo-$x &&
398 cd gitrepo-$x &&
400 echo alpha > alpha &&
401 git add alpha &&
402 git commit -m "add alpha" &&
403 git checkout -q -b not-master
404 ) &&
407 hg_clone_$x gitrepo-$x hgrepo-$x &&
408 cd hgrepo-$x &&
410 hg co master &&
411 echo beta > beta &&
412 hg add beta &&
413 hg commit -u "test" -m "add beta" &&
415 echo gamma >> beta &&
416 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
418 echo gamma > gamma &&
419 hg add gamma &&
420 hg commit -u "<test@example.com>" -m "add gamma" &&
422 echo delta > delta &&
423 hg add delta &&
424 hg commit -u "name<test@example.com>" -m "add delta" &&
426 echo epsilon > epsilon &&
427 hg add epsilon &&
428 hg commit -u "name <test@example.com" -m "add epsilon" &&
430 echo zeta > zeta &&
431 hg add zeta &&
432 hg commit -u " test " -m "add zeta" &&
434 echo eta > eta &&
435 hg add eta &&
436 hg commit -u "test < test@example.com >" -m "add eta" &&
438 echo theta > theta &&
439 hg add theta &&
440 hg commit -u "test >test@example.com>" -m "add theta" &&
442 echo iota > iota &&
443 hg add iota &&
444 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
445 ) &&
447 hg_push_$x hgrepo-$x gitrepo-$x &&
448 hg_clone_$x gitrepo-$x hgrepo2-$x &&
450 hg_log hgrepo2-$x > hg-log-$x &&
451 git_log gitrepo-$x > git-log-$x
452 done &&
454 test_cmp git-log-hg git-log-git &&
456 test_cmp hg-log-hg hg-log-git &&
457 test_cmp git-log-hg git-log-git
460 test_expect_success 'hg branch' '
461 mkdir -p tmp && cd tmp &&
462 test_when_finished "cd .. && rm -rf tmp" &&
464 for x in hg git; do
466 git init -q gitrepo-$x &&
467 cd gitrepo-$x &&
469 echo alpha > alpha &&
470 git add alpha &&
471 git commit -q -m "add alpha" &&
472 git checkout -q -b not-master
473 ) &&
476 hg_clone_$x gitrepo-$x hgrepo-$x &&
478 cd hgrepo-$x &&
479 hg -q co master &&
480 hg mv alpha beta &&
481 hg -q commit -m "rename alpha to beta" &&
482 hg branch gamma | grep -v "permanent and global" &&
483 hg -q commit -m "started branch gamma"
484 ) &&
486 hg_push_$x hgrepo-$x gitrepo-$x &&
487 hg_clone_$x gitrepo-$x hgrepo2-$x &&
489 hg_log hgrepo2-$x > hg-log-$x &&
490 git_log gitrepo-$x > git-log-$x
491 done &&
493 test_cmp hg-log-hg hg-log-git &&
494 test_cmp git-log-hg git-log-git
497 test_expect_success 'hg tags' '
498 mkdir -p tmp && cd tmp &&
499 test_when_finished "cd .. && rm -rf tmp" &&
501 for x in hg git; do
503 git init -q gitrepo-$x &&
504 cd gitrepo-$x &&
506 echo alpha > alpha &&
507 git add alpha &&
508 git commit -m "add alpha" &&
509 git checkout -q -b not-master
510 ) &&
513 hg_clone_$x gitrepo-$x hgrepo-$x &&
515 cd hgrepo-$x &&
516 hg co master &&
517 hg tag alpha
518 ) &&
520 hg_push_$x hgrepo-$x gitrepo-$x &&
521 hg_clone_$x gitrepo-$x hgrepo2-$x &&
524 git --git-dir=gitrepo-$x/.git tag -l &&
525 hg_log hgrepo2-$x &&
526 cat hgrepo2-$x/.hgtags
527 ) > output-$x
528 done &&
530 test_cmp output-hg output-git
533 test_done