/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_commit.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
 
20
 
import bzrlib
21
 
from bzrlib import (
 
20
import breezy
 
21
from .. import (
22
22
    config,
23
23
    controldir,
24
24
    errors,
25
25
    )
26
 
from bzrlib.branch import Branch
27
 
from bzrlib.bzrdir import BzrDirMetaFormat1
28
 
from bzrlib.commit import Commit, NullCommitReporter
29
 
from bzrlib.errors import (
 
26
from ..branch import Branch
 
27
from ..bzrdir import BzrDirMetaFormat1
 
28
from ..commit import Commit, NullCommitReporter
 
29
from ..errors import (
30
30
    PointlessCommit,
31
31
    BzrError,
32
32
    SigningFailed,
33
33
    LockContention,
34
34
    )
35
 
from bzrlib.tests import (
 
35
from . import (
36
36
    TestCaseWithTransport,
37
37
    test_foreign,
38
38
    )
39
 
from bzrlib.tests.features import (
 
39
from .features import (
40
40
    SymlinkFeature,
41
41
    )
42
 
from bzrlib.tests.matchers import MatchesAncestry
 
42
from .matchers import MatchesAncestry
43
43
 
44
44
 
45
45
# TODO: Test commit with some added, and added-but-missing files
377
377
 
378
378
    def test_strict_commit(self):
379
379
        """Try and commit with unknown files and strict = True, should fail."""
380
 
        from bzrlib.errors import StrictCommitFailed
 
380
        from ..errors import StrictCommitFailed
381
381
        wt = self.make_branch_and_tree('.')
382
382
        b = wt.branch
383
383
        with file('hello', 'w') as f: f.write('hello world')
414
414
        wt.commit(message='add hello', strict=False)
415
415
 
416
416
    def test_signed_commit(self):
417
 
        import bzrlib.gpg
418
 
        import bzrlib.commit as commit
419
 
        oldstrategy = bzrlib.gpg.GPGStrategy
 
417
        import breezy.gpg
 
418
        import breezy.commit as commit
 
419
        oldstrategy = breezy.gpg.GPGStrategy
420
420
        wt = self.make_branch_and_tree('.')
421
421
        branch = wt.branch
422
422
        wt.commit("base", allow_pointless=True, rev_id='A')
423
423
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
424
424
        try:
425
 
            from bzrlib.testament import Testament
 
425
            from ..testament import Testament
426
426
            # monkey patch gpg signing mechanism
427
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
427
            breezy.gpg.GPGStrategy = breezy.gpg.LoopbackGPGStrategy
428
428
            conf = config.MemoryStack('''
429
429
gpg_signing_command=cat -
430
430
create_signatures=always
433
433
                message="base", allow_pointless=True, rev_id='B',
434
434
                working_tree=wt)
435
435
            def sign(text):
436
 
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
 
436
                return breezy.gpg.LoopbackGPGStrategy(None).sign(text)
437
437
            self.assertEqual(sign(Testament.from_revision(branch.repository,
438
438
                                                          'B').as_short_text()),
439
439
                             branch.repository.get_signature_text('B'))
440
440
        finally:
441
 
            bzrlib.gpg.GPGStrategy = oldstrategy
 
441
            breezy.gpg.GPGStrategy = oldstrategy
442
442
 
443
443
    def test_commit_failed_signature(self):
444
 
        import bzrlib.gpg
445
 
        import bzrlib.commit as commit
446
 
        oldstrategy = bzrlib.gpg.GPGStrategy
 
444
        import breezy.gpg
 
445
        import breezy.commit as commit
 
446
        oldstrategy = breezy.gpg.GPGStrategy
447
447
        wt = self.make_branch_and_tree('.')
448
448
        branch = wt.branch
449
449
        wt.commit("base", allow_pointless=True, rev_id='A')
450
450
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
451
451
        try:
452
452
            # monkey patch gpg signing mechanism
453
 
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.DisabledGPGStrategy
 
453
            breezy.gpg.GPGStrategy = breezy.gpg.DisabledGPGStrategy
454
454
            conf = config.MemoryStack('''
455
455
gpg_signing_command=cat -
456
456
create_signatures=always
465
465
            self.assertEqual(branch.last_revision(), 'A')
466
466
            self.assertFalse(branch.repository.has_revision('B'))
467
467
        finally:
468
 
            bzrlib.gpg.GPGStrategy = oldstrategy
 
468
            breezy.gpg.GPGStrategy = oldstrategy
469
469
 
470
470
    def test_commit_invokes_hooks(self):
471
 
        import bzrlib.commit as commit
 
471
        import breezy.commit as commit
472
472
        wt = self.make_branch_and_tree('.')
473
473
        branch = wt.branch
474
474
        calls = []
475
475
        def called(branch, rev_id):
476
476
            calls.append('called')
477
 
        bzrlib.ahook = called
 
477
        breezy.ahook = called
478
478
        try:
479
 
            conf = config.MemoryStack('post_commit=bzrlib.ahook bzrlib.ahook')
 
479
            conf = config.MemoryStack('post_commit=breezy.ahook breezy.ahook')
480
480
            commit.Commit(config_stack=conf).commit(
481
481
                message = "base", allow_pointless=True, rev_id='A',
482
482
                working_tree = wt)
483
483
            self.assertEqual(['called', 'called'], calls)
484
484
        finally:
485
 
            del bzrlib.ahook
 
485
            del breezy.ahook
486
486
 
487
487
    def test_commit_object_doesnt_set_nick(self):
488
488
        # using the Commit object directly does not set the branch nick.
589
589
        this_tree.merge_from_branch(other_tree.branch)
590
590
        reporter = CapturingReporter()
591
591
        this_tree.commit('do the commit', reporter=reporter)
592
 
        expected = set([
 
592
        expected = {
593
593
            ('change', 'modified', 'filetomodify'),
594
594
            ('change', 'added', 'newdir'),
595
595
            ('change', 'added', 'newfile'),
599
599
            ('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
600
600
            ('deleted', 'dirtoremove'),
601
601
            ('deleted', 'filetoremove'),
602
 
            ])
 
602
            }
603
603
        result = set(reporter.calls)
604
604
        missing = expected - result
605
605
        new = result - expected
720
720
        tree = self.make_branch_and_tree('.')
721
721
        try:
722
722
            tree.commit()
723
 
        except Exception, e:
 
723
        except Exception as e:
724
724
            self.assertTrue(isinstance(e, BzrError))
725
725
            self.assertEqual('The message or message_callback keyword'
726
726
                             ' parameter is required for commit().', str(e))