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