~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    osutils,
30
30
    ignores,
31
31
    msgeditor,
 
32
    tests,
32
33
    )
33
 
from bzrlib.controldir import ControlDir
 
34
from bzrlib.bzrdir import BzrDir
34
35
from bzrlib.tests import (
 
36
    probe_bad_non_ascii,
35
37
    test_foreign,
 
38
    TestSkipped,
36
39
    features,
37
40
    )
38
41
from bzrlib.tests import TestCaseWithTransport
39
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
42
 
41
43
 
42
44
class TestCommit(TestCaseWithTransport):
117
119
    def prepare_simple_history(self):
118
120
        """Prepare and return a working tree with one commit of one file"""
119
121
        # Commit with modified file should say so
120
 
        wt = ControlDir.create_standalone_workingtree('.')
 
122
        wt = BzrDir.create_standalone_workingtree('.')
121
123
        self.build_tree(['hello.txt', 'extra.txt'])
122
124
        wt.add(['hello.txt'])
123
125
        wt.commit(message='added')
139
141
        self.requireFeature(features.UnicodeFilenameFeature)
140
142
        file_name = u'\N{euro sign}'
141
143
        self.run_bzr(['init'])
142
 
        with open(file_name, 'w') as f: f.write('hello world')
 
144
        open(file_name, 'w').write('hello world')
143
145
        self.run_bzr(['add'])
144
146
        out, err = self.run_bzr(['commit', '-m', file_name])
145
147
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
157
159
        try:
158
160
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
159
161
            file_name = u'foo\u1234'
160
 
            with open(file_name, 'w') as f: f.write('hello world')
 
162
            open(file_name, 'w').write('hello world')
161
163
            self.run_bzr(['add'])
162
164
            out, err = self.run_bzr(['commit', '-m', file_name])
163
165
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
168
170
        finally:
169
171
            osutils.get_terminal_encoding = default_get_terminal_enc
170
172
 
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
 
 
191
173
    def test_warn_about_forgotten_commit_message(self):
192
174
        """Test that the lack of -m parameter is caught"""
193
175
        wt = self.make_branch_and_tree('.')
225
207
    def test_verbose_commit_with_unknown(self):
226
208
        """Unknown files should not be listed by default in verbose output"""
227
209
        # Is that really the best policy?
228
 
        wt = ControlDir.create_standalone_workingtree('.')
 
210
        wt = BzrDir.create_standalone_workingtree('.')
229
211
        self.build_tree(['hello.txt', 'extra.txt'])
230
212
        wt.add(['hello.txt'])
231
213
        out,err = self.run_bzr('commit -m added')
328
310
        finally:
329
311
            other_tree.unlock()
330
312
        this_tree.merge_from_branch(other_tree.branch)
331
 
        out, err = self.run_bzr('commit -m added', working_dir='this')
 
313
        os.chdir('this')
 
314
        out,err = self.run_bzr('commit -m added')
332
315
        self.assertEqual('', out)
333
316
        self.assertEqual(set([
334
 
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
 
317
            'Committing to: %s/' % osutils.getcwd(),
335
318
            'modified filetomodify',
336
319
            'added newdir',
337
320
            'added newfile',
349
332
        tree = self.make_branch_and_tree('.')
350
333
        self.build_tree_contents([('foo.c', 'int main() {}')])
351
334
        tree.add('foo.c')
352
 
        self.run_bzr('commit -m ""')
 
335
        self.run_bzr('commit -m ""', retcode=3)
353
336
 
354
337
    def test_other_branch_commit(self):
355
338
        # this branch is to ensure consistent behaviour, whether we're run
471
454
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
472
455
        t.commit('Create')
473
456
        t.remove(['file-a', 'dir-a/file-b'])
474
 
        result = self.run_bzr('commit . -m removed-file-b',
475
 
                              working_dir='dir-a')[1]
 
457
        os.chdir('dir-a')
 
458
        result = self.run_bzr('commit . -m removed-file-b')[1]
476
459
        self.assertNotContainsRe(result, 'file-a')
477
 
        result = self.run_bzr('status', working_dir='dir-a')[0]
 
460
        result = self.run_bzr('status')[0]
478
461
        self.assertContainsRe(result, 'removed:\n  file-a')
479
462
 
480
463
    def test_strict_commit(self):
484
467
        self.build_tree(['tree/a'])
485
468
        tree.add('a')
486
469
        # A simple change should just work
487
 
        self.run_bzr('commit --strict -m adding-a', working_dir='tree')
 
470
        self.run_bzr('commit --strict -m adding-a',
 
471
                     working_dir='tree')
488
472
 
489
473
    def test_strict_commit_no_changes(self):
490
474
        """commit --strict gives "no changes" if there is nothing to commit"""
615
599
            'commit -m add-b --fixes=xxx:123',
616
600
            working_dir='tree')
617
601
 
618
 
    def test_fixes_bug_with_default_tracker(self):
619
 
        """commit --fixes=234 uses the default bug tracker."""
620
 
        tree = self.make_branch_and_tree('tree')
621
 
        self.build_tree(['tree/hello.txt'])
622
 
        tree.add('hello.txt')
623
 
        self.run_bzr_error(
624
 
            ["bzr: ERROR: No tracker specified for bug 123. Use the form "
625
 
            "'tracker:id' or specify a default bug tracker using the "
626
 
            "`bugtracker` option.\n"
627
 
            "See \"bzr help bugs\" for more information on this feature. "
628
 
            "Commit refused."],
629
 
            'commit -m add-b --fixes=123',
630
 
            working_dir='tree')
631
 
        tree.branch.get_config_stack().set("bugtracker", "lp")
632
 
        self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
633
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
634
 
        self.assertEqual('https://launchpad.net/bugs/234 fixed',
635
 
                         last_rev.properties['bugs'])
636
 
 
637
602
    def test_fixes_invalid_bug_number(self):
638
603
        tree = self.make_branch_and_tree('tree')
639
604
        self.build_tree(['tree/hello.txt'])
651
616
        self.build_tree(['tree/hello.txt'])
652
617
        tree.add('hello.txt')
653
618
        self.run_bzr_error(
654
 
            [r"Invalid bug orange:apples:bananas. Must be in the form of "
655
 
             r"'tracker:id'\. See \"bzr help bugs\" for more information on "
656
 
             r"this feature.\nCommit refused\."],
657
 
            'commit -m add-b --fixes=orange:apples:bananas',
 
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',
658
623
            working_dir='tree')
659
624
 
660
625
    def test_no_author(self):
713
678
        self.assertEqual(
714
679
            'Sat 2009-10-10 08:00:00 +0100',
715
680
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
716
 
 
717
 
    def test_commit_time_negative_windows(self):
718
 
        tree = self.make_branch_and_tree('tree')
719
 
        self.build_tree(['tree/hello.txt'])
720
 
        tree.add('hello.txt')
721
 
        out, err = self.run_bzr("commit -m hello "
722
 
            "--commit-time='1969-10-10 00:00:00 +0000' tree/hello.txt")
723
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
724
 
        self.assertEqual(
725
 
            'Fri 1969-10-10 00:00:00 +0000',
726
 
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
727
 
 
728
 
    def test_commit_time_negative_32bit(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='1900-01-01 00:00:00 +0000' tree/hello.txt")
734
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
735
 
        self.assertEqual(
736
 
            'Mon 1900-01-01 00:00:00 +0000',
737
 
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
738
 
 
739
 
    def test_commit_time_positive_32bit(self):
740
 
        tree = self.make_branch_and_tree('tree')
741
 
        self.build_tree(['tree/hello.txt'])
742
 
        tree.add('hello.txt')
743
 
        out, err = self.run_bzr("commit -m hello "
744
 
            "--commit-time='2039-01-01 00:00:00 +0000' tree/hello.txt")
745
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
746
 
        self.assertEqual(
747
 
            'Sat 2039-01-01 00:00:00 +0000',
748
 
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
749
 
 
 
681
        
750
682
    def test_commit_time_bad_time(self):
751
683
        tree = self.make_branch_and_tree('tree')
752
684
        self.build_tree(['tree/hello.txt'])
756
688
        self.assertStartsWith(
757
689
            err, "bzr: ERROR: Could not parse --commit-time:")
758
690
 
759
 
    def test_commit_time_missing_tz(self):
760
 
        tree = self.make_branch_and_tree('tree')
761
 
        self.build_tree(['tree/hello.txt'])
762
 
        tree.add('hello.txt')
763
 
        out, err = self.run_bzr("commit -m hello "
764
 
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
765
 
        self.assertStartsWith(
766
 
            err, "bzr: ERROR: Could not parse --commit-time:")
767
 
        # Test that it is actually checking and does not simply crash with
768
 
        # some other exception
769
 
        self.assertContainsString(err, "missing a timezone offset")
770
 
 
771
691
    def test_partial_commit_with_renames_in_tree(self):
772
692
        # this test illustrates bug #140419
773
693
        t = self.make_branch_and_tree('.')
782
702
        self.build_tree_contents([('test', 'changes in test')])
783
703
        # partial commit
784
704
        out, err = self.run_bzr('commit test -m "partial commit"')
785
 
        self.assertEqual('', out)
 
705
        self.assertEquals('', out)
786
706
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
787
707
 
788
708
    def test_commit_readonly_checkout(self):
790
710
        # "UnlockableTransport error trying to commit in checkout of readonly
791
711
        # branch"
792
712
        self.make_branch('master')
793
 
        master = ControlDir.open_from_transport(
 
713
        master = BzrDir.open_from_transport(
794
714
            self.get_readonly_transport('master')).open_branch()
795
715
        master.create_checkout('checkout')
796
716
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
821
741
        tree.add('hello.txt')
822
742
        return tree
823
743
 
824
 
    def test_edit_empty_message(self):
825
 
        tree = self.make_branch_and_tree('tree')
826
 
        self.setup_editor()
827
 
        self.build_tree(['tree/hello.txt'])
828
 
        tree.add('hello.txt')
829
 
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
830
 
            stdin="y\n")
831
 
        self.assertContainsRe(err,
832
 
            "bzr: ERROR: Empty commit message specified")
833
 
 
834
744
    def test_commit_hook_template_accepted(self):
835
745
        tree = self.setup_commit_with_template()
836
746
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
861
771
        """Ensure commit error if username is not set.
862
772
        """
863
773
        self.run_bzr(['init', 'foo'])
864
 
        with open('foo/foo.txt', 'w') as f:
865
 
            f.write('hello')
866
 
        self.run_bzr(['add'], working_dir='foo')
 
774
        os.chdir('foo')
 
775
        open('foo.txt', 'w').write('hello')
 
776
        self.run_bzr(['add'])
867
777
        self.overrideEnv('EMAIL', None)
868
778
        self.overrideEnv('BZR_EMAIL', None)
869
779
        # Also, make sure that it's not inferred from mailname.
870
780
        self.overrideAttr(config, '_auto_user_id',
871
781
            lambda: (None, None))
872
 
        self.run_bzr_error(
873
 
            ['Unable to determine your name'],
874
 
            ['commit', '-m', 'initial'], working_dir='foo')
 
782
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
 
783
        self.assertContainsRe(err, 'Unable to determine your name')
875
784
 
876
785
    def test_commit_recursive_checkout(self):
877
786
        """Ensure that a commit to a recursive checkout fails cleanly.
878
787
        """
879
788
        self.run_bzr(['init', 'test_branch'])
880
789
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
881
 
        self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
882
 
        with open('test_checkout/foo.txt', 'w') as f:
883
 
            f.write('hello')
884
 
        self.run_bzr(['add'], working_dir='test_checkout')
885
 
        out, err = self.run_bzr_error(
886
 
            ['Branch.*test_checkout.*appears to be bound to itself'],
887
 
            ['commit', '-m', 'addedfoo'], working_dir='test_checkout')
888
 
 
889
 
    def test_mv_dirs_non_ascii(self):
890
 
        """Move directory with non-ascii name and containing files.
891
 
 
892
 
        Regression test for bug 185211.
893
 
        """
894
 
        tree = self.make_branch_and_tree('.')
895
 
        self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
896
 
 
897
 
        tree.add([u'abc\xa7/', u'abc\xa7/foo'])
898
 
        tree.commit('checkin')
899
 
 
900
 
        tree.rename_one(u'abc\xa7','abc')
901
 
 
902
 
        self.run_bzr('ci -m "non-ascii mv"')
903
 
 
904
 
 
905
 
class TestSmartServerCommit(TestCaseWithTransport):
906
 
 
907
 
    def test_commit_to_lightweight(self):
908
 
        self.setup_smart_server_with_call_log()
909
 
        t = self.make_branch_and_tree('from')
910
 
        for count in range(9):
911
 
            t.commit(message='commit %d' % count)
912
 
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
913
 
            'target'])
914
 
        self.reset_smart_call_log()
915
 
        self.build_tree(['target/afile'])
916
 
        self.run_bzr(['add', 'target/afile'])
917
 
        out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
918
 
        # This figure represent the amount of work to perform this use case. It
919
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
920
 
        # being too low. If rpc_count increases, more network roundtrips have
921
 
        # become necessary for this use case. Please do not adjust this number
922
 
        # upwards without agreement from bzr's network support maintainers.
923
 
        self.assertLength(211, self.hpss_calls)
924
 
        self.assertLength(2, self.hpss_connections)
925
 
        self.expectFailure("commit still uses VFS calls",
926
 
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
790
        os.chdir('test_checkout')
 
791
        self.run_bzr(['bind', '.']) # bind to self
 
792
        open('foo.txt', 'w').write('hello')
 
793
        self.run_bzr(['add'])
 
794
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
 
795
        self.assertEqual(out, '')
 
796
        self.assertContainsRe(err,
 
797
            'Branch.*test_checkout.*appears to be bound to itself')