Merge branch 'jc/graduate-remote-hg-bzr' (early part)
[git/git.git] / contrib / remote-helpers / test-hg-bidi.sh
CommitLineData
74954ee8
FC
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
831d57a0 9test_description='Test bidirectionality of remote-hg'
74954ee8 10
fe45cfb5
FC
11test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12. "$TEST_DIRECTORY"/test-lib.sh
74954ee8 13
ff867963
JH
14if ! test_have_prereq PYTHON
15then
74954ee8
FC
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
18fi
19
ff867963
JH
20if ! python -c 'import mercurial'
21then
74954ee8
FC
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
24fi
25
26# clone to a git repo
27git_clone () {
5f5e92fb 28 git clone -q "hg::$1" $2
74954ee8
FC
29}
30
31# clone to an hg repo
32hg_clone () {
33 (
34 hg init $2 &&
35 cd $1 &&
5f5e92fb 36 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
74954ee8
FC
37 ) &&
38
39 (cd $2 && hg -q update)
40}
41
42# push an hg repo
43hg_push () {
44 (
45 cd $2
74954ee8 46 git checkout -q -b tmp &&
5f5e92fb 47 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
f6f00b46 48 git checkout -q @{-1} &&
ff867963 49 git branch -q -D tmp 2>/dev/null || true
74954ee8
FC
50 )
51}
52
53hg_log () {
91347ea3 54 hg -R $1 log --graph --debug
74954ee8
FC
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\""
9a57988b
AP
66 echo "[extensions]"
67 echo "graphlog ="
ff867963 68 ) >>"$HOME"/.hgrc &&
74954ee8 69 git config --global remote-hg.hg-git-compat true
91347ea3 70 git config --global remote-hg.track-branches true
74954ee8 71
93cd8d97
TB
72 HGEDITOR=/usr/bin/true
73 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
74 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
75 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
74954ee8
FC
76}
77
78setup
79
80test_expect_success 'encoding' '
531594e5 81 test_when_finished "rm -rf gitrepo* hgrepo*" &&
74954ee8
FC
82
83 (
84 git init -q gitrepo &&
85 cd gitrepo &&
86
ff867963 87 echo alpha >alpha &&
74954ee8
FC
88 git add alpha &&
89 git commit -m "add älphà" &&
90
93cd8d97
TB
91 GIT_AUTHOR_NAME="tést èncödîng" &&
92 export GIT_AUTHOR_NAME &&
ff867963 93 echo beta >beta &&
74954ee8
FC
94 git add beta &&
95 git commit -m "add beta" &&
96
ff867963 97 echo gamma >gamma &&
74954ee8
FC
98 git add gamma &&
99 git commit -m "add gämmâ" &&
100
101 : TODO git config i18n.commitencoding latin-1 &&
ff867963 102 echo delta >delta &&
74954ee8
FC
103 git add delta &&
104 git commit -m "add déltà"
105 ) &&
106
107 hg_clone gitrepo hgrepo &&
108 git_clone hgrepo gitrepo2 &&
109 hg_clone gitrepo2 hgrepo2 &&
110
ff867963
JH
111 HGENCODING=utf-8 hg_log hgrepo >expected &&
112 HGENCODING=utf-8 hg_log hgrepo2 >actual &&
74954ee8
FC
113
114 test_cmp expected actual
115'
116
117test_expect_success 'file removal' '
531594e5 118 test_when_finished "rm -rf gitrepo* hgrepo*" &&
74954ee8
FC
119
120 (
121 git init -q gitrepo &&
122 cd gitrepo &&
ff867963 123 echo alpha >alpha &&
74954ee8
FC
124 git add alpha &&
125 git commit -m "add alpha" &&
ff867963 126 echo beta >beta &&
74954ee8
FC
127 git add beta &&
128 git commit -m "add beta"
129 mkdir foo &&
ff867963 130 echo blah >foo/bar &&
74954ee8
FC
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
ff867963
JH
143 hg_log hgrepo >expected &&
144 hg_log hgrepo2 >actual &&
74954ee8
FC
145
146 test_cmp expected actual
147'
148
149test_expect_success 'git tags' '
531594e5 150 test_when_finished "rm -rf gitrepo* hgrepo*" &&
74954ee8
FC
151
152 (
153 git init -q gitrepo &&
154 cd gitrepo &&
155 git config receive.denyCurrentBranch ignore &&
ff867963 156 echo alpha >alpha &&
74954ee8
FC
157 git add alpha &&
158 git commit -m "add alpha" &&
159 git tag alpha &&
160
ff867963 161 echo beta >beta &&
74954ee8
FC
162 git add beta &&
163 git commit -m "add beta" &&
164 git tag -a -m "added tag beta" beta
165 ) &&
166
167 hg_clone gitrepo hgrepo &&
168 git_clone hgrepo gitrepo2 &&
169 hg_clone gitrepo2 hgrepo2 &&
170
ff867963
JH
171 hg_log hgrepo >expected &&
172 hg_log hgrepo2 >actual &&
74954ee8
FC
173
174 test_cmp expected actual
175'
176
177test_expect_success 'hg branch' '
531594e5 178 test_when_finished "rm -rf gitrepo* hgrepo*" &&
74954ee8
FC
179
180 (
181 git init -q gitrepo &&
182 cd gitrepo &&
183
ff867963 184 echo alpha >alpha &&
74954ee8
FC
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 &&
91347ea3 194 hg -q co default &&
74954ee8
FC
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
71c6c95c
FC
204 : Back to the common revision &&
205 (cd hgrepo && hg checkout default) &&
74954ee8 206
ff867963
JH
207 hg_log hgrepo >expected &&
208 hg_log hgrepo2 >actual &&
74954ee8
FC
209
210 test_cmp expected actual
211'
212
213test_expect_success 'hg tags' '
531594e5 214 test_when_finished "rm -rf gitrepo* hgrepo*" &&
74954ee8
FC
215
216 (
217 git init -q gitrepo &&
218 cd gitrepo &&
219
ff867963 220 echo alpha >alpha &&
74954ee8
FC
221 git add alpha &&
222 git commit -m "add alpha" &&
223 git checkout -q -b not-master
224 ) &&
225
226 (
227 hg_clone gitrepo hgrepo &&
228
229 cd hgrepo &&
91347ea3 230 hg co default &&
74954ee8
FC
231 hg tag alpha
232 ) &&
233
234 hg_push hgrepo gitrepo &&
235 hg_clone gitrepo hgrepo2 &&
236
ff867963
JH
237 hg_log hgrepo >expected &&
238 hg_log hgrepo2 >actual &&
74954ee8
FC
239
240 test_cmp expected actual
241'
242
243test_done