16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
from cStringIO import StringIO
24
from ...controldir import ControlDir
25
from ...bundle import serializer
26
from ...sixish import (
29
from ...transport import memory
26
from bzrlib.controldir import ControlDir
27
from bzrlib.bundle import serializer
28
from bzrlib.transport import memory
29
from bzrlib.tests import (
33
from ..matchers import ContainsNoVfsCalls
32
from bzrlib.tests.matchers import ContainsNoVfsCalls
36
35
load_tests = scenarios.load_tests_apply_scenarios
50
49
error_regexes=err_re)
52
51
def get_MD(self, args, cmd=None, wd='branch'):
53
out = BytesIO(self.run_send(args, cmd=cmd, wd=wd)[0])
52
out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
54
53
return merge_directive.MergeDirective.from_lines(out)
56
55
def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
57
56
md = self.get_MD(args, cmd=cmd, wd=wd)
58
br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
57
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
59
58
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
65
64
super(TestSend, self).setUp()
66
65
grandparent_tree = ControlDir.create_standalone_workingtree(
68
self.build_tree_contents([('grandparent/file1', b'grandparent')])
67
self.build_tree_contents([('grandparent/file1', 'grandparent')])
69
68
grandparent_tree.add('file1')
70
grandparent_tree.commit('initial commit', rev_id=b'rev1')
69
grandparent_tree.commit('initial commit', rev_id='rev1')
72
parent_bzrdir = grandparent_tree.controldir.sprout('parent')
71
parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
73
72
parent_tree = parent_bzrdir.open_workingtree()
74
parent_tree.commit('next commit', rev_id=b'rev2')
73
parent_tree.commit('next commit', rev_id='rev2')
76
branch_tree = parent_tree.controldir.sprout('branch').open_workingtree()
77
self.build_tree_contents([('branch/file1', b'branch')])
78
branch_tree.commit('last commit', rev_id=b'rev3')
75
branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
76
self.build_tree_contents([('branch/file1', 'branch')])
77
branch_tree.commit('last commit', rev_id='rev3')
80
79
def assertFormatIs(self, fmt_string, md):
81
80
self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
268
267
location = self.get_url('absentdir/')
269
268
out, err = self.run_bzr(["send", "--from", location], retcode=3)
270
269
self.assertEqual(out, '')
271
self.assertEqual(err, 'brz: ERROR: Not a branch: "%s".\n' % location)
270
self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
274
273
class TestSendStrictMixin(TestSendMixin):
276
275
def make_parent_and_local_branches(self):
277
276
# Create a 'parent' branch as the base
278
277
self.parent_tree = ControlDir.create_standalone_workingtree('parent')
279
self.build_tree_contents([('parent/file', b'parent')])
278
self.build_tree_contents([('parent/file', 'parent')])
280
279
self.parent_tree.add('file')
281
self.parent_tree.commit('first commit', rev_id=b'parent')
280
self.parent_tree.commit('first commit', rev_id='parent')
282
281
# Branch 'local' from parent and do a change
283
local_bzrdir = self.parent_tree.controldir.sprout('local')
282
local_bzrdir = self.parent_tree.bzrdir.sprout('local')
284
283
self.local_tree = local_bzrdir.open_workingtree()
285
self.build_tree_contents([('local/file', b'local')])
286
self.local_tree.commit('second commit', rev_id=b'local')
284
self.build_tree_contents([('local/file', 'local')])
285
self.local_tree.commit('second commit', rev_id='local')
288
287
_default_command = ['send', '-o-', '../parent']
289
288
_default_wd = 'local'
290
289
_default_sent_revs = ['local']
291
290
_default_errors = ['Working tree ".*/local/" has uncommitted '
292
'changes \(See brz status\)\.',]
291
'changes \(See bzr status\)\.',]
293
292
_default_additional_error = 'Use --no-strict to force the send.\n'
294
293
_default_additional_warning = 'Uncommitted changes will not be sent.'
317
316
self.assertContainsRe(err, self._default_additional_warning)
318
317
self.assertEndsWith(err, bundling_revs)
320
self.assertEqual(bundling_revs, err)
321
md = merge_directive.MergeDirective.from_lines(BytesIO(out))
319
self.assertEquals(bundling_revs, err)
320
md = merge_directive.MergeDirective.from_lines(StringIO(out))
322
321
self.assertEqual('parent', md.base_revision_id)
323
br = serializer.read_bundle(BytesIO(md.get_raw_bundle()))
322
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
324
323
self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
380
379
def _uncommitted_changes(self):
381
380
self.make_parent_and_local_branches()
382
381
# Make a change without committing it
383
self.build_tree_contents([('local/file', b'modified')])
382
self.build_tree_contents([('local/file', 'modified')])
385
384
def _pending_merges(self):
386
385
self.make_parent_and_local_branches()
387
386
# Create 'other' branch containing a new file
388
other_bzrdir = self.parent_tree.controldir.sprout('other')
387
other_bzrdir = self.parent_tree.bzrdir.sprout('other')
389
388
other_tree = other_bzrdir.open_workingtree()
390
self.build_tree_contents([('other/other-file', b'other')])
389
self.build_tree_contents([('other/other-file', 'other')])
391
390
other_tree.add('other-file')
392
other_tree.commit('other commit', rev_id=b'other')
391
other_tree.commit('other commit', rev_id='other')
393
392
# Merge and revert, leaving a pending merge
394
393
self.local_tree.merge_from_branch(other_tree.branch)
395
394
self.local_tree.revert(filenames=['other-file'], backups=False)
398
397
self.make_parent_and_local_branches()
399
398
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
400
399
# Make a change and commit it
401
self.build_tree_contents([('local/file', b'modified in local')])
402
self.local_tree.commit('modify file', rev_id=b'modified-in-local')
400
self.build_tree_contents([('local/file', 'modified in local')])
401
self.local_tree.commit('modify file', rev_id='modified-in-local')
403
402
# Exercise commands from the checkout directory
404
403
self._default_wd = 'checkout'
405
404
self._default_errors = ["Working tree is out of date, please run"
407
406
self._default_sent_revs = ['modified-in-local', 'local']
409
408
def test_send_default(self):
448
447
def test_send(self):
449
448
self.setup_smart_server_with_call_log()
450
449
t = self.make_branch_and_tree('branch')
451
self.build_tree_contents([('branch/foo', b'thecontents')])
450
self.build_tree_contents([('branch/foo', 'thecontents')])
453
452
t.commit("message")
454
local = t.controldir.sprout('local-branch').open_workingtree()
455
self.build_tree_contents([('branch/foo', b'thenewcontents')])
453
local = t.bzrdir.sprout('local-branch').open_workingtree()
454
self.build_tree_contents([('branch/foo', 'thenewcontents')])
456
455
local.commit("anothermessage")
457
456
self.reset_smart_call_log()
458
457
out, err = self.run_bzr(