~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Martin Pool
  • Date: 2006-05-12 08:29:23 UTC
  • mfrom: (1668.1.7 bzr-0.8.mbp)
  • mto: This revision was merged to the branch mainline in revision 1710.
  • Revision ID: mbp@sourcefrog.net-20060512082923-38e14b057e08246e
[merge] work from 0.8 fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.branch import Branch
23
23
from bzrlib.bzrdir import BzrDir, BzrDirMetaFormat1
24
24
from bzrlib.workingtree import WorkingTree
25
 
from bzrlib.commit import Commit
 
25
from bzrlib.commit import Commit, NullCommitReporter
26
26
from bzrlib.config import BranchConfig
27
27
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed, 
28
28
                           LockContention)
45
45
        return "bzrlib.ahook bzrlib.ahook"
46
46
 
47
47
 
 
48
class CapturingReporter(NullCommitReporter):
 
49
    """This reporter captures the calls made to it for evaluation later."""
 
50
 
 
51
    def __init__(self):
 
52
        # a list of the calls this received
 
53
        self.calls = []
 
54
 
 
55
    def snapshot_change(self, change, path):
 
56
        self.calls.append(('change', change, path))
 
57
 
 
58
    def deleted(self, file_id):
 
59
        self.calls.append(('deleted', file_id))
 
60
 
 
61
    def missing(self, path):
 
62
        self.calls.append(('missing', path))
 
63
 
 
64
    def renamed(self, change, old_path, new_path):
 
65
        self.calls.append(('renamed', change, old_path, new_path))
 
66
 
 
67
 
48
68
class TestCommit(TestCaseWithTransport):
49
69
 
50
70
    def test_simple_commit(self):
422
442
        # before #34959 was fixed, this failed with 'revision not present in
423
443
        # weave' when trying to implicitly push from the bound branch to the master
424
444
        bound_tree.commit(message='commit of merge in bound tree')
 
445
 
 
446
    def test_commit_reporting_after_merge(self):
 
447
        # when doing a commit of a merge, the reporter needs to still 
 
448
        # be called for each item that is added/removed/deleted.
 
449
        this_tree = self.make_branch_and_tree('this')
 
450
        # we need a bunch of files and dirs, to perform one action on each.
 
451
        self.build_tree([
 
452
            'this/dirtorename/',
 
453
            'this/dirtoreparent/',
 
454
            'this/dirtoleave/',
 
455
            'this/dirtoremove/',
 
456
            'this/filetoreparent',
 
457
            'this/filetorename',
 
458
            'this/filetomodify',
 
459
            'this/filetoremove',
 
460
            'this/filetoleave']
 
461
            )
 
462
        this_tree.add([
 
463
            'dirtorename',
 
464
            'dirtoreparent',
 
465
            'dirtoleave',
 
466
            'dirtoremove',
 
467
            'filetoreparent',
 
468
            'filetorename',
 
469
            'filetomodify',
 
470
            'filetoremove',
 
471
            'filetoleave']
 
472
            )
 
473
        this_tree.commit('create_files')
 
474
        other_dir = this_tree.bzrdir.sprout('other')
 
475
        other_tree = other_dir.open_workingtree()
 
476
        other_tree.lock_write()
 
477
        # perform the needed actions on the files and dirs.
 
478
        try:
 
479
            other_tree.rename_one('dirtorename', 'renameddir')
 
480
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
 
481
            other_tree.rename_one('filetorename', 'renamedfile')
 
482
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
483
            other_tree.remove(['dirtoremove', 'filetoremove'])
 
484
            self.build_tree_contents([
 
485
                ('other/newdir/', ),
 
486
                ('other/filetomodify', 'new content'),
 
487
                ('other/newfile', 'new file content')])
 
488
            other_tree.add('newfile')
 
489
            other_tree.add('newdir/')
 
490
            other_tree.commit('modify all sample files and dirs.')
 
491
        finally:
 
492
            other_tree.unlock()
 
493
        self.merge(other_tree.branch, this_tree)
 
494
        reporter = CapturingReporter()
 
495
        this_tree.commit('do the commit', reporter=reporter)
 
496
        self.assertEqual([
 
497
            ('change', 'unchanged', 'dirtoleave'),
 
498
            ('change', 'unchanged', 'filetoleave'),
 
499
            ('change', 'modified', 'filetomodify'),
 
500
            ('change', 'added', 'newdir'),
 
501
            ('change', 'added', 'newfile'),
 
502
            ('renamed', 'renamed', 'dirtorename', 'renameddir'),
 
503
            ('renamed', 'renamed', 'dirtoreparent', 'renameddir/reparenteddir'),
 
504
            ('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
 
505
            ('renamed', 'renamed', 'filetorename', 'renamedfile'),
 
506
            ('deleted', 'dirtoremove'),
 
507
            ('deleted', 'filetoremove'),
 
508
            ],
 
509
            reporter.calls)