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