33
33
from ...controldir import ControlDir
34
from ...sixish import PY3
39
38
from .. import TestCaseWithTransport
40
39
from ..matchers import ContainsNoVfsCalls
41
from ..test_bedding import override_whoami
44
42
class TestCommit(TestCaseWithTransport):
60
58
brz: ERROR: No changes to commit.\
61
59
Please 'brz add' the files you want to commit,\
62
60
or use --unchanged to force an empty commit.
63
""", flags=doctest.ELLIPSIS | doctest.REPORT_UDIFF))
61
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
65
63
def test_commit_success(self):
66
64
"""Successful commit should not leave behind a bzr-commit-* file"""
81
79
def test_commit_lossy_foreign(self):
82
80
test_foreign.register_dummy_foreign_for_test(self)
83
81
self.make_branch_and_tree('.',
84
format=test_foreign.DummyForeignVcsDirFormat())
82
format=test_foreign.DummyForeignVcsDirFormat())
85
83
self.run_bzr('commit --lossy --unchanged -m message')
86
84
output = self.run_bzr('revision-info')[0]
87
85
self.assertTrue(output.startswith('1 dummy-'))
145
143
f.write('hello world')
146
144
self.run_bzr(['add'])
147
145
out, err = self.run_bzr(['commit', '-m', file_name])
148
reflags = re.MULTILINE | re.DOTALL | re.UNICODE
146
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
149
147
te = osutils.get_terminal_encoding()
150
self.assertContainsRe(err if PY3 else err.decode(te),
151
u'The commit message is a file name:',
148
self.assertContainsRe(err.decode(te),
149
u'The commit message is a file name:',
154
152
# Run same test with a filename that causes encode
155
153
# error for the terminal encoding. We do this
164
162
f.write('hello world')
165
163
self.run_bzr(['add'])
166
164
out, err = self.run_bzr(['commit', '-m', file_name])
167
reflags = re.MULTILINE | re.DOTALL | re.UNICODE
165
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
168
166
te = osutils.get_terminal_encoding()
169
self.assertContainsRe(err if PY3 else err.decode(te, 'replace'),
170
u'The commit message is a file name:',
167
self.assertContainsRe(err.decode(te, 'replace'),
168
u'The commit message is a file name:',
173
171
osutils.get_terminal_encoding = default_get_terminal_enc
177
175
tree = self.make_branch_and_tree(".")
178
176
self.build_tree(["f"])
180
out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
181
encoding="utf-8", retcode=3)
182
self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
178
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
179
encoding="utf-8", retcode=3)
180
self.assertContainsRe(err, "(?m)not versioned: \"\xc2\xa7\"$")
184
182
def test_non_ascii_file_unversioned_iso_8859_5(self):
185
183
self.requireFeature(features.UnicodeFilenameFeature)
186
184
tree = self.make_branch_and_tree(".")
187
185
self.build_tree(["f"])
189
out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
190
encoding="iso-8859-5", retcode=3)
192
self.expectFailure("Error messages are always written as UTF-8",
193
self.assertNotContainsString, err, b"\xc2\xa7")
195
self.assertNotContainsString(err, b"\xc2\xa7")
196
self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
187
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
188
encoding="iso-8859-5", retcode=3)
189
self.expectFailure("Error messages are always written as UTF-8",
190
self.assertNotContainsString, err, "\xc2\xa7")
191
self.assertContainsRe(err, "(?m)not versioned: \"\xfd\"$")
198
193
def test_warn_about_forgotten_commit_message(self):
199
194
"""Test that the lack of -m parameter is caught"""
316
311
this_tree.commit('create_files')
317
312
other_dir = this_tree.controldir.sprout('other')
318
313
other_tree = other_dir.open_workingtree()
319
with other_tree.lock_write():
320
# perform the needed actions on the files and dirs.
314
other_tree.lock_write()
315
# perform the needed actions on the files and dirs.
321
317
other_tree.rename_one('dirtorename', 'renameddir')
322
318
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
323
319
other_tree.rename_one('filetorename', 'renamedfile')
331
327
other_tree.add('newfile')
332
328
other_tree.add('newdir/')
333
329
other_tree.commit('modify all sample files and dirs.')
334
332
this_tree.merge_from_branch(other_tree.branch)
335
333
out, err = self.run_bzr('commit -m added', working_dir='this')
336
334
self.assertEqual('', out)
371
369
# can commit to branch - records bar.c
372
370
self.run_bzr('commit -m newstuff branch')
373
371
# No changes left
374
self.run_bzr_error(["No changes to commit"],
375
'commit -m newstuff branch')
372
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
377
374
def test_out_of_date_tree_commit(self):
378
375
# check we get an error code and a clear message committing with an out
385
382
# now commit to the checkout should emit
386
383
# ERROR: Out of date with the branch, 'brz update' is suggested
387
384
output = self.run_bzr('commit --unchanged -m checkout_message '
388
'checkout', retcode=3)
385
'checkout', retcode=3)
389
386
self.assertEqual(output,
391
388
"brz: ERROR: Working tree is out of date, please "
417
414
self.run_bzr('commit -m checkin-from-u2 u2')
419
416
# make an offline commits
420
self.build_tree_contents(
421
[('u1/hosts', b'first offline change in u1\n')])
417
self.build_tree_contents([('u1/hosts', b'first offline change in u1\n')])
422
418
self.run_bzr('commit -m checkin-offline --local u1')
424
420
# now try to pull in online work from u2, and then commit our offline
425
421
# work as a merge
426
422
# retcode 1 as we expect a text conflict
427
423
self.run_bzr('update u1', retcode=1)
428
self.assertFileEqual(b'''\
424
self.assertFileEqual('''\
430
426
first offline change in u1
544
540
tree = self.make_branch_and_tree('tree')
545
541
self.build_tree(['tree/hello.txt'])
546
542
tree.add('hello.txt')
547
output, err = self.run_bzr_raw(
543
output, err = self.run_bzr(
548
544
['commit', '-m', 'hello',
549
545
u'--fixes=generic:\u20ac', 'tree/hello.txt'],
550
546
encoding='utf-8', retcode=3)
551
547
self.assertEqual(b'', output)
552
548
self.assertContainsRe(err,
553
b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
549
b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
555
551
def test_no_bugs_no_properties(self):
556
552
"""If no bugs are fixed, the bugs property is not set.
568
564
del properties['branch-nick']
569
565
self.assertFalse('bugs' in properties)
571
def test_bugs_sets_property(self):
572
"""commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
573
tree = self.make_branch_and_tree('tree')
574
self.build_tree(['tree/hello.txt'])
575
tree.add('hello.txt')
576
self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
578
# Get the revision properties, ignoring the branch-nick property, which
579
# we don't care about for this test.
580
last_rev = tree.branch.repository.get_revision(tree.last_revision())
581
properties = dict(last_rev.properties)
582
del properties[u'branch-nick']
584
self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
587
567
def test_fixes_bug_sets_property(self):
588
568
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
589
569
tree = self.make_branch_and_tree('tree')
595
575
# we don't care about for this test.
596
576
last_rev = tree.branch.repository.get_revision(tree.last_revision())
597
577
properties = dict(last_rev.properties)
598
del properties[u'branch-nick']
578
del properties['branch-nick']
600
self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 fixed'},
580
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
603
583
def test_fixes_multiple_bugs_sets_properties(self):
615
595
del properties['branch-nick']
617
597
self.assertEqual(
618
{u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
619
'https://launchpad.net/bugs/235 fixed'},
598
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
599
'https://launchpad.net/bugs/235 fixed'},
622
602
def test_fixes_bug_with_alternate_trackers(self):
628
608
'trac_twisted_url', 'http://twistedmatrix.com/trac')
629
609
self.build_tree(['tree/hello.txt'])
630
610
tree.add('hello.txt')
632
'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
611
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
634
613
# Get the revision properties, ignoring the branch-nick property, which
635
614
# we don't care about for this test.
658
637
tree.add('hello.txt')
659
638
self.run_bzr_error(
660
639
["brz: ERROR: No tracker specified for bug 123. Use the form "
661
"'tracker:id' or specify a default bug tracker using the "
662
"`bugtracker` option.\n"
663
"See \"brz help bugs\" for more information on this feature. "
640
"'tracker:id' or specify a default bug tracker using the "
641
"`bugtracker` option.\n"
642
"See \"brz help bugs\" for more information on this feature. "
665
644
'commit -m add-b --fixes=123',
666
645
working_dir='tree')
667
646
tree.branch.get_config_stack().set("bugtracker", "lp")
698
677
tree = self.make_branch_and_tree('tree')
699
678
self.build_tree(['tree/hello.txt'])
700
679
tree.add('hello.txt')
701
self.run_bzr('commit -m hello tree/hello.txt')
680
self.run_bzr( 'commit -m hello tree/hello.txt')
702
681
last_rev = tree.branch.repository.get_revision(tree.last_revision())
703
682
properties = last_rev.properties
704
683
self.assertFalse('author' in properties)
712
691
tree.add('hello.txt')
713
692
self.run_bzr(["commit", '-m', 'hello',
714
693
'--author', u'John D\xf6 <jdoe@example.com>',
716
695
last_rev = tree.branch.repository.get_revision(tree.last_revision())
717
696
properties = last_rev.properties
718
self.assertEqual(u'John D\xf6 <jdoe@example.com>',
719
properties['authors'])
697
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
721
699
def test_author_no_email(self):
722
700
"""Author's name without an email address is allowed, too."""
745
723
self.build_tree(['tree/hello.txt'])
746
724
tree.add('hello.txt')
747
725
out, err = self.run_bzr("commit -m hello "
748
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
726
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
749
727
last_rev = tree.branch.repository.get_revision(tree.last_revision())
750
728
self.assertEqual(
751
729
'Sat 2009-10-10 08:00:00 +0100',
752
730
osutils.format_date(last_rev.timestamp, last_rev.timezone))
754
732
def test_commit_time_bad_time(self):
755
733
tree = self.make_branch_and_tree('tree')
756
734
self.build_tree(['tree/hello.txt'])
757
735
tree.add('hello.txt')
758
736
out, err = self.run_bzr("commit -m hello "
759
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
737
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
760
738
self.assertStartsWith(
761
739
err, "brz: ERROR: Could not parse --commit-time:")
765
743
self.build_tree(['tree/hello.txt'])
766
744
tree.add('hello.txt')
767
745
out, err = self.run_bzr("commit -m hello "
768
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
746
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
769
747
self.assertStartsWith(
770
748
err, "brz: ERROR: Could not parse --commit-time:")
771
749
# Test that it is actually checking and does not simply crash with
798
776
self.get_readonly_transport('master')).open_branch()
799
777
master.create_checkout('checkout')
800
778
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
802
780
self.assertContainsRe(err,
803
r'^brz: ERROR: Cannot lock.*readonly transport')
781
r'^brz: ERROR: Cannot lock.*readonly transport')
805
783
def setup_editor(self):
806
784
# Test that commit template hooks work
817
795
def setup_commit_with_template(self):
818
796
self.setup_editor()
819
797
msgeditor.hooks.install_named_hook("commit_message_template",
820
lambda commit_obj, msg: "save me some typing\n", None)
798
lambda commit_obj, msg: "save me some typing\n", None)
821
799
tree = self.make_branch_and_tree('tree')
822
800
self.build_tree(['tree/hello.txt'])
823
801
tree.add('hello.txt')
829
807
self.build_tree(['tree/hello.txt'])
830
808
tree.add('hello.txt')
831
809
out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
833
811
self.assertContainsRe(err,
834
"brz: ERROR: Empty commit message specified")
812
"brz: ERROR: Empty commit message specified")
836
814
def test_commit_hook_template_accepted(self):
837
815
tree = self.setup_commit_with_template()
843
821
tree = self.setup_commit_with_template()
844
822
expected = tree.last_revision()
845
823
out, err = self.run_bzr_error(["Empty commit message specified."
846
" Please specify a commit message with either"
847
" --message or --file or leave a blank message"
848
" with --message \"\"."],
849
"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")
850
828
self.assertEqual(expected, tree.last_revision())
852
830
def test_set_commit_message(self):
853
831
msgeditor.hooks.install_named_hook("set_commit_message",
854
lambda commit_obj, msg: "save me some typing\n", None)
832
lambda commit_obj, msg: "save me some typing\n", None)
855
833
tree = self.make_branch_and_tree('tree')
856
834
self.build_tree(['tree/hello.txt'])
857
835
tree.add('hello.txt')
866
844
with open('foo/foo.txt', 'w') as f:
868
846
self.run_bzr(['add'], working_dir='foo')
869
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))
870
852
self.run_bzr_error(
871
853
['Unable to determine your name'],
872
854
['commit', '-m', 'initial'], working_dir='foo')
877
859
self.run_bzr(['init', 'test_branch'])
878
860
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
880
self.run_bzr(['bind', '.'], working_dir='test_checkout')
861
self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
881
862
with open('test_checkout/foo.txt', 'w') as f:
883
864
self.run_bzr(['add'], working_dir='test_checkout')
909
890
for count in range(9):
910
891
t.commit(message='commit %d' % count)
911
892
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
913
894
self.reset_smart_call_log()
914
895
self.build_tree(['target/afile'])
915
896
self.run_bzr(['add', 'target/afile'])
922
903
self.assertLength(211, self.hpss_calls)
923
904
self.assertLength(2, self.hpss_connections)
924
905
self.expectFailure("commit still uses VFS calls",
925
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
906
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)