/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
16
17
18
"""Tests for the commit CLI of bzr."""
19
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
20
import doctest
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
21
import os
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
22
import re
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
23
import sys
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
24
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
25
from testtools.matchers import DocTestMatches
26
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from ... import (
5609.31.1 by mbp at sourcefrog
Blackbox tests for no identity set must disable whoami inference
28
    config,
2846.2.1 by Alexander Belchenko
merge approved chunks
29
    osutils,
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
30
    ignores,
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
31
    msgeditor,
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
32
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from ...controldir import ControlDir
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
34
from ...sixish import PY3
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
35
from .. import (
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
36
    test_foreign,
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
37
    features,
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
38
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
39
from .. import TestCaseWithTransport
40
from ..matchers import ContainsNoVfsCalls
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
41
42
43
class TestCommit(TestCaseWithTransport):
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
44
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
45
    def test_05_empty_commit(self):
46
        """Commit of tree with no versioned files should fail"""
47
        # If forced, it should succeed, but this is not tested here.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
48
        self.make_branch_and_tree('.')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
49
        self.build_tree(['hello.txt'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
50
        out, err = self.run_bzr('commit -m empty', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
51
        self.assertEqual('', out)
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
52
        # Two ugly bits here.
53
        # 1) We really don't want 'aborting commit write group' anymore.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
54
        # 2) brz: ERROR: is a really long line, so we wrap it with '\'
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
55
        self.assertThat(
56
            err,
57
            DocTestMatches("""\
58
Committing to: ...
6622.1.29 by Jelmer Vernooij
Fix some more tests.
59
brz: ERROR: No changes to commit.\
60
 Please 'brz add' the files you want to commit,\
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
61
 or use --unchanged to force an empty commit.
7143.15.2 by Jelmer Vernooij
Run autopep8.
62
""", flags=doctest.ELLIPSIS | doctest.REPORT_UDIFF))
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
63
64
    def test_commit_success(self):
65
        """Successful commit should not leave behind a bzr-commit-* file"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
66
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
67
        self.run_bzr('commit --unchanged -m message')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
68
        self.assertEqual('', self.run_bzr('unknowns')[0])
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
69
70
        # same for unicode messages
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
71
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
72
        self.assertEqual('', self.run_bzr('unknowns')[0])
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
73
5777.6.4 by Jelmer Vernooij
Add test for lossy commit to native branch.
74
    def test_commit_lossy_native(self):
75
        """A --lossy option to commit is supported."""
76
        self.make_branch_and_tree('.')
77
        self.run_bzr('commit --lossy --unchanged -m message')
78
        self.assertEqual('', self.run_bzr('unknowns')[0])
79
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
80
    def test_commit_lossy_foreign(self):
5777.6.6 by Jelmer Vernooij
Add lossy tests.
81
        test_foreign.register_dummy_foreign_for_test(self)
82
        self.make_branch_and_tree('.',
7143.15.2 by Jelmer Vernooij
Run autopep8.
83
                                  format=test_foreign.DummyForeignVcsDirFormat())
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
84
        self.run_bzr('commit --lossy --unchanged -m message')
5777.6.6 by Jelmer Vernooij
Add lossy tests.
85
        output = self.run_bzr('revision-info')[0]
86
        self.assertTrue(output.startswith('1 dummy-'))
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
87
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
88
    def test_commit_with_path(self):
89
        """Commit tree with path of root specified"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
90
        a_tree = self.make_branch_and_tree('a')
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
91
        self.build_tree(['a/a_file'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
92
        a_tree.add('a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
93
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
94
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
95
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
96
        self.build_tree_contents([('b/a_file', b'changes in b')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
97
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
98
6855.4.1 by Jelmer Vernooij
Yet more bees.
99
        self.build_tree_contents([('a/a_file', b'new contents')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
100
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
101
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
102
        b_tree.merge_from_branch(a_tree.branch)
2738.4.2 by Daniel Watkins
Now test for conflicts where appropriate.
103
        self.assertEqual(len(b_tree.conflicts()), 1)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
104
        self.run_bzr('resolved b/a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
105
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
106
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
107
    def test_10_verbose_commit(self):
108
        """Add one file and examine verbose commit output"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
109
        tree = self.make_branch_and_tree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
110
        self.build_tree(['hello.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
111
        tree.add("hello.txt")
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
112
        out, err = self.run_bzr('commit -m added')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
113
        self.assertEqual('', out)
114
        self.assertContainsRe(err, '^Committing to: .*\n'
115
                              'added hello.txt\n'
116
                              'Committed revision 1.\n$',)
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
117
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
118
    def prepare_simple_history(self):
119
        """Prepare and return a working tree with one commit of one file"""
120
        # Commit with modified file should say so
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
121
        wt = ControlDir.create_standalone_workingtree('.')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
122
        self.build_tree(['hello.txt', 'extra.txt'])
123
        wt.add(['hello.txt'])
124
        wt.commit(message='added')
125
        return wt
126
127
    def test_verbose_commit_modified(self):
128
        # Verbose commit of modified file should say so
129
        wt = self.prepare_simple_history()
6855.4.1 by Jelmer Vernooij
Yet more bees.
130
        self.build_tree_contents([('hello.txt', b'new contents')])
2789.2.11 by Ian Clatworthy
remove more reporting stuff
131
        out, err = self.run_bzr('commit -m modified')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
132
        self.assertEqual('', out)
133
        self.assertContainsRe(err, '^Committing to: .*\n'
134
                              'modified hello\\.txt\n'
135
                              'Committed revision 2\\.\n$')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
136
5167.1.4 by Parth Malwankar
show_warning now uses 'replace' option for encoding the message.
137
    def test_unicode_commit_message_is_filename(self):
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
138
        """Unicode commit message same as a filename (Bug #563646).
139
        """
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
140
        self.requireFeature(features.UnicodeFilenameFeature)
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
141
        file_name = u'\N{euro sign}'
142
        self.run_bzr(['init'])
6973.7.5 by Jelmer Vernooij
s/file/open.
143
        with open(file_name, 'w') as f:
144
            f.write('hello world')
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
145
        self.run_bzr(['add'])
146
        out, err = self.run_bzr(['commit', '-m', file_name])
7143.15.2 by Jelmer Vernooij
Run autopep8.
147
        reflags = re.MULTILINE | re.DOTALL | re.UNICODE
5167.1.4 by Parth Malwankar
show_warning now uses 'replace' option for encoding the message.
148
        te = osutils.get_terminal_encoding()
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
149
        self.assertContainsRe(err if PY3 else err.decode(te),
7143.15.2 by Jelmer Vernooij
Run autopep8.
150
                              u'The commit message is a file name:',
151
                              flags=reflags)
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
152
5167.1.6 by Parth Malwankar
fixed comment.
153
        # Run same test with a filename that causes encode
5167.1.5 by Parth Malwankar
added test to handle case if filename cannot be shown in terminal encoding
154
        # error for the terminal encoding. We do this
155
        # by forcing terminal encoding of ascii for
156
        # osutils.get_terminal_encoding which is used
157
        # by ui.text.show_warning
158
        default_get_terminal_enc = osutils.get_terminal_encoding
159
        try:
5320.2.7 by Robert Collins
Sanity check that new_trace_file in pop_log_file is valid, and also fix a test that monkey patched get_terminal_encoding.
160
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
5167.1.5 by Parth Malwankar
added test to handle case if filename cannot be shown in terminal encoding
161
            file_name = u'foo\u1234'
6973.7.5 by Jelmer Vernooij
s/file/open.
162
            with open(file_name, 'w') as f:
163
                f.write('hello world')
5167.1.5 by Parth Malwankar
added test to handle case if filename cannot be shown in terminal encoding
164
            self.run_bzr(['add'])
165
            out, err = self.run_bzr(['commit', '-m', file_name])
7143.15.2 by Jelmer Vernooij
Run autopep8.
166
            reflags = re.MULTILINE | re.DOTALL | re.UNICODE
5167.1.5 by Parth Malwankar
added test to handle case if filename cannot be shown in terminal encoding
167
            te = osutils.get_terminal_encoding()
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
168
            self.assertContainsRe(err if PY3 else err.decode(te, 'replace'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
169
                                  u'The commit message is a file name:',
170
                                  flags=reflags)
5167.1.5 by Parth Malwankar
added test to handle case if filename cannot be shown in terminal encoding
171
        finally:
172
            osutils.get_terminal_encoding = default_get_terminal_enc
173
6345.1.1 by Martin Packman
Add tests for non-ascii unversioned file error during commit
174
    def test_non_ascii_file_unversioned_utf8(self):
175
        self.requireFeature(features.UnicodeFilenameFeature)
176
        tree = self.make_branch_and_tree(".")
177
        self.build_tree(["f"])
178
        tree.add(["f"])
7065.3.6 by Jelmer Vernooij
Fix some more tests.
179
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
180
                                    encoding="utf-8", retcode=3)
7065.3.6 by Jelmer Vernooij
Fix some more tests.
181
        self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
6345.1.1 by Martin Packman
Add tests for non-ascii unversioned file error during commit
182
183
    def test_non_ascii_file_unversioned_iso_8859_5(self):
184
        self.requireFeature(features.UnicodeFilenameFeature)
185
        tree = self.make_branch_and_tree(".")
186
        self.build_tree(["f"])
187
        tree.add(["f"])
7065.3.6 by Jelmer Vernooij
Fix some more tests.
188
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
189
                                    encoding="iso-8859-5", retcode=3)
7065.3.6 by Jelmer Vernooij
Fix some more tests.
190
        if not PY3:
191
            self.expectFailure("Error messages are always written as UTF-8",
7143.15.2 by Jelmer Vernooij
Run autopep8.
192
                               self.assertNotContainsString, err, b"\xc2\xa7")
7065.3.6 by Jelmer Vernooij
Fix some more tests.
193
        else:
194
            self.assertNotContainsString(err, b"\xc2\xa7")
195
        self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
6345.1.1 by Martin Packman
Add tests for non-ascii unversioned file error during commit
196
4795.5.12 by Gioele Barabucci
Non-interactive warning for forgotten -m parameter
197
    def test_warn_about_forgotten_commit_message(self):
4795.5.8 by Gioele Barabucci
Test commit cancellation in presence of a suspect -m parameter
198
        """Test that the lack of -m parameter is caught"""
199
        wt = self.make_branch_and_tree('.')
200
        self.build_tree(['one', 'two'])
201
        wt.add(['two'])
4795.5.12 by Gioele Barabucci
Non-interactive warning for forgotten -m parameter
202
        out, err = self.run_bzr('commit -m one two')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
203
        self.assertContainsRe(err, "The commit message is a file name")
4795.5.8 by Gioele Barabucci
Test commit cancellation in presence of a suspect -m parameter
204
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
205
    def test_verbose_commit_renamed(self):
206
        # Verbose commit of renamed file should say so
207
        wt = self.prepare_simple_history()
208
        wt.rename_one('hello.txt', 'gutentag.txt')
2789.2.11 by Ian Clatworthy
remove more reporting stuff
209
        out, err = self.run_bzr('commit -m renamed')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
210
        self.assertEqual('', out)
211
        self.assertContainsRe(err, '^Committing to: .*\n'
212
                              'renamed hello\\.txt => gutentag\\.txt\n'
213
                              'Committed revision 2\\.$\n')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
214
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
215
    def test_verbose_commit_moved(self):
216
        # Verbose commit of file moved to new directory should say so
217
        wt = self.prepare_simple_history()
218
        os.mkdir('subdir')
219
        wt.add(['subdir'])
220
        wt.rename_one('hello.txt', 'subdir/hello.txt')
2789.2.11 by Ian Clatworthy
remove more reporting stuff
221
        out, err = self.run_bzr('commit -m renamed')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
222
        self.assertEqual('', out)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
223
        self.assertEqual({
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
224
            'Committing to: %s/' % osutils.getcwd(),
225
            'added subdir',
226
            'renamed hello.txt => subdir/hello.txt',
227
            'Committed revision 2.',
228
            '',
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
229
            }, set(err.split('\n')))
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
230
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
231
    def test_verbose_commit_with_unknown(self):
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
232
        """Unknown files should not be listed by default in verbose output"""
233
        # Is that really the best policy?
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
234
        wt = ControlDir.create_standalone_workingtree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
235
        self.build_tree(['hello.txt', 'extra.txt'])
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
236
        wt.add(['hello.txt'])
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
237
        out, err = self.run_bzr('commit -m added')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
238
        self.assertEqual('', out)
239
        self.assertContainsRe(err, '^Committing to: .*\n'
240
                              'added hello\\.txt\n'
241
                              'Committed revision 1\\.\n$')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
242
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
243
    def test_verbose_commit_with_unchanged(self):
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
244
        """Unchanged files should not be listed by default in verbose output"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
245
        tree = self.make_branch_and_tree('.')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
246
        self.build_tree(['hello.txt', 'unchanged.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
247
        tree.add('unchanged.txt')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
248
        self.run_bzr('commit -m unchanged unchanged.txt')
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
249
        tree.add("hello.txt")
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
250
        out, err = self.run_bzr('commit -m added')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
251
        self.assertEqual('', out)
252
        self.assertContainsRe(err, '^Committing to: .*\n'
253
                              'added hello\\.txt\n'
254
                              'Committed revision 2\\.$\n')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
255
2747.6.13 by Daniel Watkins
Renamed test to reflect what it is actually doing.
256
    def test_verbose_commit_includes_master_location(self):
2747.6.4 by Daniel Watkins
Modified test as suggested on-list.
257
        """Location of master is displayed when committing to bound branch"""
2747.6.2 by Daniel Watkins
Added test for behaviour.
258
        a_tree = self.make_branch_and_tree('a')
259
        self.build_tree(['a/b'])
260
        a_tree.add('b')
261
        a_tree.commit(message='Initial message')
262
263
        b_tree = a_tree.branch.create_checkout('b')
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
264
        expected = "%s/" % (osutils.abspath('a'), )
2747.6.4 by Daniel Watkins
Modified test as suggested on-list.
265
        out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
266
        self.assertEqual(err, 'Committing to: %s\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
267
                         'Committed revision 2.\n' % expected)
2747.6.2 by Daniel Watkins
Added test for behaviour.
268
4634.94.4 by John Arbash Meinel
Fix bug #433779, sanitize '\r' characters in commit.
269
    def test_commit_sanitizes_CR_in_message(self):
270
        # See bug #433779, basically Emacs likes to pass '\r\n' style line
6622.1.29 by Jelmer Vernooij
Fix some more tests.
271
        # endings to 'brz commit -m ""' which breaks because we don't allow
4634.94.4 by John Arbash Meinel
Fix bug #433779, sanitize '\r' characters in commit.
272
        # '\r' in commit messages. (Mostly because of issues where XML style
273
        # formats arbitrarily strip it out of the data while parsing.)
274
        # To make life easier for users, we just always translate '\r\n' =>
275
        # '\n'. And '\r' => '\n'.
276
        a_tree = self.make_branch_and_tree('a')
277
        self.build_tree(['a/b'])
278
        a_tree.add('b')
279
        self.run_bzr(['commit',
280
                      '-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
281
                     working_dir='a')
282
        rev_id = a_tree.branch.last_revision()
283
        rev = a_tree.branch.repository.get_revision(rev_id)
284
        self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
285
                             rev.message)
286
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
287
    def test_commit_merge_reports_all_modified_files(self):
288
        # the commit command should show all the files that are shown by
6622.1.29 by Jelmer Vernooij
Fix some more tests.
289
        # brz diff or brz status when committing, even when they were not
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
290
        # changed by the user but rather through doing a merge.
291
        this_tree = self.make_branch_and_tree('this')
292
        # we need a bunch of files and dirs, to perform one action on each.
293
        self.build_tree([
294
            'this/dirtorename/',
295
            'this/dirtoreparent/',
296
            'this/dirtoleave/',
297
            'this/dirtoremove/',
298
            'this/filetoreparent',
299
            'this/filetorename',
300
            'this/filetomodify',
301
            'this/filetoremove',
302
            'this/filetoleave']
303
            )
304
        this_tree.add([
305
            'dirtorename',
306
            'dirtoreparent',
307
            'dirtoleave',
308
            'dirtoremove',
309
            'filetoreparent',
310
            'filetorename',
311
            'filetomodify',
312
            'filetoremove',
313
            'filetoleave']
314
            )
315
        this_tree.commit('create_files')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
316
        other_dir = this_tree.controldir.sprout('other')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
317
        other_tree = other_dir.open_workingtree()
318
        other_tree.lock_write()
319
        # perform the needed actions on the files and dirs.
320
        try:
321
            other_tree.rename_one('dirtorename', 'renameddir')
322
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
323
            other_tree.rename_one('filetorename', 'renamedfile')
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
324
            other_tree.rename_one('filetoreparent',
325
                                  'renameddir/reparentedfile')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
326
            other_tree.remove(['dirtoremove', 'filetoremove'])
327
            self.build_tree_contents([
2738.4.5 by Daniel Watkins
Fixed whitespace issues.
328
                ('other/newdir/',),
6855.4.1 by Jelmer Vernooij
Yet more bees.
329
                ('other/filetomodify', b'new content'),
330
                ('other/newfile', b'new file content')])
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
331
            other_tree.add('newfile')
332
            other_tree.add('newdir/')
333
            other_tree.commit('modify all sample files and dirs.')
334
        finally:
335
            other_tree.unlock()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
336
        this_tree.merge_from_branch(other_tree.branch)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
337
        out, err = self.run_bzr('commit -m added', working_dir='this')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
338
        self.assertEqual('', out)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
339
        self.assertEqual({
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
340
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
341
            'modified filetomodify',
342
            'added newdir',
343
            'added newfile',
344
            'renamed dirtorename => renameddir',
345
            'renamed filetorename => renamedfile',
346
            'renamed dirtoreparent => renameddir/reparenteddir',
347
            'renamed filetoreparent => renameddir/reparentedfile',
348
            'deleted dirtoremove',
349
            'deleted filetoremove',
350
            'Committed revision 2.',
351
            ''
352
            }, set(err.split('\n')))
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
353
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
354
    def test_empty_commit_message(self):
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
355
        tree = self.make_branch_and_tree('.')
6855.4.1 by Jelmer Vernooij
Yet more bees.
356
        self.build_tree_contents([('foo.c', b'int main() {}')])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
357
        tree.add('foo.c')
6064.1.1 by Jelmer Vernooij
Allow committing with an explicit empty commit message.
358
        self.run_bzr('commit -m ""')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
359
360
    def test_other_branch_commit(self):
361
        # this branch is to ensure consistent behaviour, whether we're run
362
        # inside a branch, or not.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
363
        outer_tree = self.make_branch_and_tree('.')
364
        inner_tree = self.make_branch_and_tree('branch')
365
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
366
            ('branch/foo.c', b'int main() {}'),
367
            ('branch/bar.c', b'int main() {}')])
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
368
        inner_tree.add(['foo.c', 'bar.c'])
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
369
        # can't commit files in different trees; sane error
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
370
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
371
        # can commit to branch - records foo.c only
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
372
        self.run_bzr('commit -m newstuff branch/foo.c')
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
373
        # can commit to branch - records bar.c
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
374
        self.run_bzr('commit -m newstuff branch')
4570.4.3 by Robert Collins
Fix a couple of small bugs in the patch - use specific files with record_iter_changs, and the CLI shouldn't generate a filter of [] for commit.
375
        # No changes left
7143.15.2 by Jelmer Vernooij
Run autopep8.
376
        self.run_bzr_error(["No changes to commit"],
377
                           'commit -m newstuff branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
378
379
    def test_out_of_date_tree_commit(self):
380
        # check we get an error code and a clear message committing with an out
381
        # of date checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
382
        tree = self.make_branch_and_tree('branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
383
        # make a checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
384
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
385
        # commit to the original branch to make the checkout out of date
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
386
        tree.commit('message branch', allow_pointless=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
387
        # now commit to the checkout should emit
6622.1.29 by Jelmer Vernooij
Fix some more tests.
388
        # ERROR: Out of date with the branch, 'brz update' is suggested
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
389
        output = self.run_bzr('commit --unchanged -m checkout_message '
7143.15.2 by Jelmer Vernooij
Run autopep8.
390
                              'checkout', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
391
        self.assertEqual(output,
392
                         ('',
6622.1.29 by Jelmer Vernooij
Fix some more tests.
393
                          "brz: ERROR: Working tree is out of date, please "
394
                          "run 'brz update'.\n"))
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
395
396
    def test_local_commit_unbound(self):
397
        # a --local commit on an unbound branch is an error
398
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
399
        out, err = self.run_bzr('commit --local', retcode=3)
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
400
        self.assertEqualDiff('', out)
6622.1.29 by Jelmer Vernooij
Fix some more tests.
401
        self.assertEqualDiff('brz: ERROR: Cannot perform local-only commits '
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
402
                             'on unbound branches.\n', err)
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
403
404
    def test_commit_a_text_merge_in_a_checkout(self):
405
        # checkouts perform multiple actions in a transaction across bond
406
        # branches and their master, and have been observed to fail in the
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
407
        # past. This is a user story reported to fail in bug #43959 where
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
408
        # a merge done in a checkout (using the update command) failed to
409
        # commit correctly.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
410
        trunk = self.make_branch_and_tree('trunk')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
411
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
412
        u1 = trunk.branch.create_checkout('u1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
413
        self.build_tree_contents([('u1/hosts', b'initial contents\n')])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
414
        u1.add('hosts')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
415
        self.run_bzr('commit -m add-hosts u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
416
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
417
        u2 = trunk.branch.create_checkout('u2')
6855.4.1 by Jelmer Vernooij
Yet more bees.
418
        self.build_tree_contents([('u2/hosts', b'altered in u2\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
419
        self.run_bzr('commit -m checkin-from-u2 u2')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
420
421
        # make an offline commits
7143.15.2 by Jelmer Vernooij
Run autopep8.
422
        self.build_tree_contents(
423
            [('u1/hosts', b'first offline change in u1\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
424
        self.run_bzr('commit -m checkin-offline --local u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
425
426
        # now try to pull in online work from u2, and then commit our offline
427
        # work as a merge
428
        # retcode 1 as we expect a text conflict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
429
        self.run_bzr('update u1', retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
430
        self.assertFileEqual(b'''\
4985.3.17 by Vincent Ladeuil
Some cleanup.
431
<<<<<<< TREE
432
first offline change in u1
433
=======
434
altered in u2
435
>>>>>>> MERGE-SOURCE
436
''',
4985.3.10 by Gerard Krol
Reformat long lines
437
                             'u1/hosts')
4985.3.1 by Gerard Krol
Werkt wel ok
438
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
439
        self.run_bzr('resolved u1/hosts')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
440
        # add a text change here to represent resolving the merge conflicts in
441
        # favour of a new version of the file not identical to either the u1
442
        # version or the u2 version.
6855.4.1 by Jelmer Vernooij
Yet more bees.
443
        self.build_tree_contents([('u1/hosts', b'merge resolution\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
444
        self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
445
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
446
    def test_commit_exclude_excludes_modified_files(self):
447
        """Commit -x foo should ignore changes to foo."""
448
        tree = self.make_branch_and_tree('.')
449
        self.build_tree(['a', 'b', 'c'])
450
        tree.smart_add(['.'])
451
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
452
        self.assertFalse('added b' in out)
453
        self.assertFalse('added b' in err)
3602.1.4 by Robert Collins
Andrew's review feedback.
454
        # If b was excluded it will still be 'added' in status.
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
455
        out, err = self.run_bzr(['added'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
456
        self.assertEqual('b\n', out)
457
        self.assertEqual('', err)
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
458
459
    def test_commit_exclude_twice_uses_both_rules(self):
460
        """Commit -x foo -x bar should ignore changes to foo and bar."""
461
        tree = self.make_branch_and_tree('.')
462
        self.build_tree(['a', 'b', 'c'])
463
        tree.smart_add(['.'])
464
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
465
        self.assertFalse('added b' in out)
466
        self.assertFalse('added c' in out)
467
        self.assertFalse('added b' in err)
468
        self.assertFalse('added c' in err)
3602.1.4 by Robert Collins
Andrew's review feedback.
469
        # If b was excluded it will still be 'added' in status.
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
470
        out, err = self.run_bzr(['added'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
471
        self.assertTrue('b\n' in out)
472
        self.assertTrue('c\n' in out)
473
        self.assertEqual('', err)
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
474
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
475
    def test_commit_respects_spec_for_removals(self):
476
        """Commit with a file spec should only commit removals that match"""
477
        t = self.make_branch_and_tree('.')
478
        self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
479
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
480
        t.commit('Create')
481
        t.remove(['file-a', 'dir-a/file-b'])
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
482
        result = self.run_bzr('commit . -m removed-file-b',
483
                              working_dir='dir-a')[1]
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
484
        self.assertNotContainsRe(result, 'file-a')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
485
        result = self.run_bzr('status', working_dir='dir-a')[0]
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
486
        self.assertContainsRe(result, 'removed:\n  file-a')
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
487
488
    def test_strict_commit(self):
489
        """Commit with --strict works if everything is known"""
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
490
        ignores._set_user_ignores([])
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
491
        tree = self.make_branch_and_tree('tree')
492
        self.build_tree(['tree/a'])
493
        tree.add('a')
494
        # A simple change should just work
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
495
        self.run_bzr('commit --strict -m adding-a', working_dir='tree')
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
496
497
    def test_strict_commit_no_changes(self):
498
        """commit --strict gives "no changes" if there is nothing to commit"""
499
        tree = self.make_branch_and_tree('tree')
500
        self.build_tree(['tree/a'])
501
        tree.add('a')
502
        tree.commit('adding a')
503
504
        # With no changes, it should just be 'no changes'
505
        # Make sure that commit is failing because there is nothing to do
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
506
        self.run_bzr_error(['No changes to commit'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
507
                           'commit --strict -m no-changes',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
508
                           working_dir='tree')
509
510
        # But --strict doesn't care if you supply --unchanged
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
511
        self.run_bzr('commit --strict --unchanged -m no-changes',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
512
                     working_dir='tree')
513
514
    def test_strict_commit_unknown(self):
515
        """commit --strict fails if a file is unknown"""
516
        tree = self.make_branch_and_tree('tree')
517
        self.build_tree(['tree/a'])
518
        tree.add('a')
519
        tree.commit('adding a')
520
521
        # Add one file so there is a change, but forget the other
522
        self.build_tree(['tree/b', 'tree/c'])
523
        tree.add('b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
524
        self.run_bzr_error(['Commit refused because there are unknown files'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
525
                           'commit --strict -m add-b',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
526
                           working_dir='tree')
527
528
        # --no-strict overrides --strict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
529
        self.run_bzr('commit --strict -m add-b --no-strict',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
530
                     working_dir='tree')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
531
532
    def test_fixes_bug_output(self):
533
        """commit --fixes=lp:23452 succeeds without output."""
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
534
        tree = self.make_branch_and_tree('tree')
535
        self.build_tree(['tree/hello.txt'])
536
        tree.add('hello.txt')
2376.4.12 by Jonathan Lange
Update NEWS file.
537
        output, err = self.run_bzr(
2789.2.11 by Ian Clatworthy
remove more reporting stuff
538
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
539
        self.assertEqual('', output)
540
        self.assertContainsRe(err, 'Committing to: .*\n'
541
                              'added hello\\.txt\n'
542
                              'Committed revision 1\\.\n')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
543
6805.1.3 by Jelmer Vernooij
Add test.
544
    def test_fixes_bug_unicode(self):
545
        """commit --fixes=lp:unicode succeeds without output."""
546
        tree = self.make_branch_and_tree('tree')
547
        self.build_tree(['tree/hello.txt'])
548
        tree.add('hello.txt')
7065.3.6 by Jelmer Vernooij
Fix some more tests.
549
        output, err = self.run_bzr_raw(
6805.1.3 by Jelmer Vernooij
Add test.
550
            ['commit', '-m', 'hello',
6805.1.4 by Jelmer Vernooij
Fixes from Martin.
551
             u'--fixes=generic:\u20ac', 'tree/hello.txt'],
6805.1.3 by Jelmer Vernooij
Add test.
552
            encoding='utf-8', retcode=3)
7065.3.6 by Jelmer Vernooij
Fix some more tests.
553
        self.assertEqual(b'', output)
6805.1.3 by Jelmer Vernooij
Add test.
554
        self.assertContainsRe(err,
7143.15.2 by Jelmer Vernooij
Run autopep8.
555
                              b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
6805.1.3 by Jelmer Vernooij
Add test.
556
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
557
    def test_no_bugs_no_properties(self):
558
        """If no bugs are fixed, the bugs property is not set.
559
560
        see https://beta.launchpad.net/bzr/+bug/109613
561
        """
562
        tree = self.make_branch_and_tree('tree')
563
        self.build_tree(['tree/hello.txt'])
564
        tree.add('hello.txt')
6805.1.3 by Jelmer Vernooij
Add test.
565
        self.run_bzr('commit -m hello tree/hello.txt')
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
566
        # Get the revision properties, ignoring the branch-nick property, which
567
        # we don't care about for this test.
568
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
569
        properties = dict(last_rev.properties)
570
        del properties['branch-nick']
571
        self.assertFalse('bugs' in properties)
572
7131.10.1 by Jelmer Vernooij
Add --bugs option to 'bzr commit'.
573
    def test_bugs_sets_property(self):
574
        """commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
575
        tree = self.make_branch_and_tree('tree')
576
        self.build_tree(['tree/hello.txt'])
577
        tree.add('hello.txt')
578
        self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
579
580
        # Get the revision properties, ignoring the branch-nick property, which
581
        # we don't care about for this test.
582
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
583
        properties = dict(last_rev.properties)
584
        del properties[u'branch-nick']
585
586
        self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
587
                         properties)
588
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
589
    def test_fixes_bug_sets_property(self):
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
590
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
591
        tree = self.make_branch_and_tree('tree')
592
        self.build_tree(['tree/hello.txt'])
593
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
594
        self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
595
596
        # Get the revision properties, ignoring the branch-nick property, which
597
        # we don't care about for this test.
598
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
599
        properties = dict(last_rev.properties)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
600
        del properties[u'branch-nick']
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
601
6973.13.2 by Jelmer Vernooij
Fix some more tests.
602
        self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 fixed'},
2376.4.7 by jml at canonical
- Add docstrings to tests.
603
                         properties)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
604
605
    def test_fixes_multiple_bugs_sets_properties(self):
606
        """--fixes can be used more than once to show that bugs are fixed."""
607
        tree = self.make_branch_and_tree('tree')
608
        self.build_tree(['tree/hello.txt'])
609
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
610
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
611
                     ' tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
612
613
        # Get the revision properties, ignoring the branch-nick property, which
614
        # we don't care about for this test.
615
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
616
        properties = dict(last_rev.properties)
617
        del properties['branch-nick']
618
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
619
        self.assertEqual(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
620
            {u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
7143.15.2 by Jelmer Vernooij
Run autopep8.
621
             'https://launchpad.net/bugs/235 fixed'},
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
622
            properties)
2376.4.7 by jml at canonical
- Add docstrings to tests.
623
624
    def test_fixes_bug_with_alternate_trackers(self):
625
        """--fixes can be used on a properly configured branch to mark bug
626
        fixes on multiple trackers.
627
        """
628
        tree = self.make_branch_and_tree('tree')
629
        tree.branch.get_config().set_user_option(
630
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
631
        self.build_tree(['tree/hello.txt'])
632
        tree.add('hello.txt')
7143.15.2 by Jelmer Vernooij
Run autopep8.
633
        self.run_bzr(
634
            'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
2376.4.7 by jml at canonical
- Add docstrings to tests.
635
636
        # Get the revision properties, ignoring the branch-nick property, which
637
        # we don't care about for this test.
638
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
639
        properties = dict(last_rev.properties)
640
        del properties['branch-nick']
641
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
642
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
643
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
644
                     'http://twistedmatrix.com/trac/ticket/235 fixed'},
645
            properties)
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
646
647
    def test_fixes_unknown_bug_prefix(self):
648
        tree = self.make_branch_and_tree('tree')
649
        self.build_tree(['tree/hello.txt'])
650
        tree.add('hello.txt')
651
        self.run_bzr_error(
652
            ["Unrecognized bug %s. Commit refused." % 'xxx:123'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
653
            'commit -m add-b --fixes=xxx:123',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
654
            working_dir='tree')
655
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
656
    def test_fixes_bug_with_default_tracker(self):
657
        """commit --fixes=234 uses the default bug tracker."""
658
        tree = self.make_branch_and_tree('tree')
659
        self.build_tree(['tree/hello.txt'])
660
        tree.add('hello.txt')
661
        self.run_bzr_error(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
662
            ["brz: ERROR: No tracker specified for bug 123. Use the form "
7143.15.2 by Jelmer Vernooij
Run autopep8.
663
             "'tracker:id' or specify a default bug tracker using the "
664
             "`bugtracker` option.\n"
665
             "See \"brz help bugs\" for more information on this feature. "
666
             "Commit refused."],
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
667
            'commit -m add-b --fixes=123',
668
            working_dir='tree')
6463.1.1 by Jelmer Vernooij
Migrate 'bugtracker' setting to config stacks.
669
        tree.branch.get_config_stack().set("bugtracker", "lp")
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
670
        self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
671
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
6120.1.3 by Jelmer Vernooij
Review feedback from vila
672
        self.assertEqual('https://launchpad.net/bugs/234 fixed',
673
                         last_rev.properties['bugs'])
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
674
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
675
    def test_fixes_invalid_bug_number(self):
676
        tree = self.make_branch_and_tree('tree')
677
        self.build_tree(['tree/hello.txt'])
678
        tree.add('hello.txt')
679
        self.run_bzr_error(
3535.10.9 by James Westby
Make the improved messages show up in the UI.
680
            ["Did not understand bug identifier orange: Must be an integer. "
6622.1.29 by Jelmer Vernooij
Fix some more tests.
681
             "See \"brz help bugs\" for more information on this feature.\n"
3535.10.9 by James Westby
Make the improved messages show up in the UI.
682
             "Commit refused."],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
683
            'commit -m add-b --fixes=lp:orange',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
684
            working_dir='tree')
2376.4.7 by jml at canonical
- Add docstrings to tests.
685
686
    def test_fixes_invalid_argument(self):
687
        """Raise an appropriate error when the fixes argument isn't tag:id."""
688
        tree = self.make_branch_and_tree('tree')
689
        self.build_tree(['tree/hello.txt'])
690
        tree.add('hello.txt')
691
        self.run_bzr_error(
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
692
            [r"Invalid bug orange:apples:bananas. Must be in the form of "
6622.1.29 by Jelmer Vernooij
Fix some more tests.
693
             r"'tracker:id'\. See \"brz help bugs\" for more information on "
6120.1.1 by Jelmer Vernooij
Support a default bug tracker.
694
             r"this feature.\nCommit refused\."],
695
            'commit -m add-b --fixes=orange:apples:bananas',
2376.4.7 by jml at canonical
- Add docstrings to tests.
696
            working_dir='tree')
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
697
698
    def test_no_author(self):
699
        """If the author is not specified, the author property is not set."""
700
        tree = self.make_branch_and_tree('tree')
701
        self.build_tree(['tree/hello.txt'])
702
        tree.add('hello.txt')
7143.15.2 by Jelmer Vernooij
Run autopep8.
703
        self.run_bzr('commit -m hello tree/hello.txt')
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
704
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
705
        properties = last_rev.properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
706
        self.assertFalse('author' in properties)
707
708
    def test_author_sets_property(self):
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
709
        """commit --author='John Doe <jdoe@example.com>' sets the author
710
           revprop.
711
        """
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
712
        tree = self.make_branch_and_tree('tree')
713
        self.build_tree(['tree/hello.txt'])
714
        tree.add('hello.txt')
3099.2.1 by John Arbash Meinel
Allow 'bzr commit --author' to take a unicode string.
715
        self.run_bzr(["commit", '-m', 'hello',
716
                      '--author', u'John D\xf6 <jdoe@example.com>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
717
                      "tree/hello.txt"])
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
718
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
719
        properties = last_rev.properties
7143.15.2 by Jelmer Vernooij
Run autopep8.
720
        self.assertEqual(u'John D\xf6 <jdoe@example.com>',
721
                         properties['authors'])
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
722
723
    def test_author_no_email(self):
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
724
        """Author's name without an email address is allowed, too."""
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
725
        tree = self.make_branch_and_tree('tree')
726
        self.build_tree(['tree/hello.txt'])
727
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
728
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
729
                                "tree/hello.txt")
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
730
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
731
        properties = last_rev.properties
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
732
        self.assertEqual('John Doe', properties['authors'])
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
733
4056.2.1 by James Westby
Allow specifying multiple authors for a revision.
734
    def test_multiple_authors(self):
735
        """Multiple authors can be specyfied, and all are stored."""
736
        tree = self.make_branch_and_tree('tree')
737
        self.build_tree(['tree/hello.txt'])
738
        tree.add('hello.txt')
739
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
740
                                "--author='Jane Rey' tree/hello.txt")
741
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
742
        properties = last_rev.properties
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
743
        self.assertEqual('John Doe\nJane Rey', properties['authors'])
4056.2.1 by James Westby
Allow specifying multiple authors for a revision.
744
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
745
    def test_commit_time(self):
746
        tree = self.make_branch_and_tree('tree')
747
        self.build_tree(['tree/hello.txt'])
748
        tree.add('hello.txt')
749
        out, err = self.run_bzr("commit -m hello "
7143.15.2 by Jelmer Vernooij
Run autopep8.
750
                                "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
751
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
752
        self.assertEqual(
753
            'Sat 2009-10-10 08:00:00 +0100',
754
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
7143.15.2 by Jelmer Vernooij
Run autopep8.
755
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
756
    def test_commit_time_bad_time(self):
757
        tree = self.make_branch_and_tree('tree')
758
        self.build_tree(['tree/hello.txt'])
759
        tree.add('hello.txt')
760
        out, err = self.run_bzr("commit -m hello "
7143.15.2 by Jelmer Vernooij
Run autopep8.
761
                                "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
762
        self.assertStartsWith(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
763
            err, "brz: ERROR: Could not parse --commit-time:")
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
764
6280.2.1 by Matt Giuca
bzrlib.timestamp: More robust handling of time stamp string. (LP: #892657)
765
    def test_commit_time_missing_tz(self):
766
        tree = self.make_branch_and_tree('tree')
767
        self.build_tree(['tree/hello.txt'])
768
        tree.add('hello.txt')
769
        out, err = self.run_bzr("commit -m hello "
7143.15.2 by Jelmer Vernooij
Run autopep8.
770
                                "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
6280.2.1 by Matt Giuca
bzrlib.timestamp: More robust handling of time stamp string. (LP: #892657)
771
        self.assertStartsWith(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
772
            err, "brz: ERROR: Could not parse --commit-time:")
6280.2.1 by Matt Giuca
bzrlib.timestamp: More robust handling of time stamp string. (LP: #892657)
773
        # Test that it is actually checking and does not simply crash with
774
        # some other exception
6280.2.3 by Matt Giuca
bzrlib.timestamp: Better error message if the string is missing a timezone offset.
775
        self.assertContainsString(err, "missing a timezone offset")
6280.2.1 by Matt Giuca
bzrlib.timestamp: More robust handling of time stamp string. (LP: #892657)
776
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
777
    def test_partial_commit_with_renames_in_tree(self):
2833.2.2 by Alexander Belchenko
Bug #140419 fixed by Robert Collins
778
        # this test illustrates bug #140419
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
779
        t = self.make_branch_and_tree('.')
780
        self.build_tree(['dir/', 'dir/a', 'test'])
781
        t.add(['dir/', 'dir/a', 'test'])
782
        t.commit('initial commit')
783
        # important part: file dir/a should change parent
784
        # and should appear before old parent
785
        # then during partial commit we have error
786
        # parent_id {dir-XXX} not in inventory
787
        t.rename_one('dir/a', 'a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
788
        self.build_tree_contents([('test', b'changes in test')])
2833.2.2 by Alexander Belchenko
Bug #140419 fixed by Robert Collins
789
        # partial commit
790
        out, err = self.run_bzr('commit test -m "partial commit"')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
791
        self.assertEqual('', out)
792
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
2872.5.1 by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).
793
794
    def test_commit_readonly_checkout(self):
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
795
        # https://bugs.launchpad.net/bzr/+bug/129701
2872.5.1 by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).
796
        # "UnlockableTransport error trying to commit in checkout of readonly
797
        # branch"
798
        self.make_branch('master')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
799
        master = ControlDir.open_from_transport(
2872.5.1 by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).
800
            self.get_readonly_transport('master')).open_branch()
801
        master.create_checkout('checkout')
802
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
803
                                retcode=3)
2872.5.1 by Martin Pool
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).
804
        self.assertContainsRe(err,
7143.15.2 by Jelmer Vernooij
Run autopep8.
805
                              r'^brz: ERROR: Cannot lock.*readonly transport')
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
806
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
807
    def setup_editor(self):
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
808
        # Test that commit template hooks work
809
        if sys.platform == "win32":
6973.7.5 by Jelmer Vernooij
s/file/open.
810
            with open('fed.bat', 'w') as f:
811
                f.write('@rem dummy fed')
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
812
            self.overrideEnv('BRZ_EDITOR', "fed.bat")
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
813
        else:
6973.7.5 by Jelmer Vernooij
s/file/open.
814
            with open('fed.sh', 'wb') as f:
815
                f.write(b'#!/bin/sh\n')
6619.3.14 by Jelmer Vernooij
Convert some octal numbers to new notations.
816
            os.chmod('fed.sh', 0o755)
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
817
            self.overrideEnv('BRZ_EDITOR', "./fed.sh")
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
818
819
    def setup_commit_with_template(self):
820
        self.setup_editor()
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
821
        msgeditor.hooks.install_named_hook("commit_message_template",
7143.15.2 by Jelmer Vernooij
Run autopep8.
822
                                           lambda commit_obj, msg: "save me some typing\n", None)
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
823
        tree = self.make_branch_and_tree('tree')
824
        self.build_tree(['tree/hello.txt'])
825
        tree.add('hello.txt')
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
826
        return tree
827
6064.1.1 by Jelmer Vernooij
Allow committing with an explicit empty commit message.
828
    def test_edit_empty_message(self):
829
        tree = self.make_branch_and_tree('tree')
830
        self.setup_editor()
831
        self.build_tree(['tree/hello.txt'])
832
        tree.add('hello.txt')
833
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
7143.15.2 by Jelmer Vernooij
Run autopep8.
834
                                stdin="y\n")
6064.1.1 by Jelmer Vernooij
Allow committing with an explicit empty commit message.
835
        self.assertContainsRe(err,
7143.15.2 by Jelmer Vernooij
Run autopep8.
836
                              "brz: ERROR: Empty commit message specified")
6064.1.1 by Jelmer Vernooij
Allow committing with an explicit empty commit message.
837
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
838
    def test_commit_hook_template_accepted(self):
839
        tree = self.setup_commit_with_template()
5137.1.1 by Robert Collins
* ``bzr commit`` will prompt before using a commit message that was
840
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
841
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
842
        self.assertEqual('save me some typing\n', last_rev.message)
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
843
844
    def test_commit_hook_template_rejected(self):
845
        tree = self.setup_commit_with_template()
846
        expected = tree.last_revision()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
847
        out, err = self.run_bzr_error(["Empty commit message specified."
7143.15.2 by Jelmer Vernooij
Run autopep8.
848
                                       " Please specify a commit message with either"
849
                                       " --message or --file or leave a blank message"
850
                                       " with --message \"\"."],
851
                                      "commit tree/hello.txt", stdin="n\n")
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
852
        self.assertEqual(expected, tree.last_revision())
5187.2.4 by Parth Malwankar
added tests.
853
5912.4.10 by Jonathan Riddell
add test for set_commit_message hook
854
    def test_set_commit_message(self):
855
        msgeditor.hooks.install_named_hook("set_commit_message",
7143.15.2 by Jelmer Vernooij
Run autopep8.
856
                                           lambda commit_obj, msg: "save me some typing\n", None)
5912.4.10 by Jonathan Riddell
add test for set_commit_message hook
857
        tree = self.make_branch_and_tree('tree')
858
        self.build_tree(['tree/hello.txt'])
859
        tree.add('hello.txt')
860
        out, err = self.run_bzr("commit tree/hello.txt")
861
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
862
        self.assertEqual('save me some typing\n', last_rev.message)
863
5187.2.4 by Parth Malwankar
added tests.
864
    def test_commit_without_username(self):
865
        """Ensure commit error if username is not set.
866
        """
867
        self.run_bzr(['init', 'foo'])
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
868
        with open('foo/foo.txt', 'w') as f:
869
            f.write('hello')
870
        self.run_bzr(['add'], working_dir='foo')
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
871
        self.overrideEnv('EMAIL', None)
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
872
        self.overrideEnv('BRZ_EMAIL', None)
5609.31.1 by mbp at sourcefrog
Blackbox tests for no identity set must disable whoami inference
873
        # Also, make sure that it's not inferred from mailname.
874
        self.overrideAttr(config, '_auto_user_id',
7143.15.2 by Jelmer Vernooij
Run autopep8.
875
                          lambda: (None, None))
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
876
        self.run_bzr_error(
877
            ['Unable to determine your name'],
878
            ['commit', '-m', 'initial'], working_dir='foo')
5050.7.1 by Parth Malwankar
added test case for recursion error
879
880
    def test_commit_recursive_checkout(self):
881
        """Ensure that a commit to a recursive checkout fails cleanly.
882
        """
883
        self.run_bzr(['init', 'test_branch'])
884
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
885
        # bind to self
886
        self.run_bzr(['bind', '.'], working_dir='test_checkout')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
887
        with open('test_checkout/foo.txt', 'w') as f:
888
            f.write('hello')
889
        self.run_bzr(['add'], working_dir='test_checkout')
890
        out, err = self.run_bzr_error(
891
            ['Branch.*test_checkout.*appears to be bound to itself'],
892
            ['commit', '-m', 'addedfoo'], working_dir='test_checkout')
6323.2.2 by Jelmer Vernooij
Add hpss call count for committing to a lightweight checkout.
893
6379.9.1 by Rory Yorke
Added test case to reproduce error (test_mv_dirs_non_ascii).
894
    def test_mv_dirs_non_ascii(self):
895
        """Move directory with non-ascii name and containing files.
6379.9.4 by Rory Yorke
Code fixes following review.
896
6379.9.1 by Rory Yorke
Added test case to reproduce error (test_mv_dirs_non_ascii).
897
        Regression test for bug 185211.
898
        """
899
        tree = self.make_branch_and_tree('.')
6426.5.1 by Martin Packman
Use a non-ascii character in test for bug 185211 that is the same in NFC and NFD
900
        self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
6379.9.1 by Rory Yorke
Added test case to reproduce error (test_mv_dirs_non_ascii).
901
6426.5.1 by Martin Packman
Use a non-ascii character in test for bug 185211 that is the same in NFC and NFD
902
        tree.add([u'abc\xa7/', u'abc\xa7/foo'])
6379.9.4 by Rory Yorke
Code fixes following review.
903
        tree.commit('checkin')
6379.9.1 by Rory Yorke
Added test case to reproduce error (test_mv_dirs_non_ascii).
904
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
905
        tree.rename_one(u'abc\xa7', 'abc')
6379.9.1 by Rory Yorke
Added test case to reproduce error (test_mv_dirs_non_ascii).
906
907
        self.run_bzr('ci -m "non-ascii mv"')
908
6323.2.2 by Jelmer Vernooij
Add hpss call count for committing to a lightweight checkout.
909
910
class TestSmartServerCommit(TestCaseWithTransport):
911
912
    def test_commit_to_lightweight(self):
913
        self.setup_smart_server_with_call_log()
914
        t = self.make_branch_and_tree('from')
915
        for count in range(9):
916
            t.commit(message='commit %d' % count)
917
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
918
                                 'target'])
6323.2.2 by Jelmer Vernooij
Add hpss call count for committing to a lightweight checkout.
919
        self.reset_smart_call_log()
920
        self.build_tree(['target/afile'])
921
        self.run_bzr(['add', 'target/afile'])
922
        out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
923
        # This figure represent the amount of work to perform this use case. It
924
        # is entirely ok to reduce this number if a test fails due to rpc_count
925
        # being too low. If rpc_count increases, more network roundtrips have
926
        # become necessary for this use case. Please do not adjust this number
927
        # upwards without agreement from bzr's network support maintainers.
6404.6.2 by Vincent Ladeuil
Merge trunk resolving conflicts and fixing more test failures related to
928
        self.assertLength(211, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
929
        self.assertLength(2, self.hpss_connections)
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
930
        self.expectFailure("commit still uses VFS calls",
7143.15.2 by Jelmer Vernooij
Run autopep8.
931
                           self.assertThat, self.hpss_calls, ContainsNoVfsCalls)