13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
18
from bzrlib import (
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
99
# Bazaar merge directive format 2 (Bazaar 0.19)\r
125
100
# revision_id: example:
126
101
# target_branch: http://example.com
134
109
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
112
class TestMergeDirective(object):
154
114
def test_merge_source(self):
353
313
tree_a = self.make_branch_and_tree('tree_a')
354
314
tree_a.branch.get_config().set_user_option('email',
355
315
'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'])
316
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
359
318
tree_a.commit('message', rev_id='rev1')
360
319
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
361
320
branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
362
321
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')])
322
self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c \n')])
365
323
tree_a.commit('Commit of rev2a', rev_id='rev2a')
366
324
return tree_a, tree_b, branch_c
372
330
tree_d.branch.base, patch_type='diff',
373
331
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
333
def test_generate_patch(self):
390
334
tree_a, tree_b, branch_c = self.make_trees()
391
335
md2 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
567
511
revision = md.install_revisions(tree_b.branch.repository)
568
512
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
515
class TestMergeDirective1Branch(tests.TestCaseWithTransport,
592
516
TestMergeDirectiveBranch):
599
523
def from_objects(self, repository, revision_id, time, timezone,
600
524
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)
525
public_branch=None, message=None):
526
return merge_directive.MergeDirective.from_objects(
527
repository, revision_id, time, timezone, target_branch,
528
patch_type, local_target_branch, public_branch, message)
613
530
def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
614
531
target_branch, patch=None, patch_type=None,
631
548
public_branch=None, message=None, base_revision_id=None):
632
549
include_patch = (patch_type in ('bundle', 'diff'))
633
550
include_bundle = (patch_type == 'bundle')
634
self.assertTrue(patch_type in ('bundle', 'diff', None))
551
assert patch_type in ('bundle', 'diff', None)
635
552
return merge_directive.MergeDirective2.from_objects(
636
553
repository, revision_id, time, timezone, target_branch,
637
554
include_patch, include_bundle, local_target_branch, public_branch,
671
588
lines = md.to_lines()
672
589
md2 = merge_directive.MergeDirective.from_lines(lines)
673
590
md2._verify_patch(tree_a.branch.repository)
674
# Strip trailing whitespace
591
# Stript trailing whitespace
675
592
md2.patch = md2.patch.replace(' \n', '\n')
676
593
md2._verify_patch(tree_a.branch.repository)
677
594
# Convert to Mac line-endings
678
md2.patch = re.sub('(\r\n|\r|\n)', '\r', md2.patch)
595
md2.patch = md2.patch.replace('\n', '\r')
679
596
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
680
597
# Convert to DOS line-endings
681
md2.patch = re.sub('(\r\n|\r|\n)', '\r\n', md2.patch)
598
md2.patch = md2.patch.replace('\r', '\r\n')
682
599
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
683
600
md2.patch = md2.patch.replace('content_c', 'content_d')
684
601
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)