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 -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 git clone -q "hg::$1" $2
26}
27
28# clone to an hg repo
29hg_clone () {
30 (
31 hg init $2 &&
32 hg -R $2 bookmark -i master &&
33 cd $1 &&
34 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
35 ) &&
36
37 (cd $2 && hg -q update)
38}
39
40# push an hg repo
41hg_push () {
42 (
43 cd $2
44 git checkout -q -b tmp &&
45 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
46 git checkout -q @{-1} &&
47 git branch -q -D tmp 2> /dev/null || true
48 )
49}
50
51hg_log () {
52 hg -R $1 log --graph --debug >log &&
53 grep -v 'tag: *default/' log
54}
55
56setup () {
57 (
58 echo "[ui]"
59 echo "username = A U Thor <author@example.com>"
60 echo "[defaults]"
61 echo "backout = -d \"0 0\""
62 echo "commit = -d \"0 0\""
63 echo "debugrawcommit = -d \"0 0\""
64 echo "tag = -d \"0 0\""
65 echo "[extensions]"
66 echo "graphlog ="
67 ) >> "$HOME"/.hgrc &&
68 git config --global remote-hg.hg-git-compat true
69
70 HGEDITOR=/usr/bin/true
71 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
72 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
73 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
74}
75
76setup
77
78test_expect_success 'encoding' '
79 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 GIT_AUTHOR_NAME="tést èncödîng" &&
90 export GIT_AUTHOR_NAME &&
91 echo beta > beta &&
92 git add beta &&
93 git commit -m "add beta" &&
94
95 echo gamma > gamma &&
96 git add gamma &&
97 git commit -m "add gämmâ" &&
98
99 : TODO git config i18n.commitencoding latin-1 &&
100 echo delta > delta &&
101 git add delta &&
102 git commit -m "add déltà"
103 ) &&
104
105 hg_clone gitrepo hgrepo &&
106 git_clone hgrepo gitrepo2 &&
107 hg_clone gitrepo2 hgrepo2 &&
108
109 HGENCODING=utf-8 hg_log hgrepo > expected &&
110 HGENCODING=utf-8 hg_log hgrepo2 > actual &&
111
112 test_cmp expected actual
113'
114
115test_expect_success 'file removal' '
116 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 test_when_finished "rm -rf gitrepo* hgrepo*" &&
149
150 (
151 git init -q gitrepo &&
152 cd gitrepo &&
153 git config receive.denyCurrentBranch ignore &&
154 echo alpha > alpha &&
155 git add alpha &&
156 git commit -m "add alpha" &&
157 git tag alpha &&
158
159 echo beta > beta &&
160 git add beta &&
161 git commit -m "add beta" &&
162 git tag -a -m "added tag beta" beta
163 ) &&
164
165 hg_clone gitrepo hgrepo &&
166 git_clone hgrepo gitrepo2 &&
167 hg_clone gitrepo2 hgrepo2 &&
168
169 hg_log hgrepo > expected &&
170 hg_log hgrepo2 > actual &&
171
172 test_cmp expected actual
173'
174
175test_expect_success 'hg branch' '
176 test_when_finished "rm -rf gitrepo* hgrepo*" &&
177
178 (
179 git init -q gitrepo &&
180 cd gitrepo &&
181
182 echo alpha > alpha &&
183 git add alpha &&
184 git commit -q -m "add alpha" &&
185 git checkout -q -b not-master
186 ) &&
187
188 (
189 hg_clone gitrepo hgrepo &&
190
191 cd hgrepo &&
192 hg -q co master &&
193 hg mv alpha beta &&
194 hg -q commit -m "rename alpha to beta" &&
195 hg branch gamma | grep -v "permanent and global" &&
196 hg -q commit -m "started branch gamma"
197 ) &&
198
199 hg_push hgrepo gitrepo &&
200 hg_clone gitrepo hgrepo2 &&
201
202 : Back to the common revision &&
203 (cd hgrepo && hg checkout default) &&
204
205 hg_log hgrepo > expected &&
206 hg_log hgrepo2 > actual &&
207
208 test_cmp expected actual
209'
210
211test_expect_success 'hg tags' '
212 test_when_finished "rm -rf gitrepo* hgrepo*" &&
213
214 (
215 git init -q gitrepo &&
216 cd gitrepo &&
217
218 echo alpha > alpha &&
219 git add alpha &&
220 git commit -m "add alpha" &&
221 git checkout -q -b not-master
222 ) &&
223
224 (
225 hg_clone gitrepo hgrepo &&
226
227 cd hgrepo &&
228 hg co master &&
229 hg tag alpha
230 ) &&
231
232 hg_push hgrepo gitrepo &&
233 hg_clone gitrepo hgrepo2 &&
234
235 hg_log hgrepo > expected &&
236 hg_log hgrepo2 > actual &&
237
238 test_cmp expected actual
239'
240
241test_done