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