1#!/bin/sh
2#
3# Copyright (c) 2012 Felipe Contreras
4#
5
6test_description='Test remote-bzr'
7
8. ./test-lib.sh
9
10if ! test_have_prereq PYTHON; then
11 skip_all='skipping remote-bzr tests; python not available'
12 test_done
13fi
14
15if ! "$PYTHON_PATH" -c 'import bzrlib'; then
16 skip_all='skipping remote-bzr tests; bzr not available'
17 test_done
18fi
19
20cmd='
21import bzrlib
22bzrlib.initialize()
23import bzrlib.plugin
24bzrlib.plugin.load_plugins()
25import bzrlib.plugins.fastimport
26'
27
28if ! "$PYTHON_PATH" -c "$cmd"; then
29 echo "consider setting BZR_PLUGIN_PATH=$HOME/.bazaar/plugins" 1>&2
30 skip_all='skipping remote-bzr tests; bzr-fastimport not available'
31 test_done
32fi
33
34check () {
35 (cd $1 &&
36 git log --format='%s' -1 &&
37 git symbolic-ref HEAD) > actual &&
38 (echo $2 &&
39 echo "refs/heads/$3") > expected &&
40 test_cmp expected actual
41}
42
43bzr whoami "A U Thor <author@example.com>"
44
45test_expect_success 'cloning' '
46 (bzr init bzrrepo &&
47 cd bzrrepo &&
48 echo one > content &&
49 bzr add content &&
50 bzr commit -m one
51 ) &&
52
53 git clone "bzr::$PWD/bzrrepo" gitrepo &&
54 check gitrepo one master
55'
56
57test_expect_success 'pulling' '
58 (cd bzrrepo &&
59 echo two > content &&
60 bzr commit -m two
61 ) &&
62
63 (cd gitrepo && git pull) &&
64
65 check gitrepo two master
66'
67
68test_expect_success 'pushing' '
69 (cd gitrepo &&
70 echo three > content &&
71 git commit -a -m three &&
72 git push
73 ) &&
74
75 echo three > expected &&
76 cat bzrrepo/content > actual &&
77 test_cmp expected actual
78'
79
80test_expect_success 'roundtrip' '
81 (cd gitrepo &&
82 git pull &&
83 git log --format="%s" -1 origin/master > actual) &&
84 echo three > expected &&
85 test_cmp expected actual &&
86
87 (cd gitrepo && git push && git pull) &&
88
89 (cd bzrrepo &&
90 echo four > content &&
91 bzr commit -m four
92 ) &&
93
94 (cd gitrepo && git pull && git push) &&
95
96 check gitrepo four master &&
97
98 (cd gitrepo &&
99 echo five > content &&
100 git commit -a -m five &&
101 git push && git pull
102 ) &&
103
104 (cd bzrrepo && bzr revert) &&
105
106 echo five > expected &&
107 cat bzrrepo/content > actual &&
108 test_cmp expected actual
109'
110
111cat > expected <<EOF
112100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
113100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
114120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
115EOF
116
117test_expect_success 'special modes' '
118 (cd bzrrepo &&
119 echo exec > executable
120 chmod +x executable &&
121 bzr add executable
122 bzr commit -m exec &&
123 ln -s content link
124 bzr add link
125 bzr commit -m link &&
126 mkdir dir &&
127 bzr add dir &&
128 bzr commit -m dir) &&
129
130 (cd gitrepo &&
131 git pull
132 git ls-tree HEAD > ../actual) &&
133
134 test_cmp expected actual &&
135
136 (cd gitrepo &&
137 git cat-file -p HEAD:link > ../actual) &&
138
139 echo -n content > expected &&
140 test_cmp expected actual
141'
142
143cat > expected <<EOF
144100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
145100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
146120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
147040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new
148EOF
149
150test_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
160 (cd gitrepo &&
161 git pull &&
162 git ls-tree HEAD > ../actual) &&
163
164 test_cmp expected actual
165'
166
167test_expect_success 'different authors' '
168 (cd bzrrepo &&
169 echo john >> content &&
170 bzr commit -m john \
171 --author "Jane Rey <jrey@example.com>" \
172 --author "John Doe <jdoe@example.com>") &&
173
174 (cd gitrepo &&
175 git pull &&
176 git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual) &&
177
178 echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected &&
179 test_cmp expected actual
180'
181
182test_expect_success 'fetch utf-8 filenames' '
183 mkdir -p tmp && cd tmp &&
184 test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
185
186 export LC_ALL=en_US.UTF-8
187
188 (
189 bzr init bzrrepo &&
190 cd bzrrepo &&
191
192 echo test >> "áéíóú" &&
193 bzr add "áéíóú" &&
194 bzr commit -m utf-8
195 ) &&
196
197 (
198 git clone "bzr::$PWD/bzrrepo" gitrepo &&
199 cd gitrepo &&
200 git ls-files > ../actual
201 ) &&
202
203 echo "\"\\303\\241\\303\\251\\303\\255\\303\\263\\303\\272\"" > expected &&
204 test_cmp expected actual
205'
206
207test_expect_success 'push utf-8 filenames' '
208 mkdir -p tmp && cd tmp &&
209 test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
210
211 export LC_ALL=en_US.UTF-8
212
213 (
214 bzr init bzrrepo &&
215 cd bzrrepo &&
216
217 echo one >> content &&
218 bzr add content &&
219 bzr commit -m one
220 ) &&
221
222 (
223 git clone "bzr::$PWD/bzrrepo" gitrepo &&
224 cd gitrepo &&
225
226 echo test >> "áéíóú" &&
227 git add "áéíóú" &&
228 git commit -m utf-8 &&
229
230 git push
231 ) &&
232
233 (cd bzrrepo && bzr ls > ../actual) &&
234 echo -e "content\náéíóú" > expected &&
235 test_cmp expected actual
236'
237
238test_done