/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005, 2006 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
"""Tests for the commit CLI of bzr."""
19
20
import os
21
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
22
from bzrlib import (
23
    ignores,
24
    )
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
25
from bzrlib.bzrdir import BzrDir
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
26
from bzrlib.tests.blackbox import ExternalBase
27
28
29
class TestCommit(ExternalBase):
30
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
31
    def test_05_empty_commit(self):
32
        """Commit of tree with no versioned files should fail"""
33
        # 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.
34
        self.make_branch_and_tree('.')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
35
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
36
        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
37
        self.assertEqual('', out)
38
        self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
39
                                  ' use --unchanged to commit anyhow\n')
40
41
    def test_commit_success(self):
42
        """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.
43
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
44
        self.run_bzr('commit --unchanged -m message')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
45
        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
46
47
        # same for unicode messages
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
48
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
49
        self.assertEqual('', self.run_bzr('unknowns')[0])
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
50
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
51
    def test_commit_with_path(self):
52
        """Commit tree with path of root specified"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
53
        a_tree = self.make_branch_and_tree('a')
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
54
        self.build_tree(['a/a_file'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
55
        a_tree.add('a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
56
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
57
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
58
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
59
        self.build_tree_contents([('b/a_file', 'changes in b')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
60
        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.
61
62
        self.build_tree_contents([('a/a_file', 'new contents')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
63
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
64
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
65
        b_tree.merge_from_branch(a_tree.branch)
2738.4.2 by Daniel Watkins
Now test for conflicts where appropriate.
66
        self.assertEqual(len(b_tree.conflicts()), 1)
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
67
        self.run_bzr('resolved b/a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
68
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
69
70
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
71
    def test_10_verbose_commit(self):
72
        """Add one file and examine verbose commit output"""
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
73
        tree = self.make_branch_and_tree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
74
        self.build_tree(['hello.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
75
        tree.add("hello.txt")
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
76
        out,err = self.run_bzr('commit -v -m added')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
77
        self.assertEqual('', out)
78
        self.assertEqual('added hello.txt\n'
79
                         'Committed revision 1.\n',
80
                         err)
81
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
82
    def test_10_quiet_commit(self):
83
        """Add one file and examine quiet commit output"""
84
        self.run_bzr("init")
85
        self.build_tree(['hello.txt'])
86
        self.run_bzr("add hello.txt")
87
        out,err = self.run_bzr('commit -q -m added')
88
        self.assertEqual('', out)
89
        self.assertEqual('', err)
90
91
    def test_10_normal_commit(self):
92
        """Add one file and examine normal commit output"""
93
        self.run_bzr("init")
94
        self.build_tree(['hello.txt'])
95
        self.run_bzr("add hello.txt")
96
        out,err = self.run_bzr('commit -m added')
97
        self.assertEqual('', out)
98
        self.assertEqual('Committed revision 1.\n',
99
                         err)
100
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
101
    def prepare_simple_history(self):
102
        """Prepare and return a working tree with one commit of one file"""
103
        # Commit with modified file should say so
104
        wt = BzrDir.create_standalone_workingtree('.')
105
        self.build_tree(['hello.txt', 'extra.txt'])
106
        wt.add(['hello.txt'])
107
        wt.commit(message='added')
108
        return wt
109
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
110
    def test_normal_commit_modified(self):
111
        # Normal commit of modified file should say just the new revision
112
        wt = self.prepare_simple_history()
113
        self.build_tree_contents([('hello.txt', 'new contents')])
114
        out, err = self.run_bzr('commit -m modified')
115
        self.assertEqual('', out)
116
        self.assertEqual('Committed revision 2.\n',
117
                         err)
118
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
119
    def test_verbose_commit_modified(self):
120
        # Verbose commit of modified file should say so
121
        wt = self.prepare_simple_history()
122
        self.build_tree_contents([('hello.txt', 'new contents')])
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
123
        out, err = self.run_bzr('commit -v -m modified')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
124
        self.assertEqual('', out)
125
        self.assertEqual('modified hello.txt\n'
126
                         'Committed revision 2.\n',
127
                         err)
128
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
129
    def test_normal_commit_renamed(self):
130
        # Verbose commit of renamed file should say just the new revision
131
        wt = self.prepare_simple_history()
132
        wt.rename_one('hello.txt', 'gutentag.txt')
133
        out, err = self.run_bzr('commit -m renamed')
134
        self.assertEqual('', out)
135
        self.assertEqual('Committed revision 2.\n',
136
                         err)
137
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
138
    def test_verbose_commit_renamed(self):
139
        # Verbose commit of renamed file should say so
140
        wt = self.prepare_simple_history()
141
        wt.rename_one('hello.txt', 'gutentag.txt')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
142
        out, err = self.run_bzr('commit -v -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
143
        self.assertEqual('', out)
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
144
        self.assertEqual('renamed hello.txt => gutentag.txt\n'
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
145
                         'Committed revision 2.\n',
146
                         err)
147
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
148
    def test_normal_commit_moved(self):
149
        # Verbose commit of file moved to new directory should say just
150
        # the new revision
151
        wt = self.prepare_simple_history()
152
        os.mkdir('subdir')
153
        wt.add(['subdir'])
154
        wt.rename_one('hello.txt', 'subdir/hello.txt')
155
        out, err = self.run_bzr('commit -m renamed')
156
        self.assertEqual('', out)
157
        self.assertEqualDiff('Committed revision 2.\n',
158
                             err)
159
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
160
    def test_verbose_commit_moved(self):
161
        # Verbose commit of file moved to new directory should say so
162
        wt = self.prepare_simple_history()
163
        os.mkdir('subdir')
164
        wt.add(['subdir'])
165
        wt.rename_one('hello.txt', 'subdir/hello.txt')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
166
        out, err = self.run_bzr('commit -v -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
167
        self.assertEqual('', out)
168
        self.assertEqualDiff('added subdir\n'
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
169
                             'renamed hello.txt => subdir/hello.txt\n'
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
170
                             'Committed revision 2.\n',
171
                             err)
172
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
173
    def test_normal_commit_with_unknown(self):
174
        """Unknown files should not be listed by default in normal output"""
175
        # Is that really the best policy?
176
        wt = BzrDir.create_standalone_workingtree('.')
177
        self.build_tree(['hello.txt', 'extra.txt'])
178
        wt.add(['hello.txt'])
179
        out,err = self.run_bzr('commit -m added')
180
        self.assertEqual('', out)
181
        self.assertEqual('Committed revision 1.\n',
182
                         err)
183
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
184
    def test_verbose_commit_with_unknown(self):
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
185
        """Unknown files should not be listed by default in verbose output"""
186
        # Is that really the best policy?
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
187
        wt = BzrDir.create_standalone_workingtree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
188
        self.build_tree(['hello.txt', 'extra.txt'])
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
189
        wt.add(['hello.txt'])
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
190
        out,err = self.run_bzr('commit -v -m added')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
191
        self.assertEqual('', out)
192
        self.assertEqual('added hello.txt\n'
193
                         'Committed revision 1.\n',
194
                         err)
195
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
196
    def test_normal_commit_with_unchanged(self):
197
        """Unchanged files should not be listed by default in normal output"""
198
        self.run_bzr("init")
199
        self.build_tree(['hello.txt', 'unchanged.txt'])
200
        self.run_bzr('add unchanged.txt')
201
        self.run_bzr('commit -m unchanged unchanged.txt')
202
        self.run_bzr("add hello.txt")
203
        out,err = self.run_bzr('commit -m added')
204
        self.assertEqual('', out)
205
        self.assertEqual('Committed revision 2.\n',
206
                         err)
207
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
208
    def test_verbose_commit_with_unchanged(self):
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
209
        """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.
210
        tree = self.make_branch_and_tree('.')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
211
        self.build_tree(['hello.txt', 'unchanged.txt'])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
212
        tree.add('unchanged.txt')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
213
        self.run_bzr('commit -m unchanged unchanged.txt')
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
214
        tree.add("hello.txt")
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
215
        out,err = self.run_bzr('commit -v -m added')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
216
        self.assertEqual('', out)
217
        self.assertEqual('added hello.txt\n'
218
                         'Committed revision 2.\n',
219
                         err)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
220
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
221
    def test_commit_merge_reports_all_modified_files(self):
222
        # the commit command should show all the files that are shown by
223
        # bzr diff or bzr status when committing, even when they were not
224
        # changed by the user but rather through doing a merge.
225
        this_tree = self.make_branch_and_tree('this')
226
        # we need a bunch of files and dirs, to perform one action on each.
227
        self.build_tree([
228
            'this/dirtorename/',
229
            'this/dirtoreparent/',
230
            'this/dirtoleave/',
231
            'this/dirtoremove/',
232
            'this/filetoreparent',
233
            'this/filetorename',
234
            'this/filetomodify',
235
            'this/filetoremove',
236
            'this/filetoleave']
237
            )
238
        this_tree.add([
239
            'dirtorename',
240
            'dirtoreparent',
241
            'dirtoleave',
242
            'dirtoremove',
243
            'filetoreparent',
244
            'filetorename',
245
            'filetomodify',
246
            'filetoremove',
247
            'filetoleave']
248
            )
249
        this_tree.commit('create_files')
250
        other_dir = this_tree.bzrdir.sprout('other')
251
        other_tree = other_dir.open_workingtree()
252
        other_tree.lock_write()
253
        # perform the needed actions on the files and dirs.
254
        try:
255
            other_tree.rename_one('dirtorename', 'renameddir')
256
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
257
            other_tree.rename_one('filetorename', 'renamedfile')
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
258
            other_tree.rename_one('filetoreparent',
259
                                  'renameddir/reparentedfile')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
260
            other_tree.remove(['dirtoremove', 'filetoremove'])
261
            self.build_tree_contents([
2738.4.5 by Daniel Watkins
Fixed whitespace issues.
262
                ('other/newdir/',),
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
263
                ('other/filetomodify', 'new content'),
264
                ('other/newfile', 'new file content')])
265
            other_tree.add('newfile')
266
            other_tree.add('newdir/')
267
            other_tree.commit('modify all sample files and dirs.')
268
        finally:
269
            other_tree.unlock()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
270
        this_tree.merge_from_branch(other_tree.branch)
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
271
        os.chdir('this')
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
272
        out,err = self.run_bzr('commit -v -m added')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
273
        os.chdir('..')
274
        self.assertEqual('', out)
275
        self.assertEqualDiff(
276
            'modified filetomodify\n'
277
            'added newdir\n'
278
            'added newfile\n'
279
            'renamed dirtorename => renameddir\n'
280
            'renamed dirtoreparent => renameddir/reparenteddir\n'
281
            'renamed filetoreparent => renameddir/reparentedfile\n'
2484.1.25 by John Arbash Meinel
[merge] bzr.dev 2612
282
            'renamed filetorename => renamedfile\n'
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
283
            'deleted dirtoremove\n'
284
            'deleted filetoremove\n'
285
            'Committed revision 2.\n',
286
            err)
287
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
288
    def test_empty_commit_message(self):
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
289
        tree = self.make_branch_and_tree('.')
290
        self.build_tree_contents([('foo.c', 'int main() {}')])
291
        tree.add('foo.c')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
292
        self.run_bzr('commit -m ""', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
293
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.
294
    def test_unsupported_encoding_commit_message(self):
295
        tree = self.make_branch_and_tree('.')
296
        self.build_tree_contents([('foo.c', 'int main() {}')])
297
        tree.add('foo.c')
298
        out,err = self.run_bzr_subprocess('commit -m "\xff"', retcode=1,
299
                                                    env_changes={'LANG': 'C'})
300
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
301
                                    'unsupported by the current encoding.')
302
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
303
    def test_other_branch_commit(self):
304
        # this branch is to ensure consistent behaviour, whether we're run
305
        # inside a branch, or not.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
306
        outer_tree = self.make_branch_and_tree('.')
307
        inner_tree = self.make_branch_and_tree('branch')
308
        self.build_tree_contents([
309
            ('branch/foo.c', 'int main() {}'),
310
            ('branch/bar.c', 'int main() {}')])
311
        inner_tree.add('foo.c')
312
        inner_tree.add('bar.c')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
313
        # 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
314
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
315
        self.run_bzr('commit -m newstuff branch/foo.c')
316
        self.run_bzr('commit -m newstuff branch')
317
        self.run_bzr('commit -m newstuff branch', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
318
319
    def test_out_of_date_tree_commit(self):
320
        # check we get an error code and a clear message committing with an out
321
        # of date checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
322
        tree = self.make_branch_and_tree('branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
323
        # make a checkout
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
324
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
325
        # 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.
326
        tree.commit('message branch', allow_pointless=True)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
327
        # now commit to the checkout should emit
328
        # 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
329
        output = self.run_bzr('commit --unchanged -m checkout_message '
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
330
                             'checkout', retcode=3)
331
        self.assertEqual(output,
332
                         ('',
2738.4.6 by Daniel Watkins
Rewrapped lines longer than 79 characters.
333
                          "bzr: ERROR: Working tree is out of date, please "
334
                          "run 'bzr update'.\n"))
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
335
336
    def test_local_commit_unbound(self):
337
        # a --local commit on an unbound branch is an error
338
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
339
        out, err = self.run_bzr('commit --local', retcode=3)
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
340
        self.assertEqualDiff('', out)
341
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
342
                             'on unbound branches.\n', err)
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
343
344
    def test_commit_a_text_merge_in_a_checkout(self):
345
        # checkouts perform multiple actions in a transaction across bond
346
        # branches and their master, and have been observed to fail in the
347
        # past. This is a user story reported to fail in bug #43959 where 
348
        # a merge done in a checkout (using the update command) failed to
349
        # commit correctly.
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
350
        trunk = self.make_branch_and_tree('trunk')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
351
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
352
        u1 = trunk.branch.create_checkout('u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
353
        self.build_tree_contents([('u1/hosts', 'initial contents')])
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
354
        u1.add('hosts')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
355
        self.run_bzr('commit -m add-hosts u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
356
2664.13.2 by Daniel Watkins
tests.blackbox.test_commit now uses internals where appropriate.
357
        u2 = trunk.branch.create_checkout('u2')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
358
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
359
        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)
360
361
        # make an offline commits
362
        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
363
        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)
364
365
        # now try to pull in online work from u2, and then commit our offline
366
        # work as a merge
367
        # retcode 1 as we expect a text conflict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
368
        self.run_bzr('update u1', retcode=1)
369
        self.run_bzr('resolved u1/hosts')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
370
        # add a text change here to represent resolving the merge conflicts in
371
        # favour of a new version of the file not identical to either the u1
372
        # version or the u2 version.
373
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
374
        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
375
376
    def test_commit_respects_spec_for_removals(self):
377
        """Commit with a file spec should only commit removals that match"""
378
        t = self.make_branch_and_tree('.')
379
        self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
380
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
381
        t.commit('Create')
382
        t.remove(['file-a', 'dir-a/file-b'])
383
        os.chdir('dir-a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
384
        result = self.run_bzr('commit . -m removed-file-b')[1]
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
385
        self.assertNotContainsRe(result, 'file-a')
386
        result = self.run_bzr('status')[0]
387
        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
388
389
    def test_strict_commit(self):
390
        """Commit with --strict works if everything is known"""
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
391
        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
392
        tree = self.make_branch_and_tree('tree')
393
        self.build_tree(['tree/a'])
394
        tree.add('a')
395
        # A simple change should just work
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
396
        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
397
                     working_dir='tree')
398
399
    def test_strict_commit_no_changes(self):
400
        """commit --strict gives "no changes" if there is nothing to commit"""
401
        tree = self.make_branch_and_tree('tree')
402
        self.build_tree(['tree/a'])
403
        tree.add('a')
404
        tree.commit('adding a')
405
406
        # With no changes, it should just be 'no changes'
407
        # Make sure that commit is failing because there is nothing to do
408
        self.run_bzr_error(['no changes to commit'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
409
                           '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
410
                           working_dir='tree')
411
412
        # But --strict doesn't care if you supply --unchanged
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
413
        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
414
                     working_dir='tree')
415
416
    def test_strict_commit_unknown(self):
417
        """commit --strict fails if a file is unknown"""
418
        tree = self.make_branch_and_tree('tree')
419
        self.build_tree(['tree/a'])
420
        tree.add('a')
421
        tree.commit('adding a')
422
423
        # Add one file so there is a change, but forget the other
424
        self.build_tree(['tree/b', 'tree/c'])
425
        tree.add('b')
426
        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.
427
                           '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
428
                           working_dir='tree')
429
430
        # --no-strict overrides --strict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
431
        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
432
                     working_dir='tree')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
433
434
    def test_fixes_bug_output(self):
435
        """commit --fixes=lp:23452 succeeds without output."""
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
436
        tree = self.make_branch_and_tree('tree')
437
        self.build_tree(['tree/hello.txt'])
438
        tree.add('hello.txt')
2376.4.12 by Jonathan Lange
Update NEWS file.
439
        output, err = self.run_bzr(
2789.2.1 by Ian Clatworthy
Make commit less verbose by default
440
            'commit -v -m hello --fixes=lp:23452 tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
441
        self.assertEqual('', output)
2376.4.12 by Jonathan Lange
Update NEWS file.
442
        self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
443
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
444
    def test_no_bugs_no_properties(self):
445
        """If no bugs are fixed, the bugs property is not set.
446
447
        see https://beta.launchpad.net/bzr/+bug/109613
448
        """
449
        tree = self.make_branch_and_tree('tree')
450
        self.build_tree(['tree/hello.txt'])
451
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
452
        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
453
        # Get the revision properties, ignoring the branch-nick property, which
454
        # we don't care about for this test.
455
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
456
        properties = dict(last_rev.properties)
457
        del properties['branch-nick']
458
        self.assertFalse('bugs' in properties)
459
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
460
    def test_fixes_bug_sets_property(self):
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
461
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
462
        tree = self.make_branch_and_tree('tree')
463
        self.build_tree(['tree/hello.txt'])
464
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
465
        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.
466
467
        # Get the revision properties, ignoring the branch-nick property, which
468
        # we don't care about for this test.
469
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
470
        properties = dict(last_rev.properties)
471
        del properties['branch-nick']
472
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
473
        self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
2376.4.7 by jml at canonical
- Add docstrings to tests.
474
                         properties)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
475
476
    def test_fixes_multiple_bugs_sets_properties(self):
477
        """--fixes can be used more than once to show that bugs are fixed."""
478
        tree = self.make_branch_and_tree('tree')
479
        self.build_tree(['tree/hello.txt'])
480
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
481
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
482
                     ' tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
483
484
        # Get the revision properties, ignoring the branch-nick property, which
485
        # we don't care about for this test.
486
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
487
        properties = dict(last_rev.properties)
488
        del properties['branch-nick']
489
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
490
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
491
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
492
                     'https://launchpad.net/bugs/235 fixed'},
493
            properties)
2376.4.7 by jml at canonical
- Add docstrings to tests.
494
495
    def test_fixes_bug_with_alternate_trackers(self):
496
        """--fixes can be used on a properly configured branch to mark bug
497
        fixes on multiple trackers.
498
        """
499
        tree = self.make_branch_and_tree('tree')
500
        tree.branch.get_config().set_user_option(
501
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
502
        self.build_tree(['tree/hello.txt'])
503
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
504
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
2376.4.7 by jml at canonical
- Add docstrings to tests.
505
506
        # Get the revision properties, ignoring the branch-nick property, which
507
        # we don't care about for this test.
508
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
509
        properties = dict(last_rev.properties)
510
        del properties['branch-nick']
511
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
512
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
513
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
514
                     'http://twistedmatrix.com/trac/ticket/235 fixed'},
515
            properties)
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
516
517
    def test_fixes_unknown_bug_prefix(self):
518
        tree = self.make_branch_and_tree('tree')
519
        self.build_tree(['tree/hello.txt'])
520
        tree.add('hello.txt')
521
        self.run_bzr_error(
522
            ["Unrecognized bug %s. Commit refused." % 'xxx:123'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
523
            'commit -m add-b --fixes=xxx:123',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
524
            working_dir='tree')
525
526
    def test_fixes_invalid_bug_number(self):
527
        tree = self.make_branch_and_tree('tree')
528
        self.build_tree(['tree/hello.txt'])
529
        tree.add('hello.txt')
530
        self.run_bzr_error(
2376.4.7 by jml at canonical
- Add docstrings to tests.
531
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
532
            'commit -m add-b --fixes=lp:orange',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
533
            working_dir='tree')
2376.4.7 by jml at canonical
- Add docstrings to tests.
534
535
    def test_fixes_invalid_argument(self):
536
        """Raise an appropriate error when the fixes argument isn't tag:id."""
537
        tree = self.make_branch_and_tree('tree')
538
        self.build_tree(['tree/hello.txt'])
539
        tree.add('hello.txt')
540
        self.run_bzr_error(
2376.4.13 by Jonathan Lange
Some stylistic cleanups
541
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
542
             r"Commit refused\."],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
543
            'commit -m add-b --fixes=orange',
2376.4.7 by jml at canonical
- Add docstrings to tests.
544
            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.
545
546
    def test_no_author(self):
547
        """If the author is not specified, the author property is not set."""
548
        tree = self.make_branch_and_tree('tree')
549
        self.build_tree(['tree/hello.txt'])
550
        tree.add('hello.txt')
551
        self.run_bzr( 'commit -m hello tree/hello.txt')
552
        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.
553
        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.
554
        self.assertFalse('author' in properties)
555
556
    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.
557
        """commit --author='John Doe <jdoe@example.com>' sets the author
558
           revprop.
559
        """
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.
560
        tree = self.make_branch_and_tree('tree')
561
        self.build_tree(['tree/hello.txt'])
562
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
563
        self.run_bzr("commit -m hello --author='John Doe <jdoe@example.com>' "
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.
564
                     "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.
565
        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.
566
        properties = last_rev.properties
567
        self.assertEqual('John Doe <jdoe@example.com>', properties['author'])
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.
568
569
    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.
570
        """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.
571
        tree = self.make_branch_and_tree('tree')
572
        self.build_tree(['tree/hello.txt'])
573
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
574
        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.
575
                                "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.
576
        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.
577
        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.
578
        self.assertEqual('John Doe', properties['author'])