Update draft release notes
[git/mingw.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob2219284382f0e987423ae00e5bd89e9b7a4b0046
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::$1" $2 &&
31 (cd $2 && git checkout master && git branch -D default)
34 # clone to an hg repo with git
35 hg_clone_git () {
37 hg init $2 &&
38 hg -R $2 bookmark -i master &&
39 cd $1 &&
40 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
41 ) &&
43 (cd $2 && hg -q update)
46 # clone to a git repo with hg
47 git_clone_hg () {
49 git init -q $2 &&
50 cd $1 &&
51 hg bookmark -i -f -r tip master &&
52 hg -q push -r master ../$2 || true
56 # clone to an hg repo with hg
57 hg_clone_hg () {
58 hg -q clone $1 $2
61 # push an hg repo with git
62 hg_push_git () {
64 cd $2
65 git checkout -q -b tmp &&
66 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
67 git branch -D default &&
68 git checkout -q @{-1} &&
69 git branch -q -D tmp 2> /dev/null || true
73 # push an hg git repo with hg
74 hg_push_hg () {
76 cd $1 &&
77 hg -q push ../$2 || true
81 hg_log () {
82 hg -R $1 log --graph --debug >log &&
83 grep -v 'tag: *default/' log
86 git_log () {
87 git --git-dir=$1/.git fast-export --branches
90 setup () {
92 echo "[ui]"
93 echo "username = A U Thor <author@example.com>"
94 echo "[defaults]"
95 echo "backout = -d \"0 0\""
96 echo "commit = -d \"0 0\""
97 echo "debugrawcommit = -d \"0 0\""
98 echo "tag = -d \"0 0\""
99 echo "[extensions]"
100 echo "hgext.bookmarks ="
101 echo "hggit ="
102 echo "graphlog ="
103 ) >> "$HOME"/.hgrc &&
104 git config --global receive.denycurrentbranch warn
105 git config --global remote-hg.hg-git-compat true
106 git config --global remote-hg.track-branches false
108 HGEDITOR=true
109 HGMERGE=true
111 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
112 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
113 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
116 setup
118 test_expect_success 'executable bit' '
119 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 test_when_finished "rm -rf gitrepo* hgrepo*" &&
157 git init -q gitrepo &&
158 cd gitrepo &&
159 echo alpha > alpha &&
160 git add alpha &&
161 git commit -m "add alpha" &&
162 ln -s alpha beta &&
163 git add beta &&
164 git commit -m "add beta"
165 ) &&
167 for x in hg git; do
169 hg_clone_$x gitrepo hgrepo-$x &&
170 cd hgrepo-$x &&
171 hg_log . &&
172 hg manifest -v
173 ) > output-$x &&
175 git_clone_$x hgrepo-$x gitrepo2-$x &&
176 git_log gitrepo2-$x > log-$x
177 done &&
179 test_cmp output-hg output-git &&
180 test_cmp log-hg log-git
183 test_expect_success 'merge conflict 1' '
184 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 hg up -r0 &&
197 echo C > afile &&
198 hg ci -m "A->C" &&
200 hg merge -r1 &&
201 echo C > afile &&
202 hg resolve -m afile &&
203 hg ci -m "merge to C"
204 ) &&
206 for x in hg git; do
207 git_clone_$x hgrepo1 gitrepo-$x &&
208 hg_clone_$x gitrepo-$x hgrepo2-$x &&
209 hg_log hgrepo2-$x > hg-log-$x &&
210 git_log gitrepo-$x > git-log-$x
211 done &&
213 test_cmp hg-log-hg hg-log-git &&
214 test_cmp git-log-hg git-log-git
217 test_expect_success 'merge conflict 2' '
218 test_when_finished "rm -rf gitrepo* hgrepo*" &&
221 hg init hgrepo1 &&
222 cd hgrepo1 &&
223 echo A > afile &&
224 hg add afile &&
225 hg ci -m "origin" &&
227 echo B > afile &&
228 hg ci -m "A->B" &&
230 hg up -r0 &&
231 echo C > afile &&
232 hg ci -m "A->C" &&
234 hg merge -r1 || true &&
235 echo B > afile &&
236 hg resolve -m afile &&
237 hg ci -m "merge to B"
238 ) &&
240 for x in hg git; do
241 git_clone_$x hgrepo1 gitrepo-$x &&
242 hg_clone_$x gitrepo-$x hgrepo2-$x &&
243 hg_log hgrepo2-$x > hg-log-$x &&
244 git_log gitrepo-$x > git-log-$x
245 done &&
247 test_cmp hg-log-hg hg-log-git &&
248 test_cmp git-log-hg git-log-git
251 test_expect_success 'converged merge' '
252 test_when_finished "rm -rf gitrepo* hgrepo*" &&
255 hg init hgrepo1 &&
256 cd hgrepo1 &&
257 echo A > afile &&
258 hg add afile &&
259 hg ci -m "origin" &&
261 echo B > afile &&
262 hg ci -m "A->B" &&
264 echo C > afile &&
265 hg ci -m "B->C" &&
267 hg up -r0 &&
268 echo C > afile &&
269 hg ci -m "A->C" &&
271 hg merge -r2 || true &&
272 hg ci -m "merge"
273 ) &&
275 for x in hg git; do
276 git_clone_$x hgrepo1 gitrepo-$x &&
277 hg_clone_$x gitrepo-$x hgrepo2-$x &&
278 hg_log hgrepo2-$x > hg-log-$x &&
279 git_log gitrepo-$x > git-log-$x
280 done &&
282 test_cmp hg-log-hg hg-log-git &&
283 test_cmp git-log-hg git-log-git
286 test_expect_success 'encoding' '
287 test_when_finished "rm -rf gitrepo* hgrepo*" &&
290 git init -q gitrepo &&
291 cd gitrepo &&
293 echo alpha > alpha &&
294 git add alpha &&
295 git commit -m "add älphà" &&
297 GIT_AUTHOR_NAME="tést èncödîng" &&
298 export GIT_AUTHOR_NAME &&
299 echo beta > beta &&
300 git add beta &&
301 git commit -m "add beta" &&
303 echo gamma > gamma &&
304 git add gamma &&
305 git commit -m "add gämmâ" &&
307 : TODO git config i18n.commitencoding latin-1 &&
308 echo delta > delta &&
309 git add delta &&
310 git commit -m "add déltà"
311 ) &&
313 for x in hg git; do
314 hg_clone_$x gitrepo hgrepo-$x &&
315 git_clone_$x hgrepo-$x gitrepo2-$x &&
317 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
318 git_log gitrepo2-$x > git-log-$x
319 done &&
321 test_cmp hg-log-hg hg-log-git &&
322 test_cmp git-log-hg git-log-git
325 test_expect_success 'file removal' '
326 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 test_when_finished "rm -rf gitrepo* hgrepo*" &&
368 git init -q gitrepo &&
369 cd gitrepo &&
370 git config receive.denyCurrentBranch ignore &&
371 echo alpha > alpha &&
372 git add alpha &&
373 git commit -m "add alpha" &&
374 git tag alpha &&
376 echo beta > beta &&
377 git add beta &&
378 git commit -m "add beta" &&
379 git tag -a -m "added tag beta" beta
380 ) &&
382 for x in hg git; do
383 hg_clone_$x gitrepo hgrepo-$x &&
384 hg_log hgrepo-$x > log-$x
385 done &&
387 test_cmp log-hg log-git
390 test_expect_success 'hg author' '
391 test_when_finished "rm -rf gitrepo* hgrepo*" &&
393 for x in hg git; do
395 git init -q gitrepo-$x &&
396 cd gitrepo-$x &&
398 echo alpha > alpha &&
399 git add alpha &&
400 git commit -m "add alpha" &&
401 git checkout -q -b not-master
402 ) &&
405 hg_clone_$x gitrepo-$x hgrepo-$x &&
406 cd hgrepo-$x &&
408 hg co master &&
409 echo beta > beta &&
410 hg add beta &&
411 hg commit -u "test" -m "add beta" &&
413 echo gamma >> beta &&
414 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
416 echo gamma > gamma &&
417 hg add gamma &&
418 hg commit -u "<test@example.com>" -m "add gamma" &&
420 echo delta > delta &&
421 hg add delta &&
422 hg commit -u "name<test@example.com>" -m "add delta" &&
424 echo epsilon > epsilon &&
425 hg add epsilon &&
426 hg commit -u "name <test@example.com" -m "add epsilon" &&
428 echo zeta > zeta &&
429 hg add zeta &&
430 hg commit -u " test " -m "add zeta" &&
432 echo eta > eta &&
433 hg add eta &&
434 hg commit -u "test < test@example.com >" -m "add eta" &&
436 echo theta > theta &&
437 hg add theta &&
438 hg commit -u "test >test@example.com>" -m "add theta" &&
440 echo iota > iota &&
441 hg add iota &&
442 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
443 ) &&
445 hg_push_$x hgrepo-$x gitrepo-$x &&
446 hg_clone_$x gitrepo-$x hgrepo2-$x &&
448 hg_log hgrepo2-$x > hg-log-$x &&
449 git_log gitrepo-$x > git-log-$x
450 done &&
452 test_cmp hg-log-hg hg-log-git &&
453 test_cmp git-log-hg git-log-git
456 test_expect_success 'hg branch' '
457 test_when_finished "rm -rf gitrepo* hgrepo*" &&
459 for x in hg git; do
461 git init -q gitrepo-$x &&
462 cd gitrepo-$x &&
464 echo alpha > alpha &&
465 git add alpha &&
466 git commit -q -m "add alpha" &&
467 git checkout -q -b not-master
468 ) &&
471 hg_clone_$x gitrepo-$x hgrepo-$x &&
473 cd hgrepo-$x &&
474 hg -q co master &&
475 hg mv alpha beta &&
476 hg -q commit -m "rename alpha to beta" &&
477 hg branch gamma | grep -v "permanent and global" &&
478 hg -q commit -m "started branch gamma"
479 ) &&
481 hg_push_$x hgrepo-$x gitrepo-$x &&
482 hg_clone_$x gitrepo-$x hgrepo2-$x &&
484 hg_log hgrepo2-$x > hg-log-$x &&
485 git_log gitrepo-$x > git-log-$x
486 done &&
488 test_cmp hg-log-hg hg-log-git &&
489 test_cmp git-log-hg git-log-git
492 test_expect_success 'hg tags' '
493 test_when_finished "rm -rf gitrepo* hgrepo*" &&
495 for x in hg git; do
497 git init -q gitrepo-$x &&
498 cd gitrepo-$x &&
500 echo alpha > alpha &&
501 git add alpha &&
502 git commit -m "add alpha" &&
503 git checkout -q -b not-master
504 ) &&
507 hg_clone_$x gitrepo-$x hgrepo-$x &&
509 cd hgrepo-$x &&
510 hg co master &&
511 hg tag alpha
512 ) &&
514 hg_push_$x hgrepo-$x gitrepo-$x &&
515 hg_clone_$x gitrepo-$x hgrepo2-$x &&
518 git --git-dir=gitrepo-$x/.git tag -l &&
519 hg_log hgrepo2-$x &&
520 cat hgrepo2-$x/.hgtags
521 ) > output-$x
522 done &&
524 test_cmp output-hg output-git
527 test_done