70
58
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
71
59
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
61
def test_commit_with_path(self):
88
62
"""Commit tree with path of root specified"""
89
63
a_tree = self.make_branch_and_tree('a')
169
143
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\"$")
191
145
def test_warn_about_forgotten_commit_message(self):
192
146
"""Test that the lack of -m parameter is caught"""
193
147
wt = self.make_branch_and_tree('.')
349
304
tree = self.make_branch_and_tree('.')
350
305
self.build_tree_contents([('foo.c', 'int main() {}')])
351
306
tree.add('foo.c')
352
self.run_bzr('commit -m ""')
307
self.run_bzr('commit -m ""', retcode=3)
309
def test_unsupported_encoding_commit_message(self):
310
if sys.platform == 'win32':
311
raise tests.TestNotApplicable('Win32 parses arguments directly'
312
' as Unicode, so we can\'t pass invalid non-ascii')
313
tree = self.make_branch_and_tree('.')
314
self.build_tree_contents([('foo.c', 'int main() {}')])
316
# LANG env variable has no effect on Windows
317
# but some characters anyway cannot be represented
318
# in default user encoding
319
char = probe_bad_non_ascii(osutils.get_user_encoding())
321
raise TestSkipped('Cannot find suitable non-ascii character'
322
'for user_encoding (%s)' % osutils.get_user_encoding())
323
out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
325
env_changes={'LANG': 'C'})
326
self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
327
'unsupported by the current encoding.')
354
329
def test_other_branch_commit(self):
355
330
# this branch is to ensure consistent behaviour, whether we're run
615
591
'commit -m add-b --fixes=xxx:123',
616
592
working_dir='tree')
618
def test_fixes_bug_with_default_tracker(self):
619
"""commit --fixes=234 uses the default bug tracker."""
620
tree = self.make_branch_and_tree('tree')
621
self.build_tree(['tree/hello.txt'])
622
tree.add('hello.txt')
624
["bzr: ERROR: No tracker specified for bug 123. Use the form "
625
"'tracker:id' or specify a default bug tracker using the "
626
"`bugtracker` option.\n"
627
"See \"bzr help bugs\" for more information on this feature. "
629
'commit -m add-b --fixes=123',
631
tree.branch.get_config_stack().set("bugtracker", "lp")
632
self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
633
last_rev = tree.branch.repository.get_revision(tree.last_revision())
634
self.assertEqual('https://launchpad.net/bugs/234 fixed',
635
last_rev.properties['bugs'])
637
594
def test_fixes_invalid_bug_number(self):
638
595
tree = self.make_branch_and_tree('tree')
639
596
self.build_tree(['tree/hello.txt'])
749
694
self.build_tree_contents([('test', 'changes in test')])
751
696
out, err = self.run_bzr('commit test -m "partial commit"')
752
self.assertEqual('', out)
697
self.assertEquals('', out)
753
698
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
755
700
def test_commit_readonly_checkout(self):
756
# https://bugs.launchpad.net/bzr/+bug/129701
701
# https://bugs.edge.launchpad.net/bzr/+bug/129701
757
702
# "UnlockableTransport error trying to commit in checkout of readonly
759
704
self.make_branch('master')
760
master = ControlDir.open_from_transport(
705
master = BzrDir.open_from_transport(
761
706
self.get_readonly_transport('master')).open_branch()
762
707
master.create_checkout('checkout')
763
708
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
807
742
def test_commit_hook_template_rejected(self):
808
743
tree = self.setup_commit_with_template()
809
744
expected = tree.last_revision()
810
out, err = self.run_bzr_error(["Empty commit message specified."
811
" Please specify a commit message with either"
812
" --message or --file or leave a blank message"
813
" with --message \"\"."],
745
out, err = self.run_bzr_error(["empty commit message"],
814
746
"commit tree/hello.txt", stdin="n\n")
815
747
self.assertEqual(expected, tree.last_revision())
817
def test_set_commit_message(self):
818
msgeditor.hooks.install_named_hook("set_commit_message",
819
lambda commit_obj, msg: "save me some typing\n", None)
820
tree = self.make_branch_and_tree('tree')
821
self.build_tree(['tree/hello.txt'])
822
tree.add('hello.txt')
823
out, err = self.run_bzr("commit tree/hello.txt")
824
last_rev = tree.branch.repository.get_revision(tree.last_revision())
825
self.assertEqual('save me some typing\n', last_rev.message)
827
749
def test_commit_without_username(self):
828
750
"""Ensure commit error if username is not set.
830
752
self.run_bzr(['init', 'foo'])
831
with open('foo/foo.txt', 'w') as f:
833
self.run_bzr(['add'], working_dir='foo')
834
self.overrideEnv('EMAIL', None)
835
self.overrideEnv('BZR_EMAIL', None)
836
# Also, make sure that it's not inferred from mailname.
837
self.overrideAttr(config, '_auto_user_id',
838
lambda: (None, None))
840
['Unable to determine your name'],
841
['commit', '-m', 'initial'], working_dir='foo')
843
def test_commit_recursive_checkout(self):
844
"""Ensure that a commit to a recursive checkout fails cleanly.
846
self.run_bzr(['init', 'test_branch'])
847
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
848
self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
849
with open('test_checkout/foo.txt', 'w') as f:
851
self.run_bzr(['add'], working_dir='test_checkout')
852
out, err = self.run_bzr_error(
853
['Branch.*test_checkout.*appears to be bound to itself'],
854
['commit', '-m', 'addedfoo'], working_dir='test_checkout')
856
def test_mv_dirs_non_ascii(self):
857
"""Move directory with non-ascii name and containing files.
859
Regression test for bug 185211.
861
tree = self.make_branch_and_tree('.')
862
self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
864
tree.add([u'abc\xa7/', u'abc\xa7/foo'])
865
tree.commit('checkin')
867
tree.rename_one(u'abc\xa7','abc')
869
self.run_bzr('ci -m "non-ascii mv"')
872
class TestSmartServerCommit(TestCaseWithTransport):
874
def test_commit_to_lightweight(self):
875
self.setup_smart_server_with_call_log()
876
t = self.make_branch_and_tree('from')
877
for count in range(9):
878
t.commit(message='commit %d' % count)
879
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
881
self.reset_smart_call_log()
882
self.build_tree(['target/afile'])
883
self.run_bzr(['add', 'target/afile'])
884
out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
885
# This figure represent the amount of work to perform this use case. It
886
# is entirely ok to reduce this number if a test fails due to rpc_count
887
# being too low. If rpc_count increases, more network roundtrips have
888
# become necessary for this use case. Please do not adjust this number
889
# upwards without agreement from bzr's network support maintainers.
890
self.assertLength(211, self.hpss_calls)
891
self.assertLength(2, self.hpss_connections)
892
self.expectFailure("commit still uses VFS calls",
893
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
754
open('foo.txt', 'w').write('hello')
755
self.run_bzr(['add'])
756
osutils.set_or_unset_env('EMAIL', None)
757
osutils.set_or_unset_env('BZR_EMAIL', None)
758
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
759
self.assertContainsRe(err, 'Unable to determine your name')