13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for the commit CLI of bzr."""
43
43
self.build_tree(['hello.txt'])
44
44
out,err = self.run_bzr('commit -m empty', retcode=3)
45
45
self.assertEqual('', out)
46
self.assertContainsRe(err, 'bzr: ERROR: no changes to commit\.'
47
' use --unchanged to commit anyhow\n')
46
self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
47
' Use --unchanged to commit anyhow.\n')
49
49
def test_commit_success(self):
50
50
"""Successful commit should not leave behind a bzr-commit-* file"""
124
124
wt.rename_one('hello.txt', 'subdir/hello.txt')
125
125
out, err = self.run_bzr('commit -m renamed')
126
126
self.assertEqual('', out)
127
self.assertContainsRe(err, '^Committing to: .*\n'
129
'renamed hello\.txt => subdir/hello\.txt\n'
130
'Committed revision 2\.\n$')
127
self.assertEqual(set([
128
'Committing to: %s/' % osutils.getcwd(),
130
'renamed hello.txt => subdir/hello.txt',
131
'Committed revision 2.',
133
]), set(err.split('\n')))
132
135
def test_verbose_commit_with_unknown(self):
133
136
"""Unknown files should not be listed by default in verbose output"""
221
224
out,err = self.run_bzr('commit -m added')
222
225
self.assertEqual('', out)
223
expected = '%s/' % (osutils.getcwd(), )
224
self.assertEqualDiff(
225
'Committing to: %s\n'
226
'modified filetomodify\n'
229
'renamed dirtorename => renameddir\n'
230
'renamed filetorename => renamedfile\n'
231
'renamed dirtoreparent => renameddir/reparenteddir\n'
232
'renamed filetoreparent => renameddir/reparentedfile\n'
233
'deleted dirtoremove\n'
234
'deleted filetoremove\n'
235
'Committed revision 2.\n' % (expected, ),
226
self.assertEqual(set([
227
'Committing to: %s/' % osutils.getcwd(),
228
'modified filetomodify',
231
'renamed dirtorename => renameddir',
232
'renamed filetorename => renamedfile',
233
'renamed dirtoreparent => renameddir/reparenteddir',
234
'renamed filetoreparent => renameddir/reparentedfile',
235
'deleted dirtoremove',
236
'deleted filetoremove',
237
'Committed revision 2.',
239
]), set(err.split('\n')))
238
241
def test_empty_commit_message(self):
239
242
tree = self.make_branch_and_tree('.')
248
251
# LANG env variable has no effect on Windows
249
252
# but some characters anyway cannot be represented
250
253
# in default user encoding
251
char = probe_bad_non_ascii(bzrlib.user_encoding)
254
char = probe_bad_non_ascii(osutils.get_user_encoding())
253
256
raise TestSkipped('Cannot find suitable non-ascii character'
254
'for user_encoding (%s)' % bzrlib.user_encoding)
257
'for user_encoding (%s)' % osutils.get_user_encoding())
255
258
out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
257
260
env_changes={'LANG': 'C'})
302
305
def test_commit_a_text_merge_in_a_checkout(self):
303
306
# checkouts perform multiple actions in a transaction across bond
304
307
# branches and their master, and have been observed to fail in the
305
# past. This is a user story reported to fail in bug #43959 where
308
# past. This is a user story reported to fail in bug #43959 where
306
309
# a merge done in a checkout (using the update command) failed to
307
310
# commit correctly.
308
311
trunk = self.make_branch_and_tree('trunk')
331
334
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
332
335
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
337
def test_commit_exclude_excludes_modified_files(self):
338
"""Commit -x foo should ignore changes to foo."""
339
tree = self.make_branch_and_tree('.')
340
self.build_tree(['a', 'b', 'c'])
341
tree.smart_add(['.'])
342
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
343
self.assertFalse('added b' in out)
344
self.assertFalse('added b' in err)
345
# If b was excluded it will still be 'added' in status.
346
out, err = self.run_bzr(['added'])
347
self.assertEqual('b\n', out)
348
self.assertEqual('', err)
350
def test_commit_exclude_twice_uses_both_rules(self):
351
"""Commit -x foo -x bar should ignore changes to foo and bar."""
352
tree = self.make_branch_and_tree('.')
353
self.build_tree(['a', 'b', 'c'])
354
tree.smart_add(['.'])
355
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
356
self.assertFalse('added b' in out)
357
self.assertFalse('added c' in out)
358
self.assertFalse('added b' in err)
359
self.assertFalse('added c' in err)
360
# If b was excluded it will still be 'added' in status.
361
out, err = self.run_bzr(['added'])
362
self.assertTrue('b\n' in out)
363
self.assertTrue('c\n' in out)
364
self.assertEqual('', err)
334
366
def test_commit_respects_spec_for_removals(self):
335
367
"""Commit with a file spec should only commit removals that match"""
336
368
t = self.make_branch_and_tree('.')
364
396
# With no changes, it should just be 'no changes'
365
397
# Make sure that commit is failing because there is nothing to do
366
self.run_bzr_error(['no changes to commit'],
398
self.run_bzr_error(['No changes to commit'],
367
399
'commit --strict -m no-changes',
368
400
working_dir='tree')
488
520
self.build_tree(['tree/hello.txt'])
489
521
tree.add('hello.txt')
490
522
self.run_bzr_error(
491
["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
523
["Did not understand bug identifier orange: Must be an integer. "
524
"See \"bzr help bugs\" for more information on this feature.\n"
492
526
'commit -m add-b --fixes=lp:orange',
493
527
working_dir='tree')
498
532
self.build_tree(['tree/hello.txt'])
499
533
tree.add('hello.txt')
500
534
self.run_bzr_error(
501
[r"Invalid bug orange. Must be in the form of 'tag:id'\. "
535
[r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
536
r"See \"bzr help bugs\" for more information on this feature.\n"
502
537
r"Commit refused\."],
503
538
'commit -m add-b --fixes=orange',
504
539
working_dir='tree')
525
560
"tree/hello.txt"])
526
561
last_rev = tree.branch.repository.get_revision(tree.last_revision())
527
562
properties = last_rev.properties
528
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['author'])
563
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
530
565
def test_author_no_email(self):
531
566
"""Author's name without an email address is allowed, too."""
536
571
"tree/hello.txt")
537
572
last_rev = tree.branch.repository.get_revision(tree.last_revision())
538
573
properties = last_rev.properties
539
self.assertEqual('John Doe', properties['author'])
574
self.assertEqual('John Doe', properties['authors'])
576
def test_multiple_authors(self):
577
"""Multiple authors can be specyfied, and all are stored."""
578
tree = self.make_branch_and_tree('tree')
579
self.build_tree(['tree/hello.txt'])
580
tree.add('hello.txt')
581
out, err = self.run_bzr("commit -m hello --author='John Doe' "
582
"--author='Jane Rey' tree/hello.txt")
583
last_rev = tree.branch.repository.get_revision(tree.last_revision())
584
properties = last_rev.properties
585
self.assertEqual('John Doe\nJane Rey', properties['authors'])
541
587
def test_partial_commit_with_renames_in_tree(self):
542
588
# this test illustrates bug #140419
568
614
self.assertContainsRe(err,
569
615
r'^bzr: ERROR: Cannot lock.*readonly transport')
617
def test_commit_hook_template(self):
618
# Test that commit template hooks work
619
def restoreDefaults():
620
msgeditor.hooks['commit_message_template'] = []
621
osutils.set_or_unset_env('BZR_EDITOR', default_editor)
622
if sys.platform == "win32":
623
f = file('fed.bat', 'w')
624
f.write('@rem dummy fed')
626
default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
628
f = file('fed.sh', 'wb')
629
f.write('#!/bin/sh\n')
631
os.chmod('fed.sh', 0755)
632
default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
633
self.addCleanup(restoreDefaults)
634
msgeditor.hooks.install_named_hook("commit_message_template",
635
lambda commit_obj, msg: "save me some typing\n", None)
636
tree = self.make_branch_and_tree('tree')
637
self.build_tree(['tree/hello.txt'])
638
tree.add('hello.txt')
639
out, err = self.run_bzr("commit tree/hello.txt")
640
last_rev = tree.branch.repository.get_revision(tree.last_revision())
641
self.assertEqual('save me some typing\n', last_rev.message)