107
109
'modified hello\.txt\n'
108
110
'Committed revision 2\.\n$')
112
def test_unicode_commit_message_is_filename(self):
113
"""Unicode commit message same as a filename (Bug #563646).
115
file_name = u'\N{euro sign}'
116
self.run_bzr(['init'])
117
open(file_name, 'w').write('hello world')
118
self.run_bzr(['add'])
119
out, err = self.run_bzr(['commit', '-m', file_name])
120
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
121
te = osutils.get_terminal_encoding()
122
self.assertContainsRe(err.decode(te),
123
u'The commit message is a file name:',
126
# Run same test with a filename that causes encode
127
# error for the terminal encoding. We do this
128
# by forcing terminal encoding of ascii for
129
# osutils.get_terminal_encoding which is used
130
# by ui.text.show_warning
131
default_get_terminal_enc = osutils.get_terminal_encoding
133
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
134
file_name = u'foo\u1234'
135
open(file_name, 'w').write('hello world')
136
self.run_bzr(['add'])
137
out, err = self.run_bzr(['commit', '-m', file_name])
138
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
139
te = osutils.get_terminal_encoding()
140
self.assertContainsRe(err.decode(te, 'replace'),
141
u'The commit message is a file name:',
144
osutils.get_terminal_encoding = default_get_terminal_enc
110
146
def test_warn_about_forgotten_commit_message(self):
111
147
"""Test that the lack of -m parameter is caught"""
112
148
wt = self.make_branch_and_tree('.')
689
725
os.chmod('fed.sh', 0755)
690
726
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
728
def setup_commit_with_template(self):
691
730
msgeditor.hooks.install_named_hook("commit_message_template",
692
731
lambda commit_obj, msg: "save me some typing\n", None)
693
732
tree = self.make_branch_and_tree('tree')
694
733
self.build_tree(['tree/hello.txt'])
695
734
tree.add('hello.txt')
696
out, err = self.run_bzr("commit tree/hello.txt")
737
def test_commit_hook_template_accepted(self):
738
tree = self.setup_commit_with_template()
739
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
697
740
last_rev = tree.branch.repository.get_revision(tree.last_revision())
698
741
self.assertEqual('save me some typing\n', last_rev.message)
743
def test_commit_hook_template_rejected(self):
744
tree = self.setup_commit_with_template()
745
expected = tree.last_revision()
746
out, err = self.run_bzr_error(["empty commit message"],
747
"commit tree/hello.txt", stdin="n\n")
748
self.assertEqual(expected, tree.last_revision())
750
def test_commit_without_username(self):
751
"""Ensure commit error if username is not set.
753
self.run_bzr(['init', 'foo'])
755
open('foo.txt', 'w').write('hello')
756
self.run_bzr(['add'])
757
osutils.set_or_unset_env('EMAIL', None)
758
osutils.set_or_unset_env('BZR_EMAIL', None)
759
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
760
self.assertContainsRe(err, 'Unable to determine your name')
762
def test_commit_recursive_checkout(self):
763
"""Ensure that a commit to a recursive checkout fails cleanly.
765
self.run_bzr(['init', 'test_branch'])
766
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
767
os.chdir('test_checkout')
768
self.run_bzr(['bind', '.']) # bind to self
769
open('foo.txt', 'w').write('hello')
770
self.run_bzr(['add'])
771
out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
772
self.assertEqual(out, '')
773
self.assertContainsRe(err,
774
'Branch.*test_checkout.*appears to be bound to itself')