~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_commit.py

  • Committer: Martin Pool
  • Date: 2010-02-23 07:43:11 UTC
  • mfrom: (4797.2.20 2.1)
  • mto: This revision was merged to the branch mainline in revision 5055.
  • Revision ID: mbp@sourcefrog.net-20100223074311-gnj55xdhrgz9l94e
Merge 2.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
20
import os
21
 
import re
22
21
import sys
23
22
 
24
23
from bzrlib import (
25
 
    bzrdir,
26
24
    osutils,
27
25
    ignores,
28
26
    msgeditor,
33
31
from bzrlib.tests import (
34
32
    probe_bad_non_ascii,
35
33
    TestSkipped,
36
 
    UnicodeFilenameFeature,
37
34
    )
38
 
from bzrlib.tests import TestCaseWithTransport
39
 
 
40
 
 
41
 
class TestCommit(TestCaseWithTransport):
 
35
from bzrlib.tests.blackbox import ExternalBase
 
36
 
 
37
 
 
38
class TestCommit(ExternalBase):
42
39
 
43
40
    def test_05_empty_commit(self):
44
41
        """Commit of tree with no versioned files should fail"""
110
107
                              'modified hello\.txt\n'
111
108
                              'Committed revision 2\.\n$')
112
109
 
113
 
    def test_unicode_commit_message_is_filename(self):
114
 
        """Unicode commit message same as a filename (Bug #563646).
115
 
        """
116
 
        self.requireFeature(UnicodeFilenameFeature)
117
 
        file_name = u'\N{euro sign}'
118
 
        self.run_bzr(['init'])
119
 
        open(file_name, 'w').write('hello world')
120
 
        self.run_bzr(['add'])
121
 
        out, err = self.run_bzr(['commit', '-m', file_name])
122
 
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
123
 
        te = osutils.get_terminal_encoding()
124
 
        self.assertContainsRe(err.decode(te),
125
 
            u'The commit message is a file name:',
126
 
            flags=reflags)
127
 
 
128
 
        # Run same test with a filename that causes encode
129
 
        # error for the terminal encoding. We do this
130
 
        # by forcing terminal encoding of ascii for
131
 
        # osutils.get_terminal_encoding which is used
132
 
        # by ui.text.show_warning
133
 
        default_get_terminal_enc = osutils.get_terminal_encoding
134
 
        try:
135
 
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
136
 
            file_name = u'foo\u1234'
137
 
            open(file_name, 'w').write('hello world')
138
 
            self.run_bzr(['add'])
139
 
            out, err = self.run_bzr(['commit', '-m', file_name])
140
 
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
141
 
            te = osutils.get_terminal_encoding()
142
 
            self.assertContainsRe(err.decode(te, 'replace'),
143
 
                u'The commit message is a file name:',
144
 
                flags=reflags)
145
 
        finally:
146
 
            osutils.get_terminal_encoding = default_get_terminal_enc
147
 
 
148
110
    def test_warn_about_forgotten_commit_message(self):
149
111
        """Test that the lack of -m parameter is caught"""
150
112
        wt = self.make_branch_and_tree('.')
701
663
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
702
664
 
703
665
    def test_commit_readonly_checkout(self):
704
 
        # https://bugs.launchpad.net/bzr/+bug/129701
 
666
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
705
667
        # "UnlockableTransport error trying to commit in checkout of readonly
706
668
        # branch"
707
669
        self.make_branch('master')
713
675
        self.assertContainsRe(err,
714
676
            r'^bzr: ERROR: Cannot lock.*readonly transport')
715
677
 
716
 
    def setup_editor(self):
 
678
    def test_commit_hook_template(self):
717
679
        # Test that commit template hooks work
718
680
        if sys.platform == "win32":
719
681
            f = file('fed.bat', 'w')
726
688
            f.close()
727
689
            os.chmod('fed.sh', 0755)
728
690
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
729
 
 
730
 
    def setup_commit_with_template(self):
731
 
        self.setup_editor()
732
691
        msgeditor.hooks.install_named_hook("commit_message_template",
733
692
                lambda commit_obj, msg: "save me some typing\n", None)
734
693
        tree = self.make_branch_and_tree('tree')
735
694
        self.build_tree(['tree/hello.txt'])
736
695
        tree.add('hello.txt')
737
 
        return tree
738
 
 
739
 
    def test_commit_hook_template_accepted(self):
740
 
        tree = self.setup_commit_with_template()
741
 
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
 
696
        out, err = self.run_bzr("commit tree/hello.txt")
742
697
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
743
698
        self.assertEqual('save me some typing\n', last_rev.message)
744
 
 
745
 
    def test_commit_hook_template_rejected(self):
746
 
        tree = self.setup_commit_with_template()
747
 
        expected = tree.last_revision()
748
 
        out, err = self.run_bzr_error(["empty commit message"],
749
 
            "commit tree/hello.txt", stdin="n\n")
750
 
        self.assertEqual(expected, tree.last_revision())
751
 
 
752
 
    def test_commit_without_username(self):
753
 
        """Ensure commit error if username is not set.
754
 
        """
755
 
        self.run_bzr(['init', 'foo'])
756
 
        os.chdir('foo')
757
 
        open('foo.txt', 'w').write('hello')
758
 
        self.run_bzr(['add'])
759
 
        osutils.set_or_unset_env('EMAIL', None)
760
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
761
 
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
762
 
        self.assertContainsRe(err, 'Unable to determine your name')
763
 
 
764
 
    def test_commit_recursive_checkout(self):
765
 
        """Ensure that a commit to a recursive checkout fails cleanly.
766
 
        """
767
 
        self.run_bzr(['init', 'test_branch'])
768
 
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
769
 
        os.chdir('test_checkout')
770
 
        self.run_bzr(['bind', '.']) # bind to self
771
 
        open('foo.txt', 'w').write('hello')
772
 
        self.run_bzr(['add'])
773
 
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
774
 
        self.assertEqual(out, '')
775
 
        self.assertContainsRe(err,
776
 
            'Branch.*test_checkout.*appears to be bound to itself')
777