Merge branch 'fg/submodule-fixup'
[alt-git.git] / contrib / remote-helpers / test-bzr.sh
blobdce281f91195cde4937b935910ec73f597bb826a
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
6 test_description='Test remote-bzr'
8 . ./test-lib.sh
10 if ! test_have_prereq PYTHON; then
11 skip_all='skipping remote-bzr tests; python not available'
12 test_done
15 if ! python -c 'import bzrlib'; then
16 skip_all='skipping remote-bzr tests; bzr not available'
17 test_done
20 check () {
21 echo $3 > expected &&
22 git --git-dir=$1/.git log --format='%s' -1 $2 > actual
23 test_cmp expected actual
26 bzr whoami "A U Thor <author@example.com>"
28 test_expect_success 'cloning' '
30 bzr init bzrrepo &&
31 cd bzrrepo &&
32 echo one > content &&
33 bzr add content &&
34 bzr commit -m one
35 ) &&
37 git clone "bzr::bzrrepo" gitrepo &&
38 check gitrepo HEAD one
41 test_expect_success 'pulling' '
43 cd bzrrepo &&
44 echo two > content &&
45 bzr commit -m two
46 ) &&
48 (cd gitrepo && git pull) &&
50 check gitrepo HEAD two
53 test_expect_success 'pushing' '
55 cd gitrepo &&
56 echo three > content &&
57 git commit -a -m three &&
58 git push
59 ) &&
61 echo three > expected &&
62 cat bzrrepo/content > actual &&
63 test_cmp expected actual
66 test_expect_success 'roundtrip' '
68 cd gitrepo &&
69 git pull &&
70 git log --format="%s" -1 origin/master > actual
71 ) &&
72 echo three > expected &&
73 test_cmp expected actual &&
75 (cd gitrepo && git push && git pull) &&
78 cd bzrrepo &&
79 echo four > content &&
80 bzr commit -m four
81 ) &&
83 (cd gitrepo && git pull && git push) &&
85 check gitrepo HEAD four &&
88 cd gitrepo &&
89 echo five > content &&
90 git commit -a -m five &&
91 git push && git pull
92 ) &&
94 (cd bzrrepo && bzr revert) &&
96 echo five > expected &&
97 cat bzrrepo/content > actual &&
98 test_cmp expected actual
101 cat > expected <<EOF
102 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
103 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
104 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
107 test_expect_success 'special modes' '
109 cd bzrrepo &&
110 echo exec > executable
111 chmod +x executable &&
112 bzr add executable
113 bzr commit -m exec &&
114 ln -s content link
115 bzr add link
116 bzr commit -m link &&
117 mkdir dir &&
118 bzr add dir &&
119 bzr commit -m dir
120 ) &&
123 cd gitrepo &&
124 git pull
125 git ls-tree HEAD > ../actual
126 ) &&
128 test_cmp expected actual &&
131 cd gitrepo &&
132 git cat-file -p HEAD:link > ../actual
133 ) &&
135 printf content > expected &&
136 test_cmp expected actual
139 cat > expected <<EOF
140 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
141 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
142 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
143 040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
146 test_expect_success 'moving directory' '
148 cd bzrrepo &&
149 mkdir movedir &&
150 echo one > movedir/one &&
151 echo two > movedir/two &&
152 bzr add movedir &&
153 bzr commit -m movedir &&
154 bzr mv movedir movedir-new &&
155 bzr commit -m movedir-new
156 ) &&
159 cd gitrepo &&
160 git pull &&
161 git ls-tree HEAD > ../actual
162 ) &&
164 test_cmp expected actual
167 test_expect_success 'different authors' '
169 cd bzrrepo &&
170 echo john >> content &&
171 bzr commit -m john \
172 --author "Jane Rey <jrey@example.com>" \
173 --author "John Doe <jdoe@example.com>"
174 ) &&
177 cd gitrepo &&
178 git pull &&
179 git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual
180 ) &&
182 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected &&
183 test_cmp expected actual
186 # cleanup previous stuff
187 rm -rf bzrrepo gitrepo
189 test_expect_success 'fetch utf-8 filenames' '
190 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
192 LC_ALL=en_US.UTF-8
193 export LC_ALL
196 bzr init bzrrepo &&
197 cd bzrrepo &&
199 echo test >> "ærø" &&
200 bzr add "ærø" &&
201 echo test >> "ø~?" &&
202 bzr add "ø~?" &&
203 bzr commit -m add-utf-8 &&
204 echo test >> "ærø" &&
205 bzr commit -m test-utf-8 &&
206 bzr rm "ø~?" &&
207 bzr mv "ærø" "ø~?" &&
208 bzr commit -m bzr-mv-utf-8
209 ) &&
212 git clone "bzr::bzrrepo" gitrepo &&
213 cd gitrepo &&
214 git -c core.quotepath=false ls-files > ../actual
215 ) &&
216 echo "ø~?" > expected &&
217 test_cmp expected actual
220 test_expect_success 'push utf-8 filenames' '
221 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
223 mkdir -p tmp && cd tmp &&
225 LC_ALL=en_US.UTF-8
226 export LC_ALL
229 bzr init bzrrepo &&
230 cd bzrrepo &&
232 echo one >> content &&
233 bzr add content &&
234 bzr commit -m one
235 ) &&
238 git clone "bzr::bzrrepo" gitrepo &&
239 cd gitrepo &&
241 echo test >> "ærø" &&
242 git add "ærø" &&
243 git commit -m utf-8 &&
245 git push
246 ) &&
248 (cd bzrrepo && bzr ls > ../actual) &&
249 printf "content\nærø\n" > expected &&
250 test_cmp expected actual
253 test_expect_success 'pushing a merge' '
254 test_when_finished "rm -rf bzrrepo gitrepo" &&
257 bzr init bzrrepo &&
258 cd bzrrepo &&
259 echo one > content &&
260 bzr add content &&
261 bzr commit -m one
262 ) &&
264 git clone "bzr::bzrrepo" gitrepo &&
267 cd bzrrepo &&
268 echo two > content &&
269 bzr commit -m two
270 ) &&
273 cd gitrepo &&
274 echo three > content &&
275 git commit -a -m three &&
276 git fetch &&
277 git merge origin/master || true &&
278 echo three > content &&
279 git commit -a --no-edit &&
280 git push
281 ) &&
283 echo three > expected &&
284 cat bzrrepo/content > actual &&
285 test_cmp expected actual
288 cat > expected <<EOF
289 origin/HEAD
290 origin/branch
291 origin/trunk
294 test_expect_success 'proper bzr repo' '
295 test_when_finished "rm -rf bzrrepo gitrepo" &&
297 bzr init-repo bzrrepo &&
300 bzr init bzrrepo/trunk &&
301 cd bzrrepo/trunk &&
302 echo one >> content &&
303 bzr add content &&
304 bzr commit -m one
305 ) &&
308 bzr branch bzrrepo/trunk bzrrepo/branch &&
309 cd bzrrepo/branch &&
310 echo two >> content &&
311 bzr commit -m one
312 ) &&
315 git clone "bzr::bzrrepo" gitrepo &&
316 cd gitrepo &&
317 git for-each-ref --format "%(refname:short)" refs/remotes/origin > ../actual
318 ) &&
320 test_cmp expected actual
323 test_expect_success 'strip' '
324 test_when_finished "rm -rf bzrrepo gitrepo" &&
327 bzr init bzrrepo &&
328 cd bzrrepo &&
330 echo one >> content &&
331 bzr add content &&
332 bzr commit -m one &&
334 echo two >> content &&
335 bzr commit -m two
336 ) &&
338 git clone "bzr::bzrrepo" gitrepo &&
341 cd bzrrepo &&
342 bzr uncommit --force &&
344 echo three >> content &&
345 bzr commit -m three &&
347 echo four >> content &&
348 bzr commit -m four &&
349 bzr log --line | sed -e "s/^[0-9][0-9]*: //" > ../expected
350 ) &&
353 cd gitrepo &&
354 git fetch &&
355 git log --format="%an %ad %s" --date=short origin/master > ../actual
356 ) &&
358 test_cmp expected actual
361 test_done