/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 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
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
27
from bzrlib 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,
4789.6.1 by John Arbash Meinel
test_unsupported_encoding_commit_message no longer applies for Windows.
32
    tests,
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
33
    )
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
34
from bzrlib.bzrdir import BzrDir
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
35
from bzrlib.tests import (
2839.6.2 by Alexander Belchenko
changes after Martin's review
36
    probe_bad_non_ascii,
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
37
    test_foreign,
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
38
    TestSkipped,
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
39
    UnicodeFilenameFeature,
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
40
    )
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
41
from bzrlib.tests import TestCaseWithTransport
42
43
44
class TestCommit(TestCaseWithTransport):
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
45
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
46
    def test_05_empty_commit(self):
47
        """Commit of tree with no versioned files should fail"""
48
        # 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.
49
        self.make_branch_and_tree('.')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
50
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
52
        self.assertEqual('', out)
5765.1.3 by John Arbash Meinel
We missed a test case that was asserting the old string.
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))
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
65
66
    def test_commit_success(self):
67
        """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.
68
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        self.run_bzr('commit --unchanged -m message')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
70
        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
71
72
        # same for unicode messages
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
73
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
74
        self.assertEqual('', self.run_bzr('unknowns')[0])
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
75
5777.6.4 by Jelmer Vernooij
Add test for lossy commit to native branch.
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
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
82
    def test_commit_lossy_foreign(self):
5777.6.6 by Jelmer Vernooij
Add lossy tests.
83
        test_foreign.register_dummy_foreign_for_test(self)
84
        self.make_branch_and_tree('.',
85
            format=test_foreign.DummyForeignVcsDirFormat())
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
86
        self.run_bzr('commit --lossy --unchanged -m message')
5777.6.6 by Jelmer Vernooij
Add lossy tests.
87
        output = self.run_bzr('revision-info')[0]
88
        self.assertTrue(output.startswith('1 dummy-'))
5777.6.5 by Jelmer Vernooij
Add tests for lossy commit.
89
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
90
    def test_commit_with_path(self):
91
        """Commit tree with path of root specified"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
92
        a_tree = self.make_branch_and_tree('a')
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
93
        self.build_tree(['a/a_file'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
94
        a_tree.add('a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
95
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
96
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
97
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
98
        self.build_tree_contents([('b/a_file', 'changes in b')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
99
        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.
100
101
        self.build_tree_contents([('a/a_file', 'new contents')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
102
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
103
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
104
        b_tree.merge_from_branch(a_tree.branch)
2738.4.2 by Daniel Watkins
Now test for conflicts where appropriate.
105
        self.assertEqual(len(b_tree.conflicts()), 1)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
106
        self.run_bzr('resolved b/a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
107
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
108
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
109
    def test_10_verbose_commit(self):
110
        """Add one file and examine verbose commit output"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
111
        tree = self.make_branch_and_tree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
112
        self.build_tree(['hello.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
113
        tree.add("hello.txt")
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
114
        out,err = self.run_bzr('commit -m added')
115
        self.assertEqual('', out)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
116
        self.assertContainsRe(err, '^Committing to: .*\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
117
                              'added hello.txt\n'
118
                              'Committed revision 1.\n$',)
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
119
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
120
    def prepare_simple_history(self):
121
        """Prepare and return a working tree with one commit of one file"""
122
        # Commit with modified file should say so
123
        wt = BzrDir.create_standalone_workingtree('.')
124
        self.build_tree(['hello.txt', 'extra.txt'])
125
        wt.add(['hello.txt'])
126
        wt.commit(message='added')
127
        return wt
128
129
    def test_verbose_commit_modified(self):
130
        # Verbose commit of modified file should say so
131
        wt = self.prepare_simple_history()
132
        self.build_tree_contents([('hello.txt', 'new contents')])
2789.2.11 by Ian Clatworthy
remove more reporting stuff
133
        out, err = self.run_bzr('commit -m modified')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
134
        self.assertEqual('', out)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
135
        self.assertContainsRe(err, '^Committing to: .*\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
136
                              'modified hello\.txt\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
137
                              'Committed revision 2\.\n$')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
138
5167.1.4 by Parth Malwankar
show_warning now uses 'replace' option for encoding the message.
139
    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
140
        """Unicode commit message same as a filename (Bug #563646).
141
        """
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
142
        self.requireFeature(UnicodeFilenameFeature)
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
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
5167.1.4 by Parth Malwankar
show_warning now uses 'replace' option for encoding the message.
149
        te = osutils.get_terminal_encoding()
150
        self.assertContainsRe(err.decode(te),
151
            u'The commit message is a file name:',
5167.1.1 by Parth Malwankar
commit command can now accept message (-m) same as a unicode filename
152
            flags=reflags)
153
5167.1.6 by Parth Malwankar
fixed comment.
154
        # 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
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:
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.
161
            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
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
4795.5.12 by Gioele Barabucci
Non-interactive warning for forgotten -m parameter
174
    def test_warn_about_forgotten_commit_message(self):
4795.5.8 by Gioele Barabucci
Test commit cancellation in presence of a suspect -m parameter
175
        """Test that the lack of -m parameter is caught"""
176
        wt = self.make_branch_and_tree('.')
177
        self.build_tree(['one', 'two'])
178
        wt.add(['two'])
4795.5.12 by Gioele Barabucci
Non-interactive warning for forgotten -m parameter
179
        out, err = self.run_bzr('commit -m one two')
180
        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
181
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
182
    def test_verbose_commit_renamed(self):
183
        # Verbose commit of renamed file should say so
184
        wt = self.prepare_simple_history()
185
        wt.rename_one('hello.txt', 'gutentag.txt')
2789.2.11 by Ian Clatworthy
remove more reporting stuff
186
        out, err = self.run_bzr('commit -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
187
        self.assertEqual('', out)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
188
        self.assertContainsRe(err, '^Committing to: .*\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
189
                              'renamed hello\.txt => gutentag\.txt\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
190
                              'Committed revision 2\.$\n')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
191
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
192
    def test_verbose_commit_moved(self):
193
        # Verbose commit of file moved to new directory should say so
194
        wt = self.prepare_simple_history()
195
        os.mkdir('subdir')
196
        wt.add(['subdir'])
197
        wt.rename_one('hello.txt', 'subdir/hello.txt')
2789.2.11 by Ian Clatworthy
remove more reporting stuff
198
        out, err = self.run_bzr('commit -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
199
        self.assertEqual('', out)
4183.5.5 by Robert Collins
Enable record_iter_changes for cases where it can work.
200
        self.assertEqual(set([
201
            'Committing to: %s/' % osutils.getcwd(),
202
            'added subdir',
203
            'renamed hello.txt => subdir/hello.txt',
204
            'Committed revision 2.',
205
            '',
206
            ]), set(err.split('\n')))
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
207
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
208
    def test_verbose_commit_with_unknown(self):
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
209
        """Unknown files should not be listed by default in verbose output"""
210
        # Is that really the best policy?
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
211
        wt = BzrDir.create_standalone_workingtree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
212
        self.build_tree(['hello.txt', 'extra.txt'])
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
213
        wt.add(['hello.txt'])
2789.2.11 by Ian Clatworthy
remove more reporting stuff
214
        out,err = self.run_bzr('commit -m added')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
215
        self.assertEqual('', out)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
216
        self.assertContainsRe(err, '^Committing to: .*\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
217
                              'added hello\.txt\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
218
                              'Committed revision 1\.\n$')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
219
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
220
    def test_verbose_commit_with_unchanged(self):
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
221
        """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.
222
        tree = self.make_branch_and_tree('.')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
223
        self.build_tree(['hello.txt', 'unchanged.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
224
        tree.add('unchanged.txt')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
225
        self.run_bzr('commit -m unchanged unchanged.txt')
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
226
        tree.add("hello.txt")
2789.2.11 by Ian Clatworthy
remove more reporting stuff
227
        out,err = self.run_bzr('commit -m added')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
228
        self.assertEqual('', out)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
229
        self.assertContainsRe(err, '^Committing to: .*\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
230
                              'added hello\.txt\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
231
                              'Committed revision 2\.$\n')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
232
2747.6.13 by Daniel Watkins
Renamed test to reflect what it is actually doing.
233
    def test_verbose_commit_includes_master_location(self):
2747.6.4 by Daniel Watkins
Modified test as suggested on-list.
234
        """Location of master is displayed when committing to bound branch"""
2747.6.2 by Daniel Watkins
Added test for behaviour.
235
        a_tree = self.make_branch_and_tree('a')
236
        self.build_tree(['a/b'])
237
        a_tree.add('b')
238
        a_tree.commit(message='Initial message')
239
240
        b_tree = a_tree.branch.create_checkout('b')
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
241
        expected = "%s/" % (osutils.abspath('a'), )
2747.6.4 by Daniel Watkins
Modified test as suggested on-list.
242
        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)
243
        self.assertEqual(err, 'Committing to: %s\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
244
                         'Committed revision 2.\n' % expected)
2747.6.2 by Daniel Watkins
Added test for behaviour.
245
4634.94.4 by John Arbash Meinel
Fix bug #433779, sanitize '\r' characters in commit.
246
    def test_commit_sanitizes_CR_in_message(self):
247
        # See bug #433779, basically Emacs likes to pass '\r\n' style line
248
        # endings to 'bzr commit -m ""' which breaks because we don't allow
249
        # '\r' in commit messages. (Mostly because of issues where XML style
250
        # formats arbitrarily strip it out of the data while parsing.)
251
        # To make life easier for users, we just always translate '\r\n' =>
252
        # '\n'. And '\r' => '\n'.
253
        a_tree = self.make_branch_and_tree('a')
254
        self.build_tree(['a/b'])
255
        a_tree.add('b')
256
        self.run_bzr(['commit',
257
                      '-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
258
                     working_dir='a')
259
        rev_id = a_tree.branch.last_revision()
260
        rev = a_tree.branch.repository.get_revision(rev_id)
261
        self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
262
                             rev.message)
263
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
264
    def test_commit_merge_reports_all_modified_files(self):
265
        # the commit command should show all the files that are shown by
266
        # bzr diff or bzr status when committing, even when they were not
267
        # changed by the user but rather through doing a merge.
268
        this_tree = self.make_branch_and_tree('this')
269
        # we need a bunch of files and dirs, to perform one action on each.
270
        self.build_tree([
271
            'this/dirtorename/',
272
            'this/dirtoreparent/',
273
            'this/dirtoleave/',
274
            'this/dirtoremove/',
275
            'this/filetoreparent',
276
            'this/filetorename',
277
            'this/filetomodify',
278
            'this/filetoremove',
279
            'this/filetoleave']
280
            )
281
        this_tree.add([
282
            'dirtorename',
283
            'dirtoreparent',
284
            'dirtoleave',
285
            'dirtoremove',
286
            'filetoreparent',
287
            'filetorename',
288
            'filetomodify',
289
            'filetoremove',
290
            'filetoleave']
291
            )
292
        this_tree.commit('create_files')
293
        other_dir = this_tree.bzrdir.sprout('other')
294
        other_tree = other_dir.open_workingtree()
295
        other_tree.lock_write()
296
        # perform the needed actions on the files and dirs.
297
        try:
298
            other_tree.rename_one('dirtorename', 'renameddir')
299
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
300
            other_tree.rename_one('filetorename', 'renamedfile')
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
301
            other_tree.rename_one('filetoreparent',
302
                                  'renameddir/reparentedfile')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
303
            other_tree.remove(['dirtoremove', 'filetoremove'])
304
            self.build_tree_contents([
2738.4.5 by Daniel Watkins
Fixed whitespace issues.
305
                ('other/newdir/',),
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
306
                ('other/filetomodify', 'new content'),
307
                ('other/newfile', 'new file content')])
308
            other_tree.add('newfile')
309
            other_tree.add('newdir/')
310
            other_tree.commit('modify all sample files and dirs.')
311
        finally:
312
            other_tree.unlock()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
313
        this_tree.merge_from_branch(other_tree.branch)
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
314
        os.chdir('this')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
315
        out,err = self.run_bzr('commit -m added')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
316
        self.assertEqual('', out)
4183.5.5 by Robert Collins
Enable record_iter_changes for cases where it can work.
317
        self.assertEqual(set([
318
            'Committing to: %s/' % osutils.getcwd(),
319
            'modified filetomodify',
320
            'added newdir',
321
            'added newfile',
322
            'renamed dirtorename => renameddir',
323
            'renamed filetorename => renamedfile',
324
            'renamed dirtoreparent => renameddir/reparenteddir',
325
            'renamed filetoreparent => renameddir/reparentedfile',
326
            'deleted dirtoremove',
327
            'deleted filetoremove',
328
            'Committed revision 2.',
329
            ''
330
            ]), set(err.split('\n')))
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
331
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
332
    def test_empty_commit_message(self):
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
333
        tree = self.make_branch_and_tree('.')
334
        self.build_tree_contents([('foo.c', 'int main() {}')])
335
        tree.add('foo.c')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
336
        self.run_bzr('commit -m ""', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
337
2625.9.2 by Daniel Watkins
Added test to ensure correct error message is given if an unencodable commit message is given at the command line.
338
    def test_unsupported_encoding_commit_message(self):
4789.6.1 by John Arbash Meinel
test_unsupported_encoding_commit_message no longer applies for Windows.
339
        if sys.platform == 'win32':
340
            raise tests.TestNotApplicable('Win32 parses arguments directly'
341
                ' as Unicode, so we can\'t pass invalid non-ascii')
2625.9.2 by Daniel Watkins
Added test to ensure correct error message is given if an unencodable commit message is given at the command line.
342
        tree = self.make_branch_and_tree('.')
343
        self.build_tree_contents([('foo.c', 'int main() {}')])
344
        tree.add('foo.c')
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
345
        # LANG env variable has no effect on Windows
346
        # but some characters anyway cannot be represented
347
        # in default user encoding
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
348
        char = probe_bad_non_ascii(osutils.get_user_encoding())
2839.6.2 by Alexander Belchenko
changes after Martin's review
349
        if char is None:
350
            raise TestSkipped('Cannot find suitable non-ascii character'
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
351
                'for user_encoding (%s)' % osutils.get_user_encoding())
2804.4.1 by Alexander Belchenko
some win32-specific fixes for selftest
352
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
353
                                          retcode=1,
354
                                          env_changes={'LANG': 'C'})
2625.9.2 by Daniel Watkins
Added test to ensure correct error message is given if an unencodable commit message is given at the command line.
355
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
356
                                    'unsupported by the current encoding.')
357
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
358
    def test_other_branch_commit(self):
359
        # this branch is to ensure consistent behaviour, whether we're run
360
        # inside a branch, or not.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
361
        outer_tree = self.make_branch_and_tree('.')
362
        inner_tree = self.make_branch_and_tree('branch')
363
        self.build_tree_contents([
364
            ('branch/foo.c', 'int main() {}'),
365
            ('branch/bar.c', '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.
366
        inner_tree.add(['foo.c', 'bar.c'])
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
367
        # 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
368
        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.
369
        # can commit to branch - records foo.c only
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')
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 bar.c
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
372
        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.
373
        # No changes left
374
        self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
375
376
    def test_out_of_date_tree_commit(self):
377
        # check we get an error code and a clear message committing with an out
378
        # of date checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
379
        tree = self.make_branch_and_tree('branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
380
        # make a checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
381
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
382
        # 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.
383
        tree.commit('message branch', allow_pointless=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
384
        # now commit to the checkout should emit
385
        # ERROR: Out of date with the branch, 'bzr update' is suggested
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
386
        output = self.run_bzr('commit --unchanged -m checkout_message '
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
387
                             'checkout', retcode=3)
388
        self.assertEqual(output,
389
                         ('',
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
390
                          "bzr: ERROR: Working tree is out of date, please "
391
                          "run 'bzr update'.\n"))
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
392
393
    def test_local_commit_unbound(self):
394
        # a --local commit on an unbound branch is an error
395
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
396
        out, err = self.run_bzr('commit --local', retcode=3)
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
397
        self.assertEqualDiff('', out)
398
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
399
                             'on unbound branches.\n', err)
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
400
401
    def test_commit_a_text_merge_in_a_checkout(self):
402
        # checkouts perform multiple actions in a transaction across bond
403
        # 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
404
        # 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)
405
        # a merge done in a checkout (using the update command) failed to
406
        # commit correctly.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
407
        trunk = self.make_branch_and_tree('trunk')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
408
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
409
        u1 = trunk.branch.create_checkout('u1')
4985.3.17 by Vincent Ladeuil
Some cleanup.
410
        self.build_tree_contents([('u1/hosts', 'initial contents\n')])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
411
        u1.add('hosts')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
412
        self.run_bzr('commit -m add-hosts u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
413
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
414
        u2 = trunk.branch.create_checkout('u2')
4985.3.17 by Vincent Ladeuil
Some cleanup.
415
        self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
416
        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)
417
418
        # make an offline commits
4985.3.17 by Vincent Ladeuil
Some cleanup.
419
        self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
420
        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)
421
422
        # now try to pull in online work from u2, and then commit our offline
423
        # work as a merge
424
        # retcode 1 as we expect a text conflict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
425
        self.run_bzr('update u1', retcode=1)
4985.3.17 by Vincent Ladeuil
Some cleanup.
426
        self.assertFileEqual('''\
427
<<<<<<< TREE
428
first offline change in u1
429
=======
430
altered in u2
431
>>>>>>> MERGE-SOURCE
432
''',
4985.3.10 by Gerard Krol
Reformat long lines
433
                             'u1/hosts')
4985.3.1 by Gerard Krol
Werkt wel ok
434
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
435
        self.run_bzr('resolved u1/hosts')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
436
        # add a text change here to represent resolving the merge conflicts in
437
        # favour of a new version of the file not identical to either the u1
438
        # version or the u2 version.
439
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
440
        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
441
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
442
    def test_commit_exclude_excludes_modified_files(self):
443
        """Commit -x foo should ignore changes to foo."""
444
        tree = self.make_branch_and_tree('.')
445
        self.build_tree(['a', 'b', 'c'])
446
        tree.smart_add(['.'])
447
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
448
        self.assertFalse('added b' in out)
449
        self.assertFalse('added b' in err)
3602.1.4 by Robert Collins
Andrew's review feedback.
450
        # 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)
451
        out, err = self.run_bzr(['added'])
452
        self.assertEqual('b\n', out)
453
        self.assertEqual('', err)
454
455
    def test_commit_exclude_twice_uses_both_rules(self):
456
        """Commit -x foo -x bar should ignore changes to foo and bar."""
457
        tree = self.make_branch_and_tree('.')
458
        self.build_tree(['a', 'b', 'c'])
459
        tree.smart_add(['.'])
460
        out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
461
        self.assertFalse('added b' in out)
462
        self.assertFalse('added c' in out)
463
        self.assertFalse('added b' in err)
464
        self.assertFalse('added c' in err)
3602.1.4 by Robert Collins
Andrew's review feedback.
465
        # 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)
466
        out, err = self.run_bzr(['added'])
3602.1.4 by Robert Collins
Andrew's review feedback.
467
        self.assertTrue('b\n' in out)
468
        self.assertTrue('c\n' in out)
3602.1.1 by Robert Collins
Add support for -x or --exclude to bzr commit, fixing bug 3117. (Robert Collins)
469
        self.assertEqual('', err)
470
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
471
    def test_commit_respects_spec_for_removals(self):
472
        """Commit with a file spec should only commit removals that match"""
473
        t = self.make_branch_and_tree('.')
474
        self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
475
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
476
        t.commit('Create')
477
        t.remove(['file-a', 'dir-a/file-b'])
478
        os.chdir('dir-a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
479
        result = self.run_bzr('commit . -m removed-file-b')[1]
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
480
        self.assertNotContainsRe(result, 'file-a')
481
        result = self.run_bzr('status')[0]
482
        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
483
484
    def test_strict_commit(self):
485
        """Commit with --strict works if everything is known"""
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
486
        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
487
        tree = self.make_branch_and_tree('tree')
488
        self.build_tree(['tree/a'])
489
        tree.add('a')
490
        # A simple change should just work
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
491
        self.run_bzr('commit --strict -m adding-a',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
492
                     working_dir='tree')
493
494
    def test_strict_commit_no_changes(self):
495
        """commit --strict gives "no changes" if there is nothing to commit"""
496
        tree = self.make_branch_and_tree('tree')
497
        self.build_tree(['tree/a'])
498
        tree.add('a')
499
        tree.commit('adding a')
500
501
        # With no changes, it should just be 'no changes'
502
        # Make sure that commit is failing because there is nothing to do
4351.1.2 by Ian Clatworthy
tweak grammar in error message
503
        self.run_bzr_error(['No changes to commit'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
504
                           '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
505
                           working_dir='tree')
506
507
        # But --strict doesn't care if you supply --unchanged
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
508
        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
509
                     working_dir='tree')
510
511
    def test_strict_commit_unknown(self):
512
        """commit --strict fails if a file is unknown"""
513
        tree = self.make_branch_and_tree('tree')
514
        self.build_tree(['tree/a'])
515
        tree.add('a')
516
        tree.commit('adding a')
517
518
        # Add one file so there is a change, but forget the other
519
        self.build_tree(['tree/b', 'tree/c'])
520
        tree.add('b')
521
        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.
522
                           '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
523
                           working_dir='tree')
524
525
        # --no-strict overrides --strict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
526
        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
527
                     working_dir='tree')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
528
529
    def test_fixes_bug_output(self):
530
        """commit --fixes=lp:23452 succeeds without output."""
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
531
        tree = self.make_branch_and_tree('tree')
532
        self.build_tree(['tree/hello.txt'])
533
        tree.add('hello.txt')
2376.4.12 by Jonathan Lange
Update NEWS file.
534
        output, err = self.run_bzr(
2789.2.11 by Ian Clatworthy
remove more reporting stuff
535
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
536
        self.assertEqual('', output)
3052.4.1 by Matt Nordhoff
bzr commit: don't print the revision number twice. (Bug #172612)
537
        self.assertContainsRe(err, 'Committing to: .*\n'
2747.6.7 by Daniel Watkins
Modify tests to reflect change in commit output.
538
                              'added hello\.txt\n'
2789.2.11 by Ian Clatworthy
remove more reporting stuff
539
                              'Committed revision 1\.\n')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
540
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
541
    def test_no_bugs_no_properties(self):
542
        """If no bugs are fixed, the bugs property is not set.
543
544
        see https://beta.launchpad.net/bzr/+bug/109613
545
        """
546
        tree = self.make_branch_and_tree('tree')
547
        self.build_tree(['tree/hello.txt'])
548
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
549
        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
550
        # Get the revision properties, ignoring the branch-nick property, which
551
        # we don't care about for this test.
552
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
553
        properties = dict(last_rev.properties)
554
        del properties['branch-nick']
555
        self.assertFalse('bugs' in properties)
556
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
557
    def test_fixes_bug_sets_property(self):
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
558
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
559
        tree = self.make_branch_and_tree('tree')
560
        self.build_tree(['tree/hello.txt'])
561
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
562
        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.
563
564
        # Get the revision properties, ignoring the branch-nick property, which
565
        # we don't care about for this test.
566
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
567
        properties = dict(last_rev.properties)
568
        del properties['branch-nick']
569
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
570
        self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
2376.4.7 by jml at canonical
- Add docstrings to tests.
571
                         properties)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
572
573
    def test_fixes_multiple_bugs_sets_properties(self):
574
        """--fixes can be used more than once to show that bugs are fixed."""
575
        tree = self.make_branch_and_tree('tree')
576
        self.build_tree(['tree/hello.txt'])
577
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
578
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
579
                     ' tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
580
581
        # Get the revision properties, ignoring the branch-nick property, which
582
        # we don't care about for this test.
583
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
584
        properties = dict(last_rev.properties)
585
        del properties['branch-nick']
586
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
587
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
588
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
589
                     'https://launchpad.net/bugs/235 fixed'},
590
            properties)
2376.4.7 by jml at canonical
- Add docstrings to tests.
591
592
    def test_fixes_bug_with_alternate_trackers(self):
593
        """--fixes can be used on a properly configured branch to mark bug
594
        fixes on multiple trackers.
595
        """
596
        tree = self.make_branch_and_tree('tree')
597
        tree.branch.get_config().set_user_option(
598
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
599
        self.build_tree(['tree/hello.txt'])
600
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
601
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
2376.4.7 by jml at canonical
- Add docstrings to tests.
602
603
        # Get the revision properties, ignoring the branch-nick property, which
604
        # we don't care about for this test.
605
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
606
        properties = dict(last_rev.properties)
607
        del properties['branch-nick']
608
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
609
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
610
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
611
                     'http://twistedmatrix.com/trac/ticket/235 fixed'},
612
            properties)
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
613
614
    def test_fixes_unknown_bug_prefix(self):
615
        tree = self.make_branch_and_tree('tree')
616
        self.build_tree(['tree/hello.txt'])
617
        tree.add('hello.txt')
618
        self.run_bzr_error(
619
            ["Unrecognized bug %s. Commit refused." % 'xxx:123'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
620
            'commit -m add-b --fixes=xxx:123',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
621
            working_dir='tree')
622
623
    def test_fixes_invalid_bug_number(self):
624
        tree = self.make_branch_and_tree('tree')
625
        self.build_tree(['tree/hello.txt'])
626
        tree.add('hello.txt')
627
        self.run_bzr_error(
3535.10.9 by James Westby
Make the improved messages show up in the UI.
628
            ["Did not understand bug identifier orange: Must be an integer. "
629
             "See \"bzr help bugs\" for more information on this feature.\n"
630
             "Commit refused."],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
631
            'commit -m add-b --fixes=lp:orange',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
632
            working_dir='tree')
2376.4.7 by jml at canonical
- Add docstrings to tests.
633
634
    def test_fixes_invalid_argument(self):
635
        """Raise an appropriate error when the fixes argument isn't tag:id."""
636
        tree = self.make_branch_and_tree('tree')
637
        self.build_tree(['tree/hello.txt'])
638
        tree.add('hello.txt')
639
        self.run_bzr_error(
3535.10.3 by James Westby
Talk about "trackers" rather than "tags" as it may be less confusing.
640
            [r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
3535.10.9 by James Westby
Make the improved messages show up in the UI.
641
             r"See \"bzr help bugs\" for more information on this feature.\n"
2376.4.13 by Jonathan Lange
Some stylistic cleanups
642
             r"Commit refused\."],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
643
            'commit -m add-b --fixes=orange',
2376.4.7 by jml at canonical
- Add docstrings to tests.
644
            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.
645
646
    def test_no_author(self):
647
        """If the author is not specified, the author property is not set."""
648
        tree = self.make_branch_and_tree('tree')
649
        self.build_tree(['tree/hello.txt'])
650
        tree.add('hello.txt')
651
        self.run_bzr( 'commit -m hello tree/hello.txt')
652
        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.
653
        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.
654
        self.assertFalse('author' in properties)
655
656
    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.
657
        """commit --author='John Doe <jdoe@example.com>' sets the author
658
           revprop.
659
        """
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.
660
        tree = self.make_branch_and_tree('tree')
661
        self.build_tree(['tree/hello.txt'])
662
        tree.add('hello.txt')
3099.2.1 by John Arbash Meinel
Allow 'bzr commit --author' to take a unicode string.
663
        self.run_bzr(["commit", '-m', 'hello',
664
                      '--author', u'John D\xf6 <jdoe@example.com>',
665
                     "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.
666
        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.
667
        properties = last_rev.properties
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
668
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', 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.
669
670
    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.
671
        """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.
672
        tree = self.make_branch_and_tree('tree')
673
        self.build_tree(['tree/hello.txt'])
674
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
675
        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.
676
                                "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.
677
        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.
678
        properties = last_rev.properties
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
679
        self.assertEqual('John Doe', properties['authors'])
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
680
4056.2.1 by James Westby
Allow specifying multiple authors for a revision.
681
    def test_multiple_authors(self):
682
        """Multiple authors can be specyfied, and all are stored."""
683
        tree = self.make_branch_and_tree('tree')
684
        self.build_tree(['tree/hello.txt'])
685
        tree.add('hello.txt')
686
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
687
                                "--author='Jane Rey' tree/hello.txt")
688
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
689
        properties = last_rev.properties
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
690
        self.assertEqual('John Doe\nJane Rey', properties['authors'])
4056.2.1 by James Westby
Allow specifying multiple authors for a revision.
691
4766.2.2 by Andrew Bennetts
Add tests, and capture timezone offset as well as timestamp.
692
    def test_commit_time(self):
693
        tree = self.make_branch_and_tree('tree')
694
        self.build_tree(['tree/hello.txt'])
695
        tree.add('hello.txt')
696
        out, err = self.run_bzr("commit -m hello "
697
            "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
698
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
699
        self.assertEqual(
700
            'Sat 2009-10-10 08:00:00 +0100',
701
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
702
        
703
    def test_commit_time_bad_time(self):
704
        tree = self.make_branch_and_tree('tree')
705
        self.build_tree(['tree/hello.txt'])
706
        tree.add('hello.txt')
707
        out, err = self.run_bzr("commit -m hello "
708
            "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
709
        self.assertStartsWith(
710
            err, "bzr: ERROR: Could not parse --commit-time:")
711
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
712
    def test_partial_commit_with_renames_in_tree(self):
2833.2.2 by Alexander Belchenko
Bug #140419 fixed by Robert Collins
713
        # this test illustrates bug #140419
2833.2.1 by Alexander Belchenko
XFAIL test for bug #140419
714
        t = self.make_branch_and_tree('.')
715
        self.build_tree(['dir/', 'dir/a', 'test'])
716
        t.add(['dir/', 'dir/a', 'test'])
717
        t.commit('initial commit')
718
        # important part: file dir/a should change parent
719
        # and should appear before old parent
720
        # then during partial commit we have error
721
        # parent_id {dir-XXX} not in inventory
722
        t.rename_one('dir/a', 'a')
723
        self.build_tree_contents([('test', 'changes in test')])
2833.2.2 by Alexander Belchenko
Bug #140419 fixed by Robert Collins
724
        # partial commit
725
        out, err = self.run_bzr('commit test -m "partial commit"')
726
        self.assertEquals('', out)
727
        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).
728
729
    def test_commit_readonly_checkout(self):
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
730
        # 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).
731
        # "UnlockableTransport error trying to commit in checkout of readonly
732
        # branch"
733
        self.make_branch('master')
734
        master = BzrDir.open_from_transport(
735
            self.get_readonly_transport('master')).open_branch()
736
        master.create_checkout('checkout')
737
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
738
            retcode=3)
739
        self.assertContainsRe(err,
2872.5.3 by Martin Pool
Pass back LockFailed from smart server lock methods
740
            r'^bzr: ERROR: Cannot lock.*readonly transport')
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
741
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
742
    def setup_editor(self):
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
743
        # Test that commit template hooks work
744
        if sys.platform == "win32":
745
            f = file('fed.bat', 'w')
746
            f.write('@rem dummy fed')
747
            f.close()
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
748
            self.overrideEnv('BZR_EDITOR', "fed.bat")
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
749
        else:
750
            f = file('fed.sh', 'wb')
751
            f.write('#!/bin/sh\n')
752
            f.close()
753
            os.chmod('fed.sh', 0755)
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
754
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
755
756
    def setup_commit_with_template(self):
757
        self.setup_editor()
3825.2.2 by Jelmer Vernooij
Add blackbox test for commit hook templates.
758
        msgeditor.hooks.install_named_hook("commit_message_template",
759
                lambda commit_obj, msg: "save me some typing\n", None)
760
        tree = self.make_branch_and_tree('tree')
761
        self.build_tree(['tree/hello.txt'])
762
        tree.add('hello.txt')
5137.1.2 by Robert Collins
Review feedback: add comment about return value and an additional test.
763
        return tree
764
765
    def test_commit_hook_template_accepted(self):
766
        tree = self.setup_commit_with_template()
5137.1.1 by Robert Collins
* ``bzr commit`` will prompt before using a commit message that was
767
        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.
768
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
769
        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.
770
771
    def test_commit_hook_template_rejected(self):
772
        tree = self.setup_commit_with_template()
773
        expected = tree.last_revision()
774
        out, err = self.run_bzr_error(["empty commit message"],
775
            "commit tree/hello.txt", stdin="n\n")
776
        self.assertEqual(expected, tree.last_revision())
5187.2.4 by Parth Malwankar
added tests.
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'])
5570.3.12 by Vincent Ladeuil
Replace osutils.set_or_unset_env calls with self.overrideEnv.
785
        self.overrideEnv('EMAIL', None)
786
        self.overrideEnv('BZR_EMAIL', None)
5609.31.1 by mbp at sourcefrog
Blackbox tests for no identity set must disable whoami inference
787
        # Also, make sure that it's not inferred from mailname.
788
        self.overrideAttr(config, '_auto_user_id',
789
            lambda: (None, None))
5187.2.4 by Parth Malwankar
added tests.
790
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
791
        self.assertContainsRe(err, 'Unable to determine your name')
5050.7.1 by Parth Malwankar
added test case for recursion error
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'])
5050.7.2 by Parth Malwankar
recursive binding now shows a clear error
802
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
5050.7.1 by Parth Malwankar
added test case for recursion error
803
        self.assertEqual(out, '')
5050.7.5 by Parth Malwankar
better error message for RecursiveBind
804
        self.assertContainsRe(err,
805
            'Branch.*test_checkout.*appears to be bound to itself')
5050.7.1 by Parth Malwankar
added test case for recursion error
806