107
110
'modified hello\.txt\n'
108
111
'Committed revision 2\.\n$')
113
def test_unicode_commit_message_is_filename(self):
114
"""Unicode commit message same as a filename (Bug #563646).
116
self.requireFeature(UnicodeFilenameFeature)
117
file_name = u'\N{euro sign}'
118
self.run_bzr(['init'])
119
open(file_name, 'w').write('hello world')
120
self.run_bzr(['add'])
121
out, err = self.run_bzr(['commit', '-m', file_name])
122
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
123
te = osutils.get_terminal_encoding()
124
self.assertContainsRe(err.decode(te),
125
u'The commit message is a file name:',
128
# Run same test with a filename that causes encode
129
# error for the terminal encoding. We do this
130
# by forcing terminal encoding of ascii for
131
# osutils.get_terminal_encoding which is used
132
# by ui.text.show_warning
133
default_get_terminal_enc = osutils.get_terminal_encoding
135
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
136
file_name = u'foo\u1234'
137
open(file_name, 'w').write('hello world')
138
self.run_bzr(['add'])
139
out, err = self.run_bzr(['commit', '-m', file_name])
140
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
141
te = osutils.get_terminal_encoding()
142
self.assertContainsRe(err.decode(te, 'replace'),
143
u'The commit message is a file name:',
146
osutils.get_terminal_encoding = default_get_terminal_enc
110
148
def test_warn_about_forgotten_commit_message(self):
111
149
"""Test that the lack of -m parameter is caught"""
112
150
wt = self.make_branch_and_tree('.')
343
381
trunk = self.make_branch_and_tree('trunk')
345
383
u1 = trunk.branch.create_checkout('u1')
346
self.build_tree_contents([('u1/hosts', 'initial contents')])
384
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
348
386
self.run_bzr('commit -m add-hosts u1')
350
388
u2 = trunk.branch.create_checkout('u2')
351
self.build_tree_contents([('u2/hosts', 'altered in u2')])
389
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
352
390
self.run_bzr('commit -m checkin-from-u2 u2')
354
392
# make an offline commits
355
self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
393
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
356
394
self.run_bzr('commit -m checkin-offline --local u1')
358
396
# now try to pull in online work from u2, and then commit our offline
359
397
# work as a merge
360
398
# retcode 1 as we expect a text conflict
361
399
self.run_bzr('update u1', retcode=1)
400
self.assertFileEqual('''\
402
first offline change in u1
362
409
self.run_bzr('resolved u1/hosts')
363
410
# add a text change here to represent resolving the merge conflicts in
364
411
# favour of a new version of the file not identical to either the u1
666
713
self.assertContainsRe(err,
667
714
r'^bzr: ERROR: Cannot lock.*readonly transport')
669
def test_commit_hook_template(self):
716
def setup_editor(self):
670
717
# Test that commit template hooks work
671
def restoreDefaults():
672
msgeditor.hooks['commit_message_template'] = []
673
osutils.set_or_unset_env('BZR_EDITOR', default_editor)
674
718
if sys.platform == "win32":
675
719
f = file('fed.bat', 'w')
676
720
f.write('@rem dummy fed')
678
default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
722
osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
680
724
f = file('fed.sh', 'wb')
681
725
f.write('#!/bin/sh\n')
683
727
os.chmod('fed.sh', 0755)
684
default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
685
self.addCleanup(restoreDefaults)
728
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
730
def setup_commit_with_template(self):
686
732
msgeditor.hooks.install_named_hook("commit_message_template",
687
733
lambda commit_obj, msg: "save me some typing\n", None)
688
734
tree = self.make_branch_and_tree('tree')
689
735
self.build_tree(['tree/hello.txt'])
690
736
tree.add('hello.txt')
691
out, err = self.run_bzr("commit tree/hello.txt")
739
def test_commit_hook_template_accepted(self):
740
tree = self.setup_commit_with_template()
741
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
692
742
last_rev = tree.branch.repository.get_revision(tree.last_revision())
693
743
self.assertEqual('save me some typing\n', last_rev.message)
745
def test_commit_hook_template_rejected(self):
746
tree = self.setup_commit_with_template()
747
expected = tree.last_revision()
748
out, err = self.run_bzr_error(["empty commit message"],
749
"commit tree/hello.txt", stdin="n\n")
750
self.assertEqual(expected, tree.last_revision())
752
def test_commit_without_username(self):
753
"""Ensure commit error if username is not set.
755
self.run_bzr(['init', 'foo'])
757
open('foo.txt', 'w').write('hello')
758
self.run_bzr(['add'])
759
osutils.set_or_unset_env('EMAIL', None)
760
osutils.set_or_unset_env('BZR_EMAIL', None)
761
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
762
self.assertContainsRe(err, 'Unable to determine your name')
764
def test_commit_recursive_checkout(self):
765
"""Ensure that a commit to a recursive checkout fails cleanly.
767
self.run_bzr(['init', 'test_branch'])
768
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
769
os.chdir('test_checkout')
770
self.run_bzr(['bind', '.']) # bind to self
771
open('foo.txt', 'w').write('hello')
772
self.run_bzr(['add'])
773
out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
774
self.assertEqual(out, '')
775
self.assertContainsRe(err,
776
'Branch.*test_checkout.*appears to be bound to itself')