4d5aba20a090209a6678e1f69f9bf8ad26a03143
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
9test_description='Test remote-hg'
10
11. ./test-lib.sh
12
13if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
16fi
17
18if ! python -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
21fi
22
23check () {
24 echo $3 > expected &&
25 git --git-dir=$1/.git log --format='%s' -1 $2 > actual
26 test_cmp expected actual
27}
28
29setup () {
30 (
31 echo "[ui]"
32 echo "username = H G Wells <wells@example.com>"
33 echo "[extensions]"
34 echo "mq ="
35 ) >> "$HOME"/.hgrc
36}
37
38setup
39
40test_expect_success 'cloning' '
41 test_when_finished "rm -rf gitrepo*" &&
42
43 (
44 hg init hgrepo &&
45 cd hgrepo &&
46 echo zero > content &&
47 hg add content &&
48 hg commit -m zero
49 ) &&
50
51 git clone "hg::hgrepo" gitrepo &&
52 check gitrepo HEAD zero
53'
54
55test_expect_success 'cloning with branches' '
56 test_when_finished "rm -rf gitrepo*" &&
57
58 (
59 cd hgrepo &&
60 hg branch next &&
61 echo next > content &&
62 hg commit -m next
63 ) &&
64
65 git clone "hg::hgrepo" gitrepo &&
66 check gitrepo origin/branches/next next
67'
68
69test_expect_success 'cloning with bookmarks' '
70 test_when_finished "rm -rf gitrepo*" &&
71
72 (
73 cd hgrepo &&
74 hg checkout default &&
75 hg bookmark feature-a &&
76 echo feature-a > content &&
77 hg commit -m feature-a
78 ) &&
79
80 git clone "hg::hgrepo" gitrepo &&
81 check gitrepo origin/feature-a feature-a
82'
83
84test_expect_success 'update bookmark' '
85 test_when_finished "rm -rf gitrepo*" &&
86
87 (
88 cd hgrepo &&
89 hg bookmark devel
90 ) &&
91
92 (
93 git clone "hg::hgrepo" gitrepo &&
94 cd gitrepo &&
95 git checkout --quiet devel &&
96 echo devel > content &&
97 git commit -a -m devel &&
98 git push --quiet
99 ) &&
100
101 hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
102'
103
104# cleanup previous stuff
105rm -rf hgrepo
106
107author_test () {
108 echo $1 >> content &&
109 hg commit -u "$2" -m "add $1" &&
110 echo "$3" >> ../expected
111}
112
113test_expect_success 'authors' '
114 test_when_finished "rm -rf hgrepo gitrepo" &&
115
116 (
117 hg init hgrepo &&
118 cd hgrepo &&
119
120 touch content &&
121 hg add content &&
122
123 > ../expected &&
124 author_test alpha "" "H G Wells <wells@example.com>" &&
125 author_test beta "test" "test <unknown>" &&
126 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
127 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
128 author_test delta "name<test@example.com>" "name <test@example.com>" &&
129 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
130 author_test zeta " test " "test <unknown>" &&
131 author_test eta "test < test@example.com >" "test <test@example.com>" &&
132 author_test theta "test >test@example.com>" "test <test@example.com>" &&
133 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
134 author_test kappa "test@example.com" "Unknown <test@example.com>"
135 ) &&
136
137 git clone "hg::hgrepo" gitrepo &&
138 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
139
140 test_cmp expected actual
141'
142
143test_expect_success 'strip' '
144 test_when_finished "rm -rf hgrepo gitrepo" &&
145
146 (
147 hg init hgrepo &&
148 cd hgrepo &&
149
150 echo one >> content &&
151 hg add content &&
152 hg commit -m one &&
153
154 echo two >> content &&
155 hg commit -m two
156 ) &&
157
158 git clone "hg::hgrepo" gitrepo &&
159
160 (
161 cd hgrepo &&
162 hg strip 1 &&
163
164 echo three >> content &&
165 hg commit -m three &&
166
167 echo four >> content &&
168 hg commit -m four
169 ) &&
170
171 (
172 cd gitrepo &&
173 git fetch &&
174 git log --format="%s" origin/master > ../actual
175 ) &&
176
177 hg -R hgrepo log --template "{desc}\n" > expected &&
178 test_cmp actual expected
179'
180
181test_done