~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_commit.py

  • Committer: Martin Pool
  • Date: 2007-09-24 06:42:21 UTC
  • mfrom: (2713.2.3 error-exitcode)
  • mto: This revision was merged to the branch mainline in revision 2874.
  • Revision ID: mbp@sourcefrog.net-20070924064221-nu12try0hbilenlj
Return exitcode 4 on internal error

Show diffs side-by-side

added added

removed removed

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