gitweb (SyntaxHighlighter): interpret #l<line-number>
[git/mingw/4msysgit.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob6dcd95d10f618ee3ac4920f5f2ae684c0b8d4d36
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
14 then
15 skip_all='skipping remote-hg tests; python not available'
16 test_done
19 if ! python -c 'import mercurial'
20 then
21 skip_all='skipping remote-hg tests; mercurial not available'
22 test_done
25 if ! python -c 'import hggit'
26 then
27 skip_all='skipping remote-hg tests; hg-git not available'
28 test_done
31 # clone to a git repo with git
32 git_clone_git () {
33 git clone -q "hg::$1" $2 &&
34 (cd $2 && git checkout master && git branch -D default)
37 # clone to an hg repo with git
38 hg_clone_git () {
40 hg init $2 &&
41 hg -R $2 bookmark -i master &&
42 cd $1 &&
43 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
44 ) &&
46 (cd $2 && hg -q update)
49 # clone to a git repo with hg
50 git_clone_hg () {
52 git init -q $2 &&
53 cd $1 &&
54 hg bookmark -i -f -r tip master &&
55 hg -q push -r master ../$2 || true
59 # clone to an hg repo with hg
60 hg_clone_hg () {
61 hg -q clone $1 $2
64 # push an hg repo with git
65 hg_push_git () {
67 cd $2
68 git checkout -q -b tmp &&
69 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
70 git branch -D default &&
71 git checkout -q @{-1} &&
72 git branch -q -D tmp 2>/dev/null || true
76 # push an hg git repo with hg
77 hg_push_hg () {
79 cd $1 &&
80 hg -q push ../$2 || true
84 hg_log () {
85 hg -R $1 log --graph --debug >log &&
86 grep -v 'tag: *default/' log
89 git_log () {
90 git --git-dir=$1/.git fast-export --branches
93 setup () {
95 echo "[ui]"
96 echo "username = A U Thor <author@example.com>"
97 echo "[defaults]"
98 echo "backout = -d \"0 0\""
99 echo "commit = -d \"0 0\""
100 echo "debugrawcommit = -d \"0 0\""
101 echo "tag = -d \"0 0\""
102 echo "[extensions]"
103 echo "hgext.bookmarks ="
104 echo "hggit ="
105 echo "graphlog ="
106 ) >>"$HOME"/.hgrc &&
107 git config --global receive.denycurrentbranch warn
108 git config --global remote-hg.hg-git-compat true
109 git config --global remote-hg.track-branches false
111 HGEDITOR=true
112 HGMERGE=true
114 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
115 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
116 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
119 setup
121 test_expect_success 'executable bit' '
122 test_when_finished "rm -rf gitrepo* hgrepo*" &&
125 git init -q gitrepo &&
126 cd gitrepo &&
127 echo alpha >alpha &&
128 chmod 0644 alpha &&
129 git add alpha &&
130 git commit -m "add alpha" &&
131 chmod 0755 alpha &&
132 git add alpha &&
133 git commit -m "set executable bit" &&
134 chmod 0644 alpha &&
135 git add alpha &&
136 git commit -m "clear executable bit"
137 ) &&
139 for x in hg git
142 hg_clone_$x gitrepo hgrepo-$x &&
143 cd hgrepo-$x &&
144 hg_log . &&
145 hg manifest -r 1 -v &&
146 hg manifest -v
147 ) >"output-$x" &&
149 git_clone_$x hgrepo-$x gitrepo2-$x &&
150 git_log gitrepo2-$x >"log-$x"
151 done &&
153 test_cmp output-hg output-git &&
154 test_cmp log-hg log-git
157 test_expect_success 'symlink' '
158 test_when_finished "rm -rf gitrepo* hgrepo*" &&
161 git init -q gitrepo &&
162 cd gitrepo &&
163 echo alpha >alpha &&
164 git add alpha &&
165 git commit -m "add alpha" &&
166 ln -s alpha beta &&
167 git add beta &&
168 git commit -m "add beta"
169 ) &&
171 for x in hg git
174 hg_clone_$x gitrepo hgrepo-$x &&
175 cd hgrepo-$x &&
176 hg_log . &&
177 hg manifest -v
178 ) >"output-$x" &&
180 git_clone_$x hgrepo-$x gitrepo2-$x &&
181 git_log gitrepo2-$x >"log-$x"
182 done &&
184 test_cmp output-hg output-git &&
185 test_cmp log-hg log-git
188 test_expect_success 'merge conflict 1' '
189 test_when_finished "rm -rf gitrepo* hgrepo*" &&
192 hg init hgrepo1 &&
193 cd hgrepo1 &&
194 echo A >afile &&
195 hg add afile &&
196 hg ci -m "origin" &&
198 echo B >afile &&
199 hg ci -m "A->B" &&
201 hg up -r0 &&
202 echo C >afile &&
203 hg ci -m "A->C" &&
205 hg merge -r1 &&
206 echo C >afile &&
207 hg resolve -m afile &&
208 hg ci -m "merge to C"
209 ) &&
211 for x in hg git
213 git_clone_$x hgrepo1 gitrepo-$x &&
214 hg_clone_$x gitrepo-$x hgrepo2-$x &&
215 hg_log hgrepo2-$x >"hg-log-$x" &&
216 git_log gitrepo-$x >"git-log-$x"
217 done &&
219 test_cmp hg-log-hg hg-log-git &&
220 test_cmp git-log-hg git-log-git
223 test_expect_success 'merge conflict 2' '
224 test_when_finished "rm -rf gitrepo* hgrepo*" &&
227 hg init hgrepo1 &&
228 cd hgrepo1 &&
229 echo A >afile &&
230 hg add afile &&
231 hg ci -m "origin" &&
233 echo B >afile &&
234 hg ci -m "A->B" &&
236 hg up -r0 &&
237 echo C >afile &&
238 hg ci -m "A->C" &&
240 hg merge -r1 || true &&
241 echo B >afile &&
242 hg resolve -m afile &&
243 hg ci -m "merge to B"
244 ) &&
246 for x in hg git
248 git_clone_$x hgrepo1 gitrepo-$x &&
249 hg_clone_$x gitrepo-$x hgrepo2-$x &&
250 hg_log hgrepo2-$x >"hg-log-$x" &&
251 git_log gitrepo-$x >"git-log-$x"
252 done &&
254 test_cmp hg-log-hg hg-log-git &&
255 test_cmp git-log-hg git-log-git
258 test_expect_success 'converged merge' '
259 test_when_finished "rm -rf gitrepo* hgrepo*" &&
262 hg init hgrepo1 &&
263 cd hgrepo1 &&
264 echo A >afile &&
265 hg add afile &&
266 hg ci -m "origin" &&
268 echo B >afile &&
269 hg ci -m "A->B" &&
271 echo C >afile &&
272 hg ci -m "B->C" &&
274 hg up -r0 &&
275 echo C >afile &&
276 hg ci -m "A->C" &&
278 hg merge -r2 || true &&
279 hg ci -m "merge"
280 ) &&
282 for x in hg git
284 git_clone_$x hgrepo1 gitrepo-$x &&
285 hg_clone_$x gitrepo-$x hgrepo2-$x &&
286 hg_log hgrepo2-$x >"hg-log-$x" &&
287 git_log gitrepo-$x >"git-log-$x"
288 done &&
290 test_cmp hg-log-hg hg-log-git &&
291 test_cmp git-log-hg git-log-git
294 test_expect_success 'encoding' '
295 test_when_finished "rm -rf gitrepo* hgrepo*" &&
298 git init -q gitrepo &&
299 cd gitrepo &&
301 echo alpha >alpha &&
302 git add alpha &&
303 git commit -m "add älphà" &&
305 GIT_AUTHOR_NAME="tést èncödîng" &&
306 export GIT_AUTHOR_NAME &&
307 echo beta >beta &&
308 git add beta &&
309 git commit -m "add beta" &&
311 echo gamma >gamma &&
312 git add gamma &&
313 git commit -m "add gämmâ" &&
315 : TODO git config i18n.commitencoding latin-1 &&
316 echo delta >delta &&
317 git add delta &&
318 git commit -m "add déltà"
319 ) &&
321 for x in hg git
323 hg_clone_$x gitrepo hgrepo-$x &&
324 git_clone_$x hgrepo-$x gitrepo2-$x &&
326 HGENCODING=utf-8 hg_log hgrepo-$x >"hg-log-$x" &&
327 git_log gitrepo2-$x >"git-log-$x"
328 done &&
330 test_cmp hg-log-hg hg-log-git &&
331 test_cmp git-log-hg git-log-git
334 test_expect_success 'file removal' '
335 test_when_finished "rm -rf gitrepo* hgrepo*" &&
338 git init -q gitrepo &&
339 cd gitrepo &&
340 echo alpha >alpha &&
341 git add alpha &&
342 git commit -m "add alpha" &&
343 echo beta >beta &&
344 git add beta &&
345 git commit -m "add beta"
346 mkdir foo &&
347 echo blah >foo/bar &&
348 git add foo &&
349 git commit -m "add foo" &&
350 git rm alpha &&
351 git commit -m "remove alpha" &&
352 git rm foo/bar &&
353 git commit -m "remove foo/bar"
354 ) &&
356 for x in hg git
359 hg_clone_$x gitrepo hgrepo-$x &&
360 cd hgrepo-$x &&
361 hg_log . &&
362 hg manifest -r 3 &&
363 hg manifest
364 ) >"output-$x" &&
366 git_clone_$x hgrepo-$x gitrepo2-$x &&
367 git_log gitrepo2-$x >"log-$x"
368 done &&
370 test_cmp output-hg output-git &&
371 test_cmp log-hg log-git
374 test_expect_success 'git tags' '
375 test_when_finished "rm -rf gitrepo* hgrepo*" &&
378 git init -q gitrepo &&
379 cd gitrepo &&
380 git config receive.denyCurrentBranch ignore &&
381 echo alpha >alpha &&
382 git add alpha &&
383 git commit -m "add alpha" &&
384 git tag alpha &&
386 echo beta >beta &&
387 git add beta &&
388 git commit -m "add beta" &&
389 git tag -a -m "added tag beta" beta
390 ) &&
392 for x in hg git
394 hg_clone_$x gitrepo hgrepo-$x &&
395 hg_log hgrepo-$x >"log-$x"
396 done &&
398 test_cmp log-hg log-git
401 test_expect_success 'hg author' '
402 test_when_finished "rm -rf gitrepo* hgrepo*" &&
404 for x in hg git
407 git init -q gitrepo-$x &&
408 cd gitrepo-$x &&
410 echo alpha >alpha &&
411 git add alpha &&
412 git commit -m "add alpha" &&
413 git checkout -q -b not-master
414 ) &&
417 hg_clone_$x gitrepo-$x hgrepo-$x &&
418 cd hgrepo-$x &&
420 hg co master &&
421 echo beta >beta &&
422 hg add beta &&
423 hg commit -u "test" -m "add beta" &&
425 echo gamma >>beta &&
426 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
428 echo gamma >gamma &&
429 hg add gamma &&
430 hg commit -u "<test@example.com>" -m "add gamma" &&
432 echo delta >delta &&
433 hg add delta &&
434 hg commit -u "name<test@example.com>" -m "add delta" &&
436 echo epsilon >epsilon &&
437 hg add epsilon &&
438 hg commit -u "name <test@example.com" -m "add epsilon" &&
440 echo zeta >zeta &&
441 hg add zeta &&
442 hg commit -u " test " -m "add zeta" &&
444 echo eta >eta &&
445 hg add eta &&
446 hg commit -u "test < test@example.com >" -m "add eta" &&
448 echo theta >theta &&
449 hg add theta &&
450 hg commit -u "test >test@example.com>" -m "add theta" &&
452 echo iota >iota &&
453 hg add iota &&
454 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
455 ) &&
457 hg_push_$x hgrepo-$x gitrepo-$x &&
458 hg_clone_$x gitrepo-$x hgrepo2-$x &&
460 hg_log hgrepo2-$x >"hg-log-$x" &&
461 git_log gitrepo-$x >"git-log-$x"
462 done &&
464 test_cmp hg-log-hg hg-log-git &&
465 test_cmp git-log-hg git-log-git
468 test_expect_success 'hg branch' '
469 test_when_finished "rm -rf gitrepo* hgrepo*" &&
471 for x in hg git
474 git init -q gitrepo-$x &&
475 cd gitrepo-$x &&
477 echo alpha >alpha &&
478 git add alpha &&
479 git commit -q -m "add alpha" &&
480 git checkout -q -b not-master
481 ) &&
484 hg_clone_$x gitrepo-$x hgrepo-$x &&
486 cd hgrepo-$x &&
487 hg -q co master &&
488 hg mv alpha beta &&
489 hg -q commit -m "rename alpha to beta" &&
490 hg branch gamma | grep -v "permanent and global" &&
491 hg -q commit -m "started branch gamma"
492 ) &&
494 hg_push_$x hgrepo-$x gitrepo-$x &&
495 hg_clone_$x gitrepo-$x hgrepo2-$x &&
497 hg_log hgrepo2-$x >"hg-log-$x" &&
498 git_log gitrepo-$x >"git-log-$x"
499 done &&
501 test_cmp hg-log-hg hg-log-git &&
502 test_cmp git-log-hg git-log-git
505 test_expect_success 'hg tags' '
506 test_when_finished "rm -rf gitrepo* hgrepo*" &&
508 for x in hg git
511 git init -q gitrepo-$x &&
512 cd gitrepo-$x &&
514 echo alpha >alpha &&
515 git add alpha &&
516 git commit -m "add alpha" &&
517 git checkout -q -b not-master
518 ) &&
521 hg_clone_$x gitrepo-$x hgrepo-$x &&
523 cd hgrepo-$x &&
524 hg co master &&
525 hg tag alpha
526 ) &&
528 hg_push_$x hgrepo-$x gitrepo-$x &&
529 hg_clone_$x gitrepo-$x hgrepo2-$x &&
532 git --git-dir=gitrepo-$x/.git tag -l &&
533 hg_log hgrepo2-$x &&
534 cat hgrepo2-$x/.hgtags
535 ) >"output-$x"
536 done &&
538 test_cmp output-hg output-git
541 test_done