1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5# Base commands from hg-git tests:
6# https://bitbucket.org/durin42/hg-git/src
7#
89
test_description='Test bidirectionality of remote-hg'
1011
test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12. "$TEST_DIRECTORY"/test-lib.sh
1314
if ! test_have_prereq PYTHON
15then
16skip_all='skipping remote-hg tests; python not available'
17test_done
18fi
1920
if ! python -c 'import mercurial'
21then
22skip_all='skipping remote-hg tests; mercurial not available'
23test_done
24fi
2526
# clone to a git repo
27git_clone () {
28git clone -q "hg::$1" $2
29}
3031
# clone to an hg repo
32hg_clone () {
33(
34hg init $2 &&
35cd $1 &&
36git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
37) &&
3839
(cd $2 && hg -q update)
40}
4142
# push an hg repo
43hg_push () {
44(
45cd $2
46git checkout -q -b tmp &&
47git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
48git checkout -q @{-1} &&
49git branch -q -D tmp 2>/dev/null || true
50)
51}
5253
hg_log () {
54hg -R $1 log --graph --debug
55}
5657
setup () {
58(
59echo "[ui]"
60echo "username = A U Thor <author@example.com>"
61echo "[defaults]"
62echo "backout = -d \"0 0\""
63echo "commit = -d \"0 0\""
64echo "debugrawcommit = -d \"0 0\""
65echo "tag = -d \"0 0\""
66echo "[extensions]"
67echo "graphlog ="
68) >>"$HOME"/.hgrc &&
69git config --global remote-hg.hg-git-compat true
70git config --global remote-hg.track-branches true
7172
HGEDITOR=/usr/bin/true
73GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
74GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
75export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
76}
7778
setup
7980
test_expect_success 'encoding' '
81test_when_finished "rm -rf gitrepo* hgrepo*" &&
8283
(
84git init -q gitrepo &&
85cd gitrepo &&
8687
echo alpha >alpha &&
88git add alpha &&
89git commit -m "add älphà" &&
9091
GIT_AUTHOR_NAME="tést èncödîng" &&
92export GIT_AUTHOR_NAME &&
93echo beta >beta &&
94git add beta &&
95git commit -m "add beta" &&
9697
echo gamma >gamma &&
98git add gamma &&
99git commit -m "add gämmâ" &&
100101
: TODO git config i18n.commitencoding latin-1 &&
102echo delta >delta &&
103git add delta &&
104git commit -m "add déltà"
105) &&
106107
hg_clone gitrepo hgrepo &&
108git_clone hgrepo gitrepo2 &&
109hg_clone gitrepo2 hgrepo2 &&
110111
HGENCODING=utf-8 hg_log hgrepo >expected &&
112HGENCODING=utf-8 hg_log hgrepo2 >actual &&
113114
test_cmp expected actual
115'
116117
test_expect_success 'file removal' '
118test_when_finished "rm -rf gitrepo* hgrepo*" &&
119120
(
121git init -q gitrepo &&
122cd gitrepo &&
123echo alpha >alpha &&
124git add alpha &&
125git commit -m "add alpha" &&
126echo beta >beta &&
127git add beta &&
128git commit -m "add beta"
129mkdir foo &&
130echo blah >foo/bar &&
131git add foo &&
132git commit -m "add foo" &&
133git rm alpha &&
134git commit -m "remove alpha" &&
135git rm foo/bar &&
136git commit -m "remove foo/bar"
137) &&
138139
hg_clone gitrepo hgrepo &&
140git_clone hgrepo gitrepo2 &&
141hg_clone gitrepo2 hgrepo2 &&
142143
hg_log hgrepo >expected &&
144hg_log hgrepo2 >actual &&
145146
test_cmp expected actual
147'
148149
test_expect_success 'git tags' '
150test_when_finished "rm -rf gitrepo* hgrepo*" &&
151152
(
153git init -q gitrepo &&
154cd gitrepo &&
155git config receive.denyCurrentBranch ignore &&
156echo alpha >alpha &&
157git add alpha &&
158git commit -m "add alpha" &&
159git tag alpha &&
160161
echo beta >beta &&
162git add beta &&
163git commit -m "add beta" &&
164git tag -a -m "added tag beta" beta
165) &&
166167
hg_clone gitrepo hgrepo &&
168git_clone hgrepo gitrepo2 &&
169hg_clone gitrepo2 hgrepo2 &&
170171
hg_log hgrepo >expected &&
172hg_log hgrepo2 >actual &&
173174
test_cmp expected actual
175'
176177
test_expect_success 'hg branch' '
178test_when_finished "rm -rf gitrepo* hgrepo*" &&
179180
(
181git init -q gitrepo &&
182cd gitrepo &&
183184
echo alpha >alpha &&
185git add alpha &&
186git commit -q -m "add alpha" &&
187git checkout -q -b not-master
188) &&
189190
(
191hg_clone gitrepo hgrepo &&
192193
cd hgrepo &&
194hg -q co default &&
195hg mv alpha beta &&
196hg -q commit -m "rename alpha to beta" &&
197hg branch gamma | grep -v "permanent and global" &&
198hg -q commit -m "started branch gamma"
199) &&
200201
hg_push hgrepo gitrepo &&
202hg_clone gitrepo hgrepo2 &&
203204
: Back to the common revision &&
205(cd hgrepo && hg checkout default) &&
206207
hg_log hgrepo >expected &&
208hg_log hgrepo2 >actual &&
209210
test_cmp expected actual
211'
212213
test_expect_success 'hg tags' '
214test_when_finished "rm -rf gitrepo* hgrepo*" &&
215216
(
217git init -q gitrepo &&
218cd gitrepo &&
219220
echo alpha >alpha &&
221git add alpha &&
222git commit -m "add alpha" &&
223git checkout -q -b not-master
224) &&
225226
(
227hg_clone gitrepo hgrepo &&
228229
cd hgrepo &&
230hg co default &&
231hg tag alpha
232) &&
233234
hg_push hgrepo gitrepo &&
235hg_clone gitrepo hgrepo2 &&
236237
hg_log hgrepo >expected &&
238hg_log hgrepo2 >actual &&
239240
test_cmp expected actual
241'
242243
test_done