remote-hg: add tests for special filenames
[git] / t / remote-helpers / hg-bidi.t
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 #
8
9 test_description='Test bidirectionality of remote-hg'
10
11 test -z "$TEST_DIRECTORY" && TEST_DIRECTORY="$PWD/.."
12 . "$TEST_DIRECTORY"/test-lib.sh
13
14 if ! test_have_prereq PYTHON; then
15         skip_all='skipping remote-hg tests; python not available'
16         test_done
17 fi
18
19 if ! "$PYTHON_PATH" -c 'import mercurial'; then
20         skip_all='skipping remote-hg tests; mercurial not available'
21         test_done
22 fi
23
24 # clone to a git repo
25 git_clone () {
26         git clone -q "hg::$1" $2
27 }
28
29 # clone to an hg repo
30 hg_clone () {
31         (
32         hg init $2 &&
33         cd $1 &&
34         git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
35         ) &&
36
37         (cd $2 && hg -q update)
38 }
39
40 # push an hg repo
41 hg_push () {
42         (
43         cd $2
44         git checkout -q -b tmp &&
45         git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
46         git checkout -q @{-1} &&
47         git branch -q -D tmp 2> /dev/null || true
48         )
49 }
50
51 hg_log () {
52         hg -R $1 log --graph --debug
53 }
54
55 setup () {
56         (
57         echo "[ui]"
58         echo "username = A U Thor <author@example.com>"
59         echo "[defaults]"
60         echo "backout = -d \"0 0\""
61         echo "commit = -d \"0 0\""
62         echo "debugrawcommit = -d \"0 0\""
63         echo "tag = -d \"0 0\""
64         echo "[extensions]"
65         echo "graphlog ="
66         ) >> "$HOME"/.hgrc &&
67         git config --global remote-hg.hg-git-compat true
68         git config --global remote-hg.track-branches true
69
70         HGEDITOR=/usr/bin/true
71         GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
72         GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
73         export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
74 }
75
76 setup
77
78 test_expect_success 'encoding' '
79         test_when_finished "rm -rf gitrepo* hgrepo*" &&
80
81         (
82         git init -q gitrepo &&
83         cd gitrepo &&
84
85         echo alpha > alpha &&
86         git add alpha &&
87         git commit -m "add älphà" &&
88
89         GIT_AUTHOR_NAME="tést èncödîng" &&
90         export GIT_AUTHOR_NAME &&
91         echo beta > beta &&
92         git add beta &&
93         git commit -m "add beta" &&
94
95         echo gamma > gamma &&
96         git add gamma &&
97         git commit -m "add gämmâ" &&
98
99         : TODO git config i18n.commitencoding latin-1 &&
100         echo delta > delta &&
101         git add delta &&
102         git commit -m "add déltà"
103         ) &&
104
105         hg_clone gitrepo hgrepo &&
106         git_clone hgrepo gitrepo2 &&
107         hg_clone gitrepo2 hgrepo2 &&
108
109         HGENCODING=utf-8 hg_log hgrepo > expected &&
110         HGENCODING=utf-8 hg_log hgrepo2 > actual &&
111
112         test_cmp expected actual
113 '
114
115 test_expect_success 'file removal' '
116         test_when_finished "rm -rf gitrepo* hgrepo*" &&
117
118         (
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         ) &&
136
137         hg_clone gitrepo hgrepo &&
138         git_clone hgrepo gitrepo2 &&
139         hg_clone gitrepo2 hgrepo2 &&
140
141         hg_log hgrepo > expected &&
142         hg_log hgrepo2 > actual &&
143
144         test_cmp expected actual
145 '
146
147 test_expect_success 'git tags' '
148         test_when_finished "rm -rf gitrepo* hgrepo*" &&
149
150         (
151         git init -q gitrepo &&
152         cd gitrepo &&
153         git config receive.denyCurrentBranch ignore &&
154         echo alpha > alpha &&
155         git add alpha &&
156         git commit -m "add alpha" &&
157         git tag alpha &&
158
159         echo beta > beta &&
160         git add beta &&
161         git commit -m "add beta" &&
162         git tag -a -m "added tag beta" beta
163         ) &&
164
165         hg_clone gitrepo hgrepo &&
166         git_clone hgrepo gitrepo2 &&
167         hg_clone gitrepo2 hgrepo2 &&
168
169         hg_log hgrepo > expected &&
170         hg_log hgrepo2 > actual &&
171
172         test_cmp expected actual
173 '
174
175 test_expect_success 'hg branch' '
176         test_when_finished "rm -rf gitrepo* hgrepo*" &&
177
178         (
179         git init -q gitrepo &&
180         cd gitrepo &&
181
182         echo alpha > alpha &&
183         git add alpha &&
184         git commit -q -m "add alpha" &&
185         git checkout -q -b not-master
186         ) &&
187
188         (
189         hg_clone gitrepo hgrepo &&
190
191         cd hgrepo &&
192         hg -q co default &&
193         hg mv alpha beta &&
194         hg -q commit -m "rename alpha to beta" &&
195         hg branch gamma | grep -v "permanent and global" &&
196         hg -q commit -m "started branch gamma"
197         ) &&
198
199         hg_push hgrepo gitrepo &&
200         hg_clone gitrepo hgrepo2 &&
201
202         : Back to the common revision &&
203         (cd hgrepo && hg checkout default) &&
204
205         hg_log hgrepo > expected &&
206         hg_log hgrepo2 > actual &&
207
208         test_cmp expected actual
209 '
210
211 test_expect_success 'hg tags' '
212         test_when_finished "rm -rf gitrepo* hgrepo*" &&
213
214         (
215         git init -q gitrepo &&
216         cd gitrepo &&
217
218         echo alpha > alpha &&
219         git add alpha &&
220         git commit -m "add alpha" &&
221         git checkout -q -b not-master
222         ) &&
223
224         (
225         hg_clone gitrepo hgrepo &&
226
227         cd hgrepo &&
228         hg co default &&
229         hg tag alpha
230         ) &&
231
232         hg_push hgrepo gitrepo &&
233         hg_clone gitrepo hgrepo2 &&
234
235         hg_log hgrepo > expected &&
236         hg_log hgrepo2 > actual &&
237
238         test_cmp expected actual
239 '
240
241 test_done