/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: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

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.
568
570
        del properties['branch-nick']
569
571
        self.assertFalse('bugs' in properties)
570
572
 
 
573
    def test_bugs_sets_property(self):
 
574
        """commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
 
575
        tree = self.make_branch_and_tree('tree')
 
576
        self.build_tree(['tree/hello.txt'])
 
577
        tree.add('hello.txt')
 
578
        self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
 
579
 
 
580
        # Get the revision properties, ignoring the branch-nick property, which
 
581
        # we don't care about for this test.
 
582
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
583
        properties = dict(last_rev.properties)
 
584
        del properties[u'branch-nick']
 
585
 
 
586
        self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
 
587
                         properties)
 
588
 
571
589
    def test_fixes_bug_sets_property(self):
572
590
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
573
591
        tree = self.make_branch_and_tree('tree')
600
618
 
601
619
        self.assertEqual(
602
620
            {u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
603
 
                     'https://launchpad.net/bugs/235 fixed'},
 
621
             'https://launchpad.net/bugs/235 fixed'},
604
622
            properties)
605
623
 
606
624
    def test_fixes_bug_with_alternate_trackers(self):
612
630
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
613
631
        self.build_tree(['tree/hello.txt'])
614
632
        tree.add('hello.txt')
615
 
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
 
633
        self.run_bzr(
 
634
            'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
616
635
 
617
636
        # Get the revision properties, ignoring the branch-nick property, which
618
637
        # we don't care about for this test.
641
660
        tree.add('hello.txt')
642
661
        self.run_bzr_error(
643
662
            ["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."],
 
663
             "'tracker:id' or specify a default bug tracker using the "
 
664
             "`bugtracker` option.\n"
 
665
             "See \"brz help bugs\" for more information on this feature. "
 
666
             "Commit refused."],
648
667
            'commit -m add-b --fixes=123',
649
668
            working_dir='tree')
650
669
        tree.branch.get_config_stack().set("bugtracker", "lp")
681
700
        tree = self.make_branch_and_tree('tree')
682
701
        self.build_tree(['tree/hello.txt'])
683
702
        tree.add('hello.txt')
684
 
        self.run_bzr( 'commit -m hello tree/hello.txt')
 
703
        self.run_bzr('commit -m hello tree/hello.txt')
685
704
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
686
705
        properties = last_rev.properties
687
706
        self.assertFalse('author' in properties)
695
714
        tree.add('hello.txt')
696
715
        self.run_bzr(["commit", '-m', 'hello',
697
716
                      '--author', u'John D\xf6 <jdoe@example.com>',
698
 
                     "tree/hello.txt"])
 
717
                      "tree/hello.txt"])
699
718
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
700
719
        properties = last_rev.properties
701
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
 
720
        self.assertEqual(u'John D\xf6 <jdoe@example.com>',
 
721
                         properties['authors'])
702
722
 
703
723
    def test_author_no_email(self):
704
724
        """Author's name without an email address is allowed, too."""
727
747
        self.build_tree(['tree/hello.txt'])
728
748
        tree.add('hello.txt')
729
749
        out, err = self.run_bzr("commit -m hello "
730
 
            "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
 
750
                                "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
731
751
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
732
752
        self.assertEqual(
733
753
            'Sat 2009-10-10 08:00:00 +0100',
734
754
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
735
 
        
 
755
 
736
756
    def test_commit_time_bad_time(self):
737
757
        tree = self.make_branch_and_tree('tree')
738
758
        self.build_tree(['tree/hello.txt'])
739
759
        tree.add('hello.txt')
740
760
        out, err = self.run_bzr("commit -m hello "
741
 
            "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
 
761
                                "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
742
762
        self.assertStartsWith(
743
763
            err, "brz: ERROR: Could not parse --commit-time:")
744
764
 
747
767
        self.build_tree(['tree/hello.txt'])
748
768
        tree.add('hello.txt')
749
769
        out, err = self.run_bzr("commit -m hello "
750
 
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
 
770
                                "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
751
771
        self.assertStartsWith(
752
772
            err, "brz: ERROR: Could not parse --commit-time:")
753
773
        # Test that it is actually checking and does not simply crash with
780
800
            self.get_readonly_transport('master')).open_branch()
781
801
        master.create_checkout('checkout')
782
802
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
783
 
            retcode=3)
 
803
                                retcode=3)
784
804
        self.assertContainsRe(err,
785
 
            r'^brz: ERROR: Cannot lock.*readonly transport')
 
805
                              r'^brz: ERROR: Cannot lock.*readonly transport')
786
806
 
787
807
    def setup_editor(self):
788
808
        # Test that commit template hooks work
799
819
    def setup_commit_with_template(self):
800
820
        self.setup_editor()
801
821
        msgeditor.hooks.install_named_hook("commit_message_template",
802
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
822
                                           lambda commit_obj, msg: "save me some typing\n", None)
803
823
        tree = self.make_branch_and_tree('tree')
804
824
        self.build_tree(['tree/hello.txt'])
805
825
        tree.add('hello.txt')
811
831
        self.build_tree(['tree/hello.txt'])
812
832
        tree.add('hello.txt')
813
833
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
814
 
            stdin="y\n")
 
834
                                stdin="y\n")
815
835
        self.assertContainsRe(err,
816
 
            "brz: ERROR: Empty commit message specified")
 
836
                              "brz: ERROR: Empty commit message specified")
817
837
 
818
838
    def test_commit_hook_template_accepted(self):
819
839
        tree = self.setup_commit_with_template()
825
845
        tree = self.setup_commit_with_template()
826
846
        expected = tree.last_revision()
827
847
        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")
 
848
                                       " Please specify a commit message with either"
 
849
                                       " --message or --file or leave a blank message"
 
850
                                       " with --message \"\"."],
 
851
                                      "commit tree/hello.txt", stdin="n\n")
832
852
        self.assertEqual(expected, tree.last_revision())
833
853
 
834
854
    def test_set_commit_message(self):
835
855
        msgeditor.hooks.install_named_hook("set_commit_message",
836
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
856
                                           lambda commit_obj, msg: "save me some typing\n", None)
837
857
        tree = self.make_branch_and_tree('tree')
838
858
        self.build_tree(['tree/hello.txt'])
839
859
        tree.add('hello.txt')
852
872
        self.overrideEnv('BRZ_EMAIL', None)
853
873
        # Also, make sure that it's not inferred from mailname.
854
874
        self.overrideAttr(config, '_auto_user_id',
855
 
            lambda: (None, None))
 
875
                          lambda: (None, None))
856
876
        self.run_bzr_error(
857
877
            ['Unable to determine your name'],
858
878
            ['commit', '-m', 'initial'], working_dir='foo')
862
882
        """
863
883
        self.run_bzr(['init', 'test_branch'])
864
884
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
865
 
        self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
 
885
        # bind to self
 
886
        self.run_bzr(['bind', '.'], working_dir='test_checkout')
866
887
        with open('test_checkout/foo.txt', 'w') as f:
867
888
            f.write('hello')
868
889
        self.run_bzr(['add'], working_dir='test_checkout')
894
915
        for count in range(9):
895
916
            t.commit(message='commit %d' % count)
896
917
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
897
 
            'target'])
 
918
                                 'target'])
898
919
        self.reset_smart_call_log()
899
920
        self.build_tree(['target/afile'])
900
921
        self.run_bzr(['add', 'target/afile'])
907
928
        self.assertLength(211, self.hpss_calls)
908
929
        self.assertLength(2, self.hpss_connections)
909
930
        self.expectFailure("commit still uses VFS calls",
910
 
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
931
                           self.assertThat, self.hpss_calls, ContainsNoVfsCalls)