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