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
29check_branch () {
30 echo $3 > expected &&
31 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
32 test_cmp expected actual
33}
34
35setup () {
36 (
37 echo "[ui]"
38 echo "username = H G Wells <wells@example.com>"
39 echo "[extensions]"
40 echo "mq ="
41 ) >> "$HOME"/.hgrc &&
42
43 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
44 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
45 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
46}
47
48setup
49
50test_expect_success 'cloning' '
51 test_when_finished "rm -rf gitrepo*" &&
52
53 (
54 hg init hgrepo &&
55 cd hgrepo &&
56 echo zero > content &&
57 hg add content &&
58 hg commit -m zero
59 ) &&
60
61 git clone "hg::hgrepo" gitrepo &&
62 check gitrepo HEAD zero
63'
64
65test_expect_success 'cloning with branches' '
66 test_when_finished "rm -rf gitrepo*" &&
67
68 (
69 cd hgrepo &&
70 hg branch next &&
71 echo next > content &&
72 hg commit -m next
73 ) &&
74
75 git clone "hg::hgrepo" gitrepo &&
76 check gitrepo origin/branches/next next
77'
78
79test_expect_success 'cloning with bookmarks' '
80 test_when_finished "rm -rf gitrepo*" &&
81
82 (
83 cd hgrepo &&
84 hg checkout default &&
85 hg bookmark feature-a &&
86 echo feature-a > content &&
87 hg commit -m feature-a
88 ) &&
89
90 git clone "hg::hgrepo" gitrepo &&
91 check gitrepo origin/feature-a feature-a
92'
93
94test_expect_success 'update bookmark' '
95 test_when_finished "rm -rf gitrepo*" &&
96
97 (
98 cd hgrepo &&
99 hg bookmark devel
100 ) &&
101
102 (
103 git clone "hg::hgrepo" gitrepo &&
104 cd gitrepo &&
105 git checkout --quiet devel &&
106 echo devel > content &&
107 git commit -a -m devel &&
108 git push --quiet
109 ) &&
110
111 hg -R hgrepo bookmarks | egrep "devel[ ]+3:"
112'
113
114# cleanup previous stuff
115rm -rf hgrepo
116
117author_test () {
118 echo $1 >> content &&
119 hg commit -u "$2" -m "add $1" &&
120 echo "$3" >> ../expected
121}
122
123test_expect_success 'authors' '
124 test_when_finished "rm -rf hgrepo gitrepo" &&
125
126 (
127 hg init hgrepo &&
128 cd hgrepo &&
129
130 touch content &&
131 hg add content &&
132
133 > ../expected &&
134 author_test alpha "" "H G Wells <wells@example.com>" &&
135 author_test beta "test" "test <unknown>" &&
136 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
137 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
138 author_test delta "name<test@example.com>" "name <test@example.com>" &&
139 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
140 author_test zeta " test " "test <unknown>" &&
141 author_test eta "test < test@example.com >" "test <test@example.com>" &&
142 author_test theta "test >test@example.com>" "test <test@example.com>" &&
143 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
144 author_test kappa "test@example.com" "Unknown <test@example.com>"
145 ) &&
146
147 git clone "hg::hgrepo" gitrepo &&
148 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
149
150 test_cmp expected actual
151'
152
153test_expect_success 'strip' '
154 test_when_finished "rm -rf hgrepo gitrepo" &&
155
156 (
157 hg init hgrepo &&
158 cd hgrepo &&
159
160 echo one >> content &&
161 hg add content &&
162 hg commit -m one &&
163
164 echo two >> content &&
165 hg commit -m two
166 ) &&
167
168 git clone "hg::hgrepo" gitrepo &&
169
170 (
171 cd hgrepo &&
172 hg strip 1 &&
173
174 echo three >> content &&
175 hg commit -m three &&
176
177 echo four >> content &&
178 hg commit -m four
179 ) &&
180
181 (
182 cd gitrepo &&
183 git fetch &&
184 git log --format="%s" origin/master > ../actual
185 ) &&
186
187 hg -R hgrepo log --template "{desc}\n" > expected &&
188 test_cmp actual expected
189'
190
191test_expect_success 'remote push with master bookmark' '
192 test_when_finished "rm -rf hgrepo gitrepo*" &&
193
194 (
195 hg init hgrepo &&
196 cd hgrepo &&
197 echo zero > content &&
198 hg add content &&
199 hg commit -m zero &&
200 hg bookmark master &&
201 echo one > content &&
202 hg commit -m one
203 ) &&
204
205 (
206 git clone "hg::hgrepo" gitrepo &&
207 cd gitrepo &&
208 echo two > content &&
209 git commit -a -m two &&
210 git push
211 ) &&
212
213 check_branch hgrepo default two
214'
215
216cat > expected <<EOF
217changeset: 0:6e2126489d3d
218tag: tip
219user: A U Thor <author@example.com>
220date: Mon Jan 01 00:00:00 2007 +0230
221summary: one
222
223EOF
224
225test_expect_success 'remote push from master branch' '
226 test_when_finished "rm -rf hgrepo gitrepo*" &&
227
228 hg init hgrepo &&
229
230 (
231 git init gitrepo &&
232 cd gitrepo &&
233 git remote add origin "hg::../hgrepo" &&
234 echo one > content &&
235 git add content &&
236 git commit -a -m one &&
237 git push origin master
238 ) &&
239
240 hg -R hgrepo log > actual &&
241 cat actual &&
242 test_cmp expected actual &&
243
244 check_branch hgrepo default one
245'
246
247test_done