58
58
brz: ERROR: No changes to commit.\
59
59
Please 'brz add' the files you want to commit,\
60
60
or use --unchanged to force an empty commit.
61
""", flags=doctest.ELLIPSIS | doctest.REPORT_UDIFF))
61
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
63
63
def test_commit_success(self):
64
64
"""Successful commit should not leave behind a bzr-commit-* file"""
79
79
def test_commit_lossy_foreign(self):
80
80
test_foreign.register_dummy_foreign_for_test(self)
81
81
self.make_branch_and_tree('.',
82
format=test_foreign.DummyForeignVcsDirFormat())
82
format=test_foreign.DummyForeignVcsDirFormat())
83
83
self.run_bzr('commit --lossy --unchanged -m message')
84
84
output = self.run_bzr('revision-info')[0]
85
85
self.assertTrue(output.startswith('1 dummy-'))
92
92
self.run_bzr(['commit', '-m', 'first commit', 'a'])
94
94
b_tree = a_tree.controldir.sprout('b').open_workingtree()
95
self.build_tree_contents([('b/a_file', b'changes in b')])
95
self.build_tree_contents([('b/a_file', 'changes in b')])
96
96
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
98
self.build_tree_contents([('a/a_file', b'new contents')])
98
self.build_tree_contents([('a/a_file', 'new contents')])
99
99
self.run_bzr(['commit', '-m', 'change in a', 'a'])
101
101
b_tree.merge_from_branch(a_tree.branch)
126
126
def test_verbose_commit_modified(self):
127
127
# Verbose commit of modified file should say so
128
128
wt = self.prepare_simple_history()
129
self.build_tree_contents([('hello.txt', b'new contents')])
129
self.build_tree_contents([('hello.txt', 'new contents')])
130
130
out, err = self.run_bzr('commit -m modified')
131
131
self.assertEqual('', out)
132
132
self.assertContainsRe(err, '^Committing to: .*\n'
139
139
self.requireFeature(features.UnicodeFilenameFeature)
140
140
file_name = u'\N{euro sign}'
141
141
self.run_bzr(['init'])
142
with open(file_name, 'w') as f:
143
f.write('hello world')
142
with open(file_name, 'w') as f: f.write('hello world')
144
143
self.run_bzr(['add'])
145
144
out, err = self.run_bzr(['commit', '-m', file_name])
146
reflags = re.MULTILINE | re.DOTALL | re.UNICODE
145
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
147
146
te = osutils.get_terminal_encoding()
148
self.assertContainsRe(err,
149
u'The commit message is a file name:',
147
self.assertContainsRe(err.decode(te),
148
u'The commit message is a file name:',
152
151
# Run same test with a filename that causes encode
153
152
# error for the terminal encoding. We do this
159
158
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
160
159
file_name = u'foo\u1234'
161
with open(file_name, 'w') as f:
162
f.write('hello world')
160
with open(file_name, 'w') as f: f.write('hello world')
163
161
self.run_bzr(['add'])
164
162
out, err = self.run_bzr(['commit', '-m', file_name])
165
reflags = re.MULTILINE | re.DOTALL | re.UNICODE
163
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
166
164
te = osutils.get_terminal_encoding()
167
self.assertContainsRe(err,
168
u'The commit message is a file name:',
165
self.assertContainsRe(err.decode(te, 'replace'),
166
u'The commit message is a file name:',
171
169
osutils.get_terminal_encoding = default_get_terminal_enc
175
173
tree = self.make_branch_and_tree(".")
176
174
self.build_tree(["f"])
178
out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
179
encoding="utf-8", retcode=3)
180
self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
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\"$")
182
180
def test_non_ascii_file_unversioned_iso_8859_5(self):
183
181
self.requireFeature(features.UnicodeFilenameFeature)
184
182
tree = self.make_branch_and_tree(".")
185
183
self.build_tree(["f"])
187
out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
188
encoding="iso-8859-5", retcode=3)
189
self.assertNotContainsString(err, b"\xc2\xa7")
190
self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
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\"$")
192
191
def test_warn_about_forgotten_commit_message(self):
193
192
"""Test that the lack of -m parameter is caught"""
310
309
this_tree.commit('create_files')
311
310
other_dir = this_tree.controldir.sprout('other')
312
311
other_tree = other_dir.open_workingtree()
313
with other_tree.lock_write():
314
# perform the needed actions on the files and dirs.
312
other_tree.lock_write()
313
# perform the needed actions on the files and dirs.
315
315
other_tree.rename_one('dirtorename', 'renameddir')
316
316
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
317
317
other_tree.rename_one('filetorename', 'renamedfile')
320
320
other_tree.remove(['dirtoremove', 'filetoremove'])
321
321
self.build_tree_contents([
322
322
('other/newdir/',),
323
('other/filetomodify', b'new content'),
324
('other/newfile', b'new file content')])
323
('other/filetomodify', 'new content'),
324
('other/newfile', 'new file content')])
325
325
other_tree.add('newfile')
326
326
other_tree.add('newdir/')
327
327
other_tree.commit('modify all sample files and dirs.')
328
330
this_tree.merge_from_branch(other_tree.branch)
329
331
out, err = self.run_bzr('commit -m added', working_dir='this')
330
332
self.assertEqual('', out)
346
348
def test_empty_commit_message(self):
347
349
tree = self.make_branch_and_tree('.')
348
self.build_tree_contents([('foo.c', b'int main() {}')])
350
self.build_tree_contents([('foo.c', 'int main() {}')])
349
351
tree.add('foo.c')
350
352
self.run_bzr('commit -m ""')
355
357
outer_tree = self.make_branch_and_tree('.')
356
358
inner_tree = self.make_branch_and_tree('branch')
357
359
self.build_tree_contents([
358
('branch/foo.c', b'int main() {}'),
359
('branch/bar.c', b'int main() {}')])
360
('branch/foo.c', 'int main() {}'),
361
('branch/bar.c', 'int main() {}')])
360
362
inner_tree.add(['foo.c', 'bar.c'])
361
363
# can't commit files in different trees; sane error
362
364
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
365
367
# can commit to branch - records bar.c
366
368
self.run_bzr('commit -m newstuff branch')
367
369
# No changes left
368
self.run_bzr_error(["No changes to commit"],
369
'commit -m newstuff branch')
370
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
371
372
def test_out_of_date_tree_commit(self):
372
373
# check we get an error code and a clear message committing with an out
379
380
# now commit to the checkout should emit
380
381
# ERROR: Out of date with the branch, 'brz update' is suggested
381
382
output = self.run_bzr('commit --unchanged -m checkout_message '
382
'checkout', retcode=3)
383
'checkout', retcode=3)
383
384
self.assertEqual(output,
385
386
"brz: ERROR: Working tree is out of date, please "
402
403
trunk = self.make_branch_and_tree('trunk')
404
405
u1 = trunk.branch.create_checkout('u1')
405
self.build_tree_contents([('u1/hosts', b'initial contents\n')])
406
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
407
408
self.run_bzr('commit -m add-hosts u1')
409
410
u2 = trunk.branch.create_checkout('u2')
410
self.build_tree_contents([('u2/hosts', b'altered in u2\n')])
411
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
411
412
self.run_bzr('commit -m checkin-from-u2 u2')
413
414
# make an offline commits
414
self.build_tree_contents(
415
[('u1/hosts', b'first offline change in u1\n')])
415
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
416
416
self.run_bzr('commit -m checkin-offline --local u1')
418
418
# now try to pull in online work from u2, and then commit our offline
419
419
# work as a merge
420
420
# retcode 1 as we expect a text conflict
421
421
self.run_bzr('update u1', retcode=1)
422
self.assertFileEqual(b'''\
422
self.assertFileEqual('''\
424
424
first offline change in u1
432
432
# add a text change here to represent resolving the merge conflicts in
433
433
# favour of a new version of the file not identical to either the u1
434
434
# version or the u2 version.
435
self.build_tree_contents([('u1/hosts', b'merge resolution\n')])
435
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
436
436
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
438
438
def test_commit_exclude_excludes_modified_files(self):
538
538
tree = self.make_branch_and_tree('tree')
539
539
self.build_tree(['tree/hello.txt'])
540
540
tree.add('hello.txt')
541
output, err = self.run_bzr_raw(
541
output, err = self.run_bzr(
542
542
['commit', '-m', 'hello',
543
543
u'--fixes=generic:\u20ac', 'tree/hello.txt'],
544
544
encoding='utf-8', retcode=3)
545
545
self.assertEqual(b'', output)
546
546
self.assertContainsRe(err,
547
b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
547
b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
549
549
def test_no_bugs_no_properties(self):
550
550
"""If no bugs are fixed, the bugs property is not set.
562
562
del properties['branch-nick']
563
563
self.assertFalse('bugs' in properties)
565
def test_bugs_sets_property(self):
566
"""commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
567
tree = self.make_branch_and_tree('tree')
568
self.build_tree(['tree/hello.txt'])
569
tree.add('hello.txt')
570
self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
572
# Get the revision properties, ignoring the branch-nick property, which
573
# we don't care about for this test.
574
last_rev = tree.branch.repository.get_revision(tree.last_revision())
575
properties = dict(last_rev.properties)
576
del properties[u'branch-nick']
578
self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
581
565
def test_fixes_bug_sets_property(self):
582
566
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
583
567
tree = self.make_branch_and_tree('tree')
589
573
# we don't care about for this test.
590
574
last_rev = tree.branch.repository.get_revision(tree.last_revision())
591
575
properties = dict(last_rev.properties)
592
del properties[u'branch-nick']
576
del properties['branch-nick']
594
self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 fixed'},
578
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
597
581
def test_fixes_multiple_bugs_sets_properties(self):
609
593
del properties['branch-nick']
611
595
self.assertEqual(
612
{u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
613
'https://launchpad.net/bugs/235 fixed'},
596
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
597
'https://launchpad.net/bugs/235 fixed'},
616
600
def test_fixes_bug_with_alternate_trackers(self):
622
606
'trac_twisted_url', 'http://twistedmatrix.com/trac')
623
607
self.build_tree(['tree/hello.txt'])
624
608
tree.add('hello.txt')
626
'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
609
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
628
611
# Get the revision properties, ignoring the branch-nick property, which
629
612
# we don't care about for this test.
652
635
tree.add('hello.txt')
653
636
self.run_bzr_error(
654
637
["brz: ERROR: No tracker specified for bug 123. Use the form "
655
"'tracker:id' or specify a default bug tracker using the "
656
"`bugtracker` option.\n"
657
"See \"brz help bugs\" for more information on this feature. "
638
"'tracker:id' or specify a default bug tracker using the "
639
"`bugtracker` option.\n"
640
"See \"brz help bugs\" for more information on this feature. "
659
642
'commit -m add-b --fixes=123',
660
643
working_dir='tree')
661
644
tree.branch.get_config_stack().set("bugtracker", "lp")
692
675
tree = self.make_branch_and_tree('tree')
693
676
self.build_tree(['tree/hello.txt'])
694
677
tree.add('hello.txt')
695
self.run_bzr('commit -m hello tree/hello.txt')
678
self.run_bzr( 'commit -m hello tree/hello.txt')
696
679
last_rev = tree.branch.repository.get_revision(tree.last_revision())
697
680
properties = last_rev.properties
698
681
self.assertFalse('author' in properties)
706
689
tree.add('hello.txt')
707
690
self.run_bzr(["commit", '-m', 'hello',
708
691
'--author', u'John D\xf6 <jdoe@example.com>',
710
693
last_rev = tree.branch.repository.get_revision(tree.last_revision())
711
694
properties = last_rev.properties
712
self.assertEqual(u'John D\xf6 <jdoe@example.com>',
713
properties['authors'])
695
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
715
697
def test_author_no_email(self):
716
698
"""Author's name without an email address is allowed, too."""
739
721
self.build_tree(['tree/hello.txt'])
740
722
tree.add('hello.txt')
741
723
out, err = self.run_bzr("commit -m hello "
742
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
724
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
743
725
last_rev = tree.branch.repository.get_revision(tree.last_revision())
744
726
self.assertEqual(
745
727
'Sat 2009-10-10 08:00:00 +0100',
746
728
osutils.format_date(last_rev.timestamp, last_rev.timezone))
748
730
def test_commit_time_bad_time(self):
749
731
tree = self.make_branch_and_tree('tree')
750
732
self.build_tree(['tree/hello.txt'])
751
733
tree.add('hello.txt')
752
734
out, err = self.run_bzr("commit -m hello "
753
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
735
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
754
736
self.assertStartsWith(
755
737
err, "brz: ERROR: Could not parse --commit-time:")
759
741
self.build_tree(['tree/hello.txt'])
760
742
tree.add('hello.txt')
761
743
out, err = self.run_bzr("commit -m hello "
762
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
744
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
763
745
self.assertStartsWith(
764
746
err, "brz: ERROR: Could not parse --commit-time:")
765
747
# Test that it is actually checking and does not simply crash with
777
759
# then during partial commit we have error
778
760
# parent_id {dir-XXX} not in inventory
779
761
t.rename_one('dir/a', 'a')
780
self.build_tree_contents([('test', b'changes in test')])
762
self.build_tree_contents([('test', 'changes in test')])
782
764
out, err = self.run_bzr('commit test -m "partial commit"')
783
765
self.assertEqual('', out)
792
774
self.get_readonly_transport('master')).open_branch()
793
775
master.create_checkout('checkout')
794
776
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
796
778
self.assertContainsRe(err,
797
r'^brz: ERROR: Cannot lock.*readonly transport')
779
r'^brz: ERROR: Cannot lock.*readonly transport')
799
781
def setup_editor(self):
800
782
# Test that commit template hooks work
801
783
if sys.platform == "win32":
802
with open('fed.bat', 'w') as f:
803
f.write('@rem dummy fed')
784
f = file('fed.bat', 'w')
785
f.write('@rem dummy fed')
804
787
self.overrideEnv('BRZ_EDITOR', "fed.bat")
806
with open('fed.sh', 'wb') as f:
807
f.write(b'#!/bin/sh\n')
789
f = file('fed.sh', 'wb')
790
f.write('#!/bin/sh\n')
808
792
os.chmod('fed.sh', 0o755)
809
793
self.overrideEnv('BRZ_EDITOR', "./fed.sh")
811
795
def setup_commit_with_template(self):
812
796
self.setup_editor()
813
797
msgeditor.hooks.install_named_hook("commit_message_template",
814
lambda commit_obj, msg: "save me some typing\n", None)
798
lambda commit_obj, msg: "save me some typing\n", None)
815
799
tree = self.make_branch_and_tree('tree')
816
800
self.build_tree(['tree/hello.txt'])
817
801
tree.add('hello.txt')
823
807
self.build_tree(['tree/hello.txt'])
824
808
tree.add('hello.txt')
825
809
out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
827
811
self.assertContainsRe(err,
828
"brz: ERROR: Empty commit message specified")
812
"brz: ERROR: Empty commit message specified")
830
814
def test_commit_hook_template_accepted(self):
831
815
tree = self.setup_commit_with_template()
837
821
tree = self.setup_commit_with_template()
838
822
expected = tree.last_revision()
839
823
out, err = self.run_bzr_error(["Empty commit message specified."
840
" Please specify a commit message with either"
841
" --message or --file or leave a blank message"
842
" with --message \"\"."],
843
"commit tree/hello.txt", stdin="n\n")
824
" Please specify a commit message with either"
825
" --message or --file or leave a blank message"
826
" with --message \"\"."],
827
"commit tree/hello.txt", stdin="n\n")
844
828
self.assertEqual(expected, tree.last_revision())
846
830
def test_set_commit_message(self):
847
831
msgeditor.hooks.install_named_hook("set_commit_message",
848
lambda commit_obj, msg: "save me some typing\n", None)
832
lambda commit_obj, msg: "save me some typing\n", None)
849
833
tree = self.make_branch_and_tree('tree')
850
834
self.build_tree(['tree/hello.txt'])
851
835
tree.add('hello.txt')
860
844
with open('foo/foo.txt', 'w') as f:
862
846
self.run_bzr(['add'], working_dir='foo')
863
override_whoami(self)
847
self.overrideEnv('EMAIL', None)
848
self.overrideEnv('BRZ_EMAIL', None)
849
# Also, make sure that it's not inferred from mailname.
850
self.overrideAttr(config, '_auto_user_id',
851
lambda: (None, None))
864
852
self.run_bzr_error(
865
853
['Unable to determine your name'],
866
854
['commit', '-m', 'initial'], working_dir='foo')
871
859
self.run_bzr(['init', 'test_branch'])
872
860
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
874
self.run_bzr(['bind', '.'], working_dir='test_checkout')
861
self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
875
862
with open('test_checkout/foo.txt', 'w') as f:
877
864
self.run_bzr(['add'], working_dir='test_checkout')
895
882
self.run_bzr('ci -m "non-ascii mv"')
885
class TestSmartServerCommit(TestCaseWithTransport):
887
def test_commit_to_lightweight(self):
888
self.setup_smart_server_with_call_log()
889
t = self.make_branch_and_tree('from')
890
for count in range(9):
891
t.commit(message='commit %d' % count)
892
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
894
self.reset_smart_call_log()
895
self.build_tree(['target/afile'])
896
self.run_bzr(['add', 'target/afile'])
897
out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
898
# This figure represent the amount of work to perform this use case. It
899
# is entirely ok to reduce this number if a test fails due to rpc_count
900
# being too low. If rpc_count increases, more network roundtrips have
901
# become necessary for this use case. Please do not adjust this number
902
# upwards without agreement from bzr's network support maintainers.
903
self.assertLength(211, self.hpss_calls)
904
self.assertLength(2, self.hpss_connections)
905
self.expectFailure("commit still uses VFS calls",
906
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)