86
65
booga""".splitlines(True)
90
I was thinking today about creating a merge directive.
96
(I've pasted it in the body of this message)
100
# Bazaar merge directive format 2 (Bazaar 0.90)\r
101
# revision_id: example:
102
# target_branch: http://example.com
103
# testament_sha1: sha
104
# timestamp: 1970-01-01 00:09:33 +0002
105
# source_branch: http://example.org
106
# base_revision_id: null:
110
booga""".splitlines(True)
114
I was thinking today about creating a merge directive.
120
(I've pasted it in the body of this message)
124
# Bazaar merge directive format 2 (Bazaar 0.19)\r
125
# revision_id: example:
126
# target_branch: http://example.com
127
# testament_sha1: sha
128
# timestamp: 1970-01-01 00:09:33 +0002
129
# source_branch: http://example.org
130
# base_revision_id: null:
134
booga""".splitlines(True)
137
OLD_DIRECTIVE_2 = """# Bazaar merge directive format 2 (Bazaar 0.19)
138
# revision_id: abentley@panoramicfeedback.com-20070807234458-\
140
# target_branch: http://panoramicfeedback.com/opensource/bzr/repo\
142
# testament_sha1: d825a5cdb267a90ec2ba86b00895f3d8a9bed6bf
143
# timestamp: 2007-08-10 16:15:02 -0400
144
# source_branch: http://panoramicfeedback.com/opensource/bzr/repo\
146
# base_revision_id: abentley@panoramicfeedback.com-20070731163346-\
152
class TestMergeDirective(object):
68
class TestMergeDirective(tests.TestCase):
154
70
def test_merge_source(self):
157
self.assertRaises(errors.NoMergeSource, self.make_merge_directive,
73
self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
158
74
'example:', 'sha', time, timezone, 'http://example.com')
159
self.assertRaises(errors.NoMergeSource, self.make_merge_directive,
75
self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
160
76
'example:', 'sha', time, timezone, 'http://example.com',
161
77
patch_type='diff')
162
self.make_merge_directive('example:', 'sha', time, timezone,
78
merge_directive.MergeDirective('example:', 'sha', time, timezone,
163
79
'http://example.com', source_branch='http://example.org')
164
md = self.make_merge_directive('null:', 'sha', time, timezone,
80
md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
165
81
'http://example.com', patch='blah', patch_type='bundle')
166
82
self.assertIs(None, md.source_branch)
167
md2 = self.make_merge_directive('null:', 'sha', time, timezone,
83
md2 = merge_directive.MergeDirective('null:', 'sha', time, timezone,
168
84
'http://example.com', patch='blah', patch_type='bundle',
169
85
source_branch='bar')
170
86
self.assertEqual('bar', md2.source_branch)
88
def test_require_patch(self):
91
self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
92
'example:', 'sha', time, timezone, 'http://example.com',
94
md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
95
'http://example.com', source_branch="http://example.org",
96
patch='', patch_type='diff')
97
self.assertEqual(md.patch, '')
172
99
def test_serialization(self):
175
md = self.make_merge_directive('example:', 'sha', time, timezone,
102
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
176
103
'http://example.com', patch='booga', patch_type='bundle')
177
self.assertEqualDiff(self.OUTPUT1, ''.join(md.to_lines()))
178
md = self.make_merge_directive('example:', 'sha', time, timezone,
104
self.assertEqualDiff(OUTPUT1, ''.join(md.to_lines()))
105
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
179
106
'http://example.com', source_branch="http://example.org",
180
107
patch='booga', patch_type='diff', message="Hi mom!")
181
self.assertEqualDiff(self.OUTPUT2, ''.join(md.to_lines()))
108
self.assertEqualDiff(OUTPUT2, ''.join(md.to_lines()))
183
110
def test_deserialize_junk(self):
185
111
self.assertRaises(errors.NotAMergeDirective,
186
112
merge_directive.MergeDirective.from_lines, 'lala')
218
144
self.assertEqual('diff', md2.patch_type)
219
145
self.assertEqual('booga', md2.patch)
220
146
self.assertEqual(None, md2.message)
221
self.set_bundle(md, "# Bazaar revision bundle v0.9\n#\n")
147
md.patch = "# Bazaar revision bundle v0.9\n#\n"
222
148
md.message = "Hi mom!"
223
lines = md.to_lines()
224
md3 = merge_directive.MergeDirective.from_lines(lines)
225
self.assertEqual("# Bazaar revision bundle v0.9\n#\n", md3.bundle)
149
md3 = merge_directive.MergeDirective.from_lines(md.to_lines())
150
self.assertEqual("# Bazaar revision bundle v0.9\n#\n", md3.patch)
226
151
self.assertEqual("bundle", md3.patch_type)
227
152
self.assertContainsRe(md3.to_lines()[0],
228
153
'^# Bazaar merge directive format ')
229
154
self.assertEqual("Hi mom!", md3.message)
231
self.assertIs(None, md3.get_raw_bundle())
155
md3.patch_type = None
232
157
md4 = merge_directive.MergeDirective.from_lines(md3.to_lines())
233
158
self.assertIs(None, md4.patch_type)
236
class TestMergeDirective1(tests.TestCase, TestMergeDirective):
237
"""Test merge directive format 1"""
245
def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
246
target_branch, patch=None, patch_type=None,
247
source_branch=None, message=None):
248
return merge_directive.MergeDirective(revision_id, testament_sha1,
249
time, timezone, target_branch, patch, patch_type,
250
source_branch, message)
253
def set_bundle(md, value):
256
def test_require_patch(self):
259
self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
260
'example:', 'sha', time, timezone, 'http://example.com',
262
md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
263
'http://example.com', source_branch="http://example.org",
264
patch='', patch_type='diff')
265
self.assertEqual(md.patch, '')
268
class TestMergeDirective2(tests.TestCase, TestMergeDirective):
269
"""Test merge directive format 2"""
277
def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
278
target_branch, patch=None, patch_type=None,
279
source_branch=None, message=None, base_revision_id='null:'):
280
if patch_type == 'bundle':
285
return merge_directive.MergeDirective2(revision_id, testament_sha1,
286
time, timezone, target_branch, patch, source_branch, message,
287
bundle, base_revision_id)
290
def set_bundle(md, value):
294
EMAIL1 = """From: "J. Random Hacker" <jrandom@example.com>
295
Subject: Commit of rev2a
297
User-Agent: Bazaar \(.*\)
299
# Bazaar merge directive format 1
301
# target_branch: (.|\n)*
303
# timestamp: 1970-01-01 00:08:56 \\+0001
304
# source_branch: (.|\n)*
308
EMAIL1_2 = """From: "J. Random Hacker" <jrandom@example.com>
309
Subject: Commit of rev2a
311
User-Agent: Bazaar \(.*\)
313
# Bazaar merge directive format 2 \\(Bazaar 0.90\\)
315
# target_branch: (.|\n)*
317
# timestamp: 1970-01-01 00:08:56 \\+0001
318
# source_branch: (.|\n)*
322
EMAIL2 = """From: "J. Random Hacker" <jrandom@example.com>
323
Subject: Commit of rev2a with special message
325
User-Agent: Bazaar \(.*\)
327
# Bazaar merge directive format 1
329
# target_branch: (.|\n)*
331
# timestamp: 1970-01-01 00:08:56 \\+0001
332
# source_branch: (.|\n)*
333
# message: Commit of rev2a with special message
336
EMAIL2_2 = """From: "J. Random Hacker" <jrandom@example.com>
337
Subject: Commit of rev2a with special message
339
User-Agent: Bazaar \(.*\)
341
# Bazaar merge directive format 2 \\(Bazaar 0.90\\)
343
# target_branch: (.|\n)*
345
# timestamp: 1970-01-01 00:08:56 \\+0001
346
# source_branch: (.|\n)*
347
# message: Commit of rev2a with special message
350
class TestMergeDirectiveBranch(object):
161
EMAIL1 = """To: pqm@example.com
162
From: J. Random Hacker <jrandom@example.com>
163
Subject: Commit of rev2a
165
# Bazaar merge directive format 1
167
# target_branch: (.|\n)*
169
# timestamp: 1970-01-01 00:08:56 \\+0001
170
# source_branch: (.|\n)*
174
EMAIL2 = """To: pqm@example.com
175
From: J. Random Hacker <jrandom@example.com>
176
Subject: Commit of rev2a with special message
178
# Bazaar merge directive format 1
180
# target_branch: (.|\n)*
182
# timestamp: 1970-01-01 00:08:56 \\+0001
183
# source_branch: (.|\n)*
184
# message: Commit of rev2a with special message
188
class TestMergeDirectiveBranch(tests.TestCaseWithTransport):
352
190
def make_trees(self):
353
191
tree_a = self.make_branch_and_tree('tree_a')
354
192
tree_a.branch.get_config().set_user_option('email',
355
193
'J. Random Hacker <jrandom@example.com>')
356
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n'),
357
('tree_a/file_2', 'content_x\rcontent_y\r')])
358
tree_a.add(['file', 'file_2'])
194
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
359
196
tree_a.commit('message', rev_id='rev1')
360
197
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
361
198
branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
362
199
tree_b.commit('message', rev_id='rev2b')
363
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c \n'),
364
('tree_a/file_2', 'content_x\rcontent_z\r')])
200
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c\n')])
365
201
tree_a.commit('Commit of rev2a', rev_id='rev2a')
366
202
return tree_a, tree_b, branch_c
368
def test_empty_target(self):
369
tree_a, tree_b, branch_c = self.make_trees()
370
tree_d = self.make_branch_and_tree('tree_d')
371
md2 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
372
tree_d.branch.base, patch_type='diff',
373
public_branch=tree_a.branch.base)
375
def test_disk_name(self):
376
tree_a, tree_b, branch_c = self.make_trees()
377
tree_a.branch.nick = 'fancy <name>'
378
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
380
self.assertEqual('fancy-name-2', md.get_disk_name(tree_a.branch))
382
def test_disk_name_old_revno(self):
383
tree_a, tree_b, branch_c = self.make_trees()
384
tree_a.branch.nick = 'fancy-name'
385
md = self.from_objects(tree_a.branch.repository, 'rev1', 500, 120,
387
self.assertEqual('fancy-name-1', md.get_disk_name(tree_a.branch))
389
204
def test_generate_patch(self):
390
205
tree_a, tree_b, branch_c = self.make_trees()
391
md2 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
392
tree_b.branch.base, patch_type='diff',
393
public_branch=tree_a.branch.base)
206
md2 = merge_directive.MergeDirective.from_objects(
207
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
208
patch_type='diff', public_branch=tree_a.branch.base)
394
209
self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
395
210
self.assertContainsRe(md2.patch, '\\+content_c')
396
211
self.assertNotContainsRe(md2.patch, '\\+\\+\\+ b/')
399
214
def test_public_branch(self):
400
215
tree_a, tree_b, branch_c = self.make_trees()
401
216
self.assertRaises(errors.PublicBranchOutOfDate,
402
self.from_objects, tree_a.branch.repository, 'rev2a', 500, 144,
403
tree_b.branch.base, public_branch=branch_c.base, patch_type='diff')
404
self.assertRaises(errors.PublicBranchOutOfDate,
405
self.from_objects, tree_a.branch.repository, 'rev2a', 500, 144,
406
tree_b.branch.base, public_branch=branch_c.base, patch_type=None)
217
merge_directive.MergeDirective.from_objects,
218
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
219
public_branch=branch_c.base, patch_type='diff')
407
220
# public branch is not checked if patch format is bundle.
408
md1 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 144,
409
tree_b.branch.base, public_branch=branch_c.base)
221
md1 = merge_directive.MergeDirective.from_objects(
222
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
223
public_branch=branch_c.base)
410
224
# public branch is provided with a bundle, despite possibly being out
411
225
# of date, because it's not required if a bundle is present.
412
226
self.assertEqual(md1.source_branch, branch_c.base)
413
227
# Once we update the public branch, we can generate a diff.
414
228
branch_c.pull(tree_a.branch)
415
md3 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 144,
416
tree_b.branch.base, patch_type=None, public_branch=branch_c.base)
229
md3 = merge_directive.MergeDirective.from_objects(
230
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
231
patch_type=None, public_branch=branch_c.base)
418
233
def test_use_public_submit_branch(self):
419
234
tree_a, tree_b, branch_c = self.make_trees()
420
235
branch_c.pull(tree_a.branch)
421
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 144,
422
tree_b.branch.base, patch_type=None, public_branch=branch_c.base)
236
md = merge_directive.MergeDirective.from_objects(
237
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
238
patch_type=None, public_branch=branch_c.base)
423
239
self.assertEqual(md.target_branch, tree_b.branch.base)
424
240
tree_b.branch.set_public_branch('http://example.com')
425
md2 = self.from_objects(
241
md2 = merge_directive.MergeDirective.from_objects(
426
242
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
427
243
patch_type=None, public_branch=branch_c.base)
428
244
self.assertEqual(md2.target_branch, 'http://example.com')
430
246
def test_message(self):
431
247
tree_a, tree_b, branch_c = self.make_trees()
432
md3 = self.from_objects(tree_a.branch.repository, 'rev1', 500, 120,
433
tree_b.branch.base, patch_type=None, public_branch=branch_c.base,
248
md3 = merge_directive.MergeDirective.from_objects(
249
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
250
patch_type=None, public_branch=branch_c.base,
434
251
message='Merge message')
436
253
self.assertIs(None, md3.patch)
439
256
def test_generate_bundle(self):
440
257
tree_a, tree_b, branch_c = self.make_trees()
441
md1 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
442
tree_b.branch.base, public_branch=branch_c.base)
444
self.assertContainsRe(md1.get_raw_bundle(), 'Bazaar revision bundle')
445
self.assertContainsRe(md1.patch, '\\+content_c')
446
self.assertNotContainsRe(md1.patch, '\\+content_a')
447
self.assertContainsRe(md1.patch, '\\+content_c')
448
self.assertNotContainsRe(md1.patch, '\\+content_a')
450
def test_broken_bundle(self):
451
tree_a, tree_b, branch_c = self.make_trees()
452
md1 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
453
tree_b.branch.base, public_branch=branch_c.base)
454
lines = md1.to_lines()
455
lines = [l.replace('\n', '\r\n') for l in lines]
456
md2 = merge_directive.MergeDirective.from_lines(lines)
457
self.assertEqual('rev2a', md2.revision_id)
258
md1 = merge_directive.MergeDirective.from_objects(
259
tree_a.branch.repository, 'rev2a', 500, 144, tree_b.branch.base,
260
public_branch=branch_c.base)
261
self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
262
self.assertContainsRe(md1.patch, '\\+content_c')
263
self.assertNotContainsRe(md1.patch, '\\+content_a')
264
self.assertContainsRe(md1.patch, '\\+content_c')
265
self.assertNotContainsRe(md1.patch, '\\+content_a')
459
267
def test_signing(self):
462
270
class FakeBranch(object):
463
271
def get_config(self):
465
273
def gpg_signing_command(self):
466
274
return 'loopback'
467
md = self.make_merge_directive('example:', 'sha', time, timezone,
275
md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
468
276
'http://example.com', source_branch="http://example.org",
469
277
patch='booga', patch_type='diff')
470
278
old_strategy = gpg.GPGStrategy
480
288
def test_email(self):
481
289
tree_a, tree_b, branch_c = self.make_trees()
482
md = self.from_objects(tree_a.branch.repository, 'rev2a', 476, 60,
483
tree_b.branch.base, patch_type=None,
484
public_branch=tree_a.branch.base)
290
md = merge_directive.MergeDirective.from_objects(
291
tree_a.branch.repository, 'rev2a', 500, 36, tree_b.branch.base,
292
patch_type=None, public_branch=tree_a.branch.base)
485
293
message = md.to_email('pqm@example.com', tree_a.branch)
486
self.assertContainsRe(message.as_string(), self.EMAIL1)
294
self.assertContainsRe(message.as_string(), EMAIL1)
487
295
md.message = 'Commit of rev2a with special message'
488
296
message = md.to_email('pqm@example.com', tree_a.branch)
489
self.assertContainsRe(message.as_string(), self.EMAIL2)
297
self.assertContainsRe(message.as_string(), EMAIL2)
491
299
def test_install_revisions_branch(self):
492
300
tree_a, tree_b, branch_c = self.make_trees()
493
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 36,
494
tree_b.branch.base, patch_type=None,
495
public_branch=tree_a.branch.base)
301
md = merge_directive.MergeDirective.from_objects(
302
tree_a.branch.repository, 'rev2a', 500, 36, tree_b.branch.base,
303
patch_type=None, public_branch=tree_a.branch.base)
496
304
self.assertFalse(tree_b.branch.repository.has_revision('rev2a'))
497
305
revision = md.install_revisions(tree_b.branch.repository)
498
306
self.assertEqual('rev2a', revision)
499
307
self.assertTrue(tree_b.branch.repository.has_revision('rev2a'))
501
def test_get_merge_request(self):
502
tree_a, tree_b, branch_c = self.make_trees()
503
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 36,
504
tree_b.branch.base, patch_type='bundle',
505
public_branch=tree_a.branch.base)
506
self.assertFalse(tree_b.branch.repository.has_revision('rev2a'))
507
md.install_revisions(tree_b.branch.repository)
508
base, revision, verified = md.get_merge_request(
509
tree_b.branch.repository)
510
if isinstance(md, merge_directive.MergeDirective):
511
self.assertIs(None, base)
512
self.assertEqual('inapplicable', verified)
514
self.assertEqual('rev1', base)
515
self.assertEqual('verified', verified)
516
self.assertEqual('rev2a', revision)
517
self.assertTrue(tree_b.branch.repository.has_revision('rev2a'))
518
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 36,
519
tree_b.branch.base, patch_type=None,
520
public_branch=tree_a.branch.base)
521
base, revision, verified = md.get_merge_request(
522
tree_b.branch.repository)
523
if isinstance(md, merge_directive.MergeDirective):
524
self.assertIs(None, base)
525
self.assertEqual('inapplicable', verified)
527
self.assertEqual('rev1', base)
528
self.assertEqual('inapplicable', verified)
529
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 36,
530
tree_b.branch.base, patch_type='diff',
531
public_branch=tree_a.branch.base)
532
base, revision, verified = md.get_merge_request(
533
tree_b.branch.repository)
534
if isinstance(md, merge_directive.MergeDirective):
535
self.assertIs(None, base)
536
self.assertEqual('inapplicable', verified)
538
self.assertEqual('rev1', base)
539
self.assertEqual('verified', verified)
541
base, revision, verified = md.get_merge_request(
542
tree_b.branch.repository)
543
if isinstance(md, merge_directive.MergeDirective):
544
self.assertIs(None, base)
545
self.assertEqual('inapplicable', verified)
547
self.assertEqual('rev1', base)
548
self.assertEqual('failed', verified)
550
309
def test_install_revisions_bundle(self):
551
310
tree_a, tree_b, branch_c = self.make_trees()
552
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 36,
553
tree_b.branch.base, patch_type='bundle',
554
public_branch=tree_a.branch.base)
311
md = merge_directive.MergeDirective.from_objects(
312
tree_a.branch.repository, 'rev2a', 500, 36, tree_b.branch.base,
313
patch_type='bundle', public_branch=tree_a.branch.base)
555
314
self.assertFalse(tree_b.branch.repository.has_revision('rev2a'))
556
315
revision = md.install_revisions(tree_b.branch.repository)
557
316
self.assertEqual('rev2a', revision)
560
319
def test_get_target_revision_nofetch(self):
561
320
tree_a, tree_b, branch_c = self.make_trees()
562
321
tree_b.branch.fetch(tree_a.branch)
563
md = self.from_objects( tree_a.branch.repository, 'rev2a', 500, 36,
564
tree_b.branch.base, patch_type=None,
565
public_branch=tree_a.branch.base)
322
md = merge_directive.MergeDirective.from_objects(
323
tree_a.branch.repository, 'rev2a', 500, 36, tree_b.branch.base,
324
patch_type=None, public_branch=tree_a.branch.base)
566
325
md.source_branch = '/dev/null'
567
326
revision = md.install_revisions(tree_b.branch.repository)
568
327
self.assertEqual('rev2a', revision)
570
def test_use_submit_for_missing_dependency(self):
571
tree_a, tree_b, branch_c = self.make_trees()
572
branch_c.pull(tree_a.branch)
573
self.build_tree_contents([('tree_a/file', 'content_q\ncontent_r\n')])
574
tree_a.commit('rev3a', rev_id='rev3a')
575
md = self.from_objects(tree_a.branch.repository, 'rev3a', 500, 36,
576
branch_c.base, base_revision_id='rev2a')
577
revision = md.install_revisions(tree_b.branch.repository)
579
def test_handle_target_not_a_branch(self):
580
tree_a, tree_b, branch_c = self.make_trees()
581
branch_c.pull(tree_a.branch)
582
self.build_tree_contents([('tree_a/file', 'content_q\ncontent_r\n')])
583
tree_a.commit('rev3a', rev_id='rev3a')
584
md = self.from_objects(tree_a.branch.repository, 'rev3a', 500, 36,
585
branch_c.base, base_revision_id='rev2a')
586
md.target_branch = self.get_url('not-a-branch')
587
self.assertRaises(errors.TargetNotBranch, md.install_revisions,
588
tree_b.branch.repository)
591
class TestMergeDirective1Branch(tests.TestCaseWithTransport,
592
TestMergeDirectiveBranch):
593
"""Test merge directive format 1 with a branch"""
599
def from_objects(self, repository, revision_id, time, timezone,
600
target_branch, patch_type='bundle', local_target_branch=None,
601
public_branch=None, message=None, base_revision_id=None):
602
if base_revision_id is not None:
603
raise tests.TestNotApplicable('This format does not support'
605
repository.lock_write()
607
return merge_directive.MergeDirective.from_objects( repository,
608
revision_id, time, timezone, target_branch, patch_type,
609
local_target_branch, public_branch, message)
613
def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
614
target_branch, patch=None, patch_type=None,
615
source_branch=None, message=None):
616
return merge_directive.MergeDirective(revision_id, testament_sha1,
617
time, timezone, target_branch, patch, patch_type,
618
source_branch, message)
621
class TestMergeDirective2Branch(tests.TestCaseWithTransport,
622
TestMergeDirectiveBranch):
623
"""Test merge directive format 2 with a branch"""
629
def from_objects(self, repository, revision_id, time, timezone,
630
target_branch, patch_type='bundle', local_target_branch=None,
631
public_branch=None, message=None, base_revision_id=None):
632
include_patch = (patch_type in ('bundle', 'diff'))
633
include_bundle = (patch_type == 'bundle')
634
self.assertTrue(patch_type in ('bundle', 'diff', None))
635
return merge_directive.MergeDirective2.from_objects(
636
repository, revision_id, time, timezone, target_branch,
637
include_patch, include_bundle, local_target_branch, public_branch,
638
message, base_revision_id)
640
def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
641
target_branch, patch=None, patch_type=None,
642
source_branch=None, message=None, base_revision_id='null:'):
643
if patch_type == 'bundle':
648
return merge_directive.MergeDirective2(revision_id, testament_sha1,
649
time, timezone, target_branch, patch, source_branch, message,
650
bundle, base_revision_id)
652
def test_base_revision(self):
653
tree_a, tree_b, branch_c = self.make_trees()
654
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 60,
655
tree_b.branch.base, patch_type='bundle',
656
public_branch=tree_a.branch.base, base_revision_id=None)
657
self.assertEqual('rev1', md.base_revision_id)
658
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 60,
659
tree_b.branch.base, patch_type='bundle',
660
public_branch=tree_a.branch.base, base_revision_id='null:')
661
self.assertEqual('null:', md.base_revision_id)
662
lines = md.to_lines()
663
md2 = merge_directive.MergeDirective.from_lines(lines)
664
self.assertEqual(md2.base_revision_id, md.base_revision_id)
666
def test_patch_verification(self):
667
tree_a, tree_b, branch_c = self.make_trees()
668
md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 60,
669
tree_b.branch.base, patch_type='bundle',
670
public_branch=tree_a.branch.base)
671
lines = md.to_lines()
672
md2 = merge_directive.MergeDirective.from_lines(lines)
673
md2._verify_patch(tree_a.branch.repository)
674
# Strip trailing whitespace
675
md2.patch = md2.patch.replace(' \n', '\n')
676
md2._verify_patch(tree_a.branch.repository)
677
# Convert to Mac line-endings
678
md2.patch = re.sub('(\r\n|\r|\n)', '\r', md2.patch)
679
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
680
# Convert to DOS line-endings
681
md2.patch = re.sub('(\r\n|\r|\n)', '\r\n', md2.patch)
682
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
683
md2.patch = md2.patch.replace('content_c', 'content_d')
684
self.assertFalse(md2._verify_patch(tree_a.branch.repository))
687
class TestParseOldMergeDirective2(tests.TestCase):
689
def test_parse_old_merge_directive(self):
690
md = merge_directive.MergeDirective.from_lines(INPUT1_2_OLD)
691
self.assertEqual('example:', md.revision_id)
692
self.assertEqual('sha', md.testament_sha1)
693
self.assertEqual('http://example.com', md.target_branch)
694
self.assertEqual('http://example.org', md.source_branch)
695
self.assertEqual(453, md.time)
696
self.assertEqual(120, md.timezone)
697
self.assertEqual('booga', md.patch)
698
self.assertEqual('diff', md.patch_type)
699
self.assertEqual('Hi mom!', md.message)