1
# Copyright (C) 2006-2011 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests for the commit CLI of bzr."""
25
from testtools.matchers import DocTestMatches
34
from bzrlib.bzrdir import BzrDir
35
from bzrlib.tests import (
38
UnicodeFilenameFeature,
40
from bzrlib.tests import TestCaseWithTransport
43
class TestCommit(TestCaseWithTransport):
45
def test_05_empty_commit(self):
46
"""Commit of tree with no versioned files should fail"""
47
# If forced, it should succeed, but this is not tested here.
48
self.make_branch_and_tree('.')
49
self.build_tree(['hello.txt'])
50
out,err = self.run_bzr('commit -m empty', retcode=3)
51
self.assertEqual('', out)
53
# 1) We really don't want 'aborting commit write group' anymore.
54
# 2) bzr: ERROR: is a really long line, so we wrap it with '\'
59
aborting commit write group: PointlessCommit(No changes to commit)
60
bzr: ERROR: No changes to commit.\
61
Please 'bzr add' the files you want to commit,\
62
or use --unchanged to force an empty commit.
63
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
65
def test_commit_success(self):
66
"""Successful commit should not leave behind a bzr-commit-* file"""
67
self.make_branch_and_tree('.')
68
self.run_bzr('commit --unchanged -m message')
69
self.assertEqual('', self.run_bzr('unknowns')[0])
71
# same for unicode messages
72
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
73
self.assertEqual('', self.run_bzr('unknowns')[0])
75
def test_commit_with_path(self):
76
"""Commit tree with path of root specified"""
77
a_tree = self.make_branch_and_tree('a')
78
self.build_tree(['a/a_file'])
80
self.run_bzr(['commit', '-m', 'first commit', 'a'])
82
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
83
self.build_tree_contents([('b/a_file', 'changes in b')])
84
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
86
self.build_tree_contents([('a/a_file', 'new contents')])
87
self.run_bzr(['commit', '-m', 'change in a', 'a'])
89
b_tree.merge_from_branch(a_tree.branch)
90
self.assertEqual(len(b_tree.conflicts()), 1)
91
self.run_bzr('resolved b/a_file')
92
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
95
def test_10_verbose_commit(self):
96
"""Add one file and examine verbose commit output"""
97
tree = self.make_branch_and_tree('.')
98
self.build_tree(['hello.txt'])
100
out,err = self.run_bzr('commit -m added')
101
self.assertEqual('', out)
102
self.assertContainsRe(err, '^Committing to: .*\n'
104
'Committed revision 1.\n$',)
106
def prepare_simple_history(self):
107
"""Prepare and return a working tree with one commit of one file"""
108
# Commit with modified file should say so
109
wt = BzrDir.create_standalone_workingtree('.')
110
self.build_tree(['hello.txt', 'extra.txt'])
111
wt.add(['hello.txt'])
112
wt.commit(message='added')
115
def test_verbose_commit_modified(self):
116
# Verbose commit of modified file should say so
117
wt = self.prepare_simple_history()
118
self.build_tree_contents([('hello.txt', 'new contents')])
119
out, err = self.run_bzr('commit -m modified')
120
self.assertEqual('', out)
121
self.assertContainsRe(err, '^Committing to: .*\n'
122
'modified hello\.txt\n'
123
'Committed revision 2\.\n$')
125
def test_unicode_commit_message_is_filename(self):
126
"""Unicode commit message same as a filename (Bug #563646).
128
self.requireFeature(UnicodeFilenameFeature)
129
file_name = u'\N{euro sign}'
130
self.run_bzr(['init'])
131
open(file_name, 'w').write('hello world')
132
self.run_bzr(['add'])
133
out, err = self.run_bzr(['commit', '-m', file_name])
134
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
135
te = osutils.get_terminal_encoding()
136
self.assertContainsRe(err.decode(te),
137
u'The commit message is a file name:',
140
# Run same test with a filename that causes encode
141
# error for the terminal encoding. We do this
142
# by forcing terminal encoding of ascii for
143
# osutils.get_terminal_encoding which is used
144
# by ui.text.show_warning
145
default_get_terminal_enc = osutils.get_terminal_encoding
147
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
148
file_name = u'foo\u1234'
149
open(file_name, 'w').write('hello world')
150
self.run_bzr(['add'])
151
out, err = self.run_bzr(['commit', '-m', file_name])
152
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
153
te = osutils.get_terminal_encoding()
154
self.assertContainsRe(err.decode(te, 'replace'),
155
u'The commit message is a file name:',
158
osutils.get_terminal_encoding = default_get_terminal_enc
160
def test_warn_about_forgotten_commit_message(self):
161
"""Test that the lack of -m parameter is caught"""
162
wt = self.make_branch_and_tree('.')
163
self.build_tree(['one', 'two'])
165
out, err = self.run_bzr('commit -m one two')
166
self.assertContainsRe(err, "The commit message is a file name")
168
def test_verbose_commit_renamed(self):
169
# Verbose commit of renamed file should say so
170
wt = self.prepare_simple_history()
171
wt.rename_one('hello.txt', 'gutentag.txt')
172
out, err = self.run_bzr('commit -m renamed')
173
self.assertEqual('', out)
174
self.assertContainsRe(err, '^Committing to: .*\n'
175
'renamed hello\.txt => gutentag\.txt\n'
176
'Committed revision 2\.$\n')
178
def test_verbose_commit_moved(self):
179
# Verbose commit of file moved to new directory should say so
180
wt = self.prepare_simple_history()
183
wt.rename_one('hello.txt', 'subdir/hello.txt')
184
out, err = self.run_bzr('commit -m renamed')
185
self.assertEqual('', out)
186
self.assertEqual(set([
187
'Committing to: %s/' % osutils.getcwd(),
189
'renamed hello.txt => subdir/hello.txt',
190
'Committed revision 2.',
192
]), set(err.split('\n')))
194
def test_verbose_commit_with_unknown(self):
195
"""Unknown files should not be listed by default in verbose output"""
196
# Is that really the best policy?
197
wt = BzrDir.create_standalone_workingtree('.')
198
self.build_tree(['hello.txt', 'extra.txt'])
199
wt.add(['hello.txt'])
200
out,err = self.run_bzr('commit -m added')
201
self.assertEqual('', out)
202
self.assertContainsRe(err, '^Committing to: .*\n'
204
'Committed revision 1\.\n$')
206
def test_verbose_commit_with_unchanged(self):
207
"""Unchanged files should not be listed by default in verbose output"""
208
tree = self.make_branch_and_tree('.')
209
self.build_tree(['hello.txt', 'unchanged.txt'])
210
tree.add('unchanged.txt')
211
self.run_bzr('commit -m unchanged unchanged.txt')
212
tree.add("hello.txt")
213
out,err = self.run_bzr('commit -m added')
214
self.assertEqual('', out)
215
self.assertContainsRe(err, '^Committing to: .*\n'
217
'Committed revision 2\.$\n')
219
def test_verbose_commit_includes_master_location(self):
220
"""Location of master is displayed when committing to bound branch"""
221
a_tree = self.make_branch_and_tree('a')
222
self.build_tree(['a/b'])
224
a_tree.commit(message='Initial message')
226
b_tree = a_tree.branch.create_checkout('b')
227
expected = "%s/" % (osutils.abspath('a'), )
228
out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
229
self.assertEqual(err, 'Committing to: %s\n'
230
'Committed revision 2.\n' % expected)
232
def test_commit_sanitizes_CR_in_message(self):
233
# See bug #433779, basically Emacs likes to pass '\r\n' style line
234
# endings to 'bzr commit -m ""' which breaks because we don't allow
235
# '\r' in commit messages. (Mostly because of issues where XML style
236
# formats arbitrarily strip it out of the data while parsing.)
237
# To make life easier for users, we just always translate '\r\n' =>
238
# '\n'. And '\r' => '\n'.
239
a_tree = self.make_branch_and_tree('a')
240
self.build_tree(['a/b'])
242
self.run_bzr(['commit',
243
'-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
245
rev_id = a_tree.branch.last_revision()
246
rev = a_tree.branch.repository.get_revision(rev_id)
247
self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
250
def test_commit_merge_reports_all_modified_files(self):
251
# the commit command should show all the files that are shown by
252
# bzr diff or bzr status when committing, even when they were not
253
# changed by the user but rather through doing a merge.
254
this_tree = self.make_branch_and_tree('this')
255
# we need a bunch of files and dirs, to perform one action on each.
258
'this/dirtoreparent/',
261
'this/filetoreparent',
278
this_tree.commit('create_files')
279
other_dir = this_tree.bzrdir.sprout('other')
280
other_tree = other_dir.open_workingtree()
281
other_tree.lock_write()
282
# perform the needed actions on the files and dirs.
284
other_tree.rename_one('dirtorename', 'renameddir')
285
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
286
other_tree.rename_one('filetorename', 'renamedfile')
287
other_tree.rename_one('filetoreparent',
288
'renameddir/reparentedfile')
289
other_tree.remove(['dirtoremove', 'filetoremove'])
290
self.build_tree_contents([
292
('other/filetomodify', 'new content'),
293
('other/newfile', 'new file content')])
294
other_tree.add('newfile')
295
other_tree.add('newdir/')
296
other_tree.commit('modify all sample files and dirs.')
299
this_tree.merge_from_branch(other_tree.branch)
301
out,err = self.run_bzr('commit -m added')
302
self.assertEqual('', out)
303
self.assertEqual(set([
304
'Committing to: %s/' % osutils.getcwd(),
305
'modified filetomodify',
308
'renamed dirtorename => renameddir',
309
'renamed filetorename => renamedfile',
310
'renamed dirtoreparent => renameddir/reparenteddir',
311
'renamed filetoreparent => renameddir/reparentedfile',
312
'deleted dirtoremove',
313
'deleted filetoremove',
314
'Committed revision 2.',
316
]), set(err.split('\n')))
318
def test_empty_commit_message(self):
319
tree = self.make_branch_and_tree('.')
320
self.build_tree_contents([('foo.c', 'int main() {}')])
322
self.run_bzr('commit -m ""', retcode=3)
324
def test_unsupported_encoding_commit_message(self):
325
if sys.platform == 'win32':
326
raise tests.TestNotApplicable('Win32 parses arguments directly'
327
' as Unicode, so we can\'t pass invalid non-ascii')
328
tree = self.make_branch_and_tree('.')
329
self.build_tree_contents([('foo.c', 'int main() {}')])
331
# LANG env variable has no effect on Windows
332
# but some characters anyway cannot be represented
333
# in default user encoding
334
char = probe_bad_non_ascii(osutils.get_user_encoding())
336
raise TestSkipped('Cannot find suitable non-ascii character'
337
'for user_encoding (%s)' % osutils.get_user_encoding())
338
out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
340
env_changes={'LANG': 'C'})
341
self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
342
'unsupported by the current encoding.')
344
def test_other_branch_commit(self):
345
# this branch is to ensure consistent behaviour, whether we're run
346
# inside a branch, or not.
347
outer_tree = self.make_branch_and_tree('.')
348
inner_tree = self.make_branch_and_tree('branch')
349
self.build_tree_contents([
350
('branch/foo.c', 'int main() {}'),
351
('branch/bar.c', 'int main() {}')])
352
inner_tree.add(['foo.c', 'bar.c'])
353
# can't commit files in different trees; sane error
354
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
355
# can commit to branch - records foo.c only
356
self.run_bzr('commit -m newstuff branch/foo.c')
357
# can commit to branch - records bar.c
358
self.run_bzr('commit -m newstuff branch')
360
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
362
def test_out_of_date_tree_commit(self):
363
# check we get an error code and a clear message committing with an out
365
tree = self.make_branch_and_tree('branch')
367
checkout = tree.branch.create_checkout('checkout', lightweight=True)
368
# commit to the original branch to make the checkout out of date
369
tree.commit('message branch', allow_pointless=True)
370
# now commit to the checkout should emit
371
# ERROR: Out of date with the branch, 'bzr update' is suggested
372
output = self.run_bzr('commit --unchanged -m checkout_message '
373
'checkout', retcode=3)
374
self.assertEqual(output,
376
"bzr: ERROR: Working tree is out of date, please "
377
"run 'bzr update'.\n"))
379
def test_local_commit_unbound(self):
380
# a --local commit on an unbound branch is an error
381
self.make_branch_and_tree('.')
382
out, err = self.run_bzr('commit --local', retcode=3)
383
self.assertEqualDiff('', out)
384
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
385
'on unbound branches.\n', err)
387
def test_commit_a_text_merge_in_a_checkout(self):
388
# checkouts perform multiple actions in a transaction across bond
389
# branches and their master, and have been observed to fail in the
390
# past. This is a user story reported to fail in bug #43959 where
391
# a merge done in a checkout (using the update command) failed to
393
trunk = self.make_branch_and_tree('trunk')
395
u1 = trunk.branch.create_checkout('u1')
396
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
398
self.run_bzr('commit -m add-hosts u1')
400
u2 = trunk.branch.create_checkout('u2')
401
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
402
self.run_bzr('commit -m checkin-from-u2 u2')
404
# make an offline commits
405
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
406
self.run_bzr('commit -m checkin-offline --local u1')
408
# now try to pull in online work from u2, and then commit our offline
410
# retcode 1 as we expect a text conflict
411
self.run_bzr('update u1', retcode=1)
412
self.assertFileEqual('''\
414
first offline change in u1
421
self.run_bzr('resolved u1/hosts')
422
# add a text change here to represent resolving the merge conflicts in
423
# favour of a new version of the file not identical to either the u1
424
# version or the u2 version.
425
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
426
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
428
def test_commit_exclude_excludes_modified_files(self):
429
"""Commit -x foo should ignore changes to foo."""
430
tree = self.make_branch_and_tree('.')
431
self.build_tree(['a', 'b', 'c'])
432
tree.smart_add(['.'])
433
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
434
self.assertFalse('added b' in out)
435
self.assertFalse('added b' in err)
436
# If b was excluded it will still be 'added' in status.
437
out, err = self.run_bzr(['added'])
438
self.assertEqual('b\n', out)
439
self.assertEqual('', err)
441
def test_commit_exclude_twice_uses_both_rules(self):
442
"""Commit -x foo -x bar should ignore changes to foo and bar."""
443
tree = self.make_branch_and_tree('.')
444
self.build_tree(['a', 'b', 'c'])
445
tree.smart_add(['.'])
446
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
447
self.assertFalse('added b' in out)
448
self.assertFalse('added c' in out)
449
self.assertFalse('added b' in err)
450
self.assertFalse('added c' in err)
451
# If b was excluded it will still be 'added' in status.
452
out, err = self.run_bzr(['added'])
453
self.assertTrue('b\n' in out)
454
self.assertTrue('c\n' in out)
455
self.assertEqual('', err)
457
def test_commit_respects_spec_for_removals(self):
458
"""Commit with a file spec should only commit removals that match"""
459
t = self.make_branch_and_tree('.')
460
self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
461
t.add(['file-a', 'dir-a', 'dir-a/file-b'])
463
t.remove(['file-a', 'dir-a/file-b'])
465
result = self.run_bzr('commit . -m removed-file-b')[1]
466
self.assertNotContainsRe(result, 'file-a')
467
result = self.run_bzr('status')[0]
468
self.assertContainsRe(result, 'removed:\n file-a')
470
def test_strict_commit(self):
471
"""Commit with --strict works if everything is known"""
472
ignores._set_user_ignores([])
473
tree = self.make_branch_and_tree('tree')
474
self.build_tree(['tree/a'])
476
# A simple change should just work
477
self.run_bzr('commit --strict -m adding-a',
480
def test_strict_commit_no_changes(self):
481
"""commit --strict gives "no changes" if there is nothing to commit"""
482
tree = self.make_branch_and_tree('tree')
483
self.build_tree(['tree/a'])
485
tree.commit('adding a')
487
# With no changes, it should just be 'no changes'
488
# Make sure that commit is failing because there is nothing to do
489
self.run_bzr_error(['No changes to commit'],
490
'commit --strict -m no-changes',
493
# But --strict doesn't care if you supply --unchanged
494
self.run_bzr('commit --strict --unchanged -m no-changes',
497
def test_strict_commit_unknown(self):
498
"""commit --strict fails if a file is unknown"""
499
tree = self.make_branch_and_tree('tree')
500
self.build_tree(['tree/a'])
502
tree.commit('adding a')
504
# Add one file so there is a change, but forget the other
505
self.build_tree(['tree/b', 'tree/c'])
507
self.run_bzr_error(['Commit refused because there are unknown files'],
508
'commit --strict -m add-b',
511
# --no-strict overrides --strict
512
self.run_bzr('commit --strict -m add-b --no-strict',
515
def test_fixes_bug_output(self):
516
"""commit --fixes=lp:23452 succeeds without output."""
517
tree = self.make_branch_and_tree('tree')
518
self.build_tree(['tree/hello.txt'])
519
tree.add('hello.txt')
520
output, err = self.run_bzr(
521
'commit -m hello --fixes=lp:23452 tree/hello.txt')
522
self.assertEqual('', output)
523
self.assertContainsRe(err, 'Committing to: .*\n'
525
'Committed revision 1\.\n')
527
def test_no_bugs_no_properties(self):
528
"""If no bugs are fixed, the bugs property is not set.
530
see https://beta.launchpad.net/bzr/+bug/109613
532
tree = self.make_branch_and_tree('tree')
533
self.build_tree(['tree/hello.txt'])
534
tree.add('hello.txt')
535
self.run_bzr( 'commit -m hello tree/hello.txt')
536
# Get the revision properties, ignoring the branch-nick property, which
537
# we don't care about for this test.
538
last_rev = tree.branch.repository.get_revision(tree.last_revision())
539
properties = dict(last_rev.properties)
540
del properties['branch-nick']
541
self.assertFalse('bugs' in properties)
543
def test_fixes_bug_sets_property(self):
544
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
545
tree = self.make_branch_and_tree('tree')
546
self.build_tree(['tree/hello.txt'])
547
tree.add('hello.txt')
548
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
550
# Get the revision properties, ignoring the branch-nick property, which
551
# we don't care about for this test.
552
last_rev = tree.branch.repository.get_revision(tree.last_revision())
553
properties = dict(last_rev.properties)
554
del properties['branch-nick']
556
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
559
def test_fixes_multiple_bugs_sets_properties(self):
560
"""--fixes can be used more than once to show that bugs are fixed."""
561
tree = self.make_branch_and_tree('tree')
562
self.build_tree(['tree/hello.txt'])
563
tree.add('hello.txt')
564
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
567
# Get the revision properties, ignoring the branch-nick property, which
568
# we don't care about for this test.
569
last_rev = tree.branch.repository.get_revision(tree.last_revision())
570
properties = dict(last_rev.properties)
571
del properties['branch-nick']
574
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
575
'https://launchpad.net/bugs/235 fixed'},
578
def test_fixes_bug_with_alternate_trackers(self):
579
"""--fixes can be used on a properly configured branch to mark bug
580
fixes on multiple trackers.
582
tree = self.make_branch_and_tree('tree')
583
tree.branch.get_config().set_user_option(
584
'trac_twisted_url', 'http://twistedmatrix.com/trac')
585
self.build_tree(['tree/hello.txt'])
586
tree.add('hello.txt')
587
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
589
# Get the revision properties, ignoring the branch-nick property, which
590
# we don't care about for this test.
591
last_rev = tree.branch.repository.get_revision(tree.last_revision())
592
properties = dict(last_rev.properties)
593
del properties['branch-nick']
596
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
597
'http://twistedmatrix.com/trac/ticket/235 fixed'},
600
def test_fixes_unknown_bug_prefix(self):
601
tree = self.make_branch_and_tree('tree')
602
self.build_tree(['tree/hello.txt'])
603
tree.add('hello.txt')
605
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
606
'commit -m add-b --fixes=xxx:123',
609
def test_fixes_invalid_bug_number(self):
610
tree = self.make_branch_and_tree('tree')
611
self.build_tree(['tree/hello.txt'])
612
tree.add('hello.txt')
614
["Did not understand bug identifier orange: Must be an integer. "
615
"See \"bzr help bugs\" for more information on this feature.\n"
617
'commit -m add-b --fixes=lp:orange',
620
def test_fixes_invalid_argument(self):
621
"""Raise an appropriate error when the fixes argument isn't tag:id."""
622
tree = self.make_branch_and_tree('tree')
623
self.build_tree(['tree/hello.txt'])
624
tree.add('hello.txt')
626
[r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
627
r"See \"bzr help bugs\" for more information on this feature.\n"
628
r"Commit refused\."],
629
'commit -m add-b --fixes=orange',
632
def test_no_author(self):
633
"""If the author is not specified, the author property is not set."""
634
tree = self.make_branch_and_tree('tree')
635
self.build_tree(['tree/hello.txt'])
636
tree.add('hello.txt')
637
self.run_bzr( 'commit -m hello tree/hello.txt')
638
last_rev = tree.branch.repository.get_revision(tree.last_revision())
639
properties = last_rev.properties
640
self.assertFalse('author' in properties)
642
def test_author_sets_property(self):
643
"""commit --author='John Doe <jdoe@example.com>' sets the author
646
tree = self.make_branch_and_tree('tree')
647
self.build_tree(['tree/hello.txt'])
648
tree.add('hello.txt')
649
self.run_bzr(["commit", '-m', 'hello',
650
'--author', u'John D\xf6 <jdoe@example.com>',
652
last_rev = tree.branch.repository.get_revision(tree.last_revision())
653
properties = last_rev.properties
654
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
656
def test_author_no_email(self):
657
"""Author's name without an email address is allowed, too."""
658
tree = self.make_branch_and_tree('tree')
659
self.build_tree(['tree/hello.txt'])
660
tree.add('hello.txt')
661
out, err = self.run_bzr("commit -m hello --author='John Doe' "
663
last_rev = tree.branch.repository.get_revision(tree.last_revision())
664
properties = last_rev.properties
665
self.assertEqual('John Doe', properties['authors'])
667
def test_multiple_authors(self):
668
"""Multiple authors can be specyfied, and all are stored."""
669
tree = self.make_branch_and_tree('tree')
670
self.build_tree(['tree/hello.txt'])
671
tree.add('hello.txt')
672
out, err = self.run_bzr("commit -m hello --author='John Doe' "
673
"--author='Jane Rey' tree/hello.txt")
674
last_rev = tree.branch.repository.get_revision(tree.last_revision())
675
properties = last_rev.properties
676
self.assertEqual('John Doe\nJane Rey', properties['authors'])
678
def test_commit_time(self):
679
tree = self.make_branch_and_tree('tree')
680
self.build_tree(['tree/hello.txt'])
681
tree.add('hello.txt')
682
out, err = self.run_bzr("commit -m hello "
683
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
684
last_rev = tree.branch.repository.get_revision(tree.last_revision())
686
'Sat 2009-10-10 08:00:00 +0100',
687
osutils.format_date(last_rev.timestamp, last_rev.timezone))
689
def test_commit_time_bad_time(self):
690
tree = self.make_branch_and_tree('tree')
691
self.build_tree(['tree/hello.txt'])
692
tree.add('hello.txt')
693
out, err = self.run_bzr("commit -m hello "
694
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
695
self.assertStartsWith(
696
err, "bzr: ERROR: Could not parse --commit-time:")
698
def test_partial_commit_with_renames_in_tree(self):
699
# this test illustrates bug #140419
700
t = self.make_branch_and_tree('.')
701
self.build_tree(['dir/', 'dir/a', 'test'])
702
t.add(['dir/', 'dir/a', 'test'])
703
t.commit('initial commit')
704
# important part: file dir/a should change parent
705
# and should appear before old parent
706
# then during partial commit we have error
707
# parent_id {dir-XXX} not in inventory
708
t.rename_one('dir/a', 'a')
709
self.build_tree_contents([('test', 'changes in test')])
711
out, err = self.run_bzr('commit test -m "partial commit"')
712
self.assertEquals('', out)
713
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
715
def test_commit_readonly_checkout(self):
716
# https://bugs.launchpad.net/bzr/+bug/129701
717
# "UnlockableTransport error trying to commit in checkout of readonly
719
self.make_branch('master')
720
master = BzrDir.open_from_transport(
721
self.get_readonly_transport('master')).open_branch()
722
master.create_checkout('checkout')
723
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
725
self.assertContainsRe(err,
726
r'^bzr: ERROR: Cannot lock.*readonly transport')
728
def setup_editor(self):
729
# Test that commit template hooks work
730
if sys.platform == "win32":
731
f = file('fed.bat', 'w')
732
f.write('@rem dummy fed')
734
self.overrideEnv('BZR_EDITOR', "fed.bat")
736
f = file('fed.sh', 'wb')
737
f.write('#!/bin/sh\n')
739
os.chmod('fed.sh', 0755)
740
self.overrideEnv('BZR_EDITOR', "./fed.sh")
742
def setup_commit_with_template(self):
744
msgeditor.hooks.install_named_hook("commit_message_template",
745
lambda commit_obj, msg: "save me some typing\n", None)
746
tree = self.make_branch_and_tree('tree')
747
self.build_tree(['tree/hello.txt'])
748
tree.add('hello.txt')
751
def test_commit_hook_template_accepted(self):
752
tree = self.setup_commit_with_template()
753
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
754
last_rev = tree.branch.repository.get_revision(tree.last_revision())
755
self.assertEqual('save me some typing\n', last_rev.message)
757
def test_commit_hook_template_rejected(self):
758
tree = self.setup_commit_with_template()
759
expected = tree.last_revision()
760
out, err = self.run_bzr_error(["empty commit message"],
761
"commit tree/hello.txt", stdin="n\n")
762
self.assertEqual(expected, tree.last_revision())
764
def test_commit_without_username(self):
765
"""Ensure commit error if username is not set.
767
self.run_bzr(['init', 'foo'])
769
open('foo.txt', 'w').write('hello')
770
self.run_bzr(['add'])
771
self.overrideEnv('EMAIL', None)
772
self.overrideEnv('BZR_EMAIL', None)
773
# Also, make sure that it's not inferred from mailname.
774
self.overrideAttr(config, '_auto_user_id',
775
lambda: (None, None))
776
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
777
self.assertContainsRe(err, 'Unable to determine your name')
779
def test_commit_recursive_checkout(self):
780
"""Ensure that a commit to a recursive checkout fails cleanly.
782
self.run_bzr(['init', 'test_branch'])
783
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
784
os.chdir('test_checkout')
785
self.run_bzr(['bind', '.']) # bind to self
786
open('foo.txt', 'w').write('hello')
787
self.run_bzr(['add'])
788
out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
789
self.assertEqual(out, '')
790
self.assertContainsRe(err,
791
'Branch.*test_checkout.*appears to be bound to itself')