14
14
# along with this program; if not, write to the Free Software
15
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
630
588
lines = md.to_lines()
631
589
md2 = merge_directive.MergeDirective.from_lines(lines)
632
590
md2._verify_patch(tree_a.branch.repository)
633
# Strip trailing whitespace
591
# Stript trailing whitespace
634
592
md2.patch = md2.patch.replace(' \n', '\n')
635
593
md2._verify_patch(tree_a.branch.repository)
636
594
# Convert to Mac line-endings
637
md2.patch = re.sub('(\r\n|\r|\n)', '\r', md2.patch)
595
md2.patch = md2.patch.replace('\n', '\r')
638
596
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
639
597
# Convert to DOS line-endings
640
md2.patch = re.sub('(\r\n|\r|\n)', '\r\n', md2.patch)
598
md2.patch = md2.patch.replace('\r', '\r\n')
641
599
self.assertTrue(md2._verify_patch(tree_a.branch.repository))
642
600
md2.patch = md2.patch.replace('content_c', 'content_d')
643
601
self.assertFalse(md2._verify_patch(tree_a.branch.repository))
646
class TestParseOldMergeDirective2(tests.TestCase):
648
def test_parse_old_merge_directive(self):
649
md = merge_directive.MergeDirective.from_lines(INPUT1_2_OLD)
650
self.assertEqual('example:', md.revision_id)
651
self.assertEqual('sha', md.testament_sha1)
652
self.assertEqual('http://example.com', md.target_branch)
653
self.assertEqual('http://example.org', md.source_branch)
654
self.assertEqual(453, md.time)
655
self.assertEqual(120, md.timezone)
656
self.assertEqual('booga', md.patch)
657
self.assertEqual('diff', md.patch_type)
658
self.assertEqual('Hi mom!', md.message)