/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-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ 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,
26
28
    config,
27
29
    osutils,
28
30
    ignores,
29
31
    msgeditor,
30
 
    osutils,
31
32
    tests,
32
33
    )
33
34
from bzrlib.bzrdir import BzrDir
34
35
from bzrlib.tests import (
35
36
    probe_bad_non_ascii,
 
37
    test_foreign,
36
38
    TestSkipped,
37
39
    UnicodeFilenameFeature,
38
40
    )
48
50
        self.build_tree(['hello.txt'])
49
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
50
52
        self.assertEqual('', out)
51
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
52
 
                                  ' 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))
53
64
 
54
65
    def test_commit_success(self):
55
66
        """Successful commit should not leave behind a bzr-commit-* file"""
61
72
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
62
73
        self.assertEqual('', self.run_bzr('unknowns')[0])
63
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
 
64
89
    def test_commit_with_path(self):
65
90
        """Commit tree with path of root specified"""
66
91
        a_tree = self.make_branch_and_tree('a')
80
105
        self.run_bzr('resolved b/a_file')
81
106
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
82
107
 
83
 
 
84
108
    def test_10_verbose_commit(self):
85
109
        """Add one file and examine verbose commit output"""
86
110
        tree = self.make_branch_and_tree('.')
310
334
        tree.add('foo.c')
311
335
        self.run_bzr('commit -m ""', retcode=3)
312
336
 
313
 
    def test_unsupported_encoding_commit_message(self):
314
 
        if sys.platform == 'win32':
315
 
            raise tests.TestNotApplicable('Win32 parses arguments directly'
316
 
                ' as Unicode, so we can\'t pass invalid non-ascii')
317
 
        tree = self.make_branch_and_tree('.')
318
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
319
 
        tree.add('foo.c')
320
 
        # LANG env variable has no effect on Windows
321
 
        # but some characters anyway cannot be represented
322
 
        # in default user encoding
323
 
        char = probe_bad_non_ascii(osutils.get_user_encoding())
324
 
        if char is None:
325
 
            raise TestSkipped('Cannot find suitable non-ascii character'
326
 
                'for user_encoding (%s)' % osutils.get_user_encoding())
327
 
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
328
 
                                          retcode=1,
329
 
                                          env_changes={'LANG': 'C'})
330
 
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
331
 
                                    'unsupported by the current encoding.')
332
 
 
333
337
    def test_other_branch_commit(self):
334
338
        # this branch is to ensure consistent behaviour, whether we're run
335
339
        # inside a branch, or not.
750
754
            "commit tree/hello.txt", stdin="n\n")
751
755
        self.assertEqual(expected, tree.last_revision())
752
756
 
 
757
    def test_set_commit_message(self):
 
758
        msgeditor.hooks.install_named_hook("set_commit_message",
 
759
                lambda commit_obj, msg: "save me some typing\n", None)
 
760
        tree = self.make_branch_and_tree('tree')
 
761
        self.build_tree(['tree/hello.txt'])
 
762
        tree.add('hello.txt')
 
763
        out, err = self.run_bzr("commit tree/hello.txt")
 
764
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
765
        self.assertEqual('save me some typing\n', last_rev.message)
 
766
 
753
767
    def test_commit_without_username(self):
754
768
        """Ensure commit error if username is not set.
755
769
        """
778
792
        self.assertEqual(out, '')
779
793
        self.assertContainsRe(err,
780
794
            'Branch.*test_checkout.*appears to be bound to itself')
781