~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_commit.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    osutils,
30
30
    ignores,
31
31
    msgeditor,
32
 
    tests,
33
32
    )
34
33
from bzrlib.bzrdir import BzrDir
35
34
from bzrlib.tests import (
36
 
    probe_bad_non_ascii,
37
35
    test_foreign,
38
 
    TestSkipped,
39
 
    UnicodeFilenameFeature,
 
36
    features,
40
37
    )
41
38
from bzrlib.tests import TestCaseWithTransport
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
42
40
 
43
41
 
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).
140
138
        """
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')
170
168
        finally:
171
169
            osutils.get_terminal_encoding = default_get_terminal_enc
172
170
 
 
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"])
 
175
        tree.add(["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\"$")
 
179
 
 
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"])
 
184
        tree.add(["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\"$")
 
190
 
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 ""')
336
354
 
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')
601
619
 
 
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')
 
625
        self.run_bzr_error(
 
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. "
 
630
            "Commit refused."],
 
631
            'commit -m add-b --fixes=123',
 
632
            working_dir='tree')
 
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'])
 
638
 
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')
624
661
 
625
662
    def test_no_author(self):
688
725
        self.assertStartsWith(
689
726
            err, "bzr: ERROR: Could not parse --commit-time:")
690
727
 
 
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")
 
739
 
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')
742
791
        return tree
743
792
 
 
793
    def test_edit_empty_message(self):
 
794
        tree = self.make_branch_and_tree('tree')
 
795
        self.setup_editor()
 
796
        self.build_tree(['tree/hello.txt'])
 
797
        tree.add('hello.txt')
 
798
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
 
799
            stdin="y\n")
 
800
        self.assertContainsRe(err,
 
801
            "bzr: ERROR: Empty commit message specified")
 
802
 
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())
756
818
 
 
819
    def test_set_commit_message(self):
 
820
        msgeditor.hooks.install_named_hook("set_commit_message",
 
821
                lambda commit_obj, msg: "save me some typing\n", None)
 
822
        tree = self.make_branch_and_tree('tree')
 
823
        self.build_tree(['tree/hello.txt'])
 
824
        tree.add('hello.txt')
 
825
        out, err = self.run_bzr("commit tree/hello.txt")
 
826
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
827
        self.assertEqual('save me some typing\n', last_rev.message)
 
828
 
757
829
    def test_commit_without_username(self):
758
830
        """Ensure commit error if username is not set.
759
831
        """
783
855
        self.assertContainsRe(err,
784
856
            'Branch.*test_checkout.*appears to be bound to itself')
785
857
 
 
858
    def test_mv_dirs_non_ascii(self):
 
859
        """Move directory with non-ascii name and containing files.
 
860
 
 
861
        Regression test for bug 185211.
 
862
        """
 
863
        tree = self.make_branch_and_tree('.')
 
864
        self.build_tree([u'abc\xc3/', u'abc\xc3/foo'])
 
865
 
 
866
        tree.add([u'abc\xc3/', u'abc\xc3/foo'])
 
867
        tree.commit('checkin')
 
868
 
 
869
        tree.rename_one(u'abc\xc3','abc')
 
870
 
 
871
        self.run_bzr('ci -m "non-ascii mv"')
 
872
 
 
873
 
 
874
class TestSmartServerCommit(TestCaseWithTransport):
 
875
 
 
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'),
 
882
            'target'])
 
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(214, self.hpss_calls)
 
893
        self.assertLength(2, self.hpss_connections)
 
894
        self.expectFailure("commit still uses VFS calls",
 
895
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)