/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: Jelmer Vernooij
  • Date: 2011-04-16 08:42:21 UTC
  • mfrom: (5777.6.11 commit-lossy)
  • mto: This revision was merged to the branch mainline in revision 5792.
  • Revision ID: jelmer@samba.org-20110416084221-g9kgp1j4o9zo0kk4
merge commit-lossy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
20
21
import os
 
22
import re
21
23
import sys
22
24
 
 
25
from testtools.matchers import DocTestMatches
 
26
 
23
27
from bzrlib import (
 
28
    config,
24
29
    osutils,
25
30
    ignores,
26
31
    msgeditor,
27
 
    osutils,
28
32
    tests,
29
33
    )
30
34
from bzrlib.bzrdir import BzrDir
31
35
from bzrlib.tests import (
32
36
    probe_bad_non_ascii,
 
37
    test_foreign,
33
38
    TestSkipped,
 
39
    UnicodeFilenameFeature,
34
40
    )
35
 
from bzrlib.tests.blackbox import ExternalBase
36
 
 
37
 
 
38
 
class TestCommit(ExternalBase):
 
41
from bzrlib.tests import TestCaseWithTransport
 
42
 
 
43
 
 
44
class TestCommit(TestCaseWithTransport):
39
45
 
40
46
    def test_05_empty_commit(self):
41
47
        """Commit of tree with no versioned files should fail"""
44
50
        self.build_tree(['hello.txt'])
45
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
46
52
        self.assertEqual('', out)
47
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
48
 
                                  ' 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
aborting commit write group: PointlessCommit(No changes to commit)
 
61
bzr: ERROR: No changes to commit.\
 
62
 Please 'bzr add' the files you want to commit,\
 
63
 or use --unchanged to force an empty commit.
 
64
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
49
65
 
50
66
    def test_commit_success(self):
51
67
        """Successful commit should not leave behind a bzr-commit-* file"""
57
73
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
58
74
        self.assertEqual('', self.run_bzr('unknowns')[0])
59
75
 
 
76
    def test_commit_lossy_native(self):
 
77
        """A --lossy option to commit is supported."""
 
78
        self.make_branch_and_tree('.')
 
79
        self.run_bzr('commit --lossy --unchanged -m message')
 
80
        self.assertEqual('', self.run_bzr('unknowns')[0])
 
81
 
 
82
    def test_commit_lossy_foreign(self):
 
83
        test_foreign.register_dummy_foreign_for_test(self)
 
84
        self.make_branch_and_tree('.',
 
85
            format=test_foreign.DummyForeignVcsDirFormat())
 
86
        self.run_bzr('commit --lossy --unchanged -m message')
 
87
        output = self.run_bzr('revision-info')[0]
 
88
        self.assertTrue(output.startswith('1 dummy-'))
 
89
 
60
90
    def test_commit_with_path(self):
61
91
        """Commit tree with path of root specified"""
62
92
        a_tree = self.make_branch_and_tree('a')
76
106
        self.run_bzr('resolved b/a_file')
77
107
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
78
108
 
79
 
 
80
109
    def test_10_verbose_commit(self):
81
110
        """Add one file and examine verbose commit output"""
82
111
        tree = self.make_branch_and_tree('.')
107
136
                              'modified hello\.txt\n'
108
137
                              'Committed revision 2\.\n$')
109
138
 
 
139
    def test_unicode_commit_message_is_filename(self):
 
140
        """Unicode commit message same as a filename (Bug #563646).
 
141
        """
 
142
        self.requireFeature(UnicodeFilenameFeature)
 
143
        file_name = u'\N{euro sign}'
 
144
        self.run_bzr(['init'])
 
145
        open(file_name, 'w').write('hello world')
 
146
        self.run_bzr(['add'])
 
147
        out, err = self.run_bzr(['commit', '-m', file_name])
 
148
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
149
        te = osutils.get_terminal_encoding()
 
150
        self.assertContainsRe(err.decode(te),
 
151
            u'The commit message is a file name:',
 
152
            flags=reflags)
 
153
 
 
154
        # Run same test with a filename that causes encode
 
155
        # error for the terminal encoding. We do this
 
156
        # by forcing terminal encoding of ascii for
 
157
        # osutils.get_terminal_encoding which is used
 
158
        # by ui.text.show_warning
 
159
        default_get_terminal_enc = osutils.get_terminal_encoding
 
160
        try:
 
161
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
 
162
            file_name = u'foo\u1234'
 
163
            open(file_name, 'w').write('hello world')
 
164
            self.run_bzr(['add'])
 
165
            out, err = self.run_bzr(['commit', '-m', file_name])
 
166
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
167
            te = osutils.get_terminal_encoding()
 
168
            self.assertContainsRe(err.decode(te, 'replace'),
 
169
                u'The commit message is a file name:',
 
170
                flags=reflags)
 
171
        finally:
 
172
            osutils.get_terminal_encoding = default_get_terminal_enc
 
173
 
110
174
    def test_warn_about_forgotten_commit_message(self):
111
175
        """Test that the lack of -m parameter is caught"""
112
176
        wt = self.make_branch_and_tree('.')
663
727
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
664
728
 
665
729
    def test_commit_readonly_checkout(self):
666
 
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
 
730
        # https://bugs.launchpad.net/bzr/+bug/129701
667
731
        # "UnlockableTransport error trying to commit in checkout of readonly
668
732
        # branch"
669
733
        self.make_branch('master')
681
745
            f = file('fed.bat', 'w')
682
746
            f.write('@rem dummy fed')
683
747
            f.close()
684
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
748
            self.overrideEnv('BZR_EDITOR', "fed.bat")
685
749
        else:
686
750
            f = file('fed.sh', 'wb')
687
751
            f.write('#!/bin/sh\n')
688
752
            f.close()
689
753
            os.chmod('fed.sh', 0755)
690
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
754
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
691
755
 
692
756
    def setup_commit_with_template(self):
693
757
        self.setup_editor()
710
774
        out, err = self.run_bzr_error(["empty commit message"],
711
775
            "commit tree/hello.txt", stdin="n\n")
712
776
        self.assertEqual(expected, tree.last_revision())
 
777
 
 
778
    def test_commit_without_username(self):
 
779
        """Ensure commit error if username is not set.
 
780
        """
 
781
        self.run_bzr(['init', 'foo'])
 
782
        os.chdir('foo')
 
783
        open('foo.txt', 'w').write('hello')
 
784
        self.run_bzr(['add'])
 
785
        self.overrideEnv('EMAIL', None)
 
786
        self.overrideEnv('BZR_EMAIL', None)
 
787
        # Also, make sure that it's not inferred from mailname.
 
788
        self.overrideAttr(config, '_auto_user_id',
 
789
            lambda: (None, None))
 
790
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
 
791
        self.assertContainsRe(err, 'Unable to determine your name')
 
792
 
 
793
    def test_commit_recursive_checkout(self):
 
794
        """Ensure that a commit to a recursive checkout fails cleanly.
 
795
        """
 
796
        self.run_bzr(['init', 'test_branch'])
 
797
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
 
798
        os.chdir('test_checkout')
 
799
        self.run_bzr(['bind', '.']) # bind to self
 
800
        open('foo.txt', 'w').write('hello')
 
801
        self.run_bzr(['add'])
 
802
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
 
803
        self.assertEqual(out, '')
 
804
        self.assertContainsRe(err,
 
805
            'Branch.*test_checkout.*appears to be bound to itself')
 
806