~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-04-21 11:27:04 UTC
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@canonical.com-20100421112704-zijso22b6pdevrxy
Simplify various code to use user_url

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,
34
32
    probe_bad_non_ascii,
35
33
    TestSkipped,
36
34
    )
37
 
from bzrlib.tests import TestCaseWithTransport
38
 
 
39
 
 
40
 
class TestCommit(TestCaseWithTransport):
 
35
from bzrlib.tests.blackbox import ExternalBase
 
36
 
 
37
 
 
38
class TestCommit(ExternalBase):
41
39
 
42
40
    def test_05_empty_commit(self):
43
41
        """Commit of tree with no versioned files should fail"""
109
107
                              'modified hello\.txt\n'
110
108
                              'Committed revision 2\.\n$')
111
109
 
112
 
    def test_unicode_commit_message_is_filename(self):
113
 
        """Unicode commit message same as a filename (Bug #563646).
114
 
        """
115
 
        file_name = u'\N{euro sign}'
116
 
        self.run_bzr(['init'])
117
 
        open(file_name, 'w').write('hello world')
118
 
        self.run_bzr(['add'])
119
 
        out, err = self.run_bzr(['commit', '-m', file_name])
120
 
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
121
 
        te = osutils.get_terminal_encoding()
122
 
        self.assertContainsRe(err.decode(te),
123
 
            u'The commit message is a file name:',
124
 
            flags=reflags)
125
 
 
126
 
        # Run same test with a filename that causes encode
127
 
        # error for the terminal encoding. We do this
128
 
        # by forcing terminal encoding of ascii for
129
 
        # osutils.get_terminal_encoding which is used
130
 
        # by ui.text.show_warning
131
 
        default_get_terminal_enc = osutils.get_terminal_encoding
132
 
        try:
133
 
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
134
 
            file_name = u'foo\u1234'
135
 
            open(file_name, 'w').write('hello world')
136
 
            self.run_bzr(['add'])
137
 
            out, err = self.run_bzr(['commit', '-m', file_name])
138
 
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
139
 
            te = osutils.get_terminal_encoding()
140
 
            self.assertContainsRe(err.decode(te, 'replace'),
141
 
                u'The commit message is a file name:',
142
 
                flags=reflags)
143
 
        finally:
144
 
            osutils.get_terminal_encoding = default_get_terminal_enc
145
 
 
146
110
    def test_warn_about_forgotten_commit_message(self):
147
111
        """Test that the lack of -m parameter is caught"""
148
112
        wt = self.make_branch_and_tree('.')
699
663
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
700
664
 
701
665
    def test_commit_readonly_checkout(self):
702
 
        # https://bugs.launchpad.net/bzr/+bug/129701
 
666
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
703
667
        # "UnlockableTransport error trying to commit in checkout of readonly
704
668
        # branch"
705
669
        self.make_branch('master')
746
710
        out, err = self.run_bzr_error(["empty commit message"],
747
711
            "commit tree/hello.txt", stdin="n\n")
748
712
        self.assertEqual(expected, tree.last_revision())
749
 
 
750
 
    def test_commit_without_username(self):
751
 
        """Ensure commit error if username is not set.
752
 
        """
753
 
        self.run_bzr(['init', 'foo'])
754
 
        os.chdir('foo')
755
 
        open('foo.txt', 'w').write('hello')
756
 
        self.run_bzr(['add'])
757
 
        osutils.set_or_unset_env('EMAIL', None)
758
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
759
 
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
760
 
        self.assertContainsRe(err, 'Unable to determine your name')
761
 
 
762
 
    def test_commit_recursive_checkout(self):
763
 
        """Ensure that a commit to a recursive checkout fails cleanly.
764
 
        """
765
 
        self.run_bzr(['init', 'test_branch'])
766
 
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
767
 
        os.chdir('test_checkout')
768
 
        self.run_bzr(['bind', '.']) # bind to self
769
 
        open('foo.txt', 'w').write('hello')
770
 
        self.run_bzr(['add'])
771
 
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
772
 
        self.assertEqual(out, '')
773
 
        self.assertContainsRe(err,
774
 
            'Branch.*test_checkout.*appears to be bound to itself')
775