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_other_branch_commit(self):
325
# this branch is to ensure consistent behaviour, whether we're run
326
# inside a branch, or not.
327
outer_tree = self.make_branch_and_tree('.')
328
inner_tree = self.make_branch_and_tree('branch')
329
self.build_tree_contents([
330
('branch/foo.c', 'int main() {}'),
331
('branch/bar.c', 'int main() {}')])
332
inner_tree.add(['foo.c', 'bar.c'])
333
# can't commit files in different trees; sane error
334
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
335
# can commit to branch - records foo.c only
336
self.run_bzr('commit -m newstuff branch/foo.c')
337
# can commit to branch - records bar.c
338
self.run_bzr('commit -m newstuff branch')
340
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
342
def test_out_of_date_tree_commit(self):
343
# check we get an error code and a clear message committing with an out
345
tree = self.make_branch_and_tree('branch')
347
checkout = tree.branch.create_checkout('checkout', lightweight=True)
348
# commit to the original branch to make the checkout out of date
349
tree.commit('message branch', allow_pointless=True)
350
# now commit to the checkout should emit
351
# ERROR: Out of date with the branch, 'bzr update' is suggested
352
output = self.run_bzr('commit --unchanged -m checkout_message '
353
'checkout', retcode=3)
354
self.assertEqual(output,
356
"bzr: ERROR: Working tree is out of date, please "
357
"run 'bzr update'.\n"))
359
def test_local_commit_unbound(self):
360
# a --local commit on an unbound branch is an error
361
self.make_branch_and_tree('.')
362
out, err = self.run_bzr('commit --local', retcode=3)
363
self.assertEqualDiff('', out)
364
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
365
'on unbound branches.\n', err)
367
def test_commit_a_text_merge_in_a_checkout(self):
368
# checkouts perform multiple actions in a transaction across bond
369
# branches and their master, and have been observed to fail in the
370
# past. This is a user story reported to fail in bug #43959 where
371
# a merge done in a checkout (using the update command) failed to
373
trunk = self.make_branch_and_tree('trunk')
375
u1 = trunk.branch.create_checkout('u1')
376
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
378
self.run_bzr('commit -m add-hosts u1')
380
u2 = trunk.branch.create_checkout('u2')
381
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
382
self.run_bzr('commit -m checkin-from-u2 u2')
384
# make an offline commits
385
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
386
self.run_bzr('commit -m checkin-offline --local u1')
388
# now try to pull in online work from u2, and then commit our offline
390
# retcode 1 as we expect a text conflict
391
self.run_bzr('update u1', retcode=1)
392
self.assertFileEqual('''\
394
first offline change in u1
401
self.run_bzr('resolved u1/hosts')
402
# add a text change here to represent resolving the merge conflicts in
403
# favour of a new version of the file not identical to either the u1
404
# version or the u2 version.
405
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
406
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
408
def test_commit_exclude_excludes_modified_files(self):
409
"""Commit -x foo should ignore changes to foo."""
410
tree = self.make_branch_and_tree('.')
411
self.build_tree(['a', 'b', 'c'])
412
tree.smart_add(['.'])
413
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
414
self.assertFalse('added b' in out)
415
self.assertFalse('added b' in err)
416
# If b was excluded it will still be 'added' in status.
417
out, err = self.run_bzr(['added'])
418
self.assertEqual('b\n', out)
419
self.assertEqual('', err)
421
def test_commit_exclude_twice_uses_both_rules(self):
422
"""Commit -x foo -x bar should ignore changes to foo and bar."""
423
tree = self.make_branch_and_tree('.')
424
self.build_tree(['a', 'b', 'c'])
425
tree.smart_add(['.'])
426
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
427
self.assertFalse('added b' in out)
428
self.assertFalse('added c' in out)
429
self.assertFalse('added b' in err)
430
self.assertFalse('added c' in err)
431
# If b was excluded it will still be 'added' in status.
432
out, err = self.run_bzr(['added'])
433
self.assertTrue('b\n' in out)
434
self.assertTrue('c\n' in out)
435
self.assertEqual('', err)
437
def test_commit_respects_spec_for_removals(self):
438
"""Commit with a file spec should only commit removals that match"""
439
t = self.make_branch_and_tree('.')
440
self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
441
t.add(['file-a', 'dir-a', 'dir-a/file-b'])
443
t.remove(['file-a', 'dir-a/file-b'])
445
result = self.run_bzr('commit . -m removed-file-b')[1]
446
self.assertNotContainsRe(result, 'file-a')
447
result = self.run_bzr('status')[0]
448
self.assertContainsRe(result, 'removed:\n file-a')
450
def test_strict_commit(self):
451
"""Commit with --strict works if everything is known"""
452
ignores._set_user_ignores([])
453
tree = self.make_branch_and_tree('tree')
454
self.build_tree(['tree/a'])
456
# A simple change should just work
457
self.run_bzr('commit --strict -m adding-a',
460
def test_strict_commit_no_changes(self):
461
"""commit --strict gives "no changes" if there is nothing to commit"""
462
tree = self.make_branch_and_tree('tree')
463
self.build_tree(['tree/a'])
465
tree.commit('adding a')
467
# With no changes, it should just be 'no changes'
468
# Make sure that commit is failing because there is nothing to do
469
self.run_bzr_error(['No changes to commit'],
470
'commit --strict -m no-changes',
473
# But --strict doesn't care if you supply --unchanged
474
self.run_bzr('commit --strict --unchanged -m no-changes',
477
def test_strict_commit_unknown(self):
478
"""commit --strict fails if a file is unknown"""
479
tree = self.make_branch_and_tree('tree')
480
self.build_tree(['tree/a'])
482
tree.commit('adding a')
484
# Add one file so there is a change, but forget the other
485
self.build_tree(['tree/b', 'tree/c'])
487
self.run_bzr_error(['Commit refused because there are unknown files'],
488
'commit --strict -m add-b',
491
# --no-strict overrides --strict
492
self.run_bzr('commit --strict -m add-b --no-strict',
495
def test_fixes_bug_output(self):
496
"""commit --fixes=lp:23452 succeeds without output."""
497
tree = self.make_branch_and_tree('tree')
498
self.build_tree(['tree/hello.txt'])
499
tree.add('hello.txt')
500
output, err = self.run_bzr(
501
'commit -m hello --fixes=lp:23452 tree/hello.txt')
502
self.assertEqual('', output)
503
self.assertContainsRe(err, 'Committing to: .*\n'
505
'Committed revision 1\.\n')
507
def test_no_bugs_no_properties(self):
508
"""If no bugs are fixed, the bugs property is not set.
510
see https://beta.launchpad.net/bzr/+bug/109613
512
tree = self.make_branch_and_tree('tree')
513
self.build_tree(['tree/hello.txt'])
514
tree.add('hello.txt')
515
self.run_bzr( 'commit -m hello tree/hello.txt')
516
# Get the revision properties, ignoring the branch-nick property, which
517
# we don't care about for this test.
518
last_rev = tree.branch.repository.get_revision(tree.last_revision())
519
properties = dict(last_rev.properties)
520
del properties['branch-nick']
521
self.assertFalse('bugs' in properties)
523
def test_fixes_bug_sets_property(self):
524
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
525
tree = self.make_branch_and_tree('tree')
526
self.build_tree(['tree/hello.txt'])
527
tree.add('hello.txt')
528
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
530
# Get the revision properties, ignoring the branch-nick property, which
531
# we don't care about for this test.
532
last_rev = tree.branch.repository.get_revision(tree.last_revision())
533
properties = dict(last_rev.properties)
534
del properties['branch-nick']
536
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
539
def test_fixes_multiple_bugs_sets_properties(self):
540
"""--fixes can be used more than once to show that bugs are fixed."""
541
tree = self.make_branch_and_tree('tree')
542
self.build_tree(['tree/hello.txt'])
543
tree.add('hello.txt')
544
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
547
# Get the revision properties, ignoring the branch-nick property, which
548
# we don't care about for this test.
549
last_rev = tree.branch.repository.get_revision(tree.last_revision())
550
properties = dict(last_rev.properties)
551
del properties['branch-nick']
554
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
555
'https://launchpad.net/bugs/235 fixed'},
558
def test_fixes_bug_with_alternate_trackers(self):
559
"""--fixes can be used on a properly configured branch to mark bug
560
fixes on multiple trackers.
562
tree = self.make_branch_and_tree('tree')
563
tree.branch.get_config().set_user_option(
564
'trac_twisted_url', 'http://twistedmatrix.com/trac')
565
self.build_tree(['tree/hello.txt'])
566
tree.add('hello.txt')
567
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
569
# Get the revision properties, ignoring the branch-nick property, which
570
# we don't care about for this test.
571
last_rev = tree.branch.repository.get_revision(tree.last_revision())
572
properties = dict(last_rev.properties)
573
del properties['branch-nick']
576
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
577
'http://twistedmatrix.com/trac/ticket/235 fixed'},
580
def test_fixes_unknown_bug_prefix(self):
581
tree = self.make_branch_and_tree('tree')
582
self.build_tree(['tree/hello.txt'])
583
tree.add('hello.txt')
585
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
586
'commit -m add-b --fixes=xxx:123',
589
def test_fixes_invalid_bug_number(self):
590
tree = self.make_branch_and_tree('tree')
591
self.build_tree(['tree/hello.txt'])
592
tree.add('hello.txt')
594
["Did not understand bug identifier orange: Must be an integer. "
595
"See \"bzr help bugs\" for more information on this feature.\n"
597
'commit -m add-b --fixes=lp:orange',
600
def test_fixes_invalid_argument(self):
601
"""Raise an appropriate error when the fixes argument isn't tag:id."""
602
tree = self.make_branch_and_tree('tree')
603
self.build_tree(['tree/hello.txt'])
604
tree.add('hello.txt')
606
[r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
607
r"See \"bzr help bugs\" for more information on this feature.\n"
608
r"Commit refused\."],
609
'commit -m add-b --fixes=orange',
612
def test_no_author(self):
613
"""If the author is not specified, the author property is not set."""
614
tree = self.make_branch_and_tree('tree')
615
self.build_tree(['tree/hello.txt'])
616
tree.add('hello.txt')
617
self.run_bzr( 'commit -m hello tree/hello.txt')
618
last_rev = tree.branch.repository.get_revision(tree.last_revision())
619
properties = last_rev.properties
620
self.assertFalse('author' in properties)
622
def test_author_sets_property(self):
623
"""commit --author='John Doe <jdoe@example.com>' sets the author
626
tree = self.make_branch_and_tree('tree')
627
self.build_tree(['tree/hello.txt'])
628
tree.add('hello.txt')
629
self.run_bzr(["commit", '-m', 'hello',
630
'--author', u'John D\xf6 <jdoe@example.com>',
632
last_rev = tree.branch.repository.get_revision(tree.last_revision())
633
properties = last_rev.properties
634
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
636
def test_author_no_email(self):
637
"""Author's name without an email address is allowed, too."""
638
tree = self.make_branch_and_tree('tree')
639
self.build_tree(['tree/hello.txt'])
640
tree.add('hello.txt')
641
out, err = self.run_bzr("commit -m hello --author='John Doe' "
643
last_rev = tree.branch.repository.get_revision(tree.last_revision())
644
properties = last_rev.properties
645
self.assertEqual('John Doe', properties['authors'])
647
def test_multiple_authors(self):
648
"""Multiple authors can be specyfied, and all are stored."""
649
tree = self.make_branch_and_tree('tree')
650
self.build_tree(['tree/hello.txt'])
651
tree.add('hello.txt')
652
out, err = self.run_bzr("commit -m hello --author='John Doe' "
653
"--author='Jane Rey' tree/hello.txt")
654
last_rev = tree.branch.repository.get_revision(tree.last_revision())
655
properties = last_rev.properties
656
self.assertEqual('John Doe\nJane Rey', properties['authors'])
658
def test_commit_time(self):
659
tree = self.make_branch_and_tree('tree')
660
self.build_tree(['tree/hello.txt'])
661
tree.add('hello.txt')
662
out, err = self.run_bzr("commit -m hello "
663
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
664
last_rev = tree.branch.repository.get_revision(tree.last_revision())
666
'Sat 2009-10-10 08:00:00 +0100',
667
osutils.format_date(last_rev.timestamp, last_rev.timezone))
669
def test_commit_time_bad_time(self):
670
tree = self.make_branch_and_tree('tree')
671
self.build_tree(['tree/hello.txt'])
672
tree.add('hello.txt')
673
out, err = self.run_bzr("commit -m hello "
674
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
675
self.assertStartsWith(
676
err, "bzr: ERROR: Could not parse --commit-time:")
678
def test_partial_commit_with_renames_in_tree(self):
679
# this test illustrates bug #140419
680
t = self.make_branch_and_tree('.')
681
self.build_tree(['dir/', 'dir/a', 'test'])
682
t.add(['dir/', 'dir/a', 'test'])
683
t.commit('initial commit')
684
# important part: file dir/a should change parent
685
# and should appear before old parent
686
# then during partial commit we have error
687
# parent_id {dir-XXX} not in inventory
688
t.rename_one('dir/a', 'a')
689
self.build_tree_contents([('test', 'changes in test')])
691
out, err = self.run_bzr('commit test -m "partial commit"')
692
self.assertEquals('', out)
693
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
695
def test_commit_readonly_checkout(self):
696
# https://bugs.launchpad.net/bzr/+bug/129701
697
# "UnlockableTransport error trying to commit in checkout of readonly
699
self.make_branch('master')
700
master = BzrDir.open_from_transport(
701
self.get_readonly_transport('master')).open_branch()
702
master.create_checkout('checkout')
703
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
705
self.assertContainsRe(err,
706
r'^bzr: ERROR: Cannot lock.*readonly transport')
708
def setup_editor(self):
709
# Test that commit template hooks work
710
if sys.platform == "win32":
711
f = file('fed.bat', 'w')
712
f.write('@rem dummy fed')
714
self.overrideEnv('BZR_EDITOR', "fed.bat")
716
f = file('fed.sh', 'wb')
717
f.write('#!/bin/sh\n')
719
os.chmod('fed.sh', 0755)
720
self.overrideEnv('BZR_EDITOR', "./fed.sh")
722
def setup_commit_with_template(self):
724
msgeditor.hooks.install_named_hook("commit_message_template",
725
lambda commit_obj, msg: "save me some typing\n", None)
726
tree = self.make_branch_and_tree('tree')
727
self.build_tree(['tree/hello.txt'])
728
tree.add('hello.txt')
731
def test_commit_hook_template_accepted(self):
732
tree = self.setup_commit_with_template()
733
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
734
last_rev = tree.branch.repository.get_revision(tree.last_revision())
735
self.assertEqual('save me some typing\n', last_rev.message)
737
def test_commit_hook_template_rejected(self):
738
tree = self.setup_commit_with_template()
739
expected = tree.last_revision()
740
out, err = self.run_bzr_error(["empty commit message"],
741
"commit tree/hello.txt", stdin="n\n")
742
self.assertEqual(expected, tree.last_revision())
744
def test_commit_without_username(self):
745
"""Ensure commit error if username is not set.
747
self.run_bzr(['init', 'foo'])
749
open('foo.txt', 'w').write('hello')
750
self.run_bzr(['add'])
751
self.overrideEnv('EMAIL', None)
752
self.overrideEnv('BZR_EMAIL', None)
753
# Also, make sure that it's not inferred from mailname.
754
self.overrideAttr(config, '_auto_user_id',
755
lambda: (None, None))
756
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
757
self.assertContainsRe(err, 'Unable to determine your name')
759
def test_commit_recursive_checkout(self):
760
"""Ensure that a commit to a recursive checkout fails cleanly.
762
self.run_bzr(['init', 'test_branch'])
763
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
764
os.chdir('test_checkout')
765
self.run_bzr(['bind', '.']) # bind to self
766
open('foo.txt', 'w').write('hello')
767
self.run_bzr(['add'])
768
out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
769
self.assertEqual(out, '')
770
self.assertContainsRe(err,
771
'Branch.*test_checkout.*appears to be bound to itself')