~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: 2009-10-13 06:08:53 UTC
  • mfrom: (4737.1.1 merge-2.0-into-devel)
  • Revision ID: pqm@pqm.ubuntu.com-20091013060853-erk2aaj80fnkrv25
(andrew) Merge lp:bzr/2.0 into lp:bzr, including fixes for #322807,
        #389413, #402623 and documentation improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 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
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
 
import doctest
21
20
import os
22
 
import re
23
21
import sys
24
22
 
25
 
from testtools.matchers import DocTestMatches
26
 
 
27
23
from bzrlib import (
28
 
    config,
29
24
    osutils,
30
25
    ignores,
31
26
    msgeditor,
 
27
    osutils,
32
28
    )
33
 
from bzrlib.controldir import ControlDir
 
29
from bzrlib.bzrdir import BzrDir
34
30
from bzrlib.tests import (
35
 
    test_foreign,
36
 
    features,
 
31
    probe_bad_non_ascii,
 
32
    TestSkipped,
37
33
    )
38
 
from bzrlib.tests import TestCaseWithTransport
39
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
 
 
41
 
 
42
 
class TestCommit(TestCaseWithTransport):
 
34
from bzrlib.tests.blackbox import ExternalBase
 
35
 
 
36
 
 
37
class TestCommit(ExternalBase):
43
38
 
44
39
    def test_05_empty_commit(self):
45
40
        """Commit of tree with no versioned files should fail"""
48
43
        self.build_tree(['hello.txt'])
49
44
        out,err = self.run_bzr('commit -m empty', retcode=3)
50
45
        self.assertEqual('', out)
51
 
        # Two ugly bits here.
52
 
        # 1) We really don't want 'aborting commit write group' anymore.
53
 
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
54
 
        self.assertThat(
55
 
            err,
56
 
            DocTestMatches("""\
57
 
Committing to: ...
58
 
bzr: ERROR: No changes to commit.\
59
 
 Please 'bzr add' the files you want to commit,\
60
 
 or use --unchanged to force an empty commit.
61
 
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
 
46
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
 
47
                                  ' Use --unchanged to commit anyhow.\n')
62
48
 
63
49
    def test_commit_success(self):
64
50
        """Successful commit should not leave behind a bzr-commit-* file"""
70
56
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
71
57
        self.assertEqual('', self.run_bzr('unknowns')[0])
72
58
 
73
 
    def test_commit_lossy_native(self):
74
 
        """A --lossy option to commit is supported."""
75
 
        self.make_branch_and_tree('.')
76
 
        self.run_bzr('commit --lossy --unchanged -m message')
77
 
        self.assertEqual('', self.run_bzr('unknowns')[0])
78
 
 
79
 
    def test_commit_lossy_foreign(self):
80
 
        test_foreign.register_dummy_foreign_for_test(self)
81
 
        self.make_branch_and_tree('.',
82
 
            format=test_foreign.DummyForeignVcsDirFormat())
83
 
        self.run_bzr('commit --lossy --unchanged -m message')
84
 
        output = self.run_bzr('revision-info')[0]
85
 
        self.assertTrue(output.startswith('1 dummy-'))
86
 
 
87
59
    def test_commit_with_path(self):
88
60
        """Commit tree with path of root specified"""
89
61
        a_tree = self.make_branch_and_tree('a')
103
75
        self.run_bzr('resolved b/a_file')
104
76
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
105
77
 
 
78
 
106
79
    def test_10_verbose_commit(self):
107
80
        """Add one file and examine verbose commit output"""
108
81
        tree = self.make_branch_and_tree('.')
117
90
    def prepare_simple_history(self):
118
91
        """Prepare and return a working tree with one commit of one file"""
119
92
        # Commit with modified file should say so
120
 
        wt = ControlDir.create_standalone_workingtree('.')
 
93
        wt = BzrDir.create_standalone_workingtree('.')
121
94
        self.build_tree(['hello.txt', 'extra.txt'])
122
95
        wt.add(['hello.txt'])
123
96
        wt.commit(message='added')
133
106
                              'modified hello\.txt\n'
134
107
                              'Committed revision 2\.\n$')
135
108
 
136
 
    def test_unicode_commit_message_is_filename(self):
137
 
        """Unicode commit message same as a filename (Bug #563646).
138
 
        """
139
 
        self.requireFeature(features.UnicodeFilenameFeature)
140
 
        file_name = u'\N{euro sign}'
141
 
        self.run_bzr(['init'])
142
 
        with open(file_name, 'w') as f: f.write('hello world')
143
 
        self.run_bzr(['add'])
144
 
        out, err = self.run_bzr(['commit', '-m', file_name])
145
 
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
146
 
        te = osutils.get_terminal_encoding()
147
 
        self.assertContainsRe(err.decode(te),
148
 
            u'The commit message is a file name:',
149
 
            flags=reflags)
150
 
 
151
 
        # Run same test with a filename that causes encode
152
 
        # error for the terminal encoding. We do this
153
 
        # by forcing terminal encoding of ascii for
154
 
        # osutils.get_terminal_encoding which is used
155
 
        # by ui.text.show_warning
156
 
        default_get_terminal_enc = osutils.get_terminal_encoding
157
 
        try:
158
 
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
159
 
            file_name = u'foo\u1234'
160
 
            with open(file_name, 'w') as f: f.write('hello world')
161
 
            self.run_bzr(['add'])
162
 
            out, err = self.run_bzr(['commit', '-m', file_name])
163
 
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
164
 
            te = osutils.get_terminal_encoding()
165
 
            self.assertContainsRe(err.decode(te, 'replace'),
166
 
                u'The commit message is a file name:',
167
 
                flags=reflags)
168
 
        finally:
169
 
            osutils.get_terminal_encoding = default_get_terminal_enc
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
 
 
191
 
    def test_warn_about_forgotten_commit_message(self):
192
 
        """Test that the lack of -m parameter is caught"""
193
 
        wt = self.make_branch_and_tree('.')
194
 
        self.build_tree(['one', 'two'])
195
 
        wt.add(['two'])
196
 
        out, err = self.run_bzr('commit -m one two')
197
 
        self.assertContainsRe(err, "The commit message is a file name")
198
 
 
199
109
    def test_verbose_commit_renamed(self):
200
110
        # Verbose commit of renamed file should say so
201
111
        wt = self.prepare_simple_history()
225
135
    def test_verbose_commit_with_unknown(self):
226
136
        """Unknown files should not be listed by default in verbose output"""
227
137
        # Is that really the best policy?
228
 
        wt = ControlDir.create_standalone_workingtree('.')
 
138
        wt = BzrDir.create_standalone_workingtree('.')
229
139
        self.build_tree(['hello.txt', 'extra.txt'])
230
140
        wt.add(['hello.txt'])
231
141
        out,err = self.run_bzr('commit -m added')
260
170
        self.assertEqual(err, 'Committing to: %s\n'
261
171
                         'Committed revision 2.\n' % expected)
262
172
 
263
 
    def test_commit_sanitizes_CR_in_message(self):
264
 
        # See bug #433779, basically Emacs likes to pass '\r\n' style line
265
 
        # endings to 'bzr commit -m ""' which breaks because we don't allow
266
 
        # '\r' in commit messages. (Mostly because of issues where XML style
267
 
        # formats arbitrarily strip it out of the data while parsing.)
268
 
        # To make life easier for users, we just always translate '\r\n' =>
269
 
        # '\n'. And '\r' => '\n'.
270
 
        a_tree = self.make_branch_and_tree('a')
271
 
        self.build_tree(['a/b'])
272
 
        a_tree.add('b')
273
 
        self.run_bzr(['commit',
274
 
                      '-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
275
 
                     working_dir='a')
276
 
        rev_id = a_tree.branch.last_revision()
277
 
        rev = a_tree.branch.repository.get_revision(rev_id)
278
 
        self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
279
 
                             rev.message)
280
 
 
281
173
    def test_commit_merge_reports_all_modified_files(self):
282
174
        # the commit command should show all the files that are shown by
283
175
        # bzr diff or bzr status when committing, even when they were not
328
220
        finally:
329
221
            other_tree.unlock()
330
222
        this_tree.merge_from_branch(other_tree.branch)
331
 
        out, err = self.run_bzr('commit -m added', working_dir='this')
 
223
        os.chdir('this')
 
224
        out,err = self.run_bzr('commit -m added')
332
225
        self.assertEqual('', out)
333
226
        self.assertEqual(set([
334
 
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
 
227
            'Committing to: %s/' % osutils.getcwd(),
335
228
            'modified filetomodify',
336
229
            'added newdir',
337
230
            'added newfile',
349
242
        tree = self.make_branch_and_tree('.')
350
243
        self.build_tree_contents([('foo.c', 'int main() {}')])
351
244
        tree.add('foo.c')
352
 
        self.run_bzr('commit -m ""')
 
245
        self.run_bzr('commit -m ""', retcode=3)
 
246
 
 
247
    def test_unsupported_encoding_commit_message(self):
 
248
        tree = self.make_branch_and_tree('.')
 
249
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
250
        tree.add('foo.c')
 
251
        # LANG env variable has no effect on Windows
 
252
        # but some characters anyway cannot be represented
 
253
        # in default user encoding
 
254
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
255
        if char is None:
 
256
            raise TestSkipped('Cannot find suitable non-ascii character'
 
257
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
258
        # TODO: jam 2009-07-23 This test seems to fail on Windows now. My best
 
259
        #       guess is that the change to use Unicode command lines means
 
260
        #       that we no longer pay any attention to LANG=C when decoding the
 
261
        #       commandline arguments.
 
262
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
 
263
                                          retcode=1,
 
264
                                          env_changes={'LANG': 'C'})
 
265
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
 
266
                                    'unsupported by the current encoding.')
353
267
 
354
268
    def test_other_branch_commit(self):
355
269
        # this branch is to ensure consistent behaviour, whether we're run
403
317
        trunk = self.make_branch_and_tree('trunk')
404
318
 
405
319
        u1 = trunk.branch.create_checkout('u1')
406
 
        self.build_tree_contents([('u1/hosts', 'initial contents\n')])
 
320
        self.build_tree_contents([('u1/hosts', 'initial contents')])
407
321
        u1.add('hosts')
408
322
        self.run_bzr('commit -m add-hosts u1')
409
323
 
410
324
        u2 = trunk.branch.create_checkout('u2')
411
 
        self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
 
325
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
412
326
        self.run_bzr('commit -m checkin-from-u2 u2')
413
327
 
414
328
        # make an offline commits
415
 
        self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
 
329
        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
416
330
        self.run_bzr('commit -m checkin-offline --local u1')
417
331
 
418
332
        # now try to pull in online work from u2, and then commit our offline
419
333
        # work as a merge
420
334
        # retcode 1 as we expect a text conflict
421
335
        self.run_bzr('update u1', retcode=1)
422
 
        self.assertFileEqual('''\
423
 
<<<<<<< TREE
424
 
first offline change in u1
425
 
=======
426
 
altered in u2
427
 
>>>>>>> MERGE-SOURCE
428
 
''',
429
 
                             'u1/hosts')
430
 
 
431
336
        self.run_bzr('resolved u1/hosts')
432
337
        # add a text change here to represent resolving the merge conflicts in
433
338
        # favour of a new version of the file not identical to either the u1
471
376
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
472
377
        t.commit('Create')
473
378
        t.remove(['file-a', 'dir-a/file-b'])
474
 
        result = self.run_bzr('commit . -m removed-file-b',
475
 
                              working_dir='dir-a')[1]
 
379
        os.chdir('dir-a')
 
380
        result = self.run_bzr('commit . -m removed-file-b')[1]
476
381
        self.assertNotContainsRe(result, 'file-a')
477
 
        result = self.run_bzr('status', working_dir='dir-a')[0]
 
382
        result = self.run_bzr('status')[0]
478
383
        self.assertContainsRe(result, 'removed:\n  file-a')
479
384
 
480
385
    def test_strict_commit(self):
484
389
        self.build_tree(['tree/a'])
485
390
        tree.add('a')
486
391
        # A simple change should just work
487
 
        self.run_bzr('commit --strict -m adding-a', working_dir='tree')
 
392
        self.run_bzr('commit --strict -m adding-a',
 
393
                     working_dir='tree')
488
394
 
489
395
    def test_strict_commit_no_changes(self):
490
396
        """commit --strict gives "no changes" if there is nothing to commit"""
615
521
            'commit -m add-b --fixes=xxx:123',
616
522
            working_dir='tree')
617
523
 
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
524
    def test_fixes_invalid_bug_number(self):
638
525
        tree = self.make_branch_and_tree('tree')
639
526
        self.build_tree(['tree/hello.txt'])
651
538
        self.build_tree(['tree/hello.txt'])
652
539
        tree.add('hello.txt')
653
540
        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',
 
541
            [r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
 
542
             r"See \"bzr help bugs\" for more information on this feature.\n"
 
543
             r"Commit refused\."],
 
544
            'commit -m add-b --fixes=orange',
658
545
            working_dir='tree')
659
546
 
660
547
    def test_no_author(self):
703
590
        properties = last_rev.properties
704
591
        self.assertEqual('John Doe\nJane Rey', properties['authors'])
705
592
 
706
 
    def test_commit_time(self):
707
 
        tree = self.make_branch_and_tree('tree')
708
 
        self.build_tree(['tree/hello.txt'])
709
 
        tree.add('hello.txt')
710
 
        out, err = self.run_bzr("commit -m hello "
711
 
            "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
712
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
713
 
        self.assertEqual(
714
 
            'Sat 2009-10-10 08:00:00 +0100',
715
 
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
716
 
        
717
 
    def test_commit_time_bad_time(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='NOT A TIME' tree/hello.txt", retcode=3)
723
 
        self.assertStartsWith(
724
 
            err, "bzr: ERROR: Could not parse --commit-time:")
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
 
 
738
593
    def test_partial_commit_with_renames_in_tree(self):
739
594
        # this test illustrates bug #140419
740
595
        t = self.make_branch_and_tree('.')
753
608
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
754
609
 
755
610
    def test_commit_readonly_checkout(self):
756
 
        # https://bugs.launchpad.net/bzr/+bug/129701
 
611
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
757
612
        # "UnlockableTransport error trying to commit in checkout of readonly
758
613
        # branch"
759
614
        self.make_branch('master')
760
 
        master = ControlDir.open_from_transport(
 
615
        master = BzrDir.open_from_transport(
761
616
            self.get_readonly_transport('master')).open_branch()
762
617
        master.create_checkout('checkout')
763
618
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
765
620
        self.assertContainsRe(err,
766
621
            r'^bzr: ERROR: Cannot lock.*readonly transport')
767
622
 
768
 
    def setup_editor(self):
 
623
    def test_commit_hook_template(self):
769
624
        # Test that commit template hooks work
 
625
        def restoreDefaults():
 
626
            msgeditor.hooks['commit_message_template'] = []
 
627
            osutils.set_or_unset_env('BZR_EDITOR', default_editor)
770
628
        if sys.platform == "win32":
771
629
            f = file('fed.bat', 'w')
772
630
            f.write('@rem dummy fed')
773
631
            f.close()
774
 
            self.overrideEnv('BZR_EDITOR', "fed.bat")
 
632
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
775
633
        else:
776
634
            f = file('fed.sh', 'wb')
777
635
            f.write('#!/bin/sh\n')
778
636
            f.close()
779
637
            os.chmod('fed.sh', 0755)
780
 
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
781
 
 
782
 
    def setup_commit_with_template(self):
783
 
        self.setup_editor()
 
638
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
639
        self.addCleanup(restoreDefaults)
784
640
        msgeditor.hooks.install_named_hook("commit_message_template",
785
641
                lambda commit_obj, msg: "save me some typing\n", None)
786
642
        tree = self.make_branch_and_tree('tree')
787
643
        self.build_tree(['tree/hello.txt'])
788
644
        tree.add('hello.txt')
789
 
        return tree
790
 
 
791
 
    def test_edit_empty_message(self):
792
 
        tree = self.make_branch_and_tree('tree')
793
 
        self.setup_editor()
794
 
        self.build_tree(['tree/hello.txt'])
795
 
        tree.add('hello.txt')
796
 
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
797
 
            stdin="y\n")
798
 
        self.assertContainsRe(err,
799
 
            "bzr: ERROR: Empty commit message specified")
800
 
 
801
 
    def test_commit_hook_template_accepted(self):
802
 
        tree = self.setup_commit_with_template()
803
 
        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
804
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
805
 
        self.assertEqual('save me some typing\n', last_rev.message)
806
 
 
807
 
    def test_commit_hook_template_rejected(self):
808
 
        tree = self.setup_commit_with_template()
809
 
        expected = tree.last_revision()
810
 
        out, err = self.run_bzr_error(["Empty commit message specified."
811
 
                  " Please specify a commit message with either"
812
 
                  " --message or --file or leave a blank message"
813
 
                  " with --message \"\"."],
814
 
            "commit tree/hello.txt", stdin="n\n")
815
 
        self.assertEqual(expected, tree.last_revision())
816
 
 
817
 
    def test_set_commit_message(self):
818
 
        msgeditor.hooks.install_named_hook("set_commit_message",
819
 
                lambda commit_obj, msg: "save me some typing\n", None)
820
 
        tree = self.make_branch_and_tree('tree')
821
 
        self.build_tree(['tree/hello.txt'])
822
 
        tree.add('hello.txt')
823
645
        out, err = self.run_bzr("commit tree/hello.txt")
824
646
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
825
647
        self.assertEqual('save me some typing\n', last_rev.message)
826
 
 
827
 
    def test_commit_without_username(self):
828
 
        """Ensure commit error if username is not set.
829
 
        """
830
 
        self.run_bzr(['init', 'foo'])
831
 
        with open('foo/foo.txt', 'w') as f:
832
 
            f.write('hello')
833
 
        self.run_bzr(['add'], working_dir='foo')
834
 
        self.overrideEnv('EMAIL', None)
835
 
        self.overrideEnv('BZR_EMAIL', None)
836
 
        # Also, make sure that it's not inferred from mailname.
837
 
        self.overrideAttr(config, '_auto_user_id',
838
 
            lambda: (None, None))
839
 
        self.run_bzr_error(
840
 
            ['Unable to determine your name'],
841
 
            ['commit', '-m', 'initial'], working_dir='foo')
842
 
 
843
 
    def test_commit_recursive_checkout(self):
844
 
        """Ensure that a commit to a recursive checkout fails cleanly.
845
 
        """
846
 
        self.run_bzr(['init', 'test_branch'])
847
 
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
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)