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