~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: 2011-03-28 01:28:09 UTC
  • mto: (5425.4.19 220464-stale-locks)
  • mto: This revision was merged to the branch mainline in revision 5970.
  • Revision ID: mbp@canonical.com-20110328012809-frw003r09tcrxkiz
Represent lock held info as an object, not just a dict

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
 
import doctest
21
20
import os
22
21
import re
23
22
import sys
24
23
 
25
 
from testtools.matchers import DocTestMatches
26
 
 
27
24
from bzrlib import (
28
 
    config,
 
25
    bzrdir,
29
26
    osutils,
30
27
    ignores,
31
28
    msgeditor,
 
29
    osutils,
32
30
    tests,
33
31
    )
34
32
from bzrlib.bzrdir import BzrDir
35
33
from bzrlib.tests import (
36
34
    probe_bad_non_ascii,
37
 
    test_foreign,
38
35
    TestSkipped,
39
 
    UnicodeFilenameFeature,
40
36
    )
41
37
from bzrlib.tests import TestCaseWithTransport
42
38
 
50
46
        self.build_tree(['hello.txt'])
51
47
        out,err = self.run_bzr('commit -m empty', retcode=3)
52
48
        self.assertEqual('', out)
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))
 
49
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
 
50
                                  ' Use --unchanged to commit anyhow.\n')
64
51
 
65
52
    def test_commit_success(self):
66
53
        """Successful commit should not leave behind a bzr-commit-* file"""
72
59
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
73
60
        self.assertEqual('', self.run_bzr('unknowns')[0])
74
61
 
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
 
 
89
62
    def test_commit_with_path(self):
90
63
        """Commit tree with path of root specified"""
91
64
        a_tree = self.make_branch_and_tree('a')
105
78
        self.run_bzr('resolved b/a_file')
106
79
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
107
80
 
 
81
 
108
82
    def test_10_verbose_commit(self):
109
83
        """Add one file and examine verbose commit output"""
110
84
        tree = self.make_branch_and_tree('.')
138
112
    def test_unicode_commit_message_is_filename(self):
139
113
        """Unicode commit message same as a filename (Bug #563646).
140
114
        """
141
 
        self.requireFeature(UnicodeFilenameFeature)
142
115
        file_name = u'\N{euro sign}'
143
116
        self.run_bzr(['init'])
144
117
        open(file_name, 'w').write('hello world')
334
307
        tree.add('foo.c')
335
308
        self.run_bzr('commit -m ""', retcode=3)
336
309
 
 
310
    def test_unsupported_encoding_commit_message(self):
 
311
        if sys.platform == 'win32':
 
312
            raise tests.TestNotApplicable('Win32 parses arguments directly'
 
313
                ' as Unicode, so we can\'t pass invalid non-ascii')
 
314
        tree = self.make_branch_and_tree('.')
 
315
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
316
        tree.add('foo.c')
 
317
        # LANG env variable has no effect on Windows
 
318
        # but some characters anyway cannot be represented
 
319
        # in default user encoding
 
320
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
321
        if char is None:
 
322
            raise TestSkipped('Cannot find suitable non-ascii character'
 
323
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
324
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
 
325
                                          retcode=1,
 
326
                                          env_changes={'LANG': 'C'})
 
327
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
 
328
                                    'unsupported by the current encoding.')
 
329
 
337
330
    def test_other_branch_commit(self):
338
331
        # this branch is to ensure consistent behaviour, whether we're run
339
332
        # inside a branch, or not.
724
717
            f = file('fed.bat', 'w')
725
718
            f.write('@rem dummy fed')
726
719
            f.close()
727
 
            self.overrideEnv('BZR_EDITOR', "fed.bat")
 
720
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
728
721
        else:
729
722
            f = file('fed.sh', 'wb')
730
723
            f.write('#!/bin/sh\n')
731
724
            f.close()
732
725
            os.chmod('fed.sh', 0755)
733
 
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
 
726
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
734
727
 
735
728
    def setup_commit_with_template(self):
736
729
        self.setup_editor()
761
754
        os.chdir('foo')
762
755
        open('foo.txt', 'w').write('hello')
763
756
        self.run_bzr(['add'])
764
 
        self.overrideEnv('EMAIL', None)
765
 
        self.overrideEnv('BZR_EMAIL', None)
766
 
        # Also, make sure that it's not inferred from mailname.
767
 
        self.overrideAttr(config, '_auto_user_id',
768
 
            lambda: (None, None))
 
757
        osutils.set_or_unset_env('EMAIL', None)
 
758
        osutils.set_or_unset_env('BZR_EMAIL', None)
769
759
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
770
760
        self.assertContainsRe(err, 'Unable to determine your name')
771
761