Documentation/git-log.txt: capitalize section names
[git.git] / contrib / remote-helpers / test-hg-hg-git.sh
blob7f579c843680897ce065bca92fe60fd29aff23b2
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 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=/usr/bin/true
109 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
110 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
111 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
114 setup
116 test_expect_success 'executable bit' '
117 mkdir -p tmp && cd tmp &&
118 test_when_finished "cd .. && rm -rf tmp" &&
121 git init -q gitrepo &&
122 cd gitrepo &&
123 echo alpha > alpha &&
124 chmod 0644 alpha &&
125 git add alpha &&
126 git commit -m "add alpha" &&
127 chmod 0755 alpha &&
128 git add alpha &&
129 git commit -m "set executable bit" &&
130 chmod 0644 alpha &&
131 git add alpha &&
132 git commit -m "clear executable bit"
133 ) &&
135 for x in hg git; do
137 hg_clone_$x gitrepo hgrepo-$x &&
138 cd hgrepo-$x &&
139 hg_log . &&
140 hg manifest -r 1 -v &&
141 hg manifest -v
142 ) > output-$x &&
144 git_clone_$x hgrepo-$x gitrepo2-$x &&
145 git_log gitrepo2-$x > log-$x
146 done &&
148 test_cmp output-hg output-git &&
149 test_cmp log-hg log-git
152 test_expect_success 'symlink' '
153 mkdir -p tmp && cd tmp &&
154 test_when_finished "cd .. && rm -rf tmp" &&
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 mkdir -p tmp && cd tmp &&
185 test_when_finished "cd .. && rm -rf tmp" &&
188 hg init hgrepo1 &&
189 cd hgrepo1 &&
190 echo A > afile &&
191 hg add afile &&
192 hg ci -m "origin" &&
194 echo B > afile &&
195 hg ci -m "A->B" &&
197 hg up -r0 &&
198 echo C > afile &&
199 hg ci -m "A->C" &&
201 hg merge -r1 || true &&
202 echo C > afile &&
203 hg resolve -m afile &&
204 hg ci -m "merge to C"
205 ) &&
207 for x in hg git; do
208 git_clone_$x hgrepo1 gitrepo-$x &&
209 hg_clone_$x gitrepo-$x hgrepo2-$x &&
210 hg_log hgrepo2-$x > hg-log-$x &&
211 git_log gitrepo-$x > git-log-$x
212 done &&
214 test_cmp hg-log-hg hg-log-git &&
215 test_cmp git-log-hg git-log-git
218 test_expect_success 'merge conflict 2' '
219 mkdir -p tmp && cd tmp &&
220 test_when_finished "cd .. && rm -rf tmp" &&
223 hg init hgrepo1 &&
224 cd hgrepo1 &&
225 echo A > afile &&
226 hg add afile &&
227 hg ci -m "origin" &&
229 echo B > afile &&
230 hg ci -m "A->B" &&
232 hg up -r0 &&
233 echo C > afile &&
234 hg ci -m "A->C" &&
236 hg merge -r1 || true &&
237 echo B > afile &&
238 hg resolve -m afile &&
239 hg ci -m "merge to B"
240 ) &&
242 for x in hg git; do
243 git_clone_$x hgrepo1 gitrepo-$x &&
244 hg_clone_$x gitrepo-$x hgrepo2-$x &&
245 hg_log hgrepo2-$x > hg-log-$x &&
246 git_log gitrepo-$x > git-log-$x
247 done &&
249 test_cmp hg-log-hg hg-log-git &&
250 test_cmp git-log-hg git-log-git
253 test_expect_success 'converged merge' '
254 mkdir -p tmp && cd tmp &&
255 test_when_finished "cd .. && rm -rf tmp" &&
258 hg init hgrepo1 &&
259 cd hgrepo1 &&
260 echo A > afile &&
261 hg add afile &&
262 hg ci -m "origin" &&
264 echo B > afile &&
265 hg ci -m "A->B" &&
267 echo C > afile &&
268 hg ci -m "B->C" &&
270 hg up -r0 &&
271 echo C > afile &&
272 hg ci -m "A->C" &&
274 hg merge -r2 || true &&
275 hg ci -m "merge"
276 ) &&
278 for x in hg git; do
279 git_clone_$x hgrepo1 gitrepo-$x &&
280 hg_clone_$x gitrepo-$x hgrepo2-$x &&
281 hg_log hgrepo2-$x > hg-log-$x &&
282 git_log gitrepo-$x > git-log-$x
283 done &&
285 test_cmp hg-log-hg hg-log-git &&
286 test_cmp git-log-hg git-log-git
289 test_expect_success 'encoding' '
290 mkdir -p tmp && cd tmp &&
291 test_when_finished "cd .. && rm -rf tmp" &&
294 git init -q gitrepo &&
295 cd gitrepo &&
297 echo alpha > alpha &&
298 git add alpha &&
299 git commit -m "add älphà" &&
301 GIT_AUTHOR_NAME="tést èncödîng" &&
302 export GIT_AUTHOR_NAME &&
303 echo beta > beta &&
304 git add beta &&
305 git commit -m "add beta" &&
307 echo gamma > gamma &&
308 git add gamma &&
309 git commit -m "add gämmâ" &&
311 : TODO git config i18n.commitencoding latin-1 &&
312 echo delta > delta &&
313 git add delta &&
314 git commit -m "add déltà"
315 ) &&
317 for x in hg git; do
318 hg_clone_$x gitrepo hgrepo-$x &&
319 git_clone_$x hgrepo-$x gitrepo2-$x &&
321 HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
322 git_log gitrepo2-$x > git-log-$x
323 done &&
325 test_cmp hg-log-hg hg-log-git &&
326 test_cmp git-log-hg git-log-git
329 test_expect_success 'file removal' '
330 mkdir -p tmp && cd tmp &&
331 test_when_finished "cd .. && rm -rf tmp" &&
334 git init -q gitrepo &&
335 cd gitrepo &&
336 echo alpha > alpha &&
337 git add alpha &&
338 git commit -m "add alpha" &&
339 echo beta > beta &&
340 git add beta &&
341 git commit -m "add beta"
342 mkdir foo &&
343 echo blah > foo/bar &&
344 git add foo &&
345 git commit -m "add foo" &&
346 git rm alpha &&
347 git commit -m "remove alpha" &&
348 git rm foo/bar &&
349 git commit -m "remove foo/bar"
350 ) &&
352 for x in hg git; do
354 hg_clone_$x gitrepo hgrepo-$x &&
355 cd hgrepo-$x &&
356 hg_log . &&
357 hg manifest -r 3 &&
358 hg manifest
359 ) > output-$x &&
361 git_clone_$x hgrepo-$x gitrepo2-$x &&
362 git_log gitrepo2-$x > log-$x
363 done &&
365 test_cmp output-hg output-git &&
366 test_cmp log-hg log-git
369 test_expect_success 'git tags' '
370 mkdir -p tmp && cd tmp &&
371 test_when_finished "cd .. && rm -rf tmp" &&
374 git init -q gitrepo &&
375 cd gitrepo &&
376 git config receive.denyCurrentBranch ignore &&
377 echo alpha > alpha &&
378 git add alpha &&
379 git commit -m "add alpha" &&
380 git tag alpha &&
382 echo beta > beta &&
383 git add beta &&
384 git commit -m "add beta" &&
385 git tag -a -m "added tag beta" beta
386 ) &&
388 for x in hg git; do
389 hg_clone_$x gitrepo hgrepo-$x &&
390 hg_log hgrepo-$x > log-$x
391 done &&
393 test_cmp log-hg log-git
396 test_expect_success 'hg author' '
397 mkdir -p tmp && cd tmp &&
398 test_when_finished "cd .. && rm -rf tmp" &&
400 for x in hg git; do
402 git init -q gitrepo-$x &&
403 cd gitrepo-$x &&
405 echo alpha > alpha &&
406 git add alpha &&
407 git commit -m "add alpha" &&
408 git checkout -q -b not-master
409 ) &&
412 hg_clone_$x gitrepo-$x hgrepo-$x &&
413 cd hgrepo-$x &&
415 hg co master &&
416 echo beta > beta &&
417 hg add beta &&
418 hg commit -u "test" -m "add beta" &&
420 echo gamma >> beta &&
421 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
423 echo gamma > gamma &&
424 hg add gamma &&
425 hg commit -u "<test@example.com>" -m "add gamma" &&
427 echo delta > delta &&
428 hg add delta &&
429 hg commit -u "name<test@example.com>" -m "add delta" &&
431 echo epsilon > epsilon &&
432 hg add epsilon &&
433 hg commit -u "name <test@example.com" -m "add epsilon" &&
435 echo zeta > zeta &&
436 hg add zeta &&
437 hg commit -u " test " -m "add zeta" &&
439 echo eta > eta &&
440 hg add eta &&
441 hg commit -u "test < test@example.com >" -m "add eta" &&
443 echo theta > theta &&
444 hg add theta &&
445 hg commit -u "test >test@example.com>" -m "add theta" &&
447 echo iota > iota &&
448 hg add iota &&
449 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
450 ) &&
452 hg_push_$x hgrepo-$x gitrepo-$x &&
453 hg_clone_$x gitrepo-$x hgrepo2-$x &&
455 hg_log hgrepo2-$x > hg-log-$x &&
456 git_log gitrepo-$x > git-log-$x
457 done &&
459 test_cmp hg-log-hg hg-log-git &&
460 test_cmp git-log-hg git-log-git
463 test_expect_success 'hg branch' '
464 mkdir -p tmp && cd tmp &&
465 test_when_finished "cd .. && rm -rf tmp" &&
467 for x in hg git; do
469 git init -q gitrepo-$x &&
470 cd gitrepo-$x &&
472 echo alpha > alpha &&
473 git add alpha &&
474 git commit -q -m "add alpha" &&
475 git checkout -q -b not-master
476 ) &&
479 hg_clone_$x gitrepo-$x hgrepo-$x &&
481 cd hgrepo-$x &&
482 hg -q co master &&
483 hg mv alpha beta &&
484 hg -q commit -m "rename alpha to beta" &&
485 hg branch gamma | grep -v "permanent and global" &&
486 hg -q commit -m "started branch gamma"
487 ) &&
489 hg_push_$x hgrepo-$x gitrepo-$x &&
490 hg_clone_$x gitrepo-$x hgrepo2-$x &&
492 hg_log hgrepo2-$x > hg-log-$x &&
493 git_log gitrepo-$x > git-log-$x
494 done &&
496 test_cmp hg-log-hg hg-log-git &&
497 test_cmp git-log-hg git-log-git
500 test_expect_success 'hg tags' '
501 mkdir -p tmp && cd tmp &&
502 test_when_finished "cd .. && rm -rf tmp" &&
504 for x in hg git; do
506 git init -q gitrepo-$x &&
507 cd gitrepo-$x &&
509 echo alpha > alpha &&
510 git add alpha &&
511 git commit -m "add alpha" &&
512 git checkout -q -b not-master
513 ) &&
516 hg_clone_$x gitrepo-$x hgrepo-$x &&
518 cd hgrepo-$x &&
519 hg co master &&
520 hg tag alpha
521 ) &&
523 hg_push_$x hgrepo-$x gitrepo-$x &&
524 hg_clone_$x gitrepo-$x hgrepo2-$x &&
527 git --git-dir=gitrepo-$x/.git tag -l &&
528 hg_log hgrepo2-$x &&
529 cat hgrepo2-$x/.hgtags
530 ) > output-$x
531 done &&
533 test_cmp output-hg output-git
536 test_done