1
# Copyright (C) 2006-2012, 2016 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
33
from ...controldir import ControlDir
38
from .. import TestCaseWithTransport
39
from ..matchers import ContainsNoVfsCalls
42
class TestCommit(TestCaseWithTransport):
44
def test_05_empty_commit(self):
45
"""Commit of tree with no versioned files should fail"""
46
# If forced, it should succeed, but this is not tested here.
47
self.make_branch_and_tree('.')
48
self.build_tree(['hello.txt'])
49
out, err = self.run_bzr('commit -m empty', retcode=3)
50
self.assertEqual(b'', out)
52
# 1) We really don't want 'aborting commit write group' anymore.
53
# 2) brz: ERROR: is a really long line, so we wrap it with '\'
58
brz: ERROR: No changes to commit.\
59
Please 'brz add' the files you want to commit,\
60
or use --unchanged to force an empty commit.
61
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
63
def test_commit_success(self):
64
"""Successful commit should not leave behind a bzr-commit-* file"""
65
self.make_branch_and_tree('.')
66
self.run_bzr('commit --unchanged -m message')
67
self.assertEqual('', self.run_bzr('unknowns')[0])
69
# same for unicode messages
70
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
71
self.assertEqual('', self.run_bzr('unknowns')[0])
73
def test_commit_lossy_native(self):
74
"""A --lossy option to commit is supported."""
75
self.make_branch_and_tree('.')
76
self.run_bzr('commit --lossy --unchanged -m message')
77
self.assertEqual('', self.run_bzr('unknowns')[0])
79
def test_commit_lossy_foreign(self):
80
test_foreign.register_dummy_foreign_for_test(self)
81
self.make_branch_and_tree('.',
82
format=test_foreign.DummyForeignVcsDirFormat())
83
self.run_bzr('commit --lossy --unchanged -m message')
84
output = self.run_bzr('revision-info')[0]
85
self.assertTrue(output.startswith('1 dummy-'))
87
def test_commit_with_path(self):
88
"""Commit tree with path of root specified"""
89
a_tree = self.make_branch_and_tree('a')
90
self.build_tree(['a/a_file'])
92
self.run_bzr(['commit', '-m', 'first commit', 'a'])
94
b_tree = a_tree.controldir.sprout('b').open_workingtree()
95
self.build_tree_contents([('b/a_file', b'changes in b')])
96
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
98
self.build_tree_contents([('a/a_file', b'new contents')])
99
self.run_bzr(['commit', '-m', 'change in a', 'a'])
101
b_tree.merge_from_branch(a_tree.branch)
102
self.assertEqual(len(b_tree.conflicts()), 1)
103
self.run_bzr('resolved b/a_file')
104
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
106
def test_10_verbose_commit(self):
107
"""Add one file and examine verbose commit output"""
108
tree = self.make_branch_and_tree('.')
109
self.build_tree(['hello.txt'])
110
tree.add("hello.txt")
111
out, err = self.run_bzr('commit -m added')
112
self.assertEqual(b'', out)
113
self.assertContainsRe(err, b'^Committing to: .*\n'
115
b'Committed revision 1.\n$',)
117
def prepare_simple_history(self):
118
"""Prepare and return a working tree with one commit of one file"""
119
# Commit with modified file should say so
120
wt = ControlDir.create_standalone_workingtree('.')
121
self.build_tree(['hello.txt', 'extra.txt'])
122
wt.add(['hello.txt'])
123
wt.commit(message='added')
126
def test_verbose_commit_modified(self):
127
# Verbose commit of modified file should say so
128
wt = self.prepare_simple_history()
129
self.build_tree_contents([('hello.txt', b'new contents')])
130
out, err = self.run_bzr('commit -m modified')
131
self.assertEqual(b'', out)
132
self.assertContainsRe(err, b'^Committing to: .*\n'
133
b'modified hello\\.txt\n'
134
b'Committed revision 2\\.\n$')
136
def test_unicode_commit_message_is_filename(self):
137
"""Unicode commit message same as a filename (Bug #563646).
139
self.requireFeature(features.UnicodeFilenameFeature)
140
file_name = u'\N{euro sign}'
141
self.run_bzr(['init'])
142
with open(file_name, 'w') as f:
143
f.write('hello world')
144
self.run_bzr(['add'])
145
out, err = self.run_bzr(['commit', '-m', file_name])
146
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
147
te = osutils.get_terminal_encoding()
148
self.assertContainsRe(err.decode(te),
149
u'The commit message is a file name:',
152
# Run same test with a filename that causes encode
153
# error for the terminal encoding. We do this
154
# by forcing terminal encoding of ascii for
155
# osutils.get_terminal_encoding which is used
156
# by ui.text.show_warning
157
default_get_terminal_enc = osutils.get_terminal_encoding
159
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
160
file_name = u'foo\u1234'
161
with open(file_name, 'w') as f:
162
f.write('hello world')
163
self.run_bzr(['add'])
164
out, err = self.run_bzr(['commit', '-m', file_name])
165
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
166
te = osutils.get_terminal_encoding()
167
self.assertContainsRe(err.decode(te, 'replace'),
168
u'The commit message is a file name:',
171
osutils.get_terminal_encoding = default_get_terminal_enc
173
def test_non_ascii_file_unversioned_utf8(self):
174
self.requireFeature(features.UnicodeFilenameFeature)
175
tree = self.make_branch_and_tree(".")
176
self.build_tree(["f"])
178
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
179
encoding="utf-8", retcode=3)
180
self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
182
def test_non_ascii_file_unversioned_iso_8859_5(self):
183
self.requireFeature(features.UnicodeFilenameFeature)
184
tree = self.make_branch_and_tree(".")
185
self.build_tree(["f"])
187
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
188
encoding="iso-8859-5", retcode=3)
189
self.expectFailure("Error messages are always written as UTF-8",
190
self.assertNotContainsString, err, "\xc2\xa7")
191
self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
193
def test_warn_about_forgotten_commit_message(self):
194
"""Test that the lack of -m parameter is caught"""
195
wt = self.make_branch_and_tree('.')
196
self.build_tree(['one', 'two'])
198
out, err = self.run_bzr('commit -m one two')
199
self.assertContainsRe(err, b"The commit message is a file name")
201
def test_verbose_commit_renamed(self):
202
# Verbose commit of renamed file should say so
203
wt = self.prepare_simple_history()
204
wt.rename_one('hello.txt', 'gutentag.txt')
205
out, err = self.run_bzr('commit -m renamed')
206
self.assertEqual(b'', out)
207
self.assertContainsRe(err, b'^Committing to: .*\n'
208
b'renamed hello\\.txt => gutentag\\.txt\n'
209
b'Committed revision 2\\.$\n')
211
def test_verbose_commit_moved(self):
212
# Verbose commit of file moved to new directory should say so
213
wt = self.prepare_simple_history()
216
wt.rename_one('hello.txt', 'subdir/hello.txt')
217
out, err = self.run_bzr('commit -m renamed')
218
self.assertEqual(b'', out)
220
b'Committing to: %s/' % osutils.getcwd(),
222
b'renamed hello.txt => subdir/hello.txt',
223
b'Committed revision 2.',
225
}, set(err.split('\n')))
227
def test_verbose_commit_with_unknown(self):
228
"""Unknown files should not be listed by default in verbose output"""
229
# Is that really the best policy?
230
wt = ControlDir.create_standalone_workingtree('.')
231
self.build_tree(['hello.txt', 'extra.txt'])
232
wt.add(['hello.txt'])
233
out, err = self.run_bzr('commit -m added')
234
self.assertEqual(b'', out)
235
self.assertContainsRe(err, b'^Committing to: .*\n'
236
b'added hello\\.txt\n'
237
b'Committed revision 1\\.\n$')
239
def test_verbose_commit_with_unchanged(self):
240
"""Unchanged files should not be listed by default in verbose output"""
241
tree = self.make_branch_and_tree('.')
242
self.build_tree(['hello.txt', 'unchanged.txt'])
243
tree.add('unchanged.txt')
244
self.run_bzr('commit -m unchanged unchanged.txt')
245
tree.add("hello.txt")
246
out, err = self.run_bzr('commit -m added')
247
self.assertEqual(b'', out)
248
self.assertContainsRe(err, b'^Committing to: .*\n'
249
b'added hello\\.txt\n'
250
b'Committed revision 2\\.$\n')
252
def test_verbose_commit_includes_master_location(self):
253
"""Location of master is displayed when committing to bound branch"""
254
a_tree = self.make_branch_and_tree('a')
255
self.build_tree(['a/b'])
257
a_tree.commit(message='Initial message')
259
b_tree = a_tree.branch.create_checkout('b')
260
expected = "%s/" % (osutils.abspath('a'), )
261
out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
262
self.assertEqual(err, 'Committing to: %s\n'
263
'Committed revision 2.\n' % expected)
265
def test_commit_sanitizes_CR_in_message(self):
266
# See bug #433779, basically Emacs likes to pass '\r\n' style line
267
# endings to 'brz commit -m ""' which breaks because we don't allow
268
# '\r' in commit messages. (Mostly because of issues where XML style
269
# formats arbitrarily strip it out of the data while parsing.)
270
# To make life easier for users, we just always translate '\r\n' =>
271
# '\n'. And '\r' => '\n'.
272
a_tree = self.make_branch_and_tree('a')
273
self.build_tree(['a/b'])
275
self.run_bzr(['commit',
276
'-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
278
rev_id = a_tree.branch.last_revision()
279
rev = a_tree.branch.repository.get_revision(rev_id)
280
self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
283
def test_commit_merge_reports_all_modified_files(self):
284
# the commit command should show all the files that are shown by
285
# brz diff or brz status when committing, even when they were not
286
# changed by the user but rather through doing a merge.
287
this_tree = self.make_branch_and_tree('this')
288
# we need a bunch of files and dirs, to perform one action on each.
291
'this/dirtoreparent/',
294
'this/filetoreparent',
311
this_tree.commit('create_files')
312
other_dir = this_tree.controldir.sprout('other')
313
other_tree = other_dir.open_workingtree()
314
other_tree.lock_write()
315
# perform the needed actions on the files and dirs.
317
other_tree.rename_one('dirtorename', 'renameddir')
318
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
319
other_tree.rename_one('filetorename', 'renamedfile')
320
other_tree.rename_one('filetoreparent',
321
'renameddir/reparentedfile')
322
other_tree.remove(['dirtoremove', 'filetoremove'])
323
self.build_tree_contents([
325
('other/filetomodify', b'new content'),
326
('other/newfile', b'new file content')])
327
other_tree.add('newfile')
328
other_tree.add('newdir/')
329
other_tree.commit('modify all sample files and dirs.')
332
this_tree.merge_from_branch(other_tree.branch)
333
out, err = self.run_bzr('commit -m added', working_dir='this')
334
self.assertEqual(b'', out)
336
b'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
337
b'modified filetomodify',
340
b'renamed dirtorename => renameddir',
341
b'renamed filetorename => renamedfile',
342
b'renamed dirtoreparent => renameddir/reparenteddir',
343
b'renamed filetoreparent => renameddir/reparentedfile',
344
b'deleted dirtoremove',
345
b'deleted filetoremove',
346
b'Committed revision 2.',
348
}, set(err.split(b'\n')))
350
def test_empty_commit_message(self):
351
tree = self.make_branch_and_tree('.')
352
self.build_tree_contents([('foo.c', b'int main() {}')])
354
self.run_bzr('commit -m ""')
356
def test_other_branch_commit(self):
357
# this branch is to ensure consistent behaviour, whether we're run
358
# inside a branch, or not.
359
outer_tree = self.make_branch_and_tree('.')
360
inner_tree = self.make_branch_and_tree('branch')
361
self.build_tree_contents([
362
('branch/foo.c', b'int main() {}'),
363
('branch/bar.c', b'int main() {}')])
364
inner_tree.add(['foo.c', 'bar.c'])
365
# can't commit files in different trees; sane error
366
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
367
# can commit to branch - records foo.c only
368
self.run_bzr('commit -m newstuff branch/foo.c')
369
# can commit to branch - records bar.c
370
self.run_bzr('commit -m newstuff branch')
372
self.run_bzr_error([b"No changes to commit"], 'commit -m newstuff branch')
374
def test_out_of_date_tree_commit(self):
375
# check we get an error code and a clear message committing with an out
377
tree = self.make_branch_and_tree('branch')
379
checkout = tree.branch.create_checkout('checkout', lightweight=True)
380
# commit to the original branch to make the checkout out of date
381
tree.commit('message branch', allow_pointless=True)
382
# now commit to the checkout should emit
383
# ERROR: Out of date with the branch, 'brz update' is suggested
384
output = self.run_bzr('commit --unchanged -m checkout_message '
385
'checkout', retcode=3)
386
self.assertEqual(output,
388
"brz: ERROR: Working tree is out of date, please "
389
"run 'brz update'.\n"))
391
def test_local_commit_unbound(self):
392
# a --local commit on an unbound branch is an error
393
self.make_branch_and_tree('.')
394
out, err = self.run_bzr('commit --local', retcode=3)
395
self.assertEqualDiff('', out)
396
self.assertEqualDiff('brz: ERROR: Cannot perform local-only commits '
397
'on unbound branches.\n', err)
399
def test_commit_a_text_merge_in_a_checkout(self):
400
# checkouts perform multiple actions in a transaction across bond
401
# branches and their master, and have been observed to fail in the
402
# past. This is a user story reported to fail in bug #43959 where
403
# a merge done in a checkout (using the update command) failed to
405
trunk = self.make_branch_and_tree('trunk')
407
u1 = trunk.branch.create_checkout('u1')
408
self.build_tree_contents([('u1/hosts', b'initial contents\n')])
410
self.run_bzr('commit -m add-hosts u1')
412
u2 = trunk.branch.create_checkout('u2')
413
self.build_tree_contents([('u2/hosts', b'altered in u2\n')])
414
self.run_bzr('commit -m checkin-from-u2 u2')
416
# make an offline commits
417
self.build_tree_contents([('u1/hosts', b'first offline change in u1\n')])
418
self.run_bzr('commit -m checkin-offline --local u1')
420
# now try to pull in online work from u2, and then commit our offline
422
# retcode 1 as we expect a text conflict
423
self.run_bzr('update u1', retcode=1)
424
self.assertFileEqual('''\
426
first offline change in u1
433
self.run_bzr('resolved u1/hosts')
434
# add a text change here to represent resolving the merge conflicts in
435
# favour of a new version of the file not identical to either the u1
436
# version or the u2 version.
437
self.build_tree_contents([('u1/hosts', b'merge resolution\n')])
438
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
440
def test_commit_exclude_excludes_modified_files(self):
441
"""Commit -x foo should ignore changes to foo."""
442
tree = self.make_branch_and_tree('.')
443
self.build_tree(['a', 'b', 'c'])
444
tree.smart_add(['.'])
445
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
446
self.assertFalse(b'added b' in out)
447
self.assertFalse(b'added b' in err)
448
# If b was excluded it will still be 'added' in status.
449
out, err = self.run_bzr(['added'])
450
self.assertEqual(b'b\n', out)
451
self.assertEqual(b'', err)
453
def test_commit_exclude_twice_uses_both_rules(self):
454
"""Commit -x foo -x bar should ignore changes to foo and bar."""
455
tree = self.make_branch_and_tree('.')
456
self.build_tree(['a', 'b', 'c'])
457
tree.smart_add(['.'])
458
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
459
self.assertFalse(b'added b' in out)
460
self.assertFalse(b'added c' in out)
461
self.assertFalse(b'added b' in err)
462
self.assertFalse(b'added c' in err)
463
# If b was excluded it will still be 'added' in status.
464
out, err = self.run_bzr(['added'])
465
self.assertTrue(b'b\n' in out)
466
self.assertTrue(b'c\n' in out)
467
self.assertEqual(b'', err)
469
def test_commit_respects_spec_for_removals(self):
470
"""Commit with a file spec should only commit removals that match"""
471
t = self.make_branch_and_tree('.')
472
self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
473
t.add(['file-a', 'dir-a', 'dir-a/file-b'])
475
t.remove(['file-a', 'dir-a/file-b'])
476
result = self.run_bzr('commit . -m removed-file-b',
477
working_dir='dir-a')[1]
478
self.assertNotContainsRe(result, 'file-a')
479
result = self.run_bzr('status', working_dir='dir-a')[0]
480
self.assertContainsRe(result, b'removed:\n file-a')
482
def test_strict_commit(self):
483
"""Commit with --strict works if everything is known"""
484
ignores._set_user_ignores([])
485
tree = self.make_branch_and_tree('tree')
486
self.build_tree(['tree/a'])
488
# A simple change should just work
489
self.run_bzr('commit --strict -m adding-a', working_dir='tree')
491
def test_strict_commit_no_changes(self):
492
"""commit --strict gives "no changes" if there is nothing to commit"""
493
tree = self.make_branch_and_tree('tree')
494
self.build_tree(['tree/a'])
496
tree.commit('adding a')
498
# With no changes, it should just be 'no changes'
499
# Make sure that commit is failing because there is nothing to do
500
self.run_bzr_error([b'No changes to commit'],
501
'commit --strict -m no-changes',
504
# But --strict doesn't care if you supply --unchanged
505
self.run_bzr('commit --strict --unchanged -m no-changes',
508
def test_strict_commit_unknown(self):
509
"""commit --strict fails if a file is unknown"""
510
tree = self.make_branch_and_tree('tree')
511
self.build_tree(['tree/a'])
513
tree.commit('adding a')
515
# Add one file so there is a change, but forget the other
516
self.build_tree(['tree/b', 'tree/c'])
518
self.run_bzr_error([b'Commit refused because there are unknown files'],
519
'commit --strict -m add-b',
522
# --no-strict overrides --strict
523
self.run_bzr('commit --strict -m add-b --no-strict',
526
def test_fixes_bug_output(self):
527
"""commit --fixes=lp:23452 succeeds without output."""
528
tree = self.make_branch_and_tree('tree')
529
self.build_tree(['tree/hello.txt'])
530
tree.add('hello.txt')
531
output, err = self.run_bzr(
532
'commit -m hello --fixes=lp:23452 tree/hello.txt')
533
self.assertEqual(b'', output)
534
self.assertContainsRe(err, b'Committing to: .*\n'
535
b'added hello\\.txt\n'
536
b'Committed revision 1\\.\n')
538
def test_fixes_bug_unicode(self):
539
"""commit --fixes=lp:unicode succeeds without output."""
540
tree = self.make_branch_and_tree('tree')
541
self.build_tree(['tree/hello.txt'])
542
tree.add('hello.txt')
543
output, err = self.run_bzr(
544
['commit', '-m', 'hello',
545
u'--fixes=generic:\u20ac', 'tree/hello.txt'],
546
encoding='utf-8', retcode=3)
547
self.assertEqual(b'', output)
548
self.assertContainsRe(err,
549
b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
551
def test_no_bugs_no_properties(self):
552
"""If no bugs are fixed, the bugs property is not set.
554
see https://beta.launchpad.net/bzr/+bug/109613
556
tree = self.make_branch_and_tree('tree')
557
self.build_tree(['tree/hello.txt'])
558
tree.add('hello.txt')
559
self.run_bzr('commit -m hello tree/hello.txt')
560
# Get the revision properties, ignoring the branch-nick property, which
561
# we don't care about for this test.
562
last_rev = tree.branch.repository.get_revision(tree.last_revision())
563
properties = dict(last_rev.properties)
564
del properties['branch-nick']
565
self.assertFalse('bugs' in properties)
567
def test_fixes_bug_sets_property(self):
568
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
569
tree = self.make_branch_and_tree('tree')
570
self.build_tree(['tree/hello.txt'])
571
tree.add('hello.txt')
572
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
574
# Get the revision properties, ignoring the branch-nick property, which
575
# we don't care about for this test.
576
last_rev = tree.branch.repository.get_revision(tree.last_revision())
577
properties = dict(last_rev.properties)
578
del properties[u'branch-nick']
580
self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 fixed'},
583
def test_fixes_multiple_bugs_sets_properties(self):
584
"""--fixes can be used more than once to show that bugs are fixed."""
585
tree = self.make_branch_and_tree('tree')
586
self.build_tree(['tree/hello.txt'])
587
tree.add('hello.txt')
588
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
591
# Get the revision properties, ignoring the branch-nick property, which
592
# we don't care about for this test.
593
last_rev = tree.branch.repository.get_revision(tree.last_revision())
594
properties = dict(last_rev.properties)
595
del properties['branch-nick']
598
{u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
599
'https://launchpad.net/bugs/235 fixed'},
602
def test_fixes_bug_with_alternate_trackers(self):
603
"""--fixes can be used on a properly configured branch to mark bug
604
fixes on multiple trackers.
606
tree = self.make_branch_and_tree('tree')
607
tree.branch.get_config().set_user_option(
608
'trac_twisted_url', 'http://twistedmatrix.com/trac')
609
self.build_tree(['tree/hello.txt'])
610
tree.add('hello.txt')
611
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
613
# Get the revision properties, ignoring the branch-nick property, which
614
# we don't care about for this test.
615
last_rev = tree.branch.repository.get_revision(tree.last_revision())
616
properties = dict(last_rev.properties)
617
del properties['branch-nick']
620
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
621
'http://twistedmatrix.com/trac/ticket/235 fixed'},
624
def test_fixes_unknown_bug_prefix(self):
625
tree = self.make_branch_and_tree('tree')
626
self.build_tree(['tree/hello.txt'])
627
tree.add('hello.txt')
629
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
630
'commit -m add-b --fixes=xxx:123',
633
def test_fixes_bug_with_default_tracker(self):
634
"""commit --fixes=234 uses the default bug tracker."""
635
tree = self.make_branch_and_tree('tree')
636
self.build_tree(['tree/hello.txt'])
637
tree.add('hello.txt')
639
["brz: ERROR: No tracker specified for bug 123. Use the form "
640
"'tracker:id' or specify a default bug tracker using the "
641
"`bugtracker` option.\n"
642
"See \"brz help bugs\" for more information on this feature. "
644
'commit -m add-b --fixes=123',
646
tree.branch.get_config_stack().set("bugtracker", "lp")
647
self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
648
last_rev = tree.branch.repository.get_revision(tree.last_revision())
649
self.assertEqual('https://launchpad.net/bugs/234 fixed',
650
last_rev.properties['bugs'])
652
def test_fixes_invalid_bug_number(self):
653
tree = self.make_branch_and_tree('tree')
654
self.build_tree(['tree/hello.txt'])
655
tree.add('hello.txt')
657
["Did not understand bug identifier orange: Must be an integer. "
658
"See \"brz help bugs\" for more information on this feature.\n"
660
'commit -m add-b --fixes=lp:orange',
663
def test_fixes_invalid_argument(self):
664
"""Raise an appropriate error when the fixes argument isn't tag:id."""
665
tree = self.make_branch_and_tree('tree')
666
self.build_tree(['tree/hello.txt'])
667
tree.add('hello.txt')
669
[r"Invalid bug orange:apples:bananas. Must be in the form of "
670
r"'tracker:id'\. See \"brz help bugs\" for more information on "
671
r"this feature.\nCommit refused\."],
672
'commit -m add-b --fixes=orange:apples:bananas',
675
def test_no_author(self):
676
"""If the author is not specified, the author property is not set."""
677
tree = self.make_branch_and_tree('tree')
678
self.build_tree(['tree/hello.txt'])
679
tree.add('hello.txt')
680
self.run_bzr( 'commit -m hello tree/hello.txt')
681
last_rev = tree.branch.repository.get_revision(tree.last_revision())
682
properties = last_rev.properties
683
self.assertFalse('author' in properties)
685
def test_author_sets_property(self):
686
"""commit --author='John Doe <jdoe@example.com>' sets the author
689
tree = self.make_branch_and_tree('tree')
690
self.build_tree(['tree/hello.txt'])
691
tree.add('hello.txt')
692
self.run_bzr(["commit", '-m', 'hello',
693
'--author', u'John D\xf6 <jdoe@example.com>',
695
last_rev = tree.branch.repository.get_revision(tree.last_revision())
696
properties = last_rev.properties
697
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
699
def test_author_no_email(self):
700
"""Author's name without an email address is allowed, too."""
701
tree = self.make_branch_and_tree('tree')
702
self.build_tree(['tree/hello.txt'])
703
tree.add('hello.txt')
704
out, err = self.run_bzr("commit -m hello --author='John Doe' "
706
last_rev = tree.branch.repository.get_revision(tree.last_revision())
707
properties = last_rev.properties
708
self.assertEqual('John Doe', properties['authors'])
710
def test_multiple_authors(self):
711
"""Multiple authors can be specyfied, and all are stored."""
712
tree = self.make_branch_and_tree('tree')
713
self.build_tree(['tree/hello.txt'])
714
tree.add('hello.txt')
715
out, err = self.run_bzr("commit -m hello --author='John Doe' "
716
"--author='Jane Rey' tree/hello.txt")
717
last_rev = tree.branch.repository.get_revision(tree.last_revision())
718
properties = last_rev.properties
719
self.assertEqual('John Doe\nJane Rey', properties['authors'])
721
def test_commit_time(self):
722
tree = self.make_branch_and_tree('tree')
723
self.build_tree(['tree/hello.txt'])
724
tree.add('hello.txt')
725
out, err = self.run_bzr("commit -m hello "
726
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
727
last_rev = tree.branch.repository.get_revision(tree.last_revision())
729
'Sat 2009-10-10 08:00:00 +0100',
730
osutils.format_date(last_rev.timestamp, last_rev.timezone))
732
def test_commit_time_bad_time(self):
733
tree = self.make_branch_and_tree('tree')
734
self.build_tree(['tree/hello.txt'])
735
tree.add('hello.txt')
736
out, err = self.run_bzr("commit -m hello "
737
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
738
self.assertStartsWith(
739
err, "brz: ERROR: Could not parse --commit-time:")
741
def test_commit_time_missing_tz(self):
742
tree = self.make_branch_and_tree('tree')
743
self.build_tree(['tree/hello.txt'])
744
tree.add('hello.txt')
745
out, err = self.run_bzr("commit -m hello "
746
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
747
self.assertStartsWith(
748
err, "brz: ERROR: Could not parse --commit-time:")
749
# Test that it is actually checking and does not simply crash with
750
# some other exception
751
self.assertContainsString(err, "missing a timezone offset")
753
def test_partial_commit_with_renames_in_tree(self):
754
# this test illustrates bug #140419
755
t = self.make_branch_and_tree('.')
756
self.build_tree(['dir/', 'dir/a', 'test'])
757
t.add(['dir/', 'dir/a', 'test'])
758
t.commit('initial commit')
759
# important part: file dir/a should change parent
760
# and should appear before old parent
761
# then during partial commit we have error
762
# parent_id {dir-XXX} not in inventory
763
t.rename_one('dir/a', 'a')
764
self.build_tree_contents([('test', b'changes in test')])
766
out, err = self.run_bzr('commit test -m "partial commit"')
767
self.assertEqual(b'', out)
768
self.assertContainsRe(err, br'modified test\nCommitted revision 2.')
770
def test_commit_readonly_checkout(self):
771
# https://bugs.launchpad.net/bzr/+bug/129701
772
# "UnlockableTransport error trying to commit in checkout of readonly
774
self.make_branch('master')
775
master = ControlDir.open_from_transport(
776
self.get_readonly_transport('master')).open_branch()
777
master.create_checkout('checkout')
778
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
780
self.assertContainsRe(err,
781
br'^brz: ERROR: Cannot lock.*readonly transport')
783
def setup_editor(self):
784
# Test that commit template hooks work
785
if sys.platform == "win32":
786
with open('fed.bat', 'w') as f:
787
f.write('@rem dummy fed')
788
self.overrideEnv('BRZ_EDITOR', "fed.bat")
790
with open('fed.sh', 'wb') as f:
791
f.write(b'#!/bin/sh\n')
792
os.chmod('fed.sh', 0o755)
793
self.overrideEnv('BRZ_EDITOR', "./fed.sh")
795
def setup_commit_with_template(self):
797
msgeditor.hooks.install_named_hook("commit_message_template",
798
lambda commit_obj, msg: "save me some typing\n", None)
799
tree = self.make_branch_and_tree('tree')
800
self.build_tree(['tree/hello.txt'])
801
tree.add('hello.txt')
804
def test_edit_empty_message(self):
805
tree = self.make_branch_and_tree('tree')
807
self.build_tree(['tree/hello.txt'])
808
tree.add('hello.txt')
809
out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
811
self.assertContainsRe(err,
812
b"brz: ERROR: Empty commit message specified")
814
def test_commit_hook_template_accepted(self):
815
tree = self.setup_commit_with_template()
816
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
817
last_rev = tree.branch.repository.get_revision(tree.last_revision())
818
self.assertEqual('save me some typing\n', last_rev.message)
820
def test_commit_hook_template_rejected(self):
821
tree = self.setup_commit_with_template()
822
expected = tree.last_revision()
823
out, err = self.run_bzr_error([b"Empty commit message specified."
824
b" Please specify a commit message with either"
825
b" --message or --file or leave a blank message"
826
b" with --message \"\"."],
827
"commit tree/hello.txt", stdin="n\n")
828
self.assertEqual(expected, tree.last_revision())
830
def test_set_commit_message(self):
831
msgeditor.hooks.install_named_hook("set_commit_message",
832
lambda commit_obj, msg: "save me some typing\n", None)
833
tree = self.make_branch_and_tree('tree')
834
self.build_tree(['tree/hello.txt'])
835
tree.add('hello.txt')
836
out, err = self.run_bzr("commit tree/hello.txt")
837
last_rev = tree.branch.repository.get_revision(tree.last_revision())
838
self.assertEqual('save me some typing\n', last_rev.message)
840
def test_commit_without_username(self):
841
"""Ensure commit error if username is not set.
843
self.run_bzr(['init', 'foo'])
844
with open('foo/foo.txt', 'w') as f:
846
self.run_bzr(['add'], working_dir='foo')
847
self.overrideEnv('EMAIL', None)
848
self.overrideEnv('BRZ_EMAIL', None)
849
# Also, make sure that it's not inferred from mailname.
850
self.overrideAttr(config, '_auto_user_id',
851
lambda: (None, None))
853
['Unable to determine your name'],
854
['commit', '-m', 'initial'], working_dir='foo')
856
def test_commit_recursive_checkout(self):
857
"""Ensure that a commit to a recursive checkout fails cleanly.
859
self.run_bzr(['init', 'test_branch'])
860
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
861
self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
862
with open('test_checkout/foo.txt', 'w') as f:
864
self.run_bzr(['add'], working_dir='test_checkout')
865
out, err = self.run_bzr_error(
866
['Branch.*test_checkout.*appears to be bound to itself'],
867
['commit', '-m', 'addedfoo'], working_dir='test_checkout')
869
def test_mv_dirs_non_ascii(self):
870
"""Move directory with non-ascii name and containing files.
872
Regression test for bug 185211.
874
tree = self.make_branch_and_tree('.')
875
self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
877
tree.add([u'abc\xa7/', u'abc\xa7/foo'])
878
tree.commit('checkin')
880
tree.rename_one(u'abc\xa7', 'abc')
882
self.run_bzr('ci -m "non-ascii mv"')
885
class TestSmartServerCommit(TestCaseWithTransport):
887
def test_commit_to_lightweight(self):
888
self.setup_smart_server_with_call_log()
889
t = self.make_branch_and_tree('from')
890
for count in range(9):
891
t.commit(message='commit %d' % count)
892
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
894
self.reset_smart_call_log()
895
self.build_tree(['target/afile'])
896
self.run_bzr(['add', 'target/afile'])
897
out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
898
# This figure represent the amount of work to perform this use case. It
899
# is entirely ok to reduce this number if a test fails due to rpc_count
900
# being too low. If rpc_count increases, more network roundtrips have
901
# become necessary for this use case. Please do not adjust this number
902
# upwards without agreement from bzr's network support maintainers.
903
self.assertLength(211, self.hpss_calls)
904
self.assertLength(2, self.hpss_connections)
905
self.expectFailure("commit still uses VFS calls",
906
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)