Merge branch 'jc/graduate-remote-hg-bzr' (early part)
[git/git.git] / contrib / remote-helpers / test-hg-hg-git.sh
CommitLineData
bb8a9564
FC
1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5# Base commands from hg-git tests:
6# https://bitbucket.org/durin42/hg-git/src
7#
8
9test_description='Test remote-hg output compared to hg-git'
10
fe45cfb5
FC
11test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12. "$TEST_DIRECTORY"/test-lib.sh
bb8a9564 13
ff867963
JH
14if ! test_have_prereq PYTHON
15then
bb8a9564
FC
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
18fi
19
ff867963
JH
20if ! python -c 'import mercurial'
21then
bb8a9564
FC
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
24fi
25
ff867963
JH
26if ! python -c 'import hggit'
27then
bb8a9564
FC
28 skip_all='skipping remote-hg tests; hg-git not available'
29 test_done
30fi
31
32# clone to a git repo with git
33git_clone_git () {
91347ea3
FC
34 git clone -q "hg::$1" $2 &&
35 (cd $2 && git checkout master && git branch -D default)
bb8a9564
FC
36}
37
38# clone to an hg repo with git
39hg_clone_git () {
40 (
41 hg init $2 &&
8120014e 42 hg -R $2 bookmark -i master &&
bb8a9564 43 cd $1 &&
5f5e92fb 44 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
bb8a9564
FC
45 ) &&
46
47 (cd $2 && hg -q update)
48}
49
50# clone to a git repo with hg
51git_clone_hg () {
52 (
53 git init -q $2 &&
54 cd $1 &&
71c6c95c 55 hg bookmark -i -f -r tip master &&
bb8a9564
FC
56 hg -q push -r master ../$2 || true
57 )
58}
59
60# clone to an hg repo with hg
61hg_clone_hg () {
62 hg -q clone $1 $2
63}
64
65# push an hg repo with git
66hg_push_git () {
67 (
68 cd $2
bb8a9564 69 git checkout -q -b tmp &&
5f5e92fb 70 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
91347ea3 71 git branch -D default &&
f6f00b46 72 git checkout -q @{-1} &&
ff867963 73 git branch -q -D tmp 2>/dev/null || true
bb8a9564
FC
74 )
75}
76
77# push an hg git repo with hg
78hg_push_hg () {
79 (
80 cd $1 &&
81 hg -q push ../$2 || true
82 )
83}
84
85hg_log () {
9a57988b
AP
86 hg -R $1 log --graph --debug >log &&
87 grep -v 'tag: *default/' log
bb8a9564
FC
88}
89
90git_log () {
91 git --git-dir=$1/.git fast-export --branches
92}
93
94setup () {
95 (
96 echo "[ui]"
97 echo "username = A U Thor <author@example.com>"
98 echo "[defaults]"
99 echo "backout = -d \"0 0\""
100 echo "commit = -d \"0 0\""
101 echo "debugrawcommit = -d \"0 0\""
102 echo "tag = -d \"0 0\""
103 echo "[extensions]"
104 echo "hgext.bookmarks ="
105 echo "hggit ="
9a57988b 106 echo "graphlog ="
ff867963 107 ) >>"$HOME"/.hgrc &&
bb8a9564
FC
108 git config --global receive.denycurrentbranch warn
109 git config --global remote-hg.hg-git-compat true
679e87c0 110 git config --global remote-hg.track-branches false
bb8a9564 111
0c27c12d
FC
112 HGEDITOR=true
113 HGMERGE=true
bb8a9564 114
86c5e148
TB
115 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
116 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
0c27c12d 117 export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
bb8a9564
FC
118}
119
120setup
121
3968e302 122test_expect_success 'executable bit' '
531594e5 123 test_when_finished "rm -rf gitrepo* hgrepo*" &&
3968e302
MH
124
125 (
126 git init -q gitrepo &&
127 cd gitrepo &&
ff867963 128 echo alpha >alpha &&
3968e302
MH
129 chmod 0644 alpha &&
130 git add alpha &&
131 git commit -m "add alpha" &&
132 chmod 0755 alpha &&
133 git add alpha &&
134 git commit -m "set executable bit" &&
135 chmod 0644 alpha &&
136 git add alpha &&
137 git commit -m "clear executable bit"
138 ) &&
139
ff867963
JH
140 for x in hg git
141 do
3968e302
MH
142 (
143 hg_clone_$x gitrepo hgrepo-$x &&
144 cd hgrepo-$x &&
145 hg_log . &&
146 hg manifest -r 1 -v &&
147 hg manifest -v
5d21adcb 148 ) >"output-$x" &&
3968e302
MH
149
150 git_clone_$x hgrepo-$x gitrepo2-$x &&
5d21adcb 151 git_log gitrepo2-$x >"log-$x"
3968e302 152 done &&
3968e302
MH
153
154 test_cmp output-hg output-git &&
155 test_cmp log-hg log-git
156'
157
158test_expect_success 'symlink' '
531594e5 159 test_when_finished "rm -rf gitrepo* hgrepo*" &&
3968e302
MH
160
161 (
162 git init -q gitrepo &&
163 cd gitrepo &&
ff867963 164 echo alpha >alpha &&
3968e302
MH
165 git add alpha &&
166 git commit -m "add alpha" &&
167 ln -s alpha beta &&
168 git add beta &&
169 git commit -m "add beta"
170 ) &&
171
ff867963
JH
172 for x in hg git
173 do
3968e302
MH
174 (
175 hg_clone_$x gitrepo hgrepo-$x &&
176 cd hgrepo-$x &&
177 hg_log . &&
178 hg manifest -v
5d21adcb 179 ) >"output-$x" &&
3968e302
MH
180
181 git_clone_$x hgrepo-$x gitrepo2-$x &&
5d21adcb 182 git_log gitrepo2-$x >"log-$x"
3968e302
MH
183 done &&
184
185 test_cmp output-hg output-git &&
186 test_cmp log-hg log-git
187'
188
bb8a9564 189test_expect_success 'merge conflict 1' '
531594e5 190 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
191
192 (
193 hg init hgrepo1 &&
194 cd hgrepo1 &&
ff867963 195 echo A >afile &&
bb8a9564
FC
196 hg add afile &&
197 hg ci -m "origin" &&
198
ff867963 199 echo B >afile &&
bb8a9564
FC
200 hg ci -m "A->B" &&
201
202 hg up -r0 &&
ff867963 203 echo C >afile &&
bb8a9564
FC
204 hg ci -m "A->C" &&
205
0c27c12d 206 hg merge -r1 &&
ff867963 207 echo C >afile &&
bb8a9564
FC
208 hg resolve -m afile &&
209 hg ci -m "merge to C"
210 ) &&
211
ff867963
JH
212 for x in hg git
213 do
bb8a9564
FC
214 git_clone_$x hgrepo1 gitrepo-$x &&
215 hg_clone_$x gitrepo-$x hgrepo2-$x &&
5d21adcb
JH
216 hg_log hgrepo2-$x >"hg-log-$x" &&
217 git_log gitrepo-$x >"git-log-$x"
bb8a9564
FC
218 done &&
219
220 test_cmp hg-log-hg hg-log-git &&
221 test_cmp git-log-hg git-log-git
222'
223
224test_expect_success 'merge conflict 2' '
531594e5 225 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
226
227 (
228 hg init hgrepo1 &&
229 cd hgrepo1 &&
ff867963 230 echo A >afile &&
bb8a9564
FC
231 hg add afile &&
232 hg ci -m "origin" &&
233
ff867963 234 echo B >afile &&
bb8a9564
FC
235 hg ci -m "A->B" &&
236
237 hg up -r0 &&
ff867963 238 echo C >afile &&
bb8a9564
FC
239 hg ci -m "A->C" &&
240
241 hg merge -r1 || true &&
ff867963 242 echo B >afile &&
bb8a9564
FC
243 hg resolve -m afile &&
244 hg ci -m "merge to B"
245 ) &&
246
ff867963
JH
247 for x in hg git
248 do
bb8a9564
FC
249 git_clone_$x hgrepo1 gitrepo-$x &&
250 hg_clone_$x gitrepo-$x hgrepo2-$x &&
5d21adcb
JH
251 hg_log hgrepo2-$x >"hg-log-$x" &&
252 git_log gitrepo-$x >"git-log-$x"
bb8a9564
FC
253 done &&
254
255 test_cmp hg-log-hg hg-log-git &&
256 test_cmp git-log-hg git-log-git
257'
258
259test_expect_success 'converged merge' '
531594e5 260 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
261
262 (
263 hg init hgrepo1 &&
264 cd hgrepo1 &&
ff867963 265 echo A >afile &&
bb8a9564
FC
266 hg add afile &&
267 hg ci -m "origin" &&
268
ff867963 269 echo B >afile &&
bb8a9564
FC
270 hg ci -m "A->B" &&
271
ff867963 272 echo C >afile &&
bb8a9564
FC
273 hg ci -m "B->C" &&
274
275 hg up -r0 &&
ff867963 276 echo C >afile &&
bb8a9564
FC
277 hg ci -m "A->C" &&
278
279 hg merge -r2 || true &&
280 hg ci -m "merge"
281 ) &&
282
ff867963
JH
283 for x in hg git
284 do
bb8a9564
FC
285 git_clone_$x hgrepo1 gitrepo-$x &&
286 hg_clone_$x gitrepo-$x hgrepo2-$x &&
5d21adcb
JH
287 hg_log hgrepo2-$x >"hg-log-$x" &&
288 git_log gitrepo-$x >"git-log-$x"
bb8a9564
FC
289 done &&
290
291 test_cmp hg-log-hg hg-log-git &&
292 test_cmp git-log-hg git-log-git
293'
294
295test_expect_success 'encoding' '
531594e5 296 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
297
298 (
299 git init -q gitrepo &&
300 cd gitrepo &&
301
ff867963 302 echo alpha >alpha &&
bb8a9564
FC
303 git add alpha &&
304 git commit -m "add älphà" &&
305
86c5e148
TB
306 GIT_AUTHOR_NAME="tést èncödîng" &&
307 export GIT_AUTHOR_NAME &&
ff867963 308 echo beta >beta &&
bb8a9564
FC
309 git add beta &&
310 git commit -m "add beta" &&
311
ff867963 312 echo gamma >gamma &&
bb8a9564
FC
313 git add gamma &&
314 git commit -m "add gämmâ" &&
315
316 : TODO git config i18n.commitencoding latin-1 &&
ff867963 317 echo delta >delta &&
bb8a9564
FC
318 git add delta &&
319 git commit -m "add déltà"
320 ) &&
321
ff867963
JH
322 for x in hg git
323 do
bb8a9564
FC
324 hg_clone_$x gitrepo hgrepo-$x &&
325 git_clone_$x hgrepo-$x gitrepo2-$x &&
326
5d21adcb
JH
327 HGENCODING=utf-8 hg_log hgrepo-$x >"hg-log-$x" &&
328 git_log gitrepo2-$x >"git-log-$x"
bb8a9564
FC
329 done &&
330
331 test_cmp hg-log-hg hg-log-git &&
332 test_cmp git-log-hg git-log-git
333'
334
335test_expect_success 'file removal' '
531594e5 336 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
337
338 (
339 git init -q gitrepo &&
340 cd gitrepo &&
ff867963 341 echo alpha >alpha &&
bb8a9564
FC
342 git add alpha &&
343 git commit -m "add alpha" &&
ff867963 344 echo beta >beta &&
bb8a9564
FC
345 git add beta &&
346 git commit -m "add beta"
347 mkdir foo &&
ff867963 348 echo blah >foo/bar &&
bb8a9564
FC
349 git add foo &&
350 git commit -m "add foo" &&
351 git rm alpha &&
352 git commit -m "remove alpha" &&
353 git rm foo/bar &&
354 git commit -m "remove foo/bar"
355 ) &&
356
ff867963
JH
357 for x in hg git
358 do
bb8a9564
FC
359 (
360 hg_clone_$x gitrepo hgrepo-$x &&
361 cd hgrepo-$x &&
362 hg_log . &&
363 hg manifest -r 3 &&
364 hg manifest
5d21adcb 365 ) >"output-$x" &&
bb8a9564
FC
366
367 git_clone_$x hgrepo-$x gitrepo2-$x &&
5d21adcb 368 git_log gitrepo2-$x >"log-$x"
bb8a9564
FC
369 done &&
370
371 test_cmp output-hg output-git &&
372 test_cmp log-hg log-git
373'
374
375test_expect_success 'git tags' '
531594e5 376 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564
FC
377
378 (
379 git init -q gitrepo &&
380 cd gitrepo &&
381 git config receive.denyCurrentBranch ignore &&
ff867963 382 echo alpha >alpha &&
bb8a9564
FC
383 git add alpha &&
384 git commit -m "add alpha" &&
385 git tag alpha &&
386
ff867963 387 echo beta >beta &&
bb8a9564
FC
388 git add beta &&
389 git commit -m "add beta" &&
390 git tag -a -m "added tag beta" beta
391 ) &&
392
ff867963
JH
393 for x in hg git
394 do
bb8a9564 395 hg_clone_$x gitrepo hgrepo-$x &&
5d21adcb 396 hg_log hgrepo-$x >"log-$x"
bb8a9564
FC
397 done &&
398
399 test_cmp log-hg log-git
400'
401
402test_expect_success 'hg author' '
531594e5 403 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564 404
ff867963
JH
405 for x in hg git
406 do
bb8a9564
FC
407 (
408 git init -q gitrepo-$x &&
409 cd gitrepo-$x &&
410
ff867963 411 echo alpha >alpha &&
bb8a9564
FC
412 git add alpha &&
413 git commit -m "add alpha" &&
414 git checkout -q -b not-master
415 ) &&
416
417 (
418 hg_clone_$x gitrepo-$x hgrepo-$x &&
419 cd hgrepo-$x &&
420
421 hg co master &&
ff867963 422 echo beta >beta &&
bb8a9564
FC
423 hg add beta &&
424 hg commit -u "test" -m "add beta" &&
425
ff867963 426 echo gamma >>beta &&
bb8a9564
FC
427 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
428
ff867963 429 echo gamma >gamma &&
bb8a9564
FC
430 hg add gamma &&
431 hg commit -u "<test@example.com>" -m "add gamma" &&
432
ff867963 433 echo delta >delta &&
bb8a9564
FC
434 hg add delta &&
435 hg commit -u "name<test@example.com>" -m "add delta" &&
436
ff867963 437 echo epsilon >epsilon &&
bb8a9564
FC
438 hg add epsilon &&
439 hg commit -u "name <test@example.com" -m "add epsilon" &&
440
ff867963 441 echo zeta >zeta &&
bb8a9564
FC
442 hg add zeta &&
443 hg commit -u " test " -m "add zeta" &&
444
ff867963 445 echo eta >eta &&
bb8a9564
FC
446 hg add eta &&
447 hg commit -u "test < test@example.com >" -m "add eta" &&
448
ff867963 449 echo theta >theta &&
bb8a9564 450 hg add theta &&
aefc605a
FC
451 hg commit -u "test >test@example.com>" -m "add theta" &&
452
ff867963 453 echo iota >iota &&
aefc605a
FC
454 hg add iota &&
455 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
bb8a9564
FC
456 ) &&
457
458 hg_push_$x hgrepo-$x gitrepo-$x &&
459 hg_clone_$x gitrepo-$x hgrepo2-$x &&
460
5d21adcb
JH
461 hg_log hgrepo2-$x >"hg-log-$x" &&
462 git_log gitrepo-$x >"git-log-$x"
bb8a9564
FC
463 done &&
464
bb8a9564
FC
465 test_cmp hg-log-hg hg-log-git &&
466 test_cmp git-log-hg git-log-git
467'
468
469test_expect_success 'hg branch' '
531594e5 470 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564 471
ff867963
JH
472 for x in hg git
473 do
bb8a9564
FC
474 (
475 git init -q gitrepo-$x &&
476 cd gitrepo-$x &&
477
ff867963 478 echo alpha >alpha &&
bb8a9564
FC
479 git add alpha &&
480 git commit -q -m "add alpha" &&
481 git checkout -q -b not-master
482 ) &&
483
484 (
485 hg_clone_$x gitrepo-$x hgrepo-$x &&
486
487 cd hgrepo-$x &&
488 hg -q co master &&
489 hg mv alpha beta &&
490 hg -q commit -m "rename alpha to beta" &&
491 hg branch gamma | grep -v "permanent and global" &&
492 hg -q commit -m "started branch gamma"
493 ) &&
494
495 hg_push_$x hgrepo-$x gitrepo-$x &&
496 hg_clone_$x gitrepo-$x hgrepo2-$x &&
497
5d21adcb
JH
498 hg_log hgrepo2-$x >"hg-log-$x" &&
499 git_log gitrepo-$x >"git-log-$x"
bb8a9564
FC
500 done &&
501
502 test_cmp hg-log-hg hg-log-git &&
503 test_cmp git-log-hg git-log-git
504'
505
506test_expect_success 'hg tags' '
531594e5 507 test_when_finished "rm -rf gitrepo* hgrepo*" &&
bb8a9564 508
ff867963
JH
509 for x in hg git
510 do
bb8a9564
FC
511 (
512 git init -q gitrepo-$x &&
513 cd gitrepo-$x &&
514
ff867963 515 echo alpha >alpha &&
bb8a9564
FC
516 git add alpha &&
517 git commit -m "add alpha" &&
518 git checkout -q -b not-master
519 ) &&
520
521 (
522 hg_clone_$x gitrepo-$x hgrepo-$x &&
523
524 cd hgrepo-$x &&
525 hg co master &&
526 hg tag alpha
527 ) &&
528
529 hg_push_$x hgrepo-$x gitrepo-$x &&
530 hg_clone_$x gitrepo-$x hgrepo2-$x &&
531
532 (
533 git --git-dir=gitrepo-$x/.git tag -l &&
534 hg_log hgrepo2-$x &&
535 cat hgrepo2-$x/.hgtags
5d21adcb 536 ) >"output-$x"
bb8a9564
FC
537 done &&
538
539 test_cmp output-hg output-git
540'
541
542test_done