/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
brz: ERROR: No changes to commit.\
60
60
 Please 'brz add' the files you want to commit,\
61
61
 or use --unchanged to force an empty commit.
62
 
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
 
62
""", flags=doctest.ELLIPSIS | doctest.REPORT_UDIFF))
63
63
 
64
64
    def test_commit_success(self):
65
65
        """Successful commit should not leave behind a bzr-commit-* file"""
80
80
    def test_commit_lossy_foreign(self):
81
81
        test_foreign.register_dummy_foreign_for_test(self)
82
82
        self.make_branch_and_tree('.',
83
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
83
                                  format=test_foreign.DummyForeignVcsDirFormat())
84
84
        self.run_bzr('commit --lossy --unchanged -m message')
85
85
        output = self.run_bzr('revision-info')[0]
86
86
        self.assertTrue(output.startswith('1 dummy-'))
144
144
            f.write('hello world')
145
145
        self.run_bzr(['add'])
146
146
        out, err = self.run_bzr(['commit', '-m', file_name])
147
 
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
147
        reflags = re.MULTILINE | re.DOTALL | re.UNICODE
148
148
        te = osutils.get_terminal_encoding()
149
149
        self.assertContainsRe(err if PY3 else err.decode(te),
150
 
            u'The commit message is a file name:',
151
 
            flags=reflags)
 
150
                              u'The commit message is a file name:',
 
151
                              flags=reflags)
152
152
 
153
153
        # Run same test with a filename that causes encode
154
154
        # error for the terminal encoding. We do this
163
163
                f.write('hello world')
164
164
            self.run_bzr(['add'])
165
165
            out, err = self.run_bzr(['commit', '-m', file_name])
166
 
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
166
            reflags = re.MULTILINE | re.DOTALL | re.UNICODE
167
167
            te = osutils.get_terminal_encoding()
168
168
            self.assertContainsRe(err if PY3 else err.decode(te, 'replace'),
169
 
                u'The commit message is a file name:',
170
 
                flags=reflags)
 
169
                                  u'The commit message is a file name:',
 
170
                                  flags=reflags)
171
171
        finally:
172
172
            osutils.get_terminal_encoding = default_get_terminal_enc
173
173
 
177
177
        self.build_tree(["f"])
178
178
        tree.add(["f"])
179
179
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
180
 
            encoding="utf-8", retcode=3)
 
180
                                    encoding="utf-8", retcode=3)
181
181
        self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
182
182
 
183
183
    def test_non_ascii_file_unversioned_iso_8859_5(self):
186
186
        self.build_tree(["f"])
187
187
        tree.add(["f"])
188
188
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
189
 
            encoding="iso-8859-5", retcode=3)
 
189
                                    encoding="iso-8859-5", retcode=3)
190
190
        if not PY3:
191
191
            self.expectFailure("Error messages are always written as UTF-8",
192
 
                self.assertNotContainsString, err, b"\xc2\xa7")
 
192
                               self.assertNotContainsString, err, b"\xc2\xa7")
193
193
        else:
194
194
            self.assertNotContainsString(err, b"\xc2\xa7")
195
195
        self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
373
373
        # can commit to branch - records bar.c
374
374
        self.run_bzr('commit -m newstuff branch')
375
375
        # No changes left
376
 
        self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
 
376
        self.run_bzr_error(["No changes to commit"],
 
377
                           'commit -m newstuff branch')
377
378
 
378
379
    def test_out_of_date_tree_commit(self):
379
380
        # check we get an error code and a clear message committing with an out
386
387
        # now commit to the checkout should emit
387
388
        # ERROR: Out of date with the branch, 'brz update' is suggested
388
389
        output = self.run_bzr('commit --unchanged -m checkout_message '
389
 
                             'checkout', retcode=3)
 
390
                              'checkout', retcode=3)
390
391
        self.assertEqual(output,
391
392
                         ('',
392
393
                          "brz: ERROR: Working tree is out of date, please "
418
419
        self.run_bzr('commit -m checkin-from-u2 u2')
419
420
 
420
421
        # make an offline commits
421
 
        self.build_tree_contents([('u1/hosts', b'first offline change in u1\n')])
 
422
        self.build_tree_contents(
 
423
            [('u1/hosts', b'first offline change in u1\n')])
422
424
        self.run_bzr('commit -m checkin-offline --local u1')
423
425
 
424
426
        # now try to pull in online work from u2, and then commit our offline
550
552
            encoding='utf-8', retcode=3)
551
553
        self.assertEqual(b'', output)
552
554
        self.assertContainsRe(err,
553
 
            b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
 
555
                              b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
554
556
 
555
557
    def test_no_bugs_no_properties(self):
556
558
        """If no bugs are fixed, the bugs property is not set.
600
602
 
601
603
        self.assertEqual(
602
604
            {u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
603
 
                     'https://launchpad.net/bugs/235 fixed'},
 
605
             'https://launchpad.net/bugs/235 fixed'},
604
606
            properties)
605
607
 
606
608
    def test_fixes_bug_with_alternate_trackers(self):
612
614
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
613
615
        self.build_tree(['tree/hello.txt'])
614
616
        tree.add('hello.txt')
615
 
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
 
617
        self.run_bzr(
 
618
            'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
616
619
 
617
620
        # Get the revision properties, ignoring the branch-nick property, which
618
621
        # we don't care about for this test.
641
644
        tree.add('hello.txt')
642
645
        self.run_bzr_error(
643
646
            ["brz: ERROR: No tracker specified for bug 123. Use the form "
644
 
            "'tracker:id' or specify a default bug tracker using the "
645
 
            "`bugtracker` option.\n"
646
 
            "See \"brz help bugs\" for more information on this feature. "
647
 
            "Commit refused."],
 
647
             "'tracker:id' or specify a default bug tracker using the "
 
648
             "`bugtracker` option.\n"
 
649
             "See \"brz help bugs\" for more information on this feature. "
 
650
             "Commit refused."],
648
651
            'commit -m add-b --fixes=123',
649
652
            working_dir='tree')
650
653
        tree.branch.get_config_stack().set("bugtracker", "lp")
681
684
        tree = self.make_branch_and_tree('tree')
682
685
        self.build_tree(['tree/hello.txt'])
683
686
        tree.add('hello.txt')
684
 
        self.run_bzr( 'commit -m hello tree/hello.txt')
 
687
        self.run_bzr('commit -m hello tree/hello.txt')
685
688
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
686
689
        properties = last_rev.properties
687
690
        self.assertFalse('author' in properties)
695
698
        tree.add('hello.txt')
696
699
        self.run_bzr(["commit", '-m', 'hello',
697
700
                      '--author', u'John D\xf6 <jdoe@example.com>',
698
 
                     "tree/hello.txt"])
 
701
                      "tree/hello.txt"])
699
702
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
700
703
        properties = last_rev.properties
701
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
 
704
        self.assertEqual(u'John D\xf6 <jdoe@example.com>',
 
705
                         properties['authors'])
702
706
 
703
707
    def test_author_no_email(self):
704
708
        """Author's name without an email address is allowed, too."""
727
731
        self.build_tree(['tree/hello.txt'])
728
732
        tree.add('hello.txt')
729
733
        out, err = self.run_bzr("commit -m hello "
730
 
            "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
 
734
                                "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
731
735
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
732
736
        self.assertEqual(
733
737
            'Sat 2009-10-10 08:00:00 +0100',
734
738
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
735
 
        
 
739
 
736
740
    def test_commit_time_bad_time(self):
737
741
        tree = self.make_branch_and_tree('tree')
738
742
        self.build_tree(['tree/hello.txt'])
739
743
        tree.add('hello.txt')
740
744
        out, err = self.run_bzr("commit -m hello "
741
 
            "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
 
745
                                "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
742
746
        self.assertStartsWith(
743
747
            err, "brz: ERROR: Could not parse --commit-time:")
744
748
 
747
751
        self.build_tree(['tree/hello.txt'])
748
752
        tree.add('hello.txt')
749
753
        out, err = self.run_bzr("commit -m hello "
750
 
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
 
754
                                "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
751
755
        self.assertStartsWith(
752
756
            err, "brz: ERROR: Could not parse --commit-time:")
753
757
        # Test that it is actually checking and does not simply crash with
780
784
            self.get_readonly_transport('master')).open_branch()
781
785
        master.create_checkout('checkout')
782
786
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
783
 
            retcode=3)
 
787
                                retcode=3)
784
788
        self.assertContainsRe(err,
785
 
            r'^brz: ERROR: Cannot lock.*readonly transport')
 
789
                              r'^brz: ERROR: Cannot lock.*readonly transport')
786
790
 
787
791
    def setup_editor(self):
788
792
        # Test that commit template hooks work
799
803
    def setup_commit_with_template(self):
800
804
        self.setup_editor()
801
805
        msgeditor.hooks.install_named_hook("commit_message_template",
802
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
806
                                           lambda commit_obj, msg: "save me some typing\n", None)
803
807
        tree = self.make_branch_and_tree('tree')
804
808
        self.build_tree(['tree/hello.txt'])
805
809
        tree.add('hello.txt')
811
815
        self.build_tree(['tree/hello.txt'])
812
816
        tree.add('hello.txt')
813
817
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
814
 
            stdin="y\n")
 
818
                                stdin="y\n")
815
819
        self.assertContainsRe(err,
816
 
            "brz: ERROR: Empty commit message specified")
 
820
                              "brz: ERROR: Empty commit message specified")
817
821
 
818
822
    def test_commit_hook_template_accepted(self):
819
823
        tree = self.setup_commit_with_template()
825
829
        tree = self.setup_commit_with_template()
826
830
        expected = tree.last_revision()
827
831
        out, err = self.run_bzr_error(["Empty commit message specified."
828
 
                  " Please specify a commit message with either"
829
 
                  " --message or --file or leave a blank message"
830
 
                  " with --message \"\"."],
831
 
            "commit tree/hello.txt", stdin="n\n")
 
832
                                       " Please specify a commit message with either"
 
833
                                       " --message or --file or leave a blank message"
 
834
                                       " with --message \"\"."],
 
835
                                      "commit tree/hello.txt", stdin="n\n")
832
836
        self.assertEqual(expected, tree.last_revision())
833
837
 
834
838
    def test_set_commit_message(self):
835
839
        msgeditor.hooks.install_named_hook("set_commit_message",
836
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
840
                                           lambda commit_obj, msg: "save me some typing\n", None)
837
841
        tree = self.make_branch_and_tree('tree')
838
842
        self.build_tree(['tree/hello.txt'])
839
843
        tree.add('hello.txt')
852
856
        self.overrideEnv('BRZ_EMAIL', None)
853
857
        # Also, make sure that it's not inferred from mailname.
854
858
        self.overrideAttr(config, '_auto_user_id',
855
 
            lambda: (None, None))
 
859
                          lambda: (None, None))
856
860
        self.run_bzr_error(
857
861
            ['Unable to determine your name'],
858
862
            ['commit', '-m', 'initial'], working_dir='foo')
862
866
        """
863
867
        self.run_bzr(['init', 'test_branch'])
864
868
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
865
 
        self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
 
869
        # bind to self
 
870
        self.run_bzr(['bind', '.'], working_dir='test_checkout')
866
871
        with open('test_checkout/foo.txt', 'w') as f:
867
872
            f.write('hello')
868
873
        self.run_bzr(['add'], working_dir='test_checkout')
894
899
        for count in range(9):
895
900
            t.commit(message='commit %d' % count)
896
901
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
897
 
            'target'])
 
902
                                 'target'])
898
903
        self.reset_smart_call_log()
899
904
        self.build_tree(['target/afile'])
900
905
        self.run_bzr(['add', 'target/afile'])
907
912
        self.assertLength(211, self.hpss_calls)
908
913
        self.assertLength(2, self.hpss_connections)
909
914
        self.expectFailure("commit still uses VFS calls",
910
 
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
915
                           self.assertThat, self.hpss_calls, ContainsNoVfsCalls)