~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import bzrlib
21
21
from bzrlib import (
22
22
    bzrdir,
 
23
    config,
23
24
    errors,
24
25
    )
25
26
from bzrlib.branch import Branch
26
27
from bzrlib.bzrdir import BzrDirMetaFormat1
27
28
from bzrlib.commit import Commit, NullCommitReporter
28
 
from bzrlib.config import BranchConfig
29
 
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
30
 
                           LockContention)
 
29
from bzrlib.errors import (
 
30
    PointlessCommit,
 
31
    BzrError,
 
32
    SigningFailed,
 
33
    LockContention,
 
34
    )
31
35
from bzrlib.tests import (
32
 
    SymlinkFeature,
33
36
    TestCaseWithTransport,
34
37
    test_foreign,
35
38
    )
 
39
from bzrlib.tests.features import (
 
40
    SymlinkFeature,
 
41
    )
 
42
from bzrlib.tests.matchers import MatchesAncestry
36
43
 
37
44
 
38
45
# TODO: Test commit with some added, and added-but-missing files
39
46
 
40
 
class MustSignConfig(BranchConfig):
41
 
 
42
 
    def signature_needed(self):
43
 
        return True
44
 
 
45
 
    def gpg_signing_command(self):
46
 
        return ['cat', '-']
47
 
 
48
 
 
49
 
class BranchWithHooks(BranchConfig):
50
 
 
51
 
    def post_commit(self):
52
 
        return "bzrlib.ahook bzrlib.ahook"
 
47
class MustSignConfig(config.MemoryStack):
 
48
 
 
49
    def __init__(self):
 
50
        super(MustSignConfig, self).__init__('''
 
51
gpg_signing_command=cat -
 
52
create_signatures=always
 
53
''')
53
54
 
54
55
 
55
56
class CapturingReporter(NullCommitReporter):
83
84
        b = wt.branch
84
85
        file('hello', 'w').write('hello world')
85
86
        wt.add('hello')
86
 
        wt.commit(message='add hello')
 
87
        rev1 = wt.commit(message='add hello')
87
88
        file_id = wt.path2id('hello')
88
89
 
89
90
        file('hello', 'w').write('version 2')
90
 
        wt.commit(message='commit 2')
 
91
        rev2 = wt.commit(message='commit 2')
91
92
 
92
93
        eq = self.assertEquals
93
94
        eq(b.revno(), 2)
94
 
        rh = b.revision_history()
95
 
        rev = b.repository.get_revision(rh[0])
 
95
        rev = b.repository.get_revision(rev1)
96
96
        eq(rev.message, 'add hello')
97
97
 
98
 
        tree1 = b.repository.revision_tree(rh[0])
 
98
        tree1 = b.repository.revision_tree(rev1)
99
99
        tree1.lock_read()
100
100
        text = tree1.get_file_text(file_id)
101
101
        tree1.unlock()
102
102
        self.assertEqual('hello world', text)
103
103
 
104
 
        tree2 = b.repository.revision_tree(rh[1])
 
104
        tree2 = b.repository.revision_tree(rev2)
105
105
        tree2.lock_read()
106
106
        text = tree2.get_file_text(file_id)
107
107
        tree2.unlock()
154
154
        wt.commit(message='add hello')
155
155
 
156
156
        os.remove('hello')
157
 
        wt.commit('removed hello', rev_id='rev2')
 
157
        reporter = CapturingReporter()
 
158
        wt.commit('removed hello', rev_id='rev2', reporter=reporter)
 
159
        self.assertEquals(
 
160
            [('missing', u'hello'), ('deleted', u'hello')],
 
161
            reporter.calls)
158
162
 
159
163
        tree = b.repository.revision_tree('rev2')
160
164
        self.assertFalse(tree.has_id('hello-id'))
354
358
            rev_ids.append(rev_id)
355
359
            wt.commit(message='rev %d' % (i+1),
356
360
                     rev_id=rev_id)
357
 
        eq = self.assertEquals
358
 
        eq(b.revision_history(), rev_ids)
359
361
        for i in range(4):
360
 
            anc = b.repository.get_ancestry(rev_ids[i])
361
 
            eq(anc, [None] + rev_ids[:i+1])
 
362
            self.assertThat(rev_ids[:i+1],
 
363
                MatchesAncestry(b.repository, rev_ids[i]))
362
364
 
363
365
    def test_commit_new_subdir_child_selective(self):
364
366
        wt = self.make_branch_and_tree('.')
423
425
            from bzrlib.testament import Testament
424
426
            # monkey patch gpg signing mechanism
425
427
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
426
 
            commit.Commit(config=MustSignConfig(branch)).commit(message="base",
427
 
                                                      allow_pointless=True,
428
 
                                                      rev_id='B',
429
 
                                                      working_tree=wt)
 
428
            conf = config.MemoryStack('''
 
429
gpg_signing_command=cat -
 
430
create_signatures=always
 
431
''')
 
432
            commit.Commit(config_stack=conf).commit(
 
433
                message="base", allow_pointless=True, rev_id='B',
 
434
                working_tree=wt)
430
435
            def sign(text):
431
436
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
432
437
            self.assertEqual(sign(Testament.from_revision(branch.repository,
433
 
                             'B').as_short_text()),
 
438
                                                          'B').as_short_text()),
434
439
                             branch.repository.get_signature_text('B'))
435
440
        finally:
436
441
            bzrlib.gpg.GPGStrategy = oldstrategy
446
451
        try:
447
452
            # monkey patch gpg signing mechanism
448
453
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
449
 
            config = MustSignConfig(branch)
 
454
            conf = config.MemoryStack('''
 
455
gpg_signing_command=cat -
 
456
create_signatures=always
 
457
''')
450
458
            self.assertRaises(SigningFailed,
451
 
                              commit.Commit(config=config).commit,
 
459
                              commit.Commit(config_stack=conf).commit,
452
460
                              message="base",
453
461
                              allow_pointless=True,
454
462
                              rev_id='B',
455
463
                              working_tree=wt)
456
464
            branch = Branch.open(self.get_url('.'))
457
 
            self.assertEqual(branch.revision_history(), ['A'])
 
465
            self.assertEqual(branch.last_revision(), 'A')
458
466
            self.assertFalse(branch.repository.has_revision('B'))
459
467
        finally:
460
468
            bzrlib.gpg.GPGStrategy = oldstrategy
468
476
            calls.append('called')
469
477
        bzrlib.ahook = called
470
478
        try:
471
 
            config = BranchWithHooks(branch)
472
 
            commit.Commit(config=config).commit(
473
 
                            message = "base",
474
 
                            allow_pointless=True,
475
 
                            rev_id='A', working_tree = wt)
 
479
            conf = config.MemoryStack('post_commit=bzrlib.ahook bzrlib.ahook')
 
480
            commit.Commit(config_stack=conf).commit(
 
481
                message = "base", allow_pointless=True, rev_id='A',
 
482
                working_tree = wt)
476
483
            self.assertEqual(['called', 'called'], calls)
477
484
        finally:
478
485
            del bzrlib.ahook