~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-04-09 19:25:42 UTC
  • mto: (5777.5.1 inventoryworkingtree)
  • mto: This revision was merged to the branch mainline in revision 5781.
  • Revision ID: jelmer@samba.org-20110409192542-8bbedp36s7nj928e
Split InventoryTree out of Tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    osutils,
30
30
    ignores,
31
31
    msgeditor,
 
32
    tests,
32
33
    )
33
34
from bzrlib.bzrdir import BzrDir
34
35
from bzrlib.tests import (
35
 
    test_foreign,
36
 
    features,
 
36
    probe_bad_non_ascii,
 
37
    TestSkipped,
 
38
    UnicodeFilenameFeature,
37
39
    )
38
40
from bzrlib.tests import TestCaseWithTransport
39
41
 
54
56
            err,
55
57
            DocTestMatches("""\
56
58
Committing to: ...
 
59
aborting commit write group: PointlessCommit(No changes to commit)
57
60
bzr: ERROR: No changes to commit.\
58
61
 Please 'bzr add' the files you want to commit,\
59
62
 or use --unchanged to force an empty commit.
69
72
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
70
73
        self.assertEqual('', self.run_bzr('unknowns')[0])
71
74
 
72
 
    def test_commit_lossy_native(self):
73
 
        """A --lossy option to commit is supported."""
74
 
        self.make_branch_and_tree('.')
75
 
        self.run_bzr('commit --lossy --unchanged -m message')
76
 
        self.assertEqual('', self.run_bzr('unknowns')[0])
77
 
 
78
 
    def test_commit_lossy_foreign(self):
79
 
        test_foreign.register_dummy_foreign_for_test(self)
80
 
        self.make_branch_and_tree('.',
81
 
            format=test_foreign.DummyForeignVcsDirFormat())
82
 
        self.run_bzr('commit --lossy --unchanged -m message')
83
 
        output = self.run_bzr('revision-info')[0]
84
 
        self.assertTrue(output.startswith('1 dummy-'))
85
 
 
86
75
    def test_commit_with_path(self):
87
76
        """Commit tree with path of root specified"""
88
77
        a_tree = self.make_branch_and_tree('a')
102
91
        self.run_bzr('resolved b/a_file')
103
92
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
104
93
 
 
94
 
105
95
    def test_10_verbose_commit(self):
106
96
        """Add one file and examine verbose commit output"""
107
97
        tree = self.make_branch_and_tree('.')
135
125
    def test_unicode_commit_message_is_filename(self):
136
126
        """Unicode commit message same as a filename (Bug #563646).
137
127
        """
138
 
        self.requireFeature(features.UnicodeFilenameFeature)
 
128
        self.requireFeature(UnicodeFilenameFeature)
139
129
        file_name = u'\N{euro sign}'
140
130
        self.run_bzr(['init'])
141
131
        open(file_name, 'w').write('hello world')
329
319
        tree = self.make_branch_and_tree('.')
330
320
        self.build_tree_contents([('foo.c', 'int main() {}')])
331
321
        tree.add('foo.c')
332
 
        self.run_bzr('commit -m ""')
 
322
        self.run_bzr('commit -m ""', retcode=3)
 
323
 
 
324
    def test_unsupported_encoding_commit_message(self):
 
325
        if sys.platform == 'win32':
 
326
            raise tests.TestNotApplicable('Win32 parses arguments directly'
 
327
                ' as Unicode, so we can\'t pass invalid non-ascii')
 
328
        tree = self.make_branch_and_tree('.')
 
329
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
330
        tree.add('foo.c')
 
331
        # LANG env variable has no effect on Windows
 
332
        # but some characters anyway cannot be represented
 
333
        # in default user encoding
 
334
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
335
        if char is None:
 
336
            raise TestSkipped('Cannot find suitable non-ascii character'
 
337
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
338
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
 
339
                                          retcode=1,
 
340
                                          env_changes={'LANG': 'C'})
 
341
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
 
342
                                    'unsupported by the current encoding.')
333
343
 
334
344
    def test_other_branch_commit(self):
335
345
        # this branch is to ensure consistent behaviour, whether we're run
596
606
            'commit -m add-b --fixes=xxx:123',
597
607
            working_dir='tree')
598
608
 
599
 
    def test_fixes_bug_with_default_tracker(self):
600
 
        """commit --fixes=234 uses the default bug tracker."""
601
 
        tree = self.make_branch_and_tree('tree')
602
 
        self.build_tree(['tree/hello.txt'])
603
 
        tree.add('hello.txt')
604
 
        self.run_bzr_error(
605
 
            ["bzr: ERROR: No tracker specified for bug 123. Use the form "
606
 
            "'tracker:id' or specify a default bug tracker using the "
607
 
            "`bugtracker` option.\n"
608
 
            "See \"bzr help bugs\" for more information on this feature. "
609
 
            "Commit refused."],
610
 
            'commit -m add-b --fixes=123',
611
 
            working_dir='tree')
612
 
        tree.branch.get_config().set_user_option("bugtracker", "lp")
613
 
        self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
614
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
615
 
        self.assertEqual('https://launchpad.net/bugs/234 fixed',
616
 
                         last_rev.properties['bugs'])
617
 
 
618
609
    def test_fixes_invalid_bug_number(self):
619
610
        tree = self.make_branch_and_tree('tree')
620
611
        self.build_tree(['tree/hello.txt'])
632
623
        self.build_tree(['tree/hello.txt'])
633
624
        tree.add('hello.txt')
634
625
        self.run_bzr_error(
635
 
            [r"Invalid bug orange:apples:bananas. Must be in the form of "
636
 
             r"'tracker:id'\. See \"bzr help bugs\" for more information on "
637
 
             r"this feature.\nCommit refused\."],
638
 
            'commit -m add-b --fixes=orange:apples:bananas',
 
626
            [r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
 
627
             r"See \"bzr help bugs\" for more information on this feature.\n"
 
628
             r"Commit refused\."],
 
629
            'commit -m add-b --fixes=orange',
639
630
            working_dir='tree')
640
631
 
641
632
    def test_no_author(self):
757
748
        tree.add('hello.txt')
758
749
        return tree
759
750
 
760
 
    def test_edit_empty_message(self):
761
 
        tree = self.make_branch_and_tree('tree')
762
 
        self.setup_editor()
763
 
        self.build_tree(['tree/hello.txt'])
764
 
        tree.add('hello.txt')
765
 
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
766
 
            stdin="y\n")
767
 
        self.assertContainsRe(err,
768
 
            "bzr: ERROR: Empty commit message specified")
769
 
 
770
751
    def test_commit_hook_template_accepted(self):
771
752
        tree = self.setup_commit_with_template()
772
753
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
776
757
    def test_commit_hook_template_rejected(self):
777
758
        tree = self.setup_commit_with_template()
778
759
        expected = tree.last_revision()
779
 
        out, err = self.run_bzr_error(["Empty commit message specified."
780
 
                  " Please specify a commit message with either"
781
 
                  " --message or --file or leave a blank message"
782
 
                  " with --message \"\"."],
 
760
        out, err = self.run_bzr_error(["empty commit message"],
783
761
            "commit tree/hello.txt", stdin="n\n")
784
762
        self.assertEqual(expected, tree.last_revision())
785
763
 
786
 
    def test_set_commit_message(self):
787
 
        msgeditor.hooks.install_named_hook("set_commit_message",
788
 
                lambda commit_obj, msg: "save me some typing\n", None)
789
 
        tree = self.make_branch_and_tree('tree')
790
 
        self.build_tree(['tree/hello.txt'])
791
 
        tree.add('hello.txt')
792
 
        out, err = self.run_bzr("commit tree/hello.txt")
793
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
794
 
        self.assertEqual('save me some typing\n', last_rev.message)
795
 
 
796
764
    def test_commit_without_username(self):
797
765
        """Ensure commit error if username is not set.
798
766
        """
821
789
        self.assertEqual(out, '')
822
790
        self.assertContainsRe(err,
823
791
            'Branch.*test_checkout.*appears to be bound to itself')
 
792