remote-hg: test: simplify previous branch checkout
[git/mingw.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob37e59d8fe8a755fdd858f369ad8661a3b498f356
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
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::../$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 git checkout -q -b tmp &&
65 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
66 git checkout -q @{-1} &&
67 git branch -q -D tmp 2> /dev/null || true
71 # push an hg git repo with hg
72 hg_push_hg () {
74 cd $1 &&
75 hg -q push ../$2 || true
79 hg_log () {
80 hg -R $1 log --graph --debug >log &&
81 grep -v 'tag: *default/' log
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 echo "graphlog ="
101 ) >> "$HOME"/.hgrc &&
102 git config --global receive.denycurrentbranch warn
103 git config --global remote-hg.hg-git-compat true
104 git config --global remote-hg.track-branches false
106 HGEDITOR=true
107 HGMERGE=true
109 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
110 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
111 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
114 setup
116 test_expect_success 'executable bit' '
117 test_when_finished "rm -rf gitrepo* hgrepo*" &&
120 git init -q gitrepo &&
121 cd gitrepo &&
122 echo alpha > alpha &&
123 chmod 0644 alpha &&
124 git add alpha &&
125 git commit -m "add alpha" &&
126 chmod 0755 alpha &&
127 git add alpha &&
128 git commit -m "set executable bit" &&
129 chmod 0644 alpha &&
130 git add alpha &&
131 git commit -m "clear executable bit"
132 ) &&
134 for x in hg git; do
136 hg_clone_$x gitrepo hgrepo-$x &&
137 cd hgrepo-$x &&
138 hg_log . &&
139 hg manifest -r 1 -v &&
140 hg manifest -v
141 ) > output-$x &&
143 git_clone_$x hgrepo-$x gitrepo2-$x &&
144 git_log gitrepo2-$x > log-$x
145 done &&
147 test_cmp output-hg output-git &&
148 test_cmp log-hg log-git
151 test_expect_success 'symlink' '
152 test_when_finished "rm -rf gitrepo* hgrepo*" &&
155 git init -q gitrepo &&
156 cd gitrepo &&
157 echo alpha > alpha &&
158 git add alpha &&
159 git commit -m "add alpha" &&
160 ln -s alpha beta &&
161 git add beta &&
162 git commit -m "add beta"
163 ) &&
165 for x in hg git; do
167 hg_clone_$x gitrepo hgrepo-$x &&
168 cd hgrepo-$x &&
169 hg_log . &&
170 hg manifest -v
171 ) > output-$x &&
173 git_clone_$x hgrepo-$x gitrepo2-$x &&
174 git_log gitrepo2-$x > log-$x
175 done &&
177 test_cmp output-hg output-git &&
178 test_cmp log-hg log-git
181 test_expect_success 'merge conflict 1' '
182 test_when_finished "rm -rf gitrepo* hgrepo*" &&
185 hg init hgrepo1 &&
186 cd hgrepo1 &&
187 echo A > afile &&
188 hg add afile &&
189 hg ci -m "origin" &&
191 echo B > afile &&
192 hg ci -m "A->B" &&
194 hg up -r0 &&
195 echo C > afile &&
196 hg ci -m "A->C" &&
198 hg merge -r1 &&
199 echo C > afile &&
200 hg resolve -m afile &&
201 hg ci -m "merge to C"
202 ) &&
204 for x in hg git; do
205 git_clone_$x hgrepo1 gitrepo-$x &&
206 hg_clone_$x gitrepo-$x hgrepo2-$x &&
207 hg_log hgrepo2-$x > hg-log-$x &&
208 git_log gitrepo-$x > git-log-$x
209 done &&
211 test_cmp hg-log-hg hg-log-git &&
212 test_cmp git-log-hg git-log-git
215 test_expect_success 'merge conflict 2' '
216 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 test_when_finished "rm -rf gitrepo* hgrepo*" &&
253 hg init hgrepo1 &&
254 cd hgrepo1 &&
255 echo A > afile &&
256 hg add afile &&
257 hg ci -m "origin" &&
259 echo B > afile &&
260 hg ci -m "A->B" &&
262 echo C > afile &&
263 hg ci -m "B->C" &&
265 hg up -r0 &&
266 echo C > afile &&
267 hg ci -m "A->C" &&
269 hg merge -r2 || true &&
270 hg ci -m "merge"
271 ) &&
273 for x in hg git; do
274 git_clone_$x hgrepo1 gitrepo-$x &&
275 hg_clone_$x gitrepo-$x hgrepo2-$x &&
276 hg_log hgrepo2-$x > hg-log-$x &&
277 git_log gitrepo-$x > git-log-$x
278 done &&
280 test_cmp hg-log-hg hg-log-git &&
281 test_cmp git-log-hg git-log-git
284 test_expect_success 'encoding' '
285 test_when_finished "rm -rf gitrepo* hgrepo*" &&
288 git init -q gitrepo &&
289 cd gitrepo &&
291 echo alpha > alpha &&
292 git add alpha &&
293 git commit -m "add älphà" &&
295 GIT_AUTHOR_NAME="tést èncödîng" &&
296 export GIT_AUTHOR_NAME &&
297 echo beta > beta &&
298 git add beta &&
299 git commit -m "add beta" &&
301 echo gamma > gamma &&
302 git add gamma &&
303 git commit -m "add gämmâ" &&
305 : TODO git config i18n.commitencoding latin-1 &&
306 echo delta > delta &&
307 git add delta &&
308 git commit -m "add déltà"
309 ) &&
311 for x in hg git; do
312 hg_clone_$x gitrepo hgrepo-$x &&
313 git_clone_$x hgrepo-$x gitrepo2-$x &&
315 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
316 git_log gitrepo2-$x > git-log-$x
317 done &&
319 test_cmp hg-log-hg hg-log-git &&
320 test_cmp git-log-hg git-log-git
323 test_expect_success 'file removal' '
324 test_when_finished "rm -rf gitrepo* hgrepo*" &&
327 git init -q gitrepo &&
328 cd gitrepo &&
329 echo alpha > alpha &&
330 git add alpha &&
331 git commit -m "add alpha" &&
332 echo beta > beta &&
333 git add beta &&
334 git commit -m "add beta"
335 mkdir foo &&
336 echo blah > foo/bar &&
337 git add foo &&
338 git commit -m "add foo" &&
339 git rm alpha &&
340 git commit -m "remove alpha" &&
341 git rm foo/bar &&
342 git commit -m "remove foo/bar"
343 ) &&
345 for x in hg git; do
347 hg_clone_$x gitrepo hgrepo-$x &&
348 cd hgrepo-$x &&
349 hg_log . &&
350 hg manifest -r 3 &&
351 hg manifest
352 ) > output-$x &&
354 git_clone_$x hgrepo-$x gitrepo2-$x &&
355 git_log gitrepo2-$x > log-$x
356 done &&
358 test_cmp output-hg output-git &&
359 test_cmp log-hg log-git
362 test_expect_success 'git tags' '
363 test_when_finished "rm -rf gitrepo* hgrepo*" &&
366 git init -q gitrepo &&
367 cd gitrepo &&
368 git config receive.denyCurrentBranch ignore &&
369 echo alpha > alpha &&
370 git add alpha &&
371 git commit -m "add alpha" &&
372 git tag alpha &&
374 echo beta > beta &&
375 git add beta &&
376 git commit -m "add beta" &&
377 git tag -a -m "added tag beta" beta
378 ) &&
380 for x in hg git; do
381 hg_clone_$x gitrepo hgrepo-$x &&
382 hg_log hgrepo-$x > log-$x
383 done &&
385 test_cmp log-hg log-git
388 test_expect_success 'hg author' '
389 test_when_finished "rm -rf gitrepo* hgrepo*" &&
391 for x in hg git; do
393 git init -q gitrepo-$x &&
394 cd gitrepo-$x &&
396 echo alpha > alpha &&
397 git add alpha &&
398 git commit -m "add alpha" &&
399 git checkout -q -b not-master
400 ) &&
403 hg_clone_$x gitrepo-$x hgrepo-$x &&
404 cd hgrepo-$x &&
406 hg co master &&
407 echo beta > beta &&
408 hg add beta &&
409 hg commit -u "test" -m "add beta" &&
411 echo gamma >> beta &&
412 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
414 echo gamma > gamma &&
415 hg add gamma &&
416 hg commit -u "<test@example.com>" -m "add gamma" &&
418 echo delta > delta &&
419 hg add delta &&
420 hg commit -u "name<test@example.com>" -m "add delta" &&
422 echo epsilon > epsilon &&
423 hg add epsilon &&
424 hg commit -u "name <test@example.com" -m "add epsilon" &&
426 echo zeta > zeta &&
427 hg add zeta &&
428 hg commit -u " test " -m "add zeta" &&
430 echo eta > eta &&
431 hg add eta &&
432 hg commit -u "test < test@example.com >" -m "add eta" &&
434 echo theta > theta &&
435 hg add theta &&
436 hg commit -u "test >test@example.com>" -m "add theta" &&
438 echo iota > iota &&
439 hg add iota &&
440 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
441 ) &&
443 hg_push_$x hgrepo-$x gitrepo-$x &&
444 hg_clone_$x gitrepo-$x hgrepo2-$x &&
446 hg_log hgrepo2-$x > hg-log-$x &&
447 git_log gitrepo-$x > git-log-$x
448 done &&
450 test_cmp hg-log-hg hg-log-git &&
451 test_cmp git-log-hg git-log-git
454 test_expect_success 'hg branch' '
455 test_when_finished "rm -rf gitrepo* hgrepo*" &&
457 for x in hg git; do
459 git init -q gitrepo-$x &&
460 cd gitrepo-$x &&
462 echo alpha > alpha &&
463 git add alpha &&
464 git commit -q -m "add alpha" &&
465 git checkout -q -b not-master
466 ) &&
469 hg_clone_$x gitrepo-$x hgrepo-$x &&
471 cd hgrepo-$x &&
472 hg -q co master &&
473 hg mv alpha beta &&
474 hg -q commit -m "rename alpha to beta" &&
475 hg branch gamma | grep -v "permanent and global" &&
476 hg -q commit -m "started branch gamma"
477 ) &&
479 hg_push_$x hgrepo-$x gitrepo-$x &&
480 hg_clone_$x gitrepo-$x hgrepo2-$x &&
482 hg_log hgrepo2-$x > hg-log-$x &&
483 git_log gitrepo-$x > git-log-$x
484 done &&
486 test_cmp hg-log-hg hg-log-git &&
487 test_cmp git-log-hg git-log-git
490 test_expect_success 'hg tags' '
491 test_when_finished "rm -rf gitrepo* hgrepo*" &&
493 for x in hg git; do
495 git init -q gitrepo-$x &&
496 cd gitrepo-$x &&
498 echo alpha > alpha &&
499 git add alpha &&
500 git commit -m "add alpha" &&
501 git checkout -q -b not-master
502 ) &&
505 hg_clone_$x gitrepo-$x hgrepo-$x &&
507 cd hgrepo-$x &&
508 hg co master &&
509 hg tag alpha
510 ) &&
512 hg_push_$x hgrepo-$x gitrepo-$x &&
513 hg_clone_$x gitrepo-$x hgrepo2-$x &&
516 git --git-dir=gitrepo-$x/.git tag -l &&
517 hg_log hgrepo2-$x &&
518 cat hgrepo2-$x/.hgtags
519 ) > output-$x
520 done &&
522 test_cmp output-hg output-git
525 test_done