~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
30
30
    ignores,
31
31
    msgeditor,
32
32
    )
33
 
from bzrlib.bzrdir import BzrDir
 
33
from bzrlib.controldir import ControlDir
34
34
from bzrlib.tests import (
35
35
    test_foreign,
36
36
    features,
37
37
    )
38
38
from bzrlib.tests import TestCaseWithTransport
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
39
40
 
40
41
 
41
42
class TestCommit(TestCaseWithTransport):
116
117
    def prepare_simple_history(self):
117
118
        """Prepare and return a working tree with one commit of one file"""
118
119
        # Commit with modified file should say so
119
 
        wt = BzrDir.create_standalone_workingtree('.')
 
120
        wt = ControlDir.create_standalone_workingtree('.')
120
121
        self.build_tree(['hello.txt', 'extra.txt'])
121
122
        wt.add(['hello.txt'])
122
123
        wt.commit(message='added')
138
139
        self.requireFeature(features.UnicodeFilenameFeature)
139
140
        file_name = u'\N{euro sign}'
140
141
        self.run_bzr(['init'])
141
 
        open(file_name, 'w').write('hello world')
 
142
        with open(file_name, 'w') as f: f.write('hello world')
142
143
        self.run_bzr(['add'])
143
144
        out, err = self.run_bzr(['commit', '-m', file_name])
144
145
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
156
157
        try:
157
158
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
158
159
            file_name = u'foo\u1234'
159
 
            open(file_name, 'w').write('hello world')
 
160
            with open(file_name, 'w') as f: f.write('hello world')
160
161
            self.run_bzr(['add'])
161
162
            out, err = self.run_bzr(['commit', '-m', file_name])
162
163
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
167
168
        finally:
168
169
            osutils.get_terminal_encoding = default_get_terminal_enc
169
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
 
170
191
    def test_warn_about_forgotten_commit_message(self):
171
192
        """Test that the lack of -m parameter is caught"""
172
193
        wt = self.make_branch_and_tree('.')
204
225
    def test_verbose_commit_with_unknown(self):
205
226
        """Unknown files should not be listed by default in verbose output"""
206
227
        # Is that really the best policy?
207
 
        wt = BzrDir.create_standalone_workingtree('.')
 
228
        wt = ControlDir.create_standalone_workingtree('.')
208
229
        self.build_tree(['hello.txt', 'extra.txt'])
209
230
        wt.add(['hello.txt'])
210
231
        out,err = self.run_bzr('commit -m added')
307
328
        finally:
308
329
            other_tree.unlock()
309
330
        this_tree.merge_from_branch(other_tree.branch)
310
 
        os.chdir('this')
311
 
        out,err = self.run_bzr('commit -m added')
 
331
        out, err = self.run_bzr('commit -m added', working_dir='this')
312
332
        self.assertEqual('', out)
313
333
        self.assertEqual(set([
314
 
            'Committing to: %s/' % osutils.getcwd(),
 
334
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
315
335
            'modified filetomodify',
316
336
            'added newdir',
317
337
            'added newfile',
451
471
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
452
472
        t.commit('Create')
453
473
        t.remove(['file-a', 'dir-a/file-b'])
454
 
        os.chdir('dir-a')
455
 
        result = self.run_bzr('commit . -m removed-file-b')[1]
 
474
        result = self.run_bzr('commit . -m removed-file-b',
 
475
                              working_dir='dir-a')[1]
456
476
        self.assertNotContainsRe(result, 'file-a')
457
 
        result = self.run_bzr('status')[0]
 
477
        result = self.run_bzr('status', working_dir='dir-a')[0]
458
478
        self.assertContainsRe(result, 'removed:\n  file-a')
459
479
 
460
480
    def test_strict_commit(self):
464
484
        self.build_tree(['tree/a'])
465
485
        tree.add('a')
466
486
        # A simple change should just work
467
 
        self.run_bzr('commit --strict -m adding-a',
468
 
                     working_dir='tree')
 
487
        self.run_bzr('commit --strict -m adding-a', working_dir='tree')
469
488
 
470
489
    def test_strict_commit_no_changes(self):
471
490
        """commit --strict gives "no changes" if there is nothing to commit"""
609
628
            "Commit refused."],
610
629
            'commit -m add-b --fixes=123',
611
630
            working_dir='tree')
612
 
        tree.branch.get_config().set_user_option("bugtracker", "lp")
 
631
        tree.branch.get_config_stack().set("bugtracker", "lp")
613
632
        self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
614
633
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
615
634
        self.assertEqual('https://launchpad.net/bugs/234 fixed',
704
723
        self.assertStartsWith(
705
724
            err, "bzr: ERROR: Could not parse --commit-time:")
706
725
 
 
726
    def test_commit_time_missing_tz(self):
 
727
        tree = self.make_branch_and_tree('tree')
 
728
        self.build_tree(['tree/hello.txt'])
 
729
        tree.add('hello.txt')
 
730
        out, err = self.run_bzr("commit -m hello "
 
731
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
 
732
        self.assertStartsWith(
 
733
            err, "bzr: ERROR: Could not parse --commit-time:")
 
734
        # Test that it is actually checking and does not simply crash with
 
735
        # some other exception
 
736
        self.assertContainsString(err, "missing a timezone offset")
 
737
 
707
738
    def test_partial_commit_with_renames_in_tree(self):
708
739
        # this test illustrates bug #140419
709
740
        t = self.make_branch_and_tree('.')
718
749
        self.build_tree_contents([('test', 'changes in test')])
719
750
        # partial commit
720
751
        out, err = self.run_bzr('commit test -m "partial commit"')
721
 
        self.assertEquals('', out)
 
752
        self.assertEqual('', out)
722
753
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
723
754
 
724
755
    def test_commit_readonly_checkout(self):
726
757
        # "UnlockableTransport error trying to commit in checkout of readonly
727
758
        # branch"
728
759
        self.make_branch('master')
729
 
        master = BzrDir.open_from_transport(
 
760
        master = ControlDir.open_from_transport(
730
761
            self.get_readonly_transport('master')).open_branch()
731
762
        master.create_checkout('checkout')
732
763
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
797
828
        """Ensure commit error if username is not set.
798
829
        """
799
830
        self.run_bzr(['init', 'foo'])
800
 
        os.chdir('foo')
801
 
        open('foo.txt', 'w').write('hello')
802
 
        self.run_bzr(['add'])
 
831
        with open('foo/foo.txt', 'w') as f:
 
832
            f.write('hello')
 
833
        self.run_bzr(['add'], working_dir='foo')
803
834
        self.overrideEnv('EMAIL', None)
804
835
        self.overrideEnv('BZR_EMAIL', None)
805
836
        # Also, make sure that it's not inferred from mailname.
806
837
        self.overrideAttr(config, '_auto_user_id',
807
838
            lambda: (None, None))
808
 
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
809
 
        self.assertContainsRe(err, 'Unable to determine your name')
 
839
        self.run_bzr_error(
 
840
            ['Unable to determine your name'],
 
841
            ['commit', '-m', 'initial'], working_dir='foo')
810
842
 
811
843
    def test_commit_recursive_checkout(self):
812
844
        """Ensure that a commit to a recursive checkout fails cleanly.
813
845
        """
814
846
        self.run_bzr(['init', 'test_branch'])
815
847
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
816
 
        os.chdir('test_checkout')
817
 
        self.run_bzr(['bind', '.']) # bind to self
818
 
        open('foo.txt', 'w').write('hello')
819
 
        self.run_bzr(['add'])
820
 
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
821
 
        self.assertEqual(out, '')
822
 
        self.assertContainsRe(err,
823
 
            'Branch.*test_checkout.*appears to be bound to itself')
 
848
        self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
 
849
        with open('test_checkout/foo.txt', 'w') as f:
 
850
            f.write('hello')
 
851
        self.run_bzr(['add'], working_dir='test_checkout')
 
852
        out, err = self.run_bzr_error(
 
853
            ['Branch.*test_checkout.*appears to be bound to itself'],
 
854
            ['commit', '-m', 'addedfoo'], working_dir='test_checkout')
 
855
 
 
856
    def test_mv_dirs_non_ascii(self):
 
857
        """Move directory with non-ascii name and containing files.
 
858
 
 
859
        Regression test for bug 185211.
 
860
        """
 
861
        tree = self.make_branch_and_tree('.')
 
862
        self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
 
863
 
 
864
        tree.add([u'abc\xa7/', u'abc\xa7/foo'])
 
865
        tree.commit('checkin')
 
866
 
 
867
        tree.rename_one(u'abc\xa7','abc')
 
868
 
 
869
        self.run_bzr('ci -m "non-ascii mv"')
 
870
 
 
871
 
 
872
class TestSmartServerCommit(TestCaseWithTransport):
 
873
 
 
874
    def test_commit_to_lightweight(self):
 
875
        self.setup_smart_server_with_call_log()
 
876
        t = self.make_branch_and_tree('from')
 
877
        for count in range(9):
 
878
            t.commit(message='commit %d' % count)
 
879
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
 
880
            'target'])
 
881
        self.reset_smart_call_log()
 
882
        self.build_tree(['target/afile'])
 
883
        self.run_bzr(['add', 'target/afile'])
 
884
        out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
 
885
        # This figure represent the amount of work to perform this use case. It
 
886
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
887
        # being too low. If rpc_count increases, more network roundtrips have
 
888
        # become necessary for this use case. Please do not adjust this number
 
889
        # upwards without agreement from bzr's network support maintainers.
 
890
        self.assertLength(211, self.hpss_calls)
 
891
        self.assertLength(2, self.hpss_connections)
 
892
        self.expectFailure("commit still uses VFS calls",
 
893
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)