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