Merge tag 'v2.3.0'
[git] / t / t5810-remote-hg.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'
10
11 test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=$(dirname $0)/
12 . "$TEST_DIRECTORY"/test-lib.sh
13
14 if ! test_have_prereq PYTHON
15 then
16         skip_all='skipping remote-hg tests; python not available'
17         test_done
18 fi
19
20 if ! "$PYTHON_PATH" -c 'import mercurial' > /dev/null 2>&1
21 then
22         skip_all='skipping remote-hg tests; mercurial not available'
23         test_done
24 fi
25
26 check () {
27         echo $3 > expected &&
28         git --git-dir=$1/.git log --format='%s' -1 $2 > actual &&
29         test_cmp expected actual
30 }
31
32 check_branch () {
33         if test -n "$3"
34         then
35                 echo $3 > expected &&
36                 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
37                 test_cmp expected actual
38         else
39                 hg -R $1 branches > out &&
40                 ! grep $2 out
41         fi
42 }
43
44 check_bookmark () {
45         if test -n "$3"
46         then
47                 echo $3 > expected &&
48                 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
49                 test_cmp expected actual
50         else
51                 hg -R $1 bookmarks > out &&
52                 ! grep $2 out
53         fi
54 }
55
56 check_files () {
57         git --git-dir=$1/.git ls-files > actual &&
58         if test $# -gt 1
59         then
60                 printf "%s\n" "$2" > expected
61         else
62                 > expected
63         fi &&
64         test_cmp expected actual
65 }
66
67 check_push () {
68         expected_ret=$1 ret=0 ref_ret=0
69
70         shift
71         git push origin "$@" 2> error
72         ret=$?
73         cat error
74
75         while IFS=':' read branch kind
76         do
77                 case "$kind" in
78                 'new')
79                         grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
80                         ;;
81                 'non-fast-forward')
82                         grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
83                         ;;
84                 'fetch-first')
85                         grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
86                         ;;
87                 'forced-update')
88                         grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
89                         ;;
90                 '')
91                         grep "^   [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
92                         ;;
93                 esac
94                 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
95         done
96
97         if test $expected_ret -ne $ret || test $ref_ret -ne 0
98         then
99                 return 1
100         fi
101
102         return 0
103 }
104
105 setup () {
106         cat > "$HOME"/.hgrc <<-EOF &&
107         [ui]
108         username = H G Wells <wells@example.com>
109         [extensions]
110         mq =
111         EOF
112
113         GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
114         GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
115         export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
116 }
117
118 setup
119
120 test_expect_success 'setup' '
121         (
122         hg init hgrepo &&
123         cd hgrepo &&
124         echo zero > content &&
125         hg add content &&
126         hg commit -m zero
127         )
128 '
129
130 test_expect_success 'cloning' '
131         test_when_finished "rm -rf gitrepo*" &&
132         git clone "hg::hgrepo" gitrepo &&
133         check gitrepo HEAD zero
134 '
135
136 test_expect_success 'cloning with branches' '
137         test_when_finished "rm -rf gitrepo*" &&
138
139         (
140         cd hgrepo &&
141         hg branch next &&
142         echo next > content &&
143         hg commit -m next
144         ) &&
145
146         git clone "hg::hgrepo" gitrepo &&
147         check gitrepo origin/branches/next next
148 '
149
150 test_expect_success 'cloning with bookmarks' '
151         test_when_finished "rm -rf gitrepo*" &&
152
153         (
154         cd hgrepo &&
155         hg checkout default &&
156         hg bookmark feature-a &&
157         echo feature-a > content &&
158         hg commit -m feature-a
159         ) &&
160
161         git clone "hg::hgrepo" gitrepo &&
162         check gitrepo origin/feature-a feature-a
163 '
164
165 test_expect_success 'update bookmark' '
166         test_when_finished "rm -rf gitrepo*" &&
167
168         (
169         cd hgrepo &&
170         hg bookmark devel
171         ) &&
172
173         (
174         git clone "hg::hgrepo" gitrepo &&
175         cd gitrepo &&
176         git checkout --quiet devel &&
177         echo devel > content &&
178         git commit -a -m devel &&
179         git push --quiet
180         ) &&
181
182         check_bookmark hgrepo devel devel
183 '
184
185 test_expect_success 'new bookmark' '
186         test_when_finished "rm -rf gitrepo*" &&
187
188         (
189         git clone "hg::hgrepo" gitrepo &&
190         cd gitrepo &&
191         git checkout --quiet -b feature-b &&
192         echo feature-b > content &&
193         git commit -a -m feature-b &&
194         git push --quiet origin feature-b
195         ) &&
196
197         check_bookmark hgrepo feature-b feature-b
198 '
199
200 # cleanup previous stuff
201 rm -rf hgrepo
202
203 author_test () {
204         echo $1 >> content &&
205         hg commit -u "$2" -m "add $1" &&
206         echo "$3" >> ../expected
207 }
208
209 test_expect_success 'authors' '
210         test_when_finished "rm -rf hgrepo gitrepo" &&
211
212         (
213         hg init hgrepo &&
214         cd hgrepo &&
215
216         touch content &&
217         hg add content &&
218
219         > ../expected &&
220         author_test alpha "" "H G Wells <wells@example.com>" &&
221         author_test beta "beta" "beta <unknown>" &&
222         author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
223         author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
224         author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
225         author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
226         author_test eta " eta " "eta <unknown>" &&
227         author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
228         author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
229         author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
230         author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
231         author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
232         ) &&
233
234         git clone "hg::hgrepo" gitrepo &&
235         git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
236
237         test_cmp expected actual
238 '
239
240 test_expect_success 'strip' '
241         test_when_finished "rm -rf hgrepo gitrepo" &&
242
243         (
244         hg init hgrepo &&
245         cd hgrepo &&
246
247         echo one >> content &&
248         hg add content &&
249         hg commit -m one &&
250
251         echo two >> content &&
252         hg commit -m two
253         ) &&
254
255         git clone "hg::hgrepo" gitrepo &&
256
257         (
258         cd hgrepo &&
259         hg strip 1 &&
260
261         echo three >> content &&
262         hg commit -m three &&
263
264         echo four >> content &&
265         hg commit -m four
266         ) &&
267
268         (
269         cd gitrepo &&
270         git fetch &&
271         git log --format="%s" origin/master > ../actual
272         ) &&
273
274         hg -R hgrepo log --template "{desc}\n" > expected &&
275         test_cmp actual expected
276 '
277
278 test_expect_success 'remote push with master bookmark' '
279         test_when_finished "rm -rf hgrepo gitrepo*" &&
280
281         (
282         hg init hgrepo &&
283         cd hgrepo &&
284         echo zero > content &&
285         hg add content &&
286         hg commit -m zero &&
287         hg bookmark master &&
288         echo one > content &&
289         hg commit -m one
290         ) &&
291
292         (
293         git clone "hg::hgrepo" gitrepo &&
294         cd gitrepo &&
295         echo two > content &&
296         git commit -a -m two &&
297         git push
298         ) &&
299
300         check_branch hgrepo default two
301 '
302
303 cat > expected <<\EOF
304 changeset:   0:6e2126489d3d
305 tag:         tip
306 user:        A U Thor <author@example.com>
307 date:        Mon Jan 01 00:00:00 2007 +0230
308 summary:     one
309
310 EOF
311
312 test_expect_success 'remote push from master branch' '
313         test_when_finished "rm -rf hgrepo gitrepo*" &&
314
315         hg init hgrepo &&
316
317         (
318         git init gitrepo &&
319         cd gitrepo &&
320         git remote add origin "hg::../hgrepo" &&
321         echo one > content &&
322         git add content &&
323         git commit -a -m one &&
324         git push origin master
325         ) &&
326
327         hg -R hgrepo log > actual &&
328         cat actual &&
329         test_cmp expected actual &&
330
331         check_branch hgrepo default one
332 '
333
334 GIT_REMOTE_HG_TEST_REMOTE=1
335 export GIT_REMOTE_HG_TEST_REMOTE
336
337 test_expect_success 'remote cloning' '
338         test_when_finished "rm -rf gitrepo*" &&
339
340         (
341         hg init hgrepo &&
342         cd hgrepo &&
343         echo zero > content &&
344         hg add content &&
345         hg commit -m zero
346         ) &&
347
348         git clone "hg::hgrepo" gitrepo &&
349         check gitrepo HEAD zero
350 '
351
352 test_expect_success 'moving remote clone' '
353         test_when_finished "rm -rf gitrepo*" &&
354
355         (
356         git clone "hg::hgrepo" gitrepo &&
357         mv gitrepo gitrepo2 &&
358         cd gitrepo2 &&
359         git fetch
360         )
361 '
362
363 test_expect_success 'remote update bookmark' '
364         test_when_finished "rm -rf gitrepo*" &&
365
366         (
367         cd hgrepo &&
368         hg bookmark devel
369         ) &&
370
371         (
372         git clone "hg::hgrepo" gitrepo &&
373         cd gitrepo &&
374         git checkout --quiet devel &&
375         echo devel > content &&
376         git commit -a -m devel &&
377         git push --quiet
378         ) &&
379
380         check_bookmark hgrepo devel devel
381 '
382
383 test_expect_success 'remote new bookmark' '
384         test_when_finished "rm -rf gitrepo*" &&
385
386         (
387         git clone "hg::hgrepo" gitrepo &&
388         cd gitrepo &&
389         git checkout --quiet -b feature-b &&
390         echo feature-b > content &&
391         git commit -a -m feature-b &&
392         git push --quiet origin feature-b
393         ) &&
394
395         check_bookmark hgrepo feature-b feature-b
396 '
397
398 test_expect_success 'remote push diverged' '
399         test_when_finished "rm -rf gitrepo*" &&
400
401         git clone "hg::hgrepo" gitrepo &&
402
403         (
404         cd hgrepo &&
405         hg checkout default &&
406         echo bump > content &&
407         hg commit -m bump
408         ) &&
409
410         (
411         cd gitrepo &&
412         echo diverge > content &&
413         git commit -a -m diverged &&
414         check_push 1 <<-\EOF
415         master:non-fast-forward
416         EOF
417         ) &&
418
419         check_branch hgrepo default bump
420 '
421
422 test_expect_success 'remote update bookmark diverge' '
423         test_when_finished "rm -rf gitrepo*" &&
424
425         (
426         cd hgrepo &&
427         hg checkout tip^ &&
428         hg bookmark diverge
429         ) &&
430
431         git clone "hg::hgrepo" gitrepo &&
432
433         (
434         cd hgrepo &&
435         echo "bump bookmark" > content &&
436         hg commit -m "bump bookmark"
437         ) &&
438
439         (
440         cd gitrepo &&
441         git checkout --quiet diverge &&
442         echo diverge > content &&
443         git commit -a -m diverge &&
444         check_push 1 <<-\EOF
445         diverge:fetch-first
446         EOF
447         ) &&
448
449         check_bookmark hgrepo diverge "bump bookmark"
450 '
451
452 test_expect_success 'remote new bookmark multiple branch head' '
453         test_when_finished "rm -rf gitrepo*" &&
454
455         (
456         git clone "hg::hgrepo" gitrepo &&
457         cd gitrepo &&
458         git checkout --quiet -b feature-c HEAD^ &&
459         echo feature-c > content &&
460         git commit -a -m feature-c &&
461         git push --quiet origin feature-c
462         ) &&
463
464         check_bookmark hgrepo feature-c feature-c
465 '
466
467 # cleanup previous stuff
468 rm -rf hgrepo
469
470 test_expect_success 'fetch special filenames' '
471         test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
472
473         LC_ALL=en_US.UTF-8
474         export LC_ALL
475
476         (
477         hg init hgrepo &&
478         cd hgrepo &&
479
480         echo test >> "æ rø" &&
481         hg add "æ rø" &&
482         echo test >> "ø~?" &&
483         hg add "ø~?" &&
484         hg commit -m add-utf-8 &&
485         echo test >> "æ rø" &&
486         hg commit -m test-utf-8 &&
487         hg rm "ø~?" &&
488         hg mv "æ rø" "ø~?" &&
489         hg commit -m hg-mv-utf-8
490         ) &&
491
492         (
493         git clone "hg::hgrepo" gitrepo &&
494         cd gitrepo &&
495         git -c core.quotepath=false ls-files > ../actual
496         ) &&
497         echo "ø~?" > expected &&
498         test_cmp expected actual
499 '
500
501 test_expect_success 'push special filenames' '
502         test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
503
504         mkdir -p tmp && cd tmp &&
505
506         LC_ALL=en_US.UTF-8
507         export LC_ALL
508
509         (
510         hg init hgrepo &&
511         cd hgrepo &&
512
513         echo one >> content &&
514         hg add content &&
515         hg commit -m one
516         ) &&
517
518         (
519         git clone "hg::hgrepo" gitrepo &&
520         cd gitrepo &&
521
522         echo test >> "æ rø" &&
523         git add "æ rø" &&
524         git commit -m utf-8 &&
525
526         git push
527         ) &&
528
529         (cd hgrepo &&
530         hg update &&
531         hg manifest > ../actual
532         ) &&
533
534         printf "content\næ rø\n" > expected &&
535         test_cmp expected actual
536 '
537
538 setup_big_push () {
539         (
540         hg init hgrepo &&
541         cd hgrepo &&
542         echo zero > content &&
543         hg add content &&
544         hg commit -m zero &&
545         hg bookmark bad_bmark1 &&
546         echo one > content &&
547         hg commit -m one &&
548         hg bookmark bad_bmark2 &&
549         hg bookmark good_bmark &&
550         hg bookmark -i good_bmark &&
551         hg -q branch good_branch &&
552         echo "good branch" > content &&
553         hg commit -m "good branch" &&
554         hg -q branch bad_branch &&
555         echo "bad branch" > content &&
556         hg commit -m "bad branch"
557         ) &&
558
559         git clone "hg::hgrepo" gitrepo &&
560
561         (
562         cd gitrepo &&
563         echo two > content &&
564         git commit -q -a -m two &&
565
566         git checkout -q good_bmark &&
567         echo three > content &&
568         git commit -q -a -m three &&
569
570         git checkout -q bad_bmark1 &&
571         git reset --hard HEAD^ &&
572         echo four > content &&
573         git commit -q -a -m four &&
574
575         git checkout -q bad_bmark2 &&
576         git reset --hard HEAD^ &&
577         echo five > content &&
578         git commit -q -a -m five &&
579
580         git checkout -q -b new_bmark master &&
581         echo six > content &&
582         git commit -q -a -m six &&
583
584         git checkout -q branches/good_branch &&
585         echo seven > content &&
586         git commit -q -a -m seven &&
587         echo eight > content &&
588         git commit -q -a -m eight &&
589
590         git checkout -q branches/bad_branch &&
591         git reset --hard HEAD^ &&
592         echo nine > content &&
593         git commit -q -a -m nine &&
594
595         git checkout -q -b branches/new_branch master &&
596         echo ten > content &&
597         git commit -q -a -m ten
598         )
599 }
600
601 test_expect_success 'remote big push' '
602         test_when_finished "rm -rf hgrepo gitrepo*" &&
603
604         setup_big_push
605
606         (
607         cd gitrepo &&
608
609         check_push 1 --all <<-\EOF
610         master
611         good_bmark
612         branches/good_branch
613         new_bmark:new
614         branches/new_branch:new
615         bad_bmark1:non-fast-forward
616         bad_bmark2:non-fast-forward
617         branches/bad_branch:non-fast-forward
618         EOF
619         ) &&
620
621         check_branch hgrepo default one &&
622         check_branch hgrepo good_branch "good branch" &&
623         check_branch hgrepo bad_branch "bad branch" &&
624         check_branch hgrepo new_branch '' &&
625         check_bookmark hgrepo good_bmark one &&
626         check_bookmark hgrepo bad_bmark1 one &&
627         check_bookmark hgrepo bad_bmark2 one &&
628         check_bookmark hgrepo new_bmark ''
629 '
630
631 test_expect_success 'remote big push fetch first' '
632         test_when_finished "rm -rf hgrepo gitrepo*" &&
633
634         (
635         hg init hgrepo &&
636         cd hgrepo &&
637         echo zero > content &&
638         hg add content &&
639         hg commit -m zero &&
640         hg bookmark bad_bmark &&
641         hg bookmark good_bmark &&
642         hg bookmark -i good_bmark &&
643         hg -q branch good_branch &&
644         echo "good branch" > content &&
645         hg commit -m "good branch" &&
646         hg -q branch bad_branch &&
647         echo "bad branch" > content &&
648         hg commit -m "bad branch"
649         ) &&
650
651         git clone "hg::hgrepo" gitrepo &&
652
653         (
654         cd hgrepo &&
655         hg bookmark -f bad_bmark &&
656         echo update_bmark > content &&
657         hg commit -m "update bmark"
658         ) &&
659
660         (
661         cd gitrepo &&
662         echo two > content &&
663         git commit -q -a -m two &&
664
665         git checkout -q good_bmark &&
666         echo three > content &&
667         git commit -q -a -m three &&
668
669         git checkout -q bad_bmark &&
670         echo four > content &&
671         git commit -q -a -m four &&
672
673         git checkout -q branches/bad_branch &&
674         echo five > content &&
675         git commit -q -a -m five &&
676
677         check_push 1 --all <<-\EOF &&
678         master
679         good_bmark
680         bad_bmark:fetch-first
681         branches/bad_branch:festch-first
682         EOF
683
684         git fetch &&
685
686         check_push 1 --all <<-\EOF
687         master
688         good_bmark
689         bad_bmark:non-fast-forward
690         branches/bad_branch:non-fast-forward
691         EOF
692         )
693 '
694
695 test_expect_success 'remote big push force' '
696         test_when_finished "rm -rf hgrepo gitrepo*" &&
697
698         setup_big_push
699
700         (
701         cd gitrepo &&
702
703         check_push 0 --force --all <<-\EOF
704         master
705         good_bmark
706         branches/good_branch
707         new_bmark:new
708         branches/new_branch:new
709         bad_bmark1:forced-update
710         bad_bmark2:forced-update
711         branches/bad_branch:forced-update
712         EOF
713         ) &&
714
715         check_branch hgrepo default six &&
716         check_branch hgrepo good_branch eight &&
717         check_branch hgrepo bad_branch nine &&
718         check_branch hgrepo new_branch ten &&
719         check_bookmark hgrepo good_bmark three &&
720         check_bookmark hgrepo bad_bmark1 four &&
721         check_bookmark hgrepo bad_bmark2 five &&
722         check_bookmark hgrepo new_bmark six
723 '
724
725 test_expect_success 'remote big push dry-run' '
726         test_when_finished "rm -rf hgrepo gitrepo*" &&
727
728         setup_big_push
729
730         (
731         cd gitrepo &&
732
733         check_push 1 --dry-run --all <<-\EOF &&
734         master
735         good_bmark
736         branches/good_branch
737         new_bmark:new
738         branches/new_branch:new
739         bad_bmark1:non-fast-forward
740         bad_bmark2:non-fast-forward
741         branches/bad_branch:non-fast-forward
742         EOF
743
744         check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
745         master
746         good_bmark
747         branches/good_branch
748         new_bmark:new
749         branches/new_branch:new
750         EOF
751         ) &&
752
753         check_branch hgrepo default one &&
754         check_branch hgrepo good_branch "good branch" &&
755         check_branch hgrepo bad_branch "bad branch" &&
756         check_branch hgrepo new_branch '' &&
757         check_bookmark hgrepo good_bmark one &&
758         check_bookmark hgrepo bad_bmark1 one &&
759         check_bookmark hgrepo bad_bmark2 one &&
760         check_bookmark hgrepo new_bmark ''
761 '
762
763 test_expect_success 'remote double failed push' '
764         test_when_finished "rm -rf hgrepo gitrepo*" &&
765
766         (
767         hg init hgrepo &&
768         cd hgrepo &&
769         echo zero > content &&
770         hg add content &&
771         hg commit -m zero &&
772         echo one > content &&
773         hg commit -m one
774         ) &&
775
776         (
777         git clone "hg::hgrepo" gitrepo &&
778         cd gitrepo &&
779         git reset --hard HEAD^ &&
780         echo two > content &&
781         git commit -a -m two &&
782         test_expect_code 1 git push &&
783         test_expect_code 1 git push
784         )
785 '
786
787 test_expect_success 'clone remote with null bookmark, then push' '
788         test_when_finished "rm -rf gitrepo* hgrepo*" &&
789
790         (
791         hg init hgrepo &&
792         cd hgrepo &&
793         echo a > a &&
794         hg add a &&
795         hg commit -m a &&
796         hg bookmark -r null bookmark
797         ) &&
798
799         (
800         git clone "hg::hgrepo" gitrepo &&
801         check gitrepo HEAD a &&
802         cd gitrepo &&
803         git checkout --quiet -b bookmark &&
804         git remote -v &&
805         echo b > b &&
806         git add b &&
807         git commit -m b &&
808         git push origin bookmark
809         )
810 '
811
812 test_expect_success 'notes' '
813         test_when_finished "rm -rf hgrepo gitrepo" &&
814
815         (
816         hg init hgrepo &&
817         cd hgrepo &&
818         echo one > content &&
819         hg add content &&
820         hg commit -m one &&
821         echo two > content &&
822         hg commit -m two
823         ) &&
824
825         git clone "hg::hgrepo" gitrepo &&
826         hg -R hgrepo log --template "{node}\n\n" > expected &&
827         git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
828         test_cmp expected actual
829 '
830
831 test_expect_failure 'push updates notes' '
832         test_when_finished "rm -rf hgrepo gitrepo" &&
833
834         (
835         hg init hgrepo &&
836         cd hgrepo &&
837         echo one > content &&
838         hg add content &&
839         hg commit -m one
840         ) &&
841
842         git clone "hg::hgrepo" gitrepo &&
843
844         (
845         cd gitrepo &&
846         echo two > content &&
847         git commit -a -m two
848         git push
849         ) &&
850
851         hg -R hgrepo log --template "{node}\n\n" > expected &&
852         git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
853         test_cmp expected actual
854 '
855
856 test_expect_success 'pull tags' '
857         test_when_finished "rm -rf hgrepo gitrepo" &&
858
859         (
860         hg init hgrepo &&
861         cd hgrepo &&
862         echo one > content &&
863         hg add content &&
864         hg commit -m one
865         ) &&
866
867         git clone "hg::hgrepo" gitrepo &&
868
869         (cd hgrepo && hg tag v1.0) &&
870         (cd gitrepo && git pull) &&
871
872         echo "v1.0" > expected &&
873         git --git-dir=gitrepo/.git tag > actual &&
874         test_cmp expected actual
875 '
876
877 test_expect_success 'push merged named branch' '
878         test_when_finished "rm -rf hgrepo gitrepo" &&
879
880         (
881         hg init hgrepo &&
882         cd hgrepo &&
883         echo one > content &&
884         hg add content &&
885         hg commit -m one &&
886         hg branch feature &&
887         echo two > content &&
888         hg commit -m two &&
889         hg update default &&
890         echo three > content &&
891         hg commit -m three
892         ) &&
893
894         (
895         git clone "hg::hgrepo" gitrepo &&
896         cd gitrepo &&
897         git merge -m Merge -Xtheirs origin/branches/feature &&
898         git push
899         ) &&
900
901         cat > expected <<-EOF
902         Merge
903         three
904         two
905         one
906         EOF
907         hg -R hgrepo log --template "{desc}\n" > actual &&
908         test_cmp expected actual
909 '
910
911 test_expect_success 'light tag sets author' '
912         test_when_finished "rm -rf hgrepo gitrepo" &&
913
914         (
915         hg init hgrepo &&
916         cd hgrepo &&
917         echo one > content &&
918         hg add content &&
919         hg commit -m one
920         ) &&
921
922         (
923         git clone "hg::hgrepo" gitrepo &&
924         cd gitrepo &&
925         git tag v1.0 &&
926         git push --tags
927         ) &&
928
929         echo "C O Mitter <committer@example.com>" > expected &&
930         hg -R hgrepo log --template "{author}\n" -r tip > actual &&
931         test_cmp expected actual
932 '
933
934 test_expect_success 'push tag different branch' '
935         test_when_finished "rm -rf hgrepo gitrepo" &&
936
937         (
938         hg init hgrepo &&
939         cd hgrepo &&
940         echo one > content &&
941         hg add content &&
942         hg commit -m one
943         hg branch feature &&
944         echo two > content &&
945         hg commit -m two
946         ) &&
947
948         (
949         git clone "hg::hgrepo" gitrepo &&
950         cd gitrepo &&
951         git branch &&
952         git checkout branches/feature &&
953         git tag v1.0 &&
954         git push --tags
955         ) &&
956
957         echo feature > expected &&
958         hg -R hgrepo log --template="{branch}\n" -r tip > actual &&
959         test_cmp expected actual
960 '
961
962 test_expect_success 'cloning a removed file works' '
963         test_when_finished "rm -rf hgrepo gitrepo" &&
964
965         (
966         hg init hgrepo &&
967         cd hgrepo &&
968
969         echo test > test_file &&
970         hg add test_file &&
971         hg commit -m add &&
972
973         hg rm test_file &&
974         hg commit -m remove
975         ) &&
976
977         git clone "hg::hgrepo" gitrepo &&
978         check_files gitrepo
979 '
980
981 test_expect_success 'cloning a file replaced with a directory' '
982         test_when_finished "rm -rf hgrepo gitrepo" &&
983
984         (
985         hg init hgrepo &&
986         cd hgrepo &&
987
988         echo test > dir_or_file &&
989         hg add dir_or_file &&
990         hg commit -m add &&
991
992         hg rm dir_or_file &&
993         mkdir dir_or_file &&
994         echo test > dir_or_file/test_file &&
995         hg add dir_or_file/test_file &&
996         hg commit -m replase
997         ) &&
998
999         git clone "hg::hgrepo" gitrepo &&
1000         check_files gitrepo "dir_or_file/test_file"
1001 '
1002
1003 test_expect_success 'clone replace directory with a file' '
1004         test_when_finished "rm -rf hgrepo gitrepo" &&
1005
1006         (
1007         hg init hgrepo &&
1008         cd hgrepo &&
1009
1010         mkdir dir_or_file &&
1011         echo test > dir_or_file/test_file &&
1012         hg add dir_or_file/test_file &&
1013         hg commit -m add &&
1014
1015         hg rm dir_or_file/test_file &&
1016         echo test > dir_or_file &&
1017         hg add dir_or_file &&
1018         hg commit -m add &&
1019
1020         hg rm dir_or_file
1021         ) &&
1022
1023         git clone "hg::hgrepo" gitrepo &&
1024         check_files gitrepo "dir_or_file"
1025 '
1026
1027 test_done