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