~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

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.MemoryStack):
 
48
 
 
49
    def __init__(self):
 
50
        super(MustSignConfig, self).__init__('''
 
51
gpg_signing_command=cat -
 
52
create_signatures=always
 
53
''')
60
54
 
61
55
 
62
56
class CapturingReporter(NullCommitReporter):
431
425
            from bzrlib.testament import Testament
432
426
            # monkey patch gpg signing mechanism
433
427
            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)
 
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)
438
435
            def sign(text):
439
436
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
440
437
            self.assertEqual(sign(Testament.from_revision(branch.repository,
441
 
                             'B').as_short_text()),
 
438
                                                          'B').as_short_text()),
442
439
                             branch.repository.get_signature_text('B'))
443
440
        finally:
444
441
            bzrlib.gpg.GPGStrategy = oldstrategy
454
451
        try:
455
452
            # monkey patch gpg signing mechanism
456
453
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
457
 
            config = MustSignConfig(branch)
 
454
            conf = config.MemoryStack('''
 
455
gpg_signing_command=cat -
 
456
create_signatures=always
 
457
''')
458
458
            self.assertRaises(SigningFailed,
459
 
                              commit.Commit(config=config).commit,
 
459
                              commit.Commit(config_stack=conf).commit,
460
460
                              message="base",
461
461
                              allow_pointless=True,
462
462
                              rev_id='B',
476
476
            calls.append('called')
477
477
        bzrlib.ahook = called
478
478
        try:
479
 
            config = BranchWithHooks(branch)
480
 
            commit.Commit(config=config).commit(
481
 
                            message = "base",
482
 
                            allow_pointless=True,
483
 
                            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)
484
483
            self.assertEqual(['called', 'called'], calls)
485
484
        finally:
486
485
            del bzrlib.ahook