Merge branch 'ml/cygwin-updates'
[git.git] / contrib / remote-helpers / test-hg-bidi.sh
blobf83d67d74fc97cb597388ab556d7a31e9d01835b
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
9 test_description='Test bidirectionality of remote-hg'
11 . ./test-lib.sh
13 if ! test_have_prereq PYTHON; then
14 skip_all='skipping remote-hg tests; python not available'
15 test_done
18 if ! python -c 'import mercurial'; then
19 skip_all='skipping remote-hg tests; mercurial not available'
20 test_done
23 # clone to a git repo
24 git_clone () {
25 git clone -q "hg::$1" $2
28 # clone to an hg repo
29 hg_clone () {
31 hg init $2 &&
32 cd $1 &&
33 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
34 ) &&
36 (cd $2 && hg -q update)
39 # push an hg repo
40 hg_push () {
42 cd $2
43 git checkout -q -b tmp &&
44 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
45 git checkout -q @{-1} &&
46 git branch -q -D tmp 2> /dev/null || true
50 hg_log () {
51 hg -R $1 log --graph --debug
54 setup () {
56 echo "[ui]"
57 echo "username = A U Thor <author@example.com>"
58 echo "[defaults]"
59 echo "backout = -d \"0 0\""
60 echo "commit = -d \"0 0\""
61 echo "debugrawcommit = -d \"0 0\""
62 echo "tag = -d \"0 0\""
63 echo "[extensions]"
64 echo "graphlog ="
65 ) >> "$HOME"/.hgrc &&
66 git config --global remote-hg.hg-git-compat true
67 git config --global remote-hg.track-branches true
69 HGEDITOR=/usr/bin/true
70 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
71 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
72 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
75 setup
77 test_expect_success 'encoding' '
78 test_when_finished "rm -rf gitrepo* hgrepo*" &&
81 git init -q gitrepo &&
82 cd gitrepo &&
84 echo alpha > alpha &&
85 git add alpha &&
86 git commit -m "add älphà" &&
88 GIT_AUTHOR_NAME="tést èncödîng" &&
89 export GIT_AUTHOR_NAME &&
90 echo beta > beta &&
91 git add beta &&
92 git commit -m "add beta" &&
94 echo gamma > gamma &&
95 git add gamma &&
96 git commit -m "add gämmâ" &&
98 : TODO git config i18n.commitencoding latin-1 &&
99 echo delta > delta &&
100 git add delta &&
101 git commit -m "add déltà"
102 ) &&
104 hg_clone gitrepo hgrepo &&
105 git_clone hgrepo gitrepo2 &&
106 hg_clone gitrepo2 hgrepo2 &&
108 HGENCODING=utf-8 hg_log hgrepo > expected &&
109 HGENCODING=utf-8 hg_log hgrepo2 > actual &&
111 test_cmp expected actual
114 test_expect_success 'file removal' '
115 test_when_finished "rm -rf gitrepo* hgrepo*" &&
118 git init -q gitrepo &&
119 cd gitrepo &&
120 echo alpha > alpha &&
121 git add alpha &&
122 git commit -m "add alpha" &&
123 echo beta > beta &&
124 git add beta &&
125 git commit -m "add beta"
126 mkdir foo &&
127 echo blah > foo/bar &&
128 git add foo &&
129 git commit -m "add foo" &&
130 git rm alpha &&
131 git commit -m "remove alpha" &&
132 git rm foo/bar &&
133 git commit -m "remove foo/bar"
134 ) &&
136 hg_clone gitrepo hgrepo &&
137 git_clone hgrepo gitrepo2 &&
138 hg_clone gitrepo2 hgrepo2 &&
140 hg_log hgrepo > expected &&
141 hg_log hgrepo2 > actual &&
143 test_cmp expected actual
146 test_expect_success 'git tags' '
147 test_when_finished "rm -rf gitrepo* hgrepo*" &&
150 git init -q gitrepo &&
151 cd gitrepo &&
152 git config receive.denyCurrentBranch ignore &&
153 echo alpha > alpha &&
154 git add alpha &&
155 git commit -m "add alpha" &&
156 git tag alpha &&
158 echo beta > beta &&
159 git add beta &&
160 git commit -m "add beta" &&
161 git tag -a -m "added tag beta" beta
162 ) &&
164 hg_clone gitrepo hgrepo &&
165 git_clone hgrepo gitrepo2 &&
166 hg_clone gitrepo2 hgrepo2 &&
168 hg_log hgrepo > expected &&
169 hg_log hgrepo2 > actual &&
171 test_cmp expected actual
174 test_expect_success 'hg branch' '
175 test_when_finished "rm -rf gitrepo* hgrepo*" &&
178 git init -q gitrepo &&
179 cd gitrepo &&
181 echo alpha > alpha &&
182 git add alpha &&
183 git commit -q -m "add alpha" &&
184 git checkout -q -b not-master
185 ) &&
188 hg_clone gitrepo hgrepo &&
190 cd hgrepo &&
191 hg -q co default &&
192 hg mv alpha beta &&
193 hg -q commit -m "rename alpha to beta" &&
194 hg branch gamma | grep -v "permanent and global" &&
195 hg -q commit -m "started branch gamma"
196 ) &&
198 hg_push hgrepo gitrepo &&
199 hg_clone gitrepo hgrepo2 &&
201 : Back to the common revision &&
202 (cd hgrepo && hg checkout default) &&
204 hg_log hgrepo > expected &&
205 hg_log hgrepo2 > actual &&
207 test_cmp expected actual
210 test_expect_success 'hg tags' '
211 test_when_finished "rm -rf gitrepo* hgrepo*" &&
214 git init -q gitrepo &&
215 cd gitrepo &&
217 echo alpha > alpha &&
218 git add alpha &&
219 git commit -m "add alpha" &&
220 git checkout -q -b not-master
221 ) &&
224 hg_clone gitrepo hgrepo &&
226 cd hgrepo &&
227 hg co default &&
228 hg tag alpha
229 ) &&
231 hg_push hgrepo gitrepo &&
232 hg_clone gitrepo hgrepo2 &&
234 hg_log hgrepo > expected &&
235 hg_log hgrepo2 > actual &&
237 test_cmp expected actual
240 test_done