Merge branch 'jn/perl-lib-extra'
[git/jrn.git] / contrib / remote-helpers / test-bzr.sh
blob5c5025178370813aabec64c8bfbd7ac59c6186a5
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
11 then
12 skip_all='skipping remote-bzr tests; python not available'
13 test_done
16 if ! python -c 'import bzrlib'
17 then
18 skip_all='skipping remote-bzr tests; bzr not available'
19 test_done
22 check () {
23 echo $3 >expected &&
24 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
25 test_cmp expected actual
28 bzr whoami "A U Thor <author@example.com>"
30 test_expect_success 'cloning' '
32 bzr init bzrrepo &&
33 cd bzrrepo &&
34 echo one >content &&
35 bzr add content &&
36 bzr commit -m one
37 ) &&
39 git clone "bzr::bzrrepo" gitrepo &&
40 check gitrepo HEAD one
43 test_expect_success 'pulling' '
45 cd bzrrepo &&
46 echo two >content &&
47 bzr commit -m two
48 ) &&
50 (cd gitrepo && git pull) &&
52 check gitrepo HEAD two
55 test_expect_success 'pushing' '
57 cd gitrepo &&
58 echo three >content &&
59 git commit -a -m three &&
60 git push
61 ) &&
63 echo three >expected &&
64 cat bzrrepo/content >actual &&
65 test_cmp expected actual
68 test_expect_success 'roundtrip' '
70 cd gitrepo &&
71 git pull &&
72 git log --format="%s" -1 origin/master >actual
73 ) &&
74 echo three >expected &&
75 test_cmp expected actual &&
77 (cd gitrepo && git push && git pull) &&
80 cd bzrrepo &&
81 echo four >content &&
82 bzr commit -m four
83 ) &&
85 (cd gitrepo && git pull && git push) &&
87 check gitrepo HEAD four &&
90 cd gitrepo &&
91 echo five >content &&
92 git commit -a -m five &&
93 git push && git pull
94 ) &&
96 (cd bzrrepo && bzr revert) &&
98 echo five >expected &&
99 cat bzrrepo/content >actual &&
100 test_cmp expected actual
103 cat >expected <<\EOF
104 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
105 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
106 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
109 test_expect_success 'special modes' '
111 cd bzrrepo &&
112 echo exec >executable
113 chmod +x executable &&
114 bzr add executable
115 bzr commit -m exec &&
116 ln -s content link
117 bzr add link
118 bzr commit -m link &&
119 mkdir dir &&
120 bzr add dir &&
121 bzr commit -m dir
122 ) &&
125 cd gitrepo &&
126 git pull
127 git ls-tree HEAD >../actual
128 ) &&
130 test_cmp expected actual &&
133 cd gitrepo &&
134 git cat-file -p HEAD:link >../actual
135 ) &&
137 printf content >expected &&
138 test_cmp expected actual
141 cat >expected <<\EOF
142 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
143 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
144 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
145 040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
148 test_expect_success 'moving directory' '
150 cd bzrrepo &&
151 mkdir movedir &&
152 echo one >movedir/one &&
153 echo two >movedir/two &&
154 bzr add movedir &&
155 bzr commit -m movedir &&
156 bzr mv movedir movedir-new &&
157 bzr commit -m movedir-new
158 ) &&
161 cd gitrepo &&
162 git pull &&
163 git ls-tree HEAD >../actual
164 ) &&
166 test_cmp expected actual
169 test_expect_success 'different authors' '
171 cd bzrrepo &&
172 echo john >>content &&
173 bzr commit -m john \
174 --author "Jane Rey <jrey@example.com>" \
175 --author "John Doe <jdoe@example.com>"
176 ) &&
179 cd gitrepo &&
180 git pull &&
181 git show --format="%an <%ae>, %cn <%ce>" --quiet >../actual
182 ) &&
184 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" >expected &&
185 test_cmp expected actual
188 # cleanup previous stuff
189 rm -rf bzrrepo gitrepo
191 test_expect_success 'fetch utf-8 filenames' '
192 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
194 LC_ALL=en_US.UTF-8
195 export LC_ALL
198 bzr init bzrrepo &&
199 cd bzrrepo &&
201 echo test >>"ærø" &&
202 bzr add "ærø" &&
203 echo test >>"ø~?" &&
204 bzr add "ø~?" &&
205 bzr commit -m add-utf-8 &&
206 echo test >>"ærø" &&
207 bzr commit -m test-utf-8 &&
208 bzr rm "ø~?" &&
209 bzr mv "ærø" "ø~?" &&
210 bzr commit -m bzr-mv-utf-8
211 ) &&
214 git clone "bzr::bzrrepo" gitrepo &&
215 cd gitrepo &&
216 git -c core.quotepath=false ls-files >../actual
217 ) &&
218 echo "ø~?" >expected &&
219 test_cmp expected actual
222 test_expect_success 'push utf-8 filenames' '
223 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
225 mkdir -p tmp && cd tmp &&
227 LC_ALL=en_US.UTF-8
228 export LC_ALL
231 bzr init bzrrepo &&
232 cd bzrrepo &&
234 echo one >>content &&
235 bzr add content &&
236 bzr commit -m one
237 ) &&
240 git clone "bzr::bzrrepo" gitrepo &&
241 cd gitrepo &&
243 echo test >>"ærø" &&
244 git add "ærø" &&
245 git commit -m utf-8 &&
247 git push
248 ) &&
250 (cd bzrrepo && bzr ls >../actual) &&
251 printf "content\nærø\n" >expected &&
252 test_cmp expected actual
255 test_expect_success 'pushing a merge' '
256 test_when_finished "rm -rf bzrrepo gitrepo" &&
259 bzr init bzrrepo &&
260 cd bzrrepo &&
261 echo one >content &&
262 bzr add content &&
263 bzr commit -m one
264 ) &&
266 git clone "bzr::bzrrepo" gitrepo &&
269 cd bzrrepo &&
270 echo two >content &&
271 bzr commit -m two
272 ) &&
275 cd gitrepo &&
276 echo three >content &&
277 git commit -a -m three &&
278 git fetch &&
279 git merge origin/master || true &&
280 echo three >content &&
281 git commit -a --no-edit &&
282 git push
283 ) &&
285 echo three >expected &&
286 cat bzrrepo/content >actual &&
287 test_cmp expected actual
290 cat >expected <<\EOF
291 origin/HEAD
292 origin/branch
293 origin/trunk
296 test_expect_success 'proper bzr repo' '
297 test_when_finished "rm -rf bzrrepo gitrepo" &&
299 bzr init-repo bzrrepo &&
302 bzr init bzrrepo/trunk &&
303 cd bzrrepo/trunk &&
304 echo one >>content &&
305 bzr add content &&
306 bzr commit -m one
307 ) &&
310 bzr branch bzrrepo/trunk bzrrepo/branch &&
311 cd bzrrepo/branch &&
312 echo two >>content &&
313 bzr commit -m one
314 ) &&
317 git clone "bzr::bzrrepo" gitrepo &&
318 cd gitrepo &&
319 git for-each-ref --format "%(refname:short)" refs/remotes/origin >../actual
320 ) &&
322 test_cmp expected actual
325 test_expect_success 'strip' '
326 test_when_finished "rm -rf bzrrepo gitrepo" &&
329 bzr init bzrrepo &&
330 cd bzrrepo &&
332 echo one >>content &&
333 bzr add content &&
334 bzr commit -m one &&
336 echo two >>content &&
337 bzr commit -m two
338 ) &&
340 git clone "bzr::bzrrepo" gitrepo &&
343 cd bzrrepo &&
344 bzr uncommit --force &&
346 echo three >>content &&
347 bzr commit -m three &&
349 echo four >>content &&
350 bzr commit -m four &&
351 bzr log --line | sed -e "s/^[0-9][0-9]*: //" >../expected
352 ) &&
355 cd gitrepo &&
356 git fetch &&
357 git log --format="%an %ad %s" --date=short origin/master >../actual
358 ) &&
360 test_cmp expected actual
363 test_expect_success 'export utf-8 authors' '
364 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C && unset GIT_COMMITTER_NAME" &&
366 LC_ALL=en_US.UTF-8
367 export LC_ALL
369 GIT_COMMITTER_NAME="Grégoire"
370 export GIT_COMMITTER_NAME
372 bzr init bzrrepo &&
375 git init gitrepo &&
376 cd gitrepo &&
377 echo greg >>content &&
378 git add content &&
379 git commit -m one &&
380 git remote add bzr "bzr::../bzrrepo" &&
381 git push bzr
382 ) &&
385 cd bzrrepo &&
386 bzr log | grep "^committer: " >../actual
387 ) &&
389 echo "committer: Grégoire <committer@example.com>" >expected &&
390 test_cmp expected actual
393 test_done