Merge branch 'jk/t5531-prepare-to-default-to-non-matching'
[git/mingw/j6t.git] / contrib / remote-helpers / test-bzr.sh
blob1e53ff9a584a302366dcbd647a2e27db3fd1b9fe
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
6 test_description='Test remote-bzr'
8 test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
9 . "$TEST_DIRECTORY"/test-lib.sh
11 if ! test_have_prereq PYTHON
12 then
13 skip_all='skipping remote-bzr tests; python not available'
14 test_done
17 if ! python -c 'import bzrlib'
18 then
19 skip_all='skipping remote-bzr tests; bzr not available'
20 test_done
23 check () {
24 echo $3 >expected &&
25 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
26 test_cmp expected actual
29 bzr whoami "A U Thor <author@example.com>"
31 test_expect_success 'cloning' '
33 bzr init bzrrepo &&
34 cd bzrrepo &&
35 echo one >content &&
36 bzr add content &&
37 bzr commit -m one
38 ) &&
40 git clone "bzr::bzrrepo" gitrepo &&
41 check gitrepo HEAD one
44 test_expect_success 'pulling' '
46 cd bzrrepo &&
47 echo two >content &&
48 bzr commit -m two
49 ) &&
51 (cd gitrepo && git pull) &&
53 check gitrepo HEAD two
56 test_expect_success 'pushing' '
58 cd gitrepo &&
59 echo three >content &&
60 git commit -a -m three &&
61 git push
62 ) &&
64 echo three >expected &&
65 cat bzrrepo/content >actual &&
66 test_cmp expected actual
69 test_expect_success 'roundtrip' '
71 cd gitrepo &&
72 git pull &&
73 git log --format="%s" -1 origin/master >actual
74 ) &&
75 echo three >expected &&
76 test_cmp expected actual &&
78 (cd gitrepo && git push && git pull) &&
81 cd bzrrepo &&
82 echo four >content &&
83 bzr commit -m four
84 ) &&
86 (cd gitrepo && git pull && git push) &&
88 check gitrepo HEAD four &&
91 cd gitrepo &&
92 echo five >content &&
93 git commit -a -m five &&
94 git push && git pull
95 ) &&
97 (cd bzrrepo && bzr revert) &&
99 echo five >expected &&
100 cat bzrrepo/content >actual &&
101 test_cmp expected actual
104 cat >expected <<\EOF
105 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
106 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
107 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
110 test_expect_success 'special modes' '
112 cd bzrrepo &&
113 echo exec >executable
114 chmod +x executable &&
115 bzr add executable
116 bzr commit -m exec &&
117 ln -s content link
118 bzr add link
119 bzr commit -m link &&
120 mkdir dir &&
121 bzr add dir &&
122 bzr commit -m dir
123 ) &&
126 cd gitrepo &&
127 git pull
128 git ls-tree HEAD >../actual
129 ) &&
131 test_cmp expected actual &&
134 cd gitrepo &&
135 git cat-file -p HEAD:link >../actual
136 ) &&
138 printf content >expected &&
139 test_cmp expected actual
142 cat >expected <<\EOF
143 100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
144 100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
145 120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
146 040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
149 test_expect_success 'moving directory' '
151 cd bzrrepo &&
152 mkdir movedir &&
153 echo one >movedir/one &&
154 echo two >movedir/two &&
155 bzr add movedir &&
156 bzr commit -m movedir &&
157 bzr mv movedir movedir-new &&
158 bzr commit -m movedir-new
159 ) &&
162 cd gitrepo &&
163 git pull &&
164 git ls-tree HEAD >../actual
165 ) &&
167 test_cmp expected actual
170 test_expect_success 'different authors' '
172 cd bzrrepo &&
173 echo john >>content &&
174 bzr commit -m john \
175 --author "Jane Rey <jrey@example.com>" \
176 --author "John Doe <jdoe@example.com>"
177 ) &&
180 cd gitrepo &&
181 git pull &&
182 git show --format="%an <%ae>, %cn <%ce>" --quiet >../actual
183 ) &&
185 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" >expected &&
186 test_cmp expected actual
189 # cleanup previous stuff
190 rm -rf bzrrepo gitrepo
192 test_expect_success 'fetch utf-8 filenames' '
193 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
195 LC_ALL=en_US.UTF-8
196 export LC_ALL
199 bzr init bzrrepo &&
200 cd bzrrepo &&
202 echo test >>"ærø" &&
203 bzr add "ærø" &&
204 echo test >>"ø~?" &&
205 bzr add "ø~?" &&
206 bzr commit -m add-utf-8 &&
207 echo test >>"ærø" &&
208 bzr commit -m test-utf-8 &&
209 bzr rm "ø~?" &&
210 bzr mv "ærø" "ø~?" &&
211 bzr commit -m bzr-mv-utf-8
212 ) &&
215 git clone "bzr::bzrrepo" gitrepo &&
216 cd gitrepo &&
217 git -c core.quotepath=false ls-files >../actual
218 ) &&
219 echo "ø~?" >expected &&
220 test_cmp expected actual
223 test_expect_success 'push utf-8 filenames' '
224 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
226 mkdir -p tmp && cd tmp &&
228 LC_ALL=en_US.UTF-8
229 export LC_ALL
232 bzr init bzrrepo &&
233 cd bzrrepo &&
235 echo one >>content &&
236 bzr add content &&
237 bzr commit -m one
238 ) &&
241 git clone "bzr::bzrrepo" gitrepo &&
242 cd gitrepo &&
244 echo test >>"ærø" &&
245 git add "ærø" &&
246 git commit -m utf-8 &&
248 git push
249 ) &&
251 (cd bzrrepo && bzr ls >../actual) &&
252 printf "content\nærø\n" >expected &&
253 test_cmp expected actual
256 test_expect_success 'pushing a merge' '
257 test_when_finished "rm -rf bzrrepo gitrepo" &&
260 bzr init bzrrepo &&
261 cd bzrrepo &&
262 echo one >content &&
263 bzr add content &&
264 bzr commit -m one
265 ) &&
267 git clone "bzr::bzrrepo" gitrepo &&
270 cd bzrrepo &&
271 echo two >content &&
272 bzr commit -m two
273 ) &&
276 cd gitrepo &&
277 echo three >content &&
278 git commit -a -m three &&
279 git fetch &&
280 git merge origin/master || true &&
281 echo three >content &&
282 git commit -a --no-edit &&
283 git push
284 ) &&
286 echo three >expected &&
287 cat bzrrepo/content >actual &&
288 test_cmp expected actual
291 cat >expected <<\EOF
292 origin/HEAD
293 origin/branch
294 origin/trunk
297 test_expect_success 'proper bzr repo' '
298 test_when_finished "rm -rf bzrrepo gitrepo" &&
300 bzr init-repo bzrrepo &&
303 bzr init bzrrepo/trunk &&
304 cd bzrrepo/trunk &&
305 echo one >>content &&
306 bzr add content &&
307 bzr commit -m one
308 ) &&
311 bzr branch bzrrepo/trunk bzrrepo/branch &&
312 cd bzrrepo/branch &&
313 echo two >>content &&
314 bzr commit -m one
315 ) &&
318 git clone "bzr::bzrrepo" gitrepo &&
319 cd gitrepo &&
320 git for-each-ref --format "%(refname:short)" refs/remotes/origin >../actual
321 ) &&
323 test_cmp expected actual
326 test_expect_success 'strip' '
327 test_when_finished "rm -rf bzrrepo gitrepo" &&
330 bzr init bzrrepo &&
331 cd bzrrepo &&
333 echo one >>content &&
334 bzr add content &&
335 bzr commit -m one &&
337 echo two >>content &&
338 bzr commit -m two
339 ) &&
341 git clone "bzr::bzrrepo" gitrepo &&
344 cd bzrrepo &&
345 bzr uncommit --force &&
347 echo three >>content &&
348 bzr commit -m three &&
350 echo four >>content &&
351 bzr commit -m four &&
352 bzr log --line | sed -e "s/^[0-9][0-9]*: //" >../expected
353 ) &&
356 cd gitrepo &&
357 git fetch &&
358 git log --format="%an %ad %s" --date=short origin/master >../actual
359 ) &&
361 test_cmp expected actual
364 test_expect_success 'export utf-8 authors' '
365 test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C && unset GIT_COMMITTER_NAME" &&
367 LC_ALL=en_US.UTF-8
368 export LC_ALL
370 GIT_COMMITTER_NAME="Grégoire"
371 export GIT_COMMITTER_NAME
373 bzr init bzrrepo &&
376 git init gitrepo &&
377 cd gitrepo &&
378 echo greg >>content &&
379 git add content &&
380 git commit -m one &&
381 git remote add bzr "bzr::../bzrrepo" &&
382 git push bzr master
383 ) &&
386 cd bzrrepo &&
387 bzr log | grep "^committer: " >../actual
388 ) &&
390 echo "committer: Grégoire <committer@example.com>" >expected &&
391 test_cmp expected actual
394 test_done