/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-08-16 13:12:40 UTC
  • mfrom: (6071 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6076.
  • Revision ID: v.ladeuil+lp@free.fr-20110816131240-gcyn9cik86dxwgz3
Merge into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
 
20
import doctest
20
21
import os
21
22
import re
22
23
import sys
23
24
 
 
25
from testtools.matchers import DocTestMatches
 
26
 
24
27
from bzrlib import (
25
 
    bzrdir,
 
28
    config,
26
29
    osutils,
27
30
    ignores,
28
31
    msgeditor,
29
 
    osutils,
30
32
    tests,
31
33
    )
32
34
from bzrlib.bzrdir import BzrDir
33
35
from bzrlib.tests import (
34
36
    probe_bad_non_ascii,
 
37
    test_foreign,
35
38
    TestSkipped,
36
 
    UnicodeFilenameFeature,
 
39
    features,
37
40
    )
38
41
from bzrlib.tests import TestCaseWithTransport
39
42
 
47
50
        self.build_tree(['hello.txt'])
48
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
49
52
        self.assertEqual('', out)
50
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
51
 
                                  ' Use --unchanged to commit anyhow.\n')
 
53
        # Two ugly bits here.
 
54
        # 1) We really don't want 'aborting commit write group' anymore.
 
55
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
 
56
        self.assertThat(
 
57
            err,
 
58
            DocTestMatches("""\
 
59
Committing to: ...
 
60
bzr: ERROR: No changes to commit.\
 
61
 Please 'bzr add' the files you want to commit,\
 
62
 or use --unchanged to force an empty commit.
 
63
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
52
64
 
53
65
    def test_commit_success(self):
54
66
        """Successful commit should not leave behind a bzr-commit-* file"""
60
72
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
61
73
        self.assertEqual('', self.run_bzr('unknowns')[0])
62
74
 
 
75
    def test_commit_lossy_native(self):
 
76
        """A --lossy option to commit is supported."""
 
77
        self.make_branch_and_tree('.')
 
78
        self.run_bzr('commit --lossy --unchanged -m message')
 
79
        self.assertEqual('', self.run_bzr('unknowns')[0])
 
80
 
 
81
    def test_commit_lossy_foreign(self):
 
82
        test_foreign.register_dummy_foreign_for_test(self)
 
83
        self.make_branch_and_tree('.',
 
84
            format=test_foreign.DummyForeignVcsDirFormat())
 
85
        self.run_bzr('commit --lossy --unchanged -m message')
 
86
        output = self.run_bzr('revision-info')[0]
 
87
        self.assertTrue(output.startswith('1 dummy-'))
 
88
 
63
89
    def test_commit_with_path(self):
64
90
        """Commit tree with path of root specified"""
65
91
        a_tree = self.make_branch_and_tree('a')
79
105
        self.run_bzr('resolved b/a_file')
80
106
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
81
107
 
82
 
 
83
108
    def test_10_verbose_commit(self):
84
109
        """Add one file and examine verbose commit output"""
85
110
        tree = self.make_branch_and_tree('.')
113
138
    def test_unicode_commit_message_is_filename(self):
114
139
        """Unicode commit message same as a filename (Bug #563646).
115
140
        """
116
 
        self.requireFeature(UnicodeFilenameFeature)
 
141
        self.requireFeature(features.UnicodeFilenameFeature)
117
142
        file_name = u'\N{euro sign}'
118
143
        self.run_bzr(['init'])
119
144
        open(file_name, 'w').write('hello world')
309
334
        tree.add('foo.c')
310
335
        self.run_bzr('commit -m ""', retcode=3)
311
336
 
312
 
    def test_unsupported_encoding_commit_message(self):
313
 
        if sys.platform == 'win32':
314
 
            raise tests.TestNotApplicable('Win32 parses arguments directly'
315
 
                ' as Unicode, so we can\'t pass invalid non-ascii')
316
 
        tree = self.make_branch_and_tree('.')
317
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
318
 
        tree.add('foo.c')
319
 
        # LANG env variable has no effect on Windows
320
 
        # but some characters anyway cannot be represented
321
 
        # in default user encoding
322
 
        char = probe_bad_non_ascii(osutils.get_user_encoding())
323
 
        if char is None:
324
 
            raise TestSkipped('Cannot find suitable non-ascii character'
325
 
                'for user_encoding (%s)' % osutils.get_user_encoding())
326
 
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
327
 
                                          retcode=1,
328
 
                                          env_changes={'LANG': 'C'})
329
 
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
330
 
                                    'unsupported by the current encoding.')
331
 
 
332
337
    def test_other_branch_commit(self):
333
338
        # this branch is to ensure consistent behaviour, whether we're run
334
339
        # inside a branch, or not.
745
750
    def test_commit_hook_template_rejected(self):
746
751
        tree = self.setup_commit_with_template()
747
752
        expected = tree.last_revision()
748
 
        out, err = self.run_bzr_error(["empty commit message"],
 
753
        out, err = self.run_bzr_error(["Empty commit message specified."
 
754
                  " Please specify a commit message with either"
 
755
                  " --message or --file or leave a blank message"
 
756
                  " with --message \"\"."],
749
757
            "commit tree/hello.txt", stdin="n\n")
750
758
        self.assertEqual(expected, tree.last_revision())
751
759
 
 
760
    def test_set_commit_message(self):
 
761
        msgeditor.hooks.install_named_hook("set_commit_message",
 
762
                lambda commit_obj, msg: "save me some typing\n", None)
 
763
        tree = self.make_branch_and_tree('tree')
 
764
        self.build_tree(['tree/hello.txt'])
 
765
        tree.add('hello.txt')
 
766
        out, err = self.run_bzr("commit tree/hello.txt")
 
767
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
768
        self.assertEqual('save me some typing\n', last_rev.message)
 
769
 
752
770
    def test_commit_without_username(self):
753
771
        """Ensure commit error if username is not set.
754
772
        """
758
776
        self.run_bzr(['add'])
759
777
        self.overrideEnv('EMAIL', None)
760
778
        self.overrideEnv('BZR_EMAIL', None)
 
779
        # Also, make sure that it's not inferred from mailname.
 
780
        self.overrideAttr(config, '_auto_user_id',
 
781
            lambda: (None, None))
761
782
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
762
783
        self.assertContainsRe(err, 'Unable to determine your name')
763
784
 
774
795
        self.assertEqual(out, '')
775
796
        self.assertContainsRe(err,
776
797
            'Branch.*test_checkout.*appears to be bound to itself')
777