26
OUTPUT1 = """# Bazaar merge directive format experimental-1
27
# revision_id: example:
28
# target_branch: http://example.com
30
# timestamp: 1970-01-01 00:09:33 +0002
35
OUTPUT2 = """# Bazaar merge directive format experimental-1
36
# revision_id: example:
37
# target_branch: http://example.com
39
# timestamp: 1970-01-01 00:09:33 +0002
40
# source_branch: http://example.org
26
46
class TestMergeDirective(tests.TestCase):
48
def test_merge_source(self):
31
51
self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
33
53
self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
34
54
'example:', 'sha', time, timezone, 'http://example.com',
36
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
56
merge_directive.MergeDirective('example:', 'sha', time, timezone,
37
57
'http://example.com', source_branch='http://example.org')
38
self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
39
'example:', 'sha', time, timezone, 'http://example.com',
41
58
md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
42
59
'http://example.com', patch='blah', patch_type='bundle')
60
self.assertIs(None, md.source_branch)
61
md2 = merge_directive.MergeDirective('null:', 'sha', time, timezone,
62
'http://example.com', patch='blah', patch_type='bundle',
64
self.assertEqual('bar', md2.source_branch)
66
def test_require_patch(self):
43
69
self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
44
70
'example:', 'sha', time, timezone, 'http://example.com',
45
source_branch="http://example.org", patch_type='diff')
46
72
md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
47
73
'http://example.com', source_branch="http://example.org",
48
74
patch='', patch_type='diff')
75
self.assertEqual(md.patch, '')
50
77
def test_serialization(self):
53
80
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
81
'http://example.com', patch='booga', patch_type='bundle')
82
self.assertEqualDiff(OUTPUT1, ''.join(md.to_lines()))
83
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
84
'http://example.com', source_branch="http://example.org",
85
patch='booga', patch_type='diff', message="Hi mom!")
86
self.assertEqualDiff(OUTPUT2, ''.join(md.to_lines()))
88
def test_roundtrip(self):
91
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
54
92
'http://example.com', source_branch="http://example.org",
55
93
patch='booga', patch_type='diff')
56
94
md2 = merge_directive.MergeDirective.from_lines(md.to_lines())
116
154
tree_a.commit('Commit of rev2a', rev_id='rev2a')
117
155
return tree_a, tree_b, branch_c
119
def test_generate(self):
157
def test_generate_patch(self):
158
tree_a, tree_b, branch_c = self.make_trees()
159
md2 = merge_directive.MergeDirective.from_objects(
160
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
161
patch_type='diff', public_branch=tree_a.branch.base)
162
self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
163
self.assertContainsRe(md2.patch, '\\+content_c')
164
self.assertNotContainsRe(md2.patch, '\\+\\+\\+ b/')
165
self.assertContainsRe(md2.patch, '\\+\\+\\+ file')
167
def test_public_branch(self):
120
168
tree_a, tree_b, branch_c = self.make_trees()
121
169
self.assertRaises(errors.PublicBranchOutOfDate,
122
170
merge_directive.MergeDirective.from_objects,
126
174
md1 = merge_directive.MergeDirective.from_objects(
127
175
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
128
176
public_branch=branch_c.base)
129
self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
130
self.assertContainsRe(md1.patch, '\\+content_c')
131
self.assertNotContainsRe(md1.patch, '\\+content_a')
132
177
# public branch is provided with a bundle, despite possibly being out
133
178
# of date, because it's not required if a bundle is present.
134
179
self.assertEqual(md1.source_branch, branch_c.base)
180
# Once we update the public branch, we can generate a diff.
135
181
branch_c.pull(tree_a.branch)
136
md2 = merge_directive.MergeDirective.from_objects(
182
md3 = merge_directive.MergeDirective.from_objects(
137
183
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
138
patch_type='diff', public_branch=branch_c.base)
139
self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
140
self.assertContainsRe(md1.patch, '\\+content_c')
141
self.assertNotContainsRe(md1.patch, '\\+content_a')
184
patch_type=None, public_branch=branch_c.base)
186
def test_message(self):
187
tree_a, tree_b, branch_c = self.make_trees()
142
188
md3 = merge_directive.MergeDirective.from_objects(
143
189
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
144
190
patch_type=None, public_branch=branch_c.base,
147
193
self.assertIs(None, md3.patch)
148
194
self.assertEqual('Merge message', md3.message)
150
def test_generate_patch(self):
196
def test_generate_bundle(self):
151
197
tree_a, tree_b, branch_c = self.make_trees()
152
md2 = merge_directive.MergeDirective.from_objects(
198
md1 = merge_directive.MergeDirective.from_objects(
153
199
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
154
patch_type='diff', public_branch=tree_a.branch.base)
155
self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
156
self.assertContainsRe(md2.patch, '\\+content_c')
157
self.assertNotContainsRe(md2.patch, '\\+\\+\\+ b/')
158
self.assertContainsRe(md2.patch, '\\+\\+\\+ file')
200
public_branch=branch_c.base)
201
self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
202
self.assertContainsRe(md1.patch, '\\+content_c')
203
self.assertNotContainsRe(md1.patch, '\\+content_a')
204
self.assertContainsRe(md1.patch, '\\+content_c')
205
self.assertNotContainsRe(md1.patch, '\\+content_a')
160
207
def test_signing(self):