~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

(jelmer) Switch the commit code over to use config stacks. (Bazaar
 Developers)

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
29
from bzrlib.errors import (
30
30
    PointlessCommit,
31
31
    BzrError,
44
44
 
45
45
# TODO: Test commit with some added, and added-but-missing files
46
46
 
47
 
class MustSignConfig(BranchConfig):
48
 
 
49
 
    def signature_needed(self):
50
 
        return True
51
 
 
52
 
    def gpg_signing_command(self):
53
 
        return ['cat', '-']
54
 
 
55
 
 
56
 
class BranchWithHooks(BranchConfig):
57
 
 
58
 
    def post_commit(self):
59
 
        return "bzrlib.ahook bzrlib.ahook"
 
47
class MustSignConfig(config.Stack):
 
48
 
 
49
    def __init__(self, branch):
 
50
        store = config.IniFileStore()
 
51
        store._load_from_string('''
 
52
gpg_signing_command=cat -
 
53
create_signatures=always
 
54
''')
 
55
        super(MustSignConfig, self).__init__([store.get_sections])
 
56
        # FIXME: Strictly speaking we should fallback to the no-name section in
 
57
        # branch.conf but no tests need that so far -- vila 2011-12-14
 
58
 
 
59
 
 
60
class BranchWithHooks(config.Stack):
 
61
 
 
62
    def __init__(self, branch):
 
63
        store = config.IniFileStore()
 
64
        store._load_from_string('post_commit=bzrlib.ahook bzrlib.ahook')
 
65
        super(BranchWithHooks, self).__init__([store.get_sections])
 
66
        # FIXME: Strictly speaking we should fallback to the no-name section in
 
67
        # branch.conf but no tests need that so far -- vila 2011-12-14
60
68
 
61
69
 
62
70
class CapturingReporter(NullCommitReporter):
431
439
            from bzrlib.testament import Testament
432
440
            # monkey patch gpg signing mechanism
433
441
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
434
 
            commit.Commit(config=MustSignConfig(branch)).commit(message="base",
435
 
                                                      allow_pointless=True,
436
 
                                                      rev_id='B',
437
 
                                                      working_tree=wt)
 
442
            commit.Commit(config_stack=MustSignConfig(branch)
 
443
                          ).commit(message="base", allow_pointless=True,
 
444
                                   rev_id='B', working_tree=wt)
438
445
            def sign(text):
439
446
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
440
447
            self.assertEqual(sign(Testament.from_revision(branch.repository,
441
 
                             'B').as_short_text()),
 
448
                                                          'B').as_short_text()),
442
449
                             branch.repository.get_signature_text('B'))
443
450
        finally:
444
451
            bzrlib.gpg.GPGStrategy = oldstrategy
456
463
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
457
464
            config = MustSignConfig(branch)
458
465
            self.assertRaises(SigningFailed,
459
 
                              commit.Commit(config=config).commit,
 
466
                              commit.Commit(config_stack=config).commit,
460
467
                              message="base",
461
468
                              allow_pointless=True,
462
469
                              rev_id='B',
477
484
        bzrlib.ahook = called
478
485
        try:
479
486
            config = BranchWithHooks(branch)
480
 
            commit.Commit(config=config).commit(
 
487
            commit.Commit(config_stack=config).commit(
481
488
                            message = "base",
482
489
                            allow_pointless=True,
483
490
                            rev_id='A', working_tree = wt)