prompt: fix show upstream with svn and zsh
[git.git] / contrib / remote-helpers / test-hg-bidi.sh
blob2a5d85dd723bc54fd198eaad8e0d44a3c9fa2576
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 cd $1 &&
34 git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
35 ) &&
37 (cd $2 && hg -q update)
40 # push an hg repo
41 hg_push () {
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
52 hg_log () {
53 hg -R $1 log --graph --debug | grep -v 'tag: *default/'
56 setup () {
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 ) >> "$HOME"/.hgrc &&
66 git config --global remote-hg.hg-git-compat true
68 HGEDITOR=/usr/bin/true
69 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
70 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
71 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
74 setup
76 test_expect_success 'encoding' '
77 mkdir -p tmp && cd tmp &&
78 test_when_finished "cd .. && rm -rf tmp" &&
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 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