Merge branch 'mk/doc-git-gui-display-untracked'
[alt-git.git] / contrib / remote-helpers / test-hg-bidi.sh
blobd86e147d3d400e226b1afb95fa2de48e42883fbd
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 -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON
15 then
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
20 if ! python -c 'import mercurial'
21 then
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
26 # clone to a git repo
27 git_clone () {
28 git clone -q "hg::$1" $2
31 # clone to an hg repo
32 hg_clone () {
34 hg init $2 &&
35 cd $1 &&
36 git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
37 ) &&
39 (cd $2 && hg -q update)
42 # push an hg repo
43 hg_push () {
45 cd $2
46 git checkout -q -b tmp &&
47 git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
48 git checkout -q @{-1} &&
49 git branch -q -D tmp 2>/dev/null || true
53 hg_log () {
54 hg -R $1 log --graph --debug
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
70 git config --global remote-hg.track-branches true
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
78 setup
80 test_expect_success 'encoding' '
81 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 test_when_finished "rm -rf gitrepo* hgrepo*" &&
121 git init -q gitrepo &&
122 cd gitrepo &&
123 echo alpha >alpha &&
124 git add alpha &&
125 git commit -m "add alpha" &&
126 echo beta >beta &&
127 git add beta &&
128 git commit -m "add beta"
129 mkdir foo &&
130 echo blah >foo/bar &&
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 ) &&
139 hg_clone gitrepo hgrepo &&
140 git_clone hgrepo gitrepo2 &&
141 hg_clone gitrepo2 hgrepo2 &&
143 hg_log hgrepo >expected &&
144 hg_log hgrepo2 >actual &&
146 test_cmp expected actual
149 test_expect_success 'git tags' '
150 test_when_finished "rm -rf gitrepo* hgrepo*" &&
153 git init -q gitrepo &&
154 cd gitrepo &&
155 git config receive.denyCurrentBranch ignore &&
156 echo alpha >alpha &&
157 git add alpha &&
158 git commit -m "add alpha" &&
159 git tag alpha &&
161 echo beta >beta &&
162 git add beta &&
163 git commit -m "add beta" &&
164 git tag -a -m "added tag beta" beta
165 ) &&
167 hg_clone gitrepo hgrepo &&
168 git_clone hgrepo gitrepo2 &&
169 hg_clone gitrepo2 hgrepo2 &&
171 hg_log hgrepo >expected &&
172 hg_log hgrepo2 >actual &&
174 test_cmp expected actual
177 test_expect_success 'hg branch' '
178 test_when_finished "rm -rf gitrepo* hgrepo*" &&
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 default &&
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 : Back to the common revision &&
205 (cd hgrepo && hg checkout default) &&
207 hg_log hgrepo >expected &&
208 hg_log hgrepo2 >actual &&
210 test_cmp expected actual
213 test_expect_success 'hg tags' '
214 test_when_finished "rm -rf gitrepo* hgrepo*" &&
217 git init -q gitrepo &&
218 cd gitrepo &&
220 echo alpha >alpha &&
221 git add alpha &&
222 git commit -m "add alpha" &&
223 git checkout -q -b not-master
224 ) &&
227 hg_clone gitrepo hgrepo &&
229 cd hgrepo &&
230 hg co default &&
231 hg tag alpha
232 ) &&
234 hg_push hgrepo gitrepo &&
235 hg_clone gitrepo hgrepo2 &&
237 hg_log hgrepo >expected &&
238 hg_log hgrepo2 >actual &&
240 test_cmp expected actual
243 test_done