20
20
from StringIO import StringIO
22
from bzrlib.bundle.serializer import read_bundle
22
from bzrlib import merge_directive
23
from bzrlib.bundle import serializer
23
24
from bzrlib.bzrdir import BzrDir
24
25
from bzrlib import tests
27
class TestBundle(tests.TestCaseWithTransport):
28
def read_bundle(fileobj):
29
md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
30
return serializer.read_bundle(StringIO(md.get_raw_bundle()))
33
class TestSubmit(tests.TestCaseWithTransport):
29
35
def make_trees(self):
30
36
grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
39
45
"""Parent location is used as a basis by default"""
41
47
os.chdir('grandparent')
42
errmsg = self.run_bzr('bundle', retcode=3)[1]
43
self.assertContainsRe(errmsg, 'No base branch known or specified')
48
errmsg = self.run_bzr('submit', retcode=3)[1]
49
self.assertContainsRe(errmsg, 'No submit branch known or specified')
44
50
os.chdir('../branch')
45
stdout, stderr = self.run_bzr('bundle')
51
stdout, stderr = self.run_bzr('submit')
46
52
self.assertEqual(stderr.count('Using saved location'), 1)
47
53
br = read_bundle(StringIO(stdout))
48
54
self.assertRevisions(br, ['revision3'])
50
56
def assertRevisions(self, bi, expected):
51
self.assertEqual([r.revision_id for r in bi.revisions], expected)
57
self.assertEqual(set(r.revision_id for r in bi.revisions),
53
60
def test_uses_submit(self):
54
61
"""Submit location can be used and set"""
57
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
64
br = read_bundle(StringIO(self.run_bzr('submit')[0]))
58
65
self.assertRevisions(br, ['revision3'])
59
br = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0]))
66
br = read_bundle(StringIO(self.run_bzr('submit ../grandparent')[0]))
60
67
self.assertRevisions(br, ['revision3', 'revision2'])
61
68
# submit location should be auto-remembered
62
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
63
self.assertRevisions(br, ['revision3', 'revision2'])
64
self.run_bzr('bundle ../parent')
65
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
66
self.assertRevisions(br, ['revision3', 'revision2'])
67
self.run_bzr('bundle ../parent --remember')
69
br = read_bundle(StringIO(self.run_bzr('submit')[0]))
70
self.assertRevisions(br, ['revision3', 'revision2'])
71
self.run_bzr('submit ../parent')
72
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
73
self.assertRevisions(br, ['revision3', 'revision2'])
74
self.run_bzr('submit ../parent --remember')
68
75
br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
69
76
self.assertRevisions(br, ['revision3'])
70
err = self.run_bzr('bundle --remember', retcode=3)[1]
71
self.assertContainsRe(err,
77
err = self.run_bzr('submit --remember', retcode=3)[1]
78
self.assertContainsRe(err,
72
79
'--remember requires a branch to be specified.')
74
81
def test_revision_branch_interaction(self):
77
84
bi = read_bundle(StringIO(self.run_bzr('bundle ../grandparent')[0]))
78
85
self.assertRevisions(bi, ['revision3', 'revision2'])
79
out = StringIO(self.run_bzr('bundle ../grandparent -r -2')[0])
86
out = StringIO(self.run_bzr('submit ../grandparent -r -2')[0])
80
87
bi = read_bundle(out)
81
88
self.assertRevisions(bi, ['revision2'])
82
bi = read_bundle(StringIO(self.run_bzr('bundle -r -2..-1')[0]))
83
self.assertRevisions(bi, ['revision3'])
84
self.run_bzr('bundle ../grandparent -r -2..-1', retcode=3)
89
sio = StringIO(self.run_bzr('submit -r -2..-1')[0])
90
md = merge_directive.MergeDirective.from_lines(sio.readlines())
91
self.assertEqual('revision2', md.base_revision_id)
92
self.assertEqual('revision3', md.revision_id)
95
self.assertRevisions(bi, ['revision2', 'revision3'])
96
self.run_bzr('submit ../grandparent -r -2..-1')
86
98
def test_output(self):
87
99
# check output for consistency
88
100
# win32 stdout converts LF to CRLF,
89
# and this is breaks the created bundle
101
# which would break patch-based bundles
91
103
os.chdir('branch')
92
stdout = self.run_bzr_subprocess('bundle')[0]
104
stdout = self.run_bzr_subprocess('submit')[0]
93
105
br = read_bundle(StringIO(stdout))
94
106
self.assertRevisions(br, ['revision3'])
96
108
def test_no_common_ancestor(self):
97
109
foo = self.make_branch_and_tree('foo')
98
111
bar = self.make_branch_and_tree('bar')
100
self.run_bzr('bundle ../bar')
114
self.run_bzr('submit ../bar')
116
def submit_directive(self, args):
117
sio = StringIO(self.run_bzr(['submit'] + args)[0])
118
return merge_directive.MergeDirective.from_lines(sio.readlines())
120
def test_content_options(self):
121
"""--no-patch and --no-bundle should work and be independant"""
124
md = self.submit_directive([])
125
self.assertIsNot(None, md.bundle)
126
self.assertIsNot(None, md.patch)
127
md = self.submit_directive(['--no-patch'])
128
self.assertIsNot(None, md.bundle)
129
self.assertIs(None, md.patch)
130
md = self.submit_directive(['--no-bundle', '.', '.'])
131
self.assertIs(None, md.bundle)
132
self.assertIsNot(None, md.patch)
133
md = self.submit_directive(['--no-bundle', '--no-patch', '.', '.'])
134
self.assertIs(None, md.bundle)
135
self.assertIs(None, md.patch)
137
def test_from_option(self):
139
self.run_bzr('submit', retcode=3)
140
md = self.submit_directive(['--from', 'branch'])
141
self.assertEqual('revision3', md.revision_id)
142
md = self.submit_directive(['-f', 'branch'])
143
self.assertEqual('revision3', md.revision_id)
145
def test_output_option(self):
147
stdout = self.run_bzr('submit -f branch --output file1')[0]
148
self.assertEqual('', stdout)
149
md_file = open('file1', 'rb')
150
self.addCleanup(md_file.close)
151
self.assertContainsRe(md_file.read(), 'revision3')