remote-hg: add tests for special filenames
[git] / t / remote-helpers / hg-hg-git.t
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 -z "$TEST_DIRECTORY" && TEST_DIRECTORY="$PWD/.."
12 . "$TEST_DIRECTORY"/test-lib.sh
13
14 if ! test_have_prereq PYTHON; then
15         skip_all='skipping remote-hg tests; python not available'
16         test_done
17 fi
18
19 if ! "$PYTHON_PATH" -c 'import mercurial'; then
20         skip_all='skipping remote-hg tests; mercurial not available'
21         test_done
22 fi
23
24 if ! "$PYTHON_PATH" -c 'import hggit'; then
25         skip_all='skipping remote-hg tests; hg-git not available'
26         test_done
27 fi
28
29 # clone to a git repo with git
30 git_clone_git () {
31         git clone -q "hg::$1" $2 &&
32         (cd $2 && git checkout master && git branch -D default)
33 }
34
35 # clone to an hg repo with git
36 hg_clone_git () {
37         (
38         hg init $2 &&
39         hg -R $2 bookmark -i master &&
40         cd $1 &&
41         git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
42         ) &&
43
44         (cd $2 && hg -q update)
45 }
46
47 # clone to a git repo with hg
48 git_clone_hg () {
49         (
50         git init -q $2 &&
51         cd $1 &&
52         hg bookmark -i -f -r tip master &&
53         hg -q push -r master ../$2 || true
54         )
55 }
56
57 # clone to an hg repo with hg
58 hg_clone_hg () {
59         hg -q clone $1 $2
60 }
61
62 # push an hg repo with git
63 hg_push_git () {
64         (
65         cd $2
66         git checkout -q -b tmp &&
67         git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
68         git branch -D default &&
69         git checkout -q @{-1} &&
70         git branch -q -D tmp 2> /dev/null || true
71         )
72 }
73
74 # push an hg git repo with hg
75 hg_push_hg () {
76         (
77         cd $1 &&
78         hg -q push ../$2 || true
79         )
80 }
81
82 hg_log () {
83         hg -R $1 log --graph --debug >log &&
84         grep -v 'tag: *default/' log
85 }
86
87 git_log () {
88         git --git-dir=$1/.git fast-export --branches
89 }
90
91 setup () {
92         (
93         echo "[ui]"
94         echo "username = A U Thor <author@example.com>"
95         echo "[defaults]"
96         echo "backout = -d \"0 0\""
97         echo "commit = -d \"0 0\""
98         echo "debugrawcommit = -d \"0 0\""
99         echo "tag = -d \"0 0\""
100         echo "[extensions]"
101         echo "hgext.bookmarks ="
102         echo "hggit ="
103         echo "graphlog ="
104         ) >> "$HOME"/.hgrc &&
105         git config --global receive.denycurrentbranch warn
106         git config --global remote-hg.hg-git-compat true
107         git config --global remote-hg.track-branches false
108
109         HGEDITOR=true
110         HGMERGE=true
111
112         GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
113         GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
114         export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
115 }
116
117 setup
118
119 test_expect_success 'executable bit' '
120         test_when_finished "rm -rf gitrepo* hgrepo*" &&
121
122         (
123         git init -q gitrepo &&
124         cd gitrepo &&
125         echo alpha > alpha &&
126         chmod 0644 alpha &&
127         git add alpha &&
128         git commit -m "add alpha" &&
129         chmod 0755 alpha &&
130         git add alpha &&
131         git commit -m "set executable bit" &&
132         chmod 0644 alpha &&
133         git add alpha &&
134         git commit -m "clear executable bit"
135         ) &&
136
137         for x in hg git; do
138                 (
139                 hg_clone_$x gitrepo hgrepo-$x &&
140                 cd hgrepo-$x &&
141                 hg_log . &&
142                 hg manifest -r 1 -v &&
143                 hg manifest -v
144                 ) > output-$x &&
145
146                 git_clone_$x hgrepo-$x gitrepo2-$x &&
147                 git_log gitrepo2-$x > log-$x
148         done &&
149
150         test_cmp output-hg output-git &&
151         test_cmp log-hg log-git
152 '
153
154 test_expect_success 'symlink' '
155         test_when_finished "rm -rf gitrepo* hgrepo*" &&
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
184 test_expect_success 'merge conflict 1' '
185         test_when_finished "rm -rf gitrepo* hgrepo*" &&
186
187         (
188         hg init hgrepo1 &&
189         cd hgrepo1 &&
190         echo A > afile &&
191         hg add afile &&
192         hg ci -m "origin" &&
193
194         echo B > afile &&
195         hg ci -m "A->B" &&
196
197         hg up -r0 &&
198         echo C > afile &&
199         hg ci -m "A->C" &&
200
201         hg merge -r1 &&
202         echo C > afile &&
203         hg resolve -m afile &&
204         hg ci -m "merge to C"
205         ) &&
206
207         for x in hg git; do
208                 git_clone_$x hgrepo1 gitrepo-$x &&
209                 hg_clone_$x gitrepo-$x hgrepo2-$x &&
210                 hg_log hgrepo2-$x > hg-log-$x &&
211                 git_log gitrepo-$x > git-log-$x
212         done &&
213
214         test_cmp hg-log-hg hg-log-git &&
215         test_cmp git-log-hg git-log-git
216 '
217
218 test_expect_success 'merge conflict 2' '
219         test_when_finished "rm -rf gitrepo* hgrepo*" &&
220
221         (
222         hg init hgrepo1 &&
223         cd hgrepo1 &&
224         echo A > afile &&
225         hg add afile &&
226         hg ci -m "origin" &&
227
228         echo B > afile &&
229         hg ci -m "A->B" &&
230
231         hg up -r0 &&
232         echo C > afile &&
233         hg ci -m "A->C" &&
234
235         hg merge -r1 || true &&
236         echo B > afile &&
237         hg resolve -m afile &&
238         hg ci -m "merge to B"
239         ) &&
240
241         for x in hg git; do
242                 git_clone_$x hgrepo1 gitrepo-$x &&
243                 hg_clone_$x gitrepo-$x hgrepo2-$x &&
244                 hg_log hgrepo2-$x > hg-log-$x &&
245                 git_log gitrepo-$x > git-log-$x
246         done &&
247
248         test_cmp hg-log-hg hg-log-git &&
249         test_cmp git-log-hg git-log-git
250 '
251
252 test_expect_success 'converged merge' '
253         test_when_finished "rm -rf gitrepo* hgrepo*" &&
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         test_when_finished "rm -rf gitrepo* hgrepo*" &&
289
290         (
291         git init -q gitrepo &&
292         cd gitrepo &&
293
294         echo alpha > alpha &&
295         git add alpha &&
296         git commit -m "add älphà" &&
297
298         GIT_AUTHOR_NAME="tést èncödîng" &&
299         export GIT_AUTHOR_NAME &&
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         test_when_finished "rm -rf gitrepo* hgrepo*" &&
328
329         (
330         git init -q gitrepo &&
331         cd gitrepo &&
332         echo alpha > alpha &&
333         git add alpha &&
334         git commit -m "add alpha" &&
335         echo beta > beta &&
336         git add beta &&
337         git commit -m "add beta"
338         mkdir foo &&
339         echo blah > foo/bar &&
340         git add foo &&
341         git commit -m "add foo" &&
342         git rm alpha &&
343         git commit -m "remove alpha" &&
344         git rm foo/bar &&
345         git commit -m "remove foo/bar"
346         ) &&
347
348         for x in hg git; do
349                 (
350                 hg_clone_$x gitrepo hgrepo-$x &&
351                 cd hgrepo-$x &&
352                 hg_log . &&
353                 hg manifest -r 3 &&
354                 hg manifest
355                 ) > output-$x &&
356
357                 git_clone_$x hgrepo-$x gitrepo2-$x &&
358                 git_log gitrepo2-$x > log-$x
359         done &&
360
361         test_cmp output-hg output-git &&
362         test_cmp log-hg log-git
363 '
364
365 test_expect_success 'git tags' '
366         test_when_finished "rm -rf gitrepo* hgrepo*" &&
367
368         (
369         git init -q gitrepo &&
370         cd gitrepo &&
371         git config receive.denyCurrentBranch ignore &&
372         echo alpha > alpha &&
373         git add alpha &&
374         git commit -m "add alpha" &&
375         git tag alpha &&
376
377         echo beta > beta &&
378         git add beta &&
379         git commit -m "add beta" &&
380         git tag -a -m "added tag beta" beta
381         ) &&
382
383         for x in hg git; do
384                 hg_clone_$x gitrepo hgrepo-$x &&
385                 hg_log hgrepo-$x > log-$x
386         done &&
387
388         test_cmp log-hg log-git
389 '
390
391 test_expect_success 'hg author' '
392         test_when_finished "rm -rf gitrepo* hgrepo*" &&
393
394         for x in hg git; do
395                 (
396                 git init -q gitrepo-$x &&
397                 cd gitrepo-$x &&
398
399                 echo alpha > alpha &&
400                 git add alpha &&
401                 git commit -m "add alpha" &&
402                 git checkout -q -b not-master
403                 ) &&
404
405                 (
406                 hg_clone_$x gitrepo-$x hgrepo-$x &&
407                 cd hgrepo-$x &&
408
409                 hg co master &&
410                 echo beta > beta &&
411                 hg add beta &&
412                 hg commit -u "test" -m "add beta" &&
413
414                 echo gamma >> beta &&
415                 hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
416
417                 echo gamma > gamma &&
418                 hg add gamma &&
419                 hg commit -u "<test@example.com>" -m "add gamma" &&
420
421                 echo delta > delta &&
422                 hg add delta &&
423                 hg commit -u "name<test@example.com>" -m "add delta" &&
424
425                 echo epsilon > epsilon &&
426                 hg add epsilon &&
427                 hg commit -u "name <test@example.com" -m "add epsilon" &&
428
429                 echo zeta > zeta &&
430                 hg add zeta &&
431                 hg commit -u " test " -m "add zeta" &&
432
433                 echo eta > eta &&
434                 hg add eta &&
435                 hg commit -u "test < test@example.com >" -m "add eta" &&
436
437                 echo theta > theta &&
438                 hg add theta &&
439                 hg commit -u "test >test@example.com>" -m "add theta" &&
440
441                 echo iota > iota &&
442                 hg add iota &&
443                 hg commit -u "test <test <at> example <dot> com>" -m "add iota"
444                 ) &&
445
446                 hg_push_$x hgrepo-$x gitrepo-$x &&
447                 hg_clone_$x gitrepo-$x hgrepo2-$x &&
448
449                 hg_log hgrepo2-$x > hg-log-$x &&
450                 git_log gitrepo-$x > git-log-$x
451         done &&
452
453         test_cmp hg-log-hg hg-log-git &&
454         test_cmp git-log-hg git-log-git
455 '
456
457 test_expect_success 'hg branch' '
458         test_when_finished "rm -rf gitrepo* hgrepo*" &&
459
460         for x in hg git; do
461                 (
462                 git init -q gitrepo-$x &&
463                 cd gitrepo-$x &&
464
465                 echo alpha > alpha &&
466                 git add alpha &&
467                 git commit -q -m "add alpha" &&
468                 git checkout -q -b not-master
469                 ) &&
470
471                 (
472                 hg_clone_$x gitrepo-$x hgrepo-$x &&
473
474                 cd hgrepo-$x &&
475                 hg -q co master &&
476                 hg mv alpha beta &&
477                 hg -q commit -m "rename alpha to beta" &&
478                 hg branch gamma | grep -v "permanent and global" &&
479                 hg -q commit -m "started branch gamma"
480                 ) &&
481
482                 hg_push_$x hgrepo-$x gitrepo-$x &&
483                 hg_clone_$x gitrepo-$x hgrepo2-$x &&
484
485                 hg_log hgrepo2-$x > hg-log-$x &&
486                 git_log gitrepo-$x > git-log-$x
487         done &&
488
489         test_cmp hg-log-hg hg-log-git &&
490         test_cmp git-log-hg git-log-git
491 '
492
493 test_expect_success 'hg tags' '
494         test_when_finished "rm -rf gitrepo* hgrepo*" &&
495
496         for x in hg git; do
497                 (
498                 git init -q gitrepo-$x &&
499                 cd gitrepo-$x &&
500
501                 echo alpha > alpha &&
502                 git add alpha &&
503                 git commit -m "add alpha" &&
504                 git checkout -q -b not-master
505                 ) &&
506
507                 (
508                 hg_clone_$x gitrepo-$x hgrepo-$x &&
509
510                 cd hgrepo-$x &&
511                 hg co master &&
512                 hg tag alpha
513                 ) &&
514
515                 hg_push_$x hgrepo-$x gitrepo-$x &&
516                 hg_clone_$x gitrepo-$x hgrepo2-$x &&
517
518                 (
519                 git --git-dir=gitrepo-$x/.git tag -l &&
520                 hg_log hgrepo2-$x &&
521                 cat hgrepo2-$x/.hgtags
522                 ) > output-$x
523         done &&
524
525         test_cmp output-hg output-git
526 '
527
528 test_done