21
21
from bzrlib import (
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 (
45
45
# TODO: Test commit with some added, and added-but-missing files
47
class MustSignConfig(BranchConfig):
49
def signature_needed(self):
52
def gpg_signing_command(self):
56
class BranchWithHooks(BranchConfig):
58
def post_commit(self):
59
return "bzrlib.ahook bzrlib.ahook"
47
class MustSignConfig(config.Stack):
49
def __init__(self, branch):
50
store = config.IniFileStore()
51
store._load_from_string('''
52
gpg_signing_command=cat -
53
create_signatures=always
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
60
class BranchWithHooks(config.Stack):
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
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,
442
commit.Commit(config_stack=MustSignConfig(branch)
443
).commit(message="base", allow_pointless=True,
444
rev_id='B', working_tree=wt)
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'))
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,
461
468
allow_pointless=True,
477
484
bzrlib.ahook = called
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)