remote-hg: make sure fake bookmarks are updated
[git/raj.git] / contrib / remote-helpers / test-hg-bidi.sh
blobfe38e49bc1c5f744ca871846a51471d1f6733ccd
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_PATH" -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 hg -R $1 bookmark -f -r tip master &&
26 git clone -q "hg::$PWD/$1" $2
29 # clone to an hg repo
30 hg_clone () {
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 ) &&
38 (cd $2 && hg -q update)
41 # push an hg repo
42 hg_push () {
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
53 hg_log () {
54 hg -R $1 log --graph --debug | grep -v 'tag: *default/'
57 setup () {
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
69 export HGEDITOR=/usr/bin/true
71 export GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
72 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
75 setup
77 test_expect_success 'encoding' '
78 mkdir -p tmp && cd tmp &&
79 test_when_finished "cd .. && rm -rf tmp" &&
82 git init -q gitrepo &&
83 cd gitrepo &&
85 echo alpha > alpha &&
86 git add alpha &&
87 git commit -m "add älphà" &&
89 export GIT_AUTHOR_NAME="tést èncödîng" &&
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 mkdir -p tmp && cd tmp &&
116 test_when_finished "cd .. && rm -rf tmp" &&
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 ) &&
137 hg_clone gitrepo hgrepo &&
138 git_clone hgrepo gitrepo2 &&
139 hg_clone gitrepo2 hgrepo2 &&
141 hg_log hgrepo > expected &&
142 hg_log hgrepo2 > actual &&
144 test_cmp expected actual
147 test_expect_success 'git tags' '
148 mkdir -p tmp && cd tmp &&
149 test_when_finished "cd .. && rm -rf tmp" &&
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 &&
160 echo beta > beta &&
161 git add beta &&
162 git commit -m "add beta" &&
163 git tag -a -m "added tag beta" beta
164 ) &&
166 hg_clone gitrepo hgrepo &&
167 git_clone hgrepo gitrepo2 &&
168 hg_clone gitrepo2 hgrepo2 &&
170 hg_log hgrepo > expected &&
171 hg_log hgrepo2 > actual &&
173 test_cmp expected actual
176 test_expect_success 'hg branch' '
177 mkdir -p tmp && cd tmp &&
178 test_when_finished "cd .. && rm -rf tmp" &&
181 git init -q gitrepo &&
182 cd gitrepo &&
184 echo alpha > alpha &&
185 git add alpha &&
186 git commit -q -m "add alpha" &&
187 git checkout -q -b not-master
188 ) &&
191 hg_clone gitrepo hgrepo &&
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 ) &&
201 hg_push hgrepo gitrepo &&
202 hg_clone gitrepo hgrepo2 &&
204 : TODO, avoid "master" bookmark &&
205 (cd hgrepo2 && hg checkout gamma) &&
207 hg_log hgrepo > expected &&
208 hg_log hgrepo2 > actual &&
210 test_cmp expected actual
213 test_expect_success 'hg tags' '
214 mkdir -p tmp && cd tmp &&
215 test_when_finished "cd .. && rm -rf tmp" &&
218 git init -q gitrepo &&
219 cd gitrepo &&
221 echo alpha > alpha &&
222 git add alpha &&
223 git commit -m "add alpha" &&
224 git checkout -q -b not-master
225 ) &&
228 hg_clone gitrepo hgrepo &&
230 cd hgrepo &&
231 hg co master &&
232 hg tag alpha
233 ) &&
235 hg_push hgrepo gitrepo &&
236 hg_clone gitrepo hgrepo2 &&
238 hg_log hgrepo > expected &&
239 hg_log hgrepo2 > actual &&
241 test_cmp expected actual
244 test_done