/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2007-06-27 16:11:12 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070627161112-t1r8d32qifq7ox07
Implement patch verification

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
# target_branch: http://example.com
37
37
# testament_sha1: sha
38
38
# timestamp: 1970-01-01 00:09:33 +0002
 
39
# base_revision_id: null:
39
40
#\x20
40
41
# Begin bundle
41
42
booga"""
57
58
# timestamp: 1970-01-01 00:09:33 +0002
58
59
# source_branch: http://example.org
59
60
# message: Hi mom!
 
61
# base_revision_id: null:
60
62
#\x20
61
63
# Begin patch
62
64
booga"""
100
102
# testament_sha1: sha
101
103
# timestamp: 1970-01-01 00:09:33 +0002
102
104
# source_branch: http://example.org
 
105
# base_revision_id: null:
103
106
# message: Hi mom!
104
107
#\x20
105
108
# Begin patch
233
236
 
234
237
    def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
235
238
                 target_branch, patch=None, patch_type=None,
236
 
                 source_branch=None, message=None):
 
239
                 source_branch=None, message=None, base_revision_id='null:'):
237
240
        if patch_type == 'bundle':
238
241
            bundle = patch
239
242
            patch = None
241
244
            bundle = None
242
245
        return merge_directive.MergeDirective2(revision_id, testament_sha1,
243
246
            time, timezone, target_branch, patch, source_branch, message,
244
 
            bundle)
 
247
            bundle, base_revision_id)
245
248
 
246
249
    @staticmethod
247
250
    def set_bundle(md, value):
312
315
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
313
316
        branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
314
317
        tree_b.commit('message', rev_id='rev2b')
315
 
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c\n')])
 
318
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c \n')])
316
319
        tree_a.commit('Commit of rev2a', rev_id='rev2a')
317
320
        return tree_a, tree_b, branch_c
318
321
 
493
496
 
494
497
    def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
495
498
                 target_branch, patch=None, patch_type=None,
496
 
                 source_branch=None, message=None):
 
499
                 source_branch=None, message=None, base_revision_id='null:'):
497
500
        if patch_type == 'bundle':
498
501
            bundle = patch
499
502
            patch = None
501
504
            bundle = None
502
505
        return merge_directive.MergeDirective2(revision_id, testament_sha1,
503
506
            time, timezone, target_branch, patch, source_branch, message,
504
 
            bundle)
505
 
 
 
507
            bundle, base_revision_id)
 
508
 
 
509
    def test_base_revision(self):
 
510
        tree_a, tree_b, branch_c = self.make_trees()
 
511
        md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 60,
 
512
            tree_b.branch.base, patch_type='bundle',
 
513
            public_branch=tree_a.branch.base)
 
514
        self.assertEqual('rev1', md.base_revision_id)
 
515
        lines = md.to_lines()
 
516
        md2 = merge_directive.MergeDirective.from_lines(lines)
 
517
        self.assertEqual(md2.base_revision_id, md.base_revision_id)
 
518
 
 
519
    def test_patch_verification(self):
 
520
        tree_a, tree_b, branch_c = self.make_trees()
 
521
        md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 60,
 
522
            tree_b.branch.base, patch_type='bundle',
 
523
            public_branch=tree_a.branch.base)
 
524
        lines = md.to_lines()
 
525
        md2 = merge_directive.MergeDirective.from_lines(lines)
 
526
        md2._verify_patch(tree_a.branch.repository)
 
527
        # Stript trailing whitespace
 
528
        md2.patch = md2.patch.replace(' \n', '\n')
 
529
        md2._verify_patch(tree_a.branch.repository)
 
530
        # Convert to Mac line-endings
 
531
        md2.patch = md2.patch.replace('\n', '\r')
 
532
        md2._verify_patch(tree_a.branch.repository)
 
533
        # Convert to DOS line-endings
 
534
        md2.patch = md2.patch.replace('\r', '\r\n')
 
535
        md2._verify_patch(tree_a.branch.repository)
 
536
        md2.patch = md2.patch.replace('content_c', 'content_d')
 
537
        self.assertRaises(errors.PatchVerificationFailed, md2._verify_patch,
 
538
            tree_a.branch.repository)
 
539
        self.assertRaises(errors.PatchVerificationFailed,
 
540
                          md2.install_revisions, tree_a.branch.repository)