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