gitweb: fix problem causing erroneous project list
[alt-git.git] / contrib / remote-helpers / test-hg-bidi.sh
blobf5696977342fc91f85a6d8b564677e6ace8a78d0
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 git clone -q "hg::$PWD/$1" $2
28 # clone to an hg repo
29 hg_clone () {
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 ) &&
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 >log &&
54 grep -v 'tag: *default/' log
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 echo "[extensions]"
67 echo "graphlog ="
68 ) >> "$HOME"/.hgrc &&
69 git config --global remote-hg.hg-git-compat true
71 HGEDITOR=/usr/bin/true
72 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
73 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
74 export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
77 setup
79 test_expect_success 'encoding' '
80 mkdir -p tmp && cd tmp &&
81 test_when_finished "cd .. && rm -rf tmp" &&
84 git init -q gitrepo &&
85 cd gitrepo &&
87 echo alpha > alpha &&
88 git add alpha &&
89 git commit -m "add älphà" &&
91 GIT_AUTHOR_NAME="tést èncödîng" &&
92 export GIT_AUTHOR_NAME &&
93 echo beta > beta &&
94 git add beta &&
95 git commit -m "add beta" &&
97 echo gamma > gamma &&
98 git add gamma &&
99 git commit -m "add gämmâ" &&
101 : TODO git config i18n.commitencoding latin-1 &&
102 echo delta > delta &&
103 git add delta &&
104 git commit -m "add déltà"
105 ) &&
107 hg_clone gitrepo hgrepo &&
108 git_clone hgrepo gitrepo2 &&
109 hg_clone gitrepo2 hgrepo2 &&
111 HGENCODING=utf-8 hg_log hgrepo > expected &&
112 HGENCODING=utf-8 hg_log hgrepo2 > actual &&
114 test_cmp expected actual
117 test_expect_success 'file removal' '
118 mkdir -p tmp && cd tmp &&
119 test_when_finished "cd .. && rm -rf tmp" &&
122 git init -q gitrepo &&
123 cd gitrepo &&
124 echo alpha > alpha &&
125 git add alpha &&
126 git commit -m "add alpha" &&
127 echo beta > beta &&
128 git add beta &&
129 git commit -m "add beta"
130 mkdir foo &&
131 echo blah > foo/bar &&
132 git add foo &&
133 git commit -m "add foo" &&
134 git rm alpha &&
135 git commit -m "remove alpha" &&
136 git rm foo/bar &&
137 git commit -m "remove foo/bar"
138 ) &&
140 hg_clone gitrepo hgrepo &&
141 git_clone hgrepo gitrepo2 &&
142 hg_clone gitrepo2 hgrepo2 &&
144 hg_log hgrepo > expected &&
145 hg_log hgrepo2 > actual &&
147 test_cmp expected actual
150 test_expect_success 'git tags' '
151 mkdir -p tmp && cd tmp &&
152 test_when_finished "cd .. && rm -rf tmp" &&
155 git init -q gitrepo &&
156 cd gitrepo &&
157 git config receive.denyCurrentBranch ignore &&
158 echo alpha > alpha &&
159 git add alpha &&
160 git commit -m "add alpha" &&
161 git tag alpha &&
163 echo beta > beta &&
164 git add beta &&
165 git commit -m "add beta" &&
166 git tag -a -m "added tag beta" beta
167 ) &&
169 hg_clone gitrepo hgrepo &&
170 git_clone hgrepo gitrepo2 &&
171 hg_clone gitrepo2 hgrepo2 &&
173 hg_log hgrepo > expected &&
174 hg_log hgrepo2 > actual &&
176 test_cmp expected actual
179 test_expect_success 'hg branch' '
180 mkdir -p tmp && cd tmp &&
181 test_when_finished "cd .. && rm -rf tmp" &&
184 git init -q gitrepo &&
185 cd gitrepo &&
187 echo alpha > alpha &&
188 git add alpha &&
189 git commit -q -m "add alpha" &&
190 git checkout -q -b not-master
191 ) &&
194 hg_clone gitrepo hgrepo &&
196 cd hgrepo &&
197 hg -q co master &&
198 hg mv alpha beta &&
199 hg -q commit -m "rename alpha to beta" &&
200 hg branch gamma | grep -v "permanent and global" &&
201 hg -q commit -m "started branch gamma"
202 ) &&
204 hg_push hgrepo gitrepo &&
205 hg_clone gitrepo hgrepo2 &&
207 : Back to the common revision &&
208 (cd hgrepo && hg checkout default) &&
210 hg_log hgrepo > expected &&
211 hg_log hgrepo2 > actual &&
213 test_cmp expected actual
216 test_expect_success 'hg tags' '
217 mkdir -p tmp && cd tmp &&
218 test_when_finished "cd .. && rm -rf tmp" &&
221 git init -q gitrepo &&
222 cd gitrepo &&
224 echo alpha > alpha &&
225 git add alpha &&
226 git commit -m "add alpha" &&
227 git checkout -q -b not-master
228 ) &&
231 hg_clone gitrepo hgrepo &&
233 cd hgrepo &&
234 hg co master &&
235 hg tag alpha
236 ) &&
238 hg_push hgrepo gitrepo &&
239 hg_clone gitrepo hgrepo2 &&
241 hg_log hgrepo > expected &&
242 hg_log hgrepo2 > actual &&
244 test_cmp expected actual
247 test_done