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