34
33
from bzrlib.bzrdir import BzrDir
35
34
from bzrlib.tests import (
39
UnicodeFilenameFeature,
41
38
from bzrlib.tests import TestCaseWithTransport
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
44
42
class TestCommit(TestCaseWithTransport):
138
136
def test_unicode_commit_message_is_filename(self):
139
137
"""Unicode commit message same as a filename (Bug #563646).
141
self.requireFeature(UnicodeFilenameFeature)
139
self.requireFeature(features.UnicodeFilenameFeature)
142
140
file_name = u'\N{euro sign}'
143
141
self.run_bzr(['init'])
144
142
open(file_name, 'w').write('hello world')
171
169
osutils.get_terminal_encoding = default_get_terminal_enc
171
def test_non_ascii_file_unversioned_utf8(self):
172
self.requireFeature(features.UnicodeFilenameFeature)
173
tree = self.make_branch_and_tree(".")
174
self.build_tree(["f"])
176
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
177
encoding="utf-8", retcode=3)
178
self.assertContainsRe(err, "(?m)not versioned: \"\xc2\xa7\"$")
180
def test_non_ascii_file_unversioned_iso_8859_5(self):
181
self.requireFeature(features.UnicodeFilenameFeature)
182
tree = self.make_branch_and_tree(".")
183
self.build_tree(["f"])
185
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
186
encoding="iso-8859-5", retcode=3)
187
self.expectFailure("Error messages are always written as UTF-8",
188
self.assertNotContainsString, err, "\xc2\xa7")
189
self.assertContainsRe(err, "(?m)not versioned: \"\xfd\"$")
173
191
def test_warn_about_forgotten_commit_message(self):
174
192
"""Test that the lack of -m parameter is caught"""
175
193
wt = self.make_branch_and_tree('.')
332
350
tree = self.make_branch_and_tree('.')
333
351
self.build_tree_contents([('foo.c', 'int main() {}')])
334
352
tree.add('foo.c')
335
self.run_bzr('commit -m ""', retcode=3)
353
self.run_bzr('commit -m ""')
337
355
def test_other_branch_commit(self):
338
356
# this branch is to ensure consistent behaviour, whether we're run
599
617
'commit -m add-b --fixes=xxx:123',
600
618
working_dir='tree')
620
def test_fixes_bug_with_default_tracker(self):
621
"""commit --fixes=234 uses the default bug tracker."""
622
tree = self.make_branch_and_tree('tree')
623
self.build_tree(['tree/hello.txt'])
624
tree.add('hello.txt')
626
["bzr: ERROR: No tracker specified for bug 123. Use the form "
627
"'tracker:id' or specify a default bug tracker using the "
628
"`bugtracker` option.\n"
629
"See \"bzr help bugs\" for more information on this feature. "
631
'commit -m add-b --fixes=123',
633
tree.branch.get_config().set_user_option("bugtracker", "lp")
634
self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
635
last_rev = tree.branch.repository.get_revision(tree.last_revision())
636
self.assertEqual('https://launchpad.net/bugs/234 fixed',
637
last_rev.properties['bugs'])
602
639
def test_fixes_invalid_bug_number(self):
603
640
tree = self.make_branch_and_tree('tree')
604
641
self.build_tree(['tree/hello.txt'])
616
653
self.build_tree(['tree/hello.txt'])
617
654
tree.add('hello.txt')
618
655
self.run_bzr_error(
619
[r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
620
r"See \"bzr help bugs\" for more information on this feature.\n"
621
r"Commit refused\."],
622
'commit -m add-b --fixes=orange',
656
[r"Invalid bug orange:apples:bananas. Must be in the form of "
657
r"'tracker:id'\. See \"bzr help bugs\" for more information on "
658
r"this feature.\nCommit refused\."],
659
'commit -m add-b --fixes=orange:apples:bananas',
623
660
working_dir='tree')
625
662
def test_no_author(self):
688
725
self.assertStartsWith(
689
726
err, "bzr: ERROR: Could not parse --commit-time:")
728
def test_commit_time_missing_tz(self):
729
tree = self.make_branch_and_tree('tree')
730
self.build_tree(['tree/hello.txt'])
731
tree.add('hello.txt')
732
out, err = self.run_bzr("commit -m hello "
733
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
734
self.assertStartsWith(
735
err, "bzr: ERROR: Could not parse --commit-time:")
736
# Test that it is actually checking and does not simply crash with
737
# some other exception
738
self.assertContainsString(err, "missing a timezone offset")
691
740
def test_partial_commit_with_renames_in_tree(self):
692
741
# this test illustrates bug #140419
693
742
t = self.make_branch_and_tree('.')
741
790
tree.add('hello.txt')
793
def test_edit_empty_message(self):
794
tree = self.make_branch_and_tree('tree')
796
self.build_tree(['tree/hello.txt'])
797
tree.add('hello.txt')
798
out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
800
self.assertContainsRe(err,
801
"bzr: ERROR: Empty commit message specified")
744
803
def test_commit_hook_template_accepted(self):
745
804
tree = self.setup_commit_with_template()
746
805
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
750
809
def test_commit_hook_template_rejected(self):
751
810
tree = self.setup_commit_with_template()
752
811
expected = tree.last_revision()
753
out, err = self.run_bzr_error(["empty commit message"],
812
out, err = self.run_bzr_error(["Empty commit message specified."
813
" Please specify a commit message with either"
814
" --message or --file or leave a blank message"
815
" with --message \"\"."],
754
816
"commit tree/hello.txt", stdin="n\n")
755
817
self.assertEqual(expected, tree.last_revision())
792
854
self.assertEqual(out, '')
793
855
self.assertContainsRe(err,
794
856
'Branch.*test_checkout.*appears to be bound to itself')
858
def test_mv_dirs_non_ascii(self):
859
"""Move directory with non-ascii name and containing files.
861
Regression test for bug 185211.
863
tree = self.make_branch_and_tree('.')
864
self.build_tree([u'abc\xc3/', u'abc\xc3/foo'])
866
tree.add([u'abc\xc3/', u'abc\xc3/foo'])
867
tree.commit('checkin')
869
tree.rename_one(u'abc\xc3','abc')
871
self.run_bzr('ci -m "non-ascii mv"')
874
class TestSmartServerCommit(TestCaseWithTransport):
876
def test_commit_to_lightweight(self):
877
self.setup_smart_server_with_call_log()
878
t = self.make_branch_and_tree('from')
879
for count in range(9):
880
t.commit(message='commit %d' % count)
881
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
883
self.reset_smart_call_log()
884
self.build_tree(['target/afile'])
885
self.run_bzr(['add', 'target/afile'])
886
out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
887
# This figure represent the amount of work to perform this use case. It
888
# is entirely ok to reduce this number if a test fails due to rpc_count
889
# being too low. If rpc_count increases, more network roundtrips have
890
# become necessary for this use case. Please do not adjust this number
891
# upwards without agreement from bzr's network support maintainers.
892
self.assertLength(211, self.hpss_calls)
893
self.expectFailure("commit still uses VFS calls",
894
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)