36
37
class TestSend(tests.TestCaseWithTransport):
39
super(TestSend, self).setUp()
40
grandparent_tree = bzrdir.BzrDir.create_standalone_workingtree(
40
grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
42
41
self.build_tree_contents([('grandparent/file1', 'grandparent')])
43
42
grandparent_tree.add('file1')
44
grandparent_tree.commit('initial commit', rev_id='rev1')
43
grandparent_tree.commit('initial commit', rev_id='revision1')
46
44
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
47
45
parent_tree = parent_bzrdir.open_workingtree()
48
parent_tree.commit('next commit', rev_id='rev2')
46
parent_tree.commit('next commit', rev_id='revision2')
50
47
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
51
48
self.build_tree_contents([('branch/file1', 'branch')])
52
branch_tree.commit('last commit', rev_id='rev3')
54
def run_send(self, args, cmd=None, rc=0, wd='branch'):
57
return self.run_bzr(cmd + args, retcode=rc, working_dir=wd)
59
def get_MD(self, args, cmd=None, wd='branch'):
60
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
61
return merge_directive.MergeDirective.from_lines(out.readlines())
63
def get_bundle(self, args, cmd=None, wd='branch'):
64
md = self.get_MD(args, cmd=cmd, wd=wd)
65
return serializer.read_bundle(StringIO(md.get_raw_bundle()))
67
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
68
out = self.run_send(args, cmd=cmd, wd=wd)[0]
69
br = read_bundle(StringIO(out))
70
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
72
def assertFormatIs(self, fmt_string, md):
73
self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
49
branch_tree.commit('last commit', rev_id='revision3')
75
51
def test_uses_parent(self):
76
52
"""Parent location is used as a basis by default"""
77
errmsg = self.run_send([], rc=3, wd='grandparent')[1]
54
os.chdir('grandparent')
55
errmsg = self.run_bzr('send -o-', retcode=3)[1]
78
56
self.assertContainsRe(errmsg, 'No submit branch known or specified')
79
stdout, stderr = self.run_send([])
58
stdout, stderr = self.run_bzr('send -o-')
80
59
self.assertEqual(stderr.count('Using saved parent location'), 1)
81
self.assertBundleContains(['rev3'], [])
60
br = read_bundle(StringIO(stdout))
61
self.assertRevisions(br, ['revision3'])
83
63
def test_bundle(self):
84
64
"""Bundle works like send, except -o is not required"""
85
errmsg = self.run_send([], cmd=['bundle'], rc=3, wd='grandparent')[1]
66
os.chdir('grandparent')
67
errmsg = self.run_bzr('bundle', retcode=3)[1]
86
68
self.assertContainsRe(errmsg, 'No submit branch known or specified')
87
stdout, stderr = self.run_send([], cmd=['bundle'])
70
stdout, stderr = self.run_bzr('bundle')
88
71
self.assertEqual(stderr.count('Using saved parent location'), 1)
89
self.assertBundleContains(['rev3'], [], cmd=['bundle'])
72
br = read_bundle(StringIO(stdout))
73
self.assertRevisions(br, ['revision3'])
75
def assertRevisions(self, bi, expected):
76
self.assertEqual(set(r.revision_id for r in bi.revisions),
91
79
def test_uses_submit(self):
92
80
"""Submit location can be used and set"""
93
self.assertBundleContains(['rev3'], [])
94
self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
83
br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
84
self.assertRevisions(br, ['revision3'])
85
br = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
86
self.assertRevisions(br, ['revision3', 'revision2'])
95
87
# submit location should be auto-remembered
96
self.assertBundleContains(['rev3', 'rev2'], [])
98
self.run_send(['../parent'])
99
# We still point to ../grandparent
100
self.assertBundleContains(['rev3', 'rev2'], [])
101
# Remember parent now
102
self.run_send(['../parent', '--remember'])
103
# Now we point to parent
104
self.assertBundleContains(['rev3'], [])
106
err = self.run_send(['--remember'], rc=3)[1]
88
br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
89
self.assertRevisions(br, ['revision3', 'revision2'])
90
self.run_bzr('send ../parent -o-')
91
br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
92
self.assertRevisions(br, ['revision3', 'revision2'])
93
self.run_bzr('send ../parent --remember -o-')
94
br = read_bundle(StringIO(self.run_bzr('send -o-')[0]))
95
self.assertRevisions(br, ['revision3'])
96
err = self.run_bzr('send --remember -o-', retcode=3)[1]
107
97
self.assertContainsRe(err,
108
98
'--remember requires a branch to be specified.')
110
100
def test_revision_branch_interaction(self):
111
self.assertBundleContains(['rev3', 'rev2'], ['../grandparent'])
112
self.assertBundleContains(['rev2'], ['../grandparent', '-r-2'])
113
self.assertBundleContains(['rev3', 'rev2'],
114
['../grandparent', '-r-2..-1'])
115
md = self.get_MD(['-r-2..-1'])
116
self.assertEqual('rev2', md.base_revision_id)
117
self.assertEqual('rev3', md.revision_id)
103
bi = read_bundle(StringIO(self.run_bzr('send ../grandparent -o-')[0]))
104
self.assertRevisions(bi, ['revision3', 'revision2'])
105
out = StringIO(self.run_bzr('send ../grandparent -r -2 -o-')[0])
106
bi = read_bundle(out)
107
self.assertRevisions(bi, ['revision2'])
108
sio = StringIO(self.run_bzr('send -r -2..-1 -o-')[0])
109
md = merge_directive.MergeDirective.from_lines(sio.readlines())
110
self.assertEqual('revision2', md.base_revision_id)
111
self.assertEqual('revision3', md.revision_id)
113
bi = read_bundle(sio)
114
self.assertRevisions(bi, ['revision2', 'revision3'])
115
self.run_bzr('send ../grandparent -r -2..-1 -o-')
119
117
def test_output(self):
120
118
# check output for consistency
121
119
# win32 stdout converts LF to CRLF,
122
120
# which would break patch-based bundles
123
self.assertBundleContains(['rev3'], [])
123
stdout = self.run_bzr_subprocess('send -o-')[0]
124
br = read_bundle(StringIO(stdout))
125
self.assertRevisions(br, ['revision3'])
125
127
def test_no_common_ancestor(self):
126
128
foo = self.make_branch_and_tree('foo')
127
129
foo.commit('rev a')
128
130
bar = self.make_branch_and_tree('bar')
129
131
bar.commit('rev b')
130
self.run_send(['--from', 'foo', '../bar'], wd='foo')
133
self.run_bzr('send ../bar -o-')
135
def send_directive(self, args):
136
sio = StringIO(self.run_bzr(['send', '-o-'] + args)[0])
137
return merge_directive.MergeDirective.from_lines(sio.readlines())
132
139
def test_content_options(self):
133
140
"""--no-patch and --no-bundle should work and be independant"""
135
self.assertIsNot(None, md.bundle)
136
self.assertIsNot(None, md.patch)
138
md = self.get_MD(['--format=0.9'])
139
self.assertIsNot(None, md.bundle)
140
self.assertIsNot(None, md.patch)
142
md = self.get_MD(['--no-patch'])
143
md = self.send_directive([])
144
self.assertIsNot(None, md.bundle)
145
self.assertIsNot(None, md.patch)
147
md = self.send_directive(['--format=0.9'])
148
self.assertIsNot(None, md.bundle)
149
self.assertIsNot(None, md.patch)
151
md = self.send_directive(['--no-patch'])
143
152
self.assertIsNot(None, md.bundle)
144
153
self.assertIs(None, md.patch)
145
154
self.run_bzr_error(['Format 0.9 does not permit bundle with no patch'],
146
['send', '--no-patch', '--format=0.9', '-o-'],
147
working_dir='branch')
148
md = self.get_MD(['--no-bundle', '.', '.'])
155
'send --no-patch --format=0.9 -o-')
157
md = self.send_directive(['--no-bundle', '.', '.'])
149
158
self.assertIs(None, md.bundle)
150
159
self.assertIsNot(None, md.patch)
152
md = self.get_MD(['--no-bundle', '--format=0.9', '../parent',
161
md = self.send_directive(['--no-bundle', '--format=0.9', '../parent',
154
163
self.assertIs(None, md.bundle)
155
164
self.assertIsNot(None, md.patch)
157
md = self.get_MD(['--no-bundle', '--no-patch', '.', '.'])
166
md = self.send_directive(['--no-bundle', '--no-patch', '.', '.'])
158
167
self.assertIs(None, md.bundle)
159
168
self.assertIs(None, md.patch)
161
md = self.get_MD(['--no-bundle', '--no-patch', '--format=0.9',
170
md = self.send_directive(['--no-bundle', '--no-patch', '--format=0.9',
163
172
self.assertIs(None, md.bundle)
164
173
self.assertIs(None, md.patch)
166
175
def test_from_option(self):
167
177
self.run_bzr('send', retcode=3)
168
md = self.get_MD(['--from', 'branch'])
169
self.assertEqual('rev3', md.revision_id)
170
md = self.get_MD(['-f', 'branch'])
171
self.assertEqual('rev3', md.revision_id)
178
md = self.send_directive(['--from', 'branch'])
179
self.assertEqual('revision3', md.revision_id)
180
md = self.send_directive(['-f', 'branch'])
181
self.assertEqual('revision3', md.revision_id)
173
183
def test_output_option(self):
174
185
stdout = self.run_bzr('send -f branch --output file1')[0]
175
186
self.assertEqual('', stdout)
176
187
md_file = open('file1', 'rb')
177
188
self.addCleanup(md_file.close)
178
self.assertContainsRe(md_file.read(), 'rev3')
189
self.assertContainsRe(md_file.read(), 'revision3')
179
190
stdout = self.run_bzr('send -f branch --output -')[0]
180
self.assertContainsRe(stdout, 'rev3')
191
self.assertContainsRe(stdout, 'revision3')
182
193
def test_note_revisions(self):
183
stderr = self.run_send([])[1]
184
self.assertEndsWith(stderr, '\nBundling 1 revision(s).\n')
195
stderr = self.run_bzr('send -f branch --output file1')[1]
196
self.assertContainsRe(stderr, r'Bundling 1 revision\(s\).\n')
186
198
def test_mailto_option(self):
187
b = branch.Branch.open('branch')
188
b.get_config().set_user_option('mail_client', 'editor')
200
branch = _mod_branch.Branch.open('branch')
201
branch.get_config().set_user_option('mail_client', 'editor')
189
202
self.run_bzr_error(
190
203
('No mail-to address \\(--mail-to\\) or output \\(-o\\) specified',
191
204
), 'send -f branch')
192
b.get_config().set_user_option('mail_client', 'bogus')
205
branch.get_config().set_user_option('mail_client', 'bogus')
206
self.run_bzr('send -f branch -o-')
194
207
self.run_bzr_error(('Unknown mail client: bogus',),
195
208
'send -f branch --mail-to jrandom@example.org')
196
b.get_config().set_user_option('submit_to', 'jrandom@example.org')
209
branch.get_config().set_user_option('submit_to', 'jrandom@example.org')
197
210
self.run_bzr_error(('Unknown mail client: bogus',),
198
211
'send -f branch')
200
213
def test_mailto_child_option(self):
201
214
"""Make sure that child_submit_to is used."""
202
b = branch.Branch.open('branch')
203
b.get_config().set_user_option('mail_client', 'bogus')
204
parent = branch.Branch.open('parent')
216
branch = _mod_branch.Branch.open('branch')
217
branch.get_config().set_user_option('mail_client', 'bogus')
218
parent = _mod_branch.Branch.open('parent')
205
219
parent.get_config().set_user_option('child_submit_to',
206
220
'somebody@example.org')
207
221
self.run_bzr_error(('Unknown mail client: bogus',),
208
222
'send -f branch')
210
224
def test_format(self):
211
md = self.get_MD(['--format=4'])
226
s = StringIO(self.run_bzr('send -f branch -o- --format=4')[0])
227
md = merge_directive.MergeDirective.from_lines(s.readlines())
212
228
self.assertIs(merge_directive.MergeDirective2, md.__class__)
213
self.assertFormatIs('# Bazaar revision bundle v4', md)
215
md = self.get_MD(['--format=0.9'])
216
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
218
md = self.get_MD(['--format=0.9'], cmd=['bundle'])
219
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
229
s = StringIO(self.run_bzr('send -f branch -o- --format=0.9')[0])
230
md = merge_directive.MergeDirective.from_lines(s.readlines())
231
self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
232
'# Bazaar revision bundle v0.9')
233
s = StringIO(self.run_bzr('bundle -f branch -o- --format=0.9')[0])
234
md = merge_directive.MergeDirective.from_lines(s.readlines())
235
self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
236
'# Bazaar revision bundle v0.9')
220
237
self.assertIs(merge_directive.MergeDirective, md.__class__)
222
238
self.run_bzr_error(['Bad value .* for option .format.'],
223
239
'send -f branch -o- --format=0.999')[0]
225
241
def test_format_child_option(self):
226
parent_config = branch.Branch.open('parent').get_config()
227
parent_config.set_user_option('child_submit_format', '4')
243
parent = _mod_branch.Branch.open('parent')
244
parent.get_config().set_user_option('child_submit_format', '4')
245
s = StringIO(self.run_bzr('send -f branch -o-')[0])
246
md = merge_directive.MergeDirective.from_lines(s.readlines())
229
247
self.assertIs(merge_directive.MergeDirective2, md.__class__)
231
parent_config.set_user_option('child_submit_format', '0.9')
233
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
235
md = self.get_MD([], cmd=['bundle'])
236
self.assertFormatIs('# Bazaar revision bundle v0.9', md)
248
parent.get_config().set_user_option('child_submit_format', '0.9')
249
s = StringIO(self.run_bzr('send -f branch -o-')[0])
250
md = merge_directive.MergeDirective.from_lines(s.readlines())
251
self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
252
'# Bazaar revision bundle v0.9')
253
s = StringIO(self.run_bzr('bundle -f branch -o-')[0])
254
md = merge_directive.MergeDirective.from_lines(s.readlines())
255
self.assertContainsRe(md.get_raw_bundle().splitlines()[0],
256
'# Bazaar revision bundle v0.9')
237
257
self.assertIs(merge_directive.MergeDirective, md.__class__)
239
parent_config.set_user_option('child_submit_format', '0.999')
258
parent.get_config().set_user_option('child_submit_format', '0.999')
240
259
self.run_bzr_error(["No such send format '0.999'"],
241
260
'send -f branch -o-')[0]
243
262
def test_message_option(self):
244
264
self.run_bzr('send', retcode=3)
265
md = self.send_directive(['--from', 'branch'])
246
266
self.assertIs(None, md.message)
247
md = self.get_MD(['-m', 'my message'])
267
md = self.send_directive(['--from', 'branch', '-m', 'my message'])
248
268
self.assertEqual('my message', md.message)
250
270
def test_omitted_revision(self):
251
md = self.get_MD(['-r-2..'])
252
self.assertEqual('rev2', md.base_revision_id)
253
self.assertEqual('rev3', md.revision_id)
254
md = self.get_MD(['-r..3', '--from', 'branch', 'grandparent'], wd='.')
255
self.assertEqual('rev1', md.base_revision_id)
256
self.assertEqual('rev3', md.revision_id)
272
md = self.send_directive(['-r-2..', '--from', 'branch'])
273
self.assertEqual('revision2', md.base_revision_id)
274
self.assertEqual('revision3', md.revision_id)
275
md = self.send_directive(['-r..3', '--from', 'branch',
277
self.assertEqual('revision1', md.base_revision_id)
278
self.assertEqual('revision3', md.revision_id)
258
280
def test_nonexistant_branch(self):
259
281
if sys.platform == "win32":