fe38e49bc1c5f744ca871846a51471d1f6733ccd
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 bidirectionality of 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_PATH" -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
21fi
22
23# clone to a git repo
24git_clone () {
25 hg -R $1 bookmark -f -r tip master &&
26 git clone -q "hg::$PWD/$1" $2
27}
28
29# clone to an hg repo
30hg_clone () {
31 (
32 hg init $2 &&
33 hg -R $2 bookmark -i master &&
34 cd $1 &&
35 git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
36 ) &&
37
38 (cd $2 && hg -q update)
39}
40
41# push an hg repo
42hg_push () {
43 (
44 cd $2
45 old=$(git symbolic-ref --short HEAD)
46 git checkout -q -b tmp &&
47 git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
48 git checkout -q $old &&
49 git branch -q -D tmp 2> /dev/null || true
50 )
51}
52
53hg_log () {
54 hg -R $1 log --graph --debug | grep -v 'tag: *default/'
55}
56
57setup () {
58 (
59 echo "[ui]"
60 echo "username = A U Thor <author@example.com>"
61 echo "[defaults]"
62 echo "backout = -d \"0 0\""
63 echo "commit = -d \"0 0\""
64 echo "debugrawcommit = -d \"0 0\""
65 echo "tag = -d \"0 0\""
66 ) >> "$HOME"/.hgrc &&
67 git config --global remote-hg.hg-git-compat true
68
69 export HGEDITOR=/usr/bin/true
70
71 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
72 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
73}
74
75setup
76
77test_expect_success 'encoding' '
78 mkdir -p tmp && cd tmp &&
79 test_when_finished "cd .. && rm -rf tmp" &&
80
81 (
82 git init -q gitrepo &&
83 cd gitrepo &&
84
85 echo alpha > alpha &&
86 git add alpha &&
87 git commit -m "add älphà" &&
88
89 export GIT_AUTHOR_NAME="tést èncödîng" &&
90 echo beta > beta &&
91 git add beta &&
92 git commit -m "add beta" &&
93
94 echo gamma > gamma &&
95 git add gamma &&
96 git commit -m "add gämmâ" &&
97
98 : TODO git config i18n.commitencoding latin-1 &&
99 echo delta > delta &&
100 git add delta &&
101 git commit -m "add déltà"
102 ) &&
103
104 hg_clone gitrepo hgrepo &&
105 git_clone hgrepo gitrepo2 &&
106 hg_clone gitrepo2 hgrepo2 &&
107
108 HGENCODING=utf-8 hg_log hgrepo > expected &&
109 HGENCODING=utf-8 hg_log hgrepo2 > actual &&
110
111 test_cmp expected actual
112'
113
114test_expect_success 'file removal' '
115 mkdir -p tmp && cd tmp &&
116 test_when_finished "cd .. && rm -rf tmp" &&
117
118 (
119 git init -q gitrepo &&
120 cd gitrepo &&
121 echo alpha > alpha &&
122 git add alpha &&
123 git commit -m "add alpha" &&
124 echo beta > beta &&
125 git add beta &&
126 git commit -m "add beta"
127 mkdir foo &&
128 echo blah > foo/bar &&
129 git add foo &&
130 git commit -m "add foo" &&
131 git rm alpha &&
132 git commit -m "remove alpha" &&
133 git rm foo/bar &&
134 git commit -m "remove foo/bar"
135 ) &&
136
137 hg_clone gitrepo hgrepo &&
138 git_clone hgrepo gitrepo2 &&
139 hg_clone gitrepo2 hgrepo2 &&
140
141 hg_log hgrepo > expected &&
142 hg_log hgrepo2 > actual &&
143
144 test_cmp expected actual
145'
146
147test_expect_success 'git tags' '
148 mkdir -p tmp && cd tmp &&
149 test_when_finished "cd .. && rm -rf tmp" &&
150
151 (
152 git init -q gitrepo &&
153 cd gitrepo &&
154 git config receive.denyCurrentBranch ignore &&
155 echo alpha > alpha &&
156 git add alpha &&
157 git commit -m "add alpha" &&
158 git tag alpha &&
159
160 echo beta > beta &&
161 git add beta &&
162 git commit -m "add beta" &&
163 git tag -a -m "added tag beta" beta
164 ) &&
165
166 hg_clone gitrepo hgrepo &&
167 git_clone hgrepo gitrepo2 &&
168 hg_clone gitrepo2 hgrepo2 &&
169
170 hg_log hgrepo > expected &&
171 hg_log hgrepo2 > actual &&
172
173 test_cmp expected actual
174'
175
176test_expect_success 'hg branch' '
177 mkdir -p tmp && cd tmp &&
178 test_when_finished "cd .. && rm -rf tmp" &&
179
180 (
181 git init -q gitrepo &&
182 cd gitrepo &&
183
184 echo alpha > alpha &&
185 git add alpha &&
186 git commit -q -m "add alpha" &&
187 git checkout -q -b not-master
188 ) &&
189
190 (
191 hg_clone gitrepo hgrepo &&
192
193 cd hgrepo &&
194 hg -q co master &&
195 hg mv alpha beta &&
196 hg -q commit -m "rename alpha to beta" &&
197 hg branch gamma | grep -v "permanent and global" &&
198 hg -q commit -m "started branch gamma"
199 ) &&
200
201 hg_push hgrepo gitrepo &&
202 hg_clone gitrepo hgrepo2 &&
203
204 : TODO, avoid "master" bookmark &&
205 (cd hgrepo2 && hg checkout gamma) &&
206
207 hg_log hgrepo > expected &&
208 hg_log hgrepo2 > actual &&
209
210 test_cmp expected actual
211'
212
213test_expect_success 'hg tags' '
214 mkdir -p tmp && cd tmp &&
215 test_when_finished "cd .. && rm -rf tmp" &&
216
217 (
218 git init -q gitrepo &&
219 cd gitrepo &&
220
221 echo alpha > alpha &&
222 git add alpha &&
223 git commit -m "add alpha" &&
224 git checkout -q -b not-master
225 ) &&
226
227 (
228 hg_clone gitrepo hgrepo &&
229
230 cd hgrepo &&
231 hg co master &&
232 hg tag alpha
233 ) &&
234
235 hg_push hgrepo gitrepo &&
236 hg_clone gitrepo hgrepo2 &&
237
238 hg_log hgrepo > expected &&
239 hg_log hgrepo2 > actual &&
240
241 test_cmp expected actual
242'
243
244test_done