/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 bzrlib/tests/blackbox/test_commit.py

  • Committer: A. S. Budden
  • Date: 2011-05-04 13:26:14 UTC
  • mto: (5816.6.16 bazaar_source)
  • mto: This revision was merged to the branch mainline in revision 5835.
  • Revision ID: abudden@gmail.com-20110504132614-3ghb1ajucl6plc5z
Set the parent location of the bound branch to that of the master branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
 
20
import doctest
20
21
import os
21
22
import re
22
23
import sys
23
24
 
 
25
from testtools.matchers import DocTestMatches
 
26
 
24
27
from bzrlib import (
 
28
    config,
25
29
    osutils,
26
30
    ignores,
27
31
    msgeditor,
28
 
    osutils,
29
32
    tests,
30
33
    )
31
34
from bzrlib.bzrdir import BzrDir
32
35
from bzrlib.tests import (
33
36
    probe_bad_non_ascii,
 
37
    test_foreign,
34
38
    TestSkipped,
 
39
    UnicodeFilenameFeature,
35
40
    )
36
 
from bzrlib.tests.blackbox import ExternalBase
37
 
 
38
 
 
39
 
class TestCommit(ExternalBase):
 
41
from bzrlib.tests import TestCaseWithTransport
 
42
 
 
43
 
 
44
class TestCommit(TestCaseWithTransport):
40
45
 
41
46
    def test_05_empty_commit(self):
42
47
        """Commit of tree with no versioned files should fail"""
45
50
        self.build_tree(['hello.txt'])
46
51
        out,err = self.run_bzr('commit -m empty', retcode=3)
47
52
        self.assertEqual('', out)
48
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
49
 
                                  ' Use --unchanged to commit anyhow.\n')
 
53
        # Two ugly bits here.
 
54
        # 1) We really don't want 'aborting commit write group' anymore.
 
55
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
 
56
        self.assertThat(
 
57
            err,
 
58
            DocTestMatches("""\
 
59
Committing to: ...
 
60
aborting commit write group: PointlessCommit(No changes to commit)
 
61
bzr: ERROR: No changes to commit.\
 
62
 Please 'bzr add' the files you want to commit,\
 
63
 or use --unchanged to force an empty commit.
 
64
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
50
65
 
51
66
    def test_commit_success(self):
52
67
        """Successful commit should not leave behind a bzr-commit-* file"""
58
73
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
59
74
        self.assertEqual('', self.run_bzr('unknowns')[0])
60
75
 
 
76
    def test_commit_lossy_native(self):
 
77
        """A --lossy option to commit is supported."""
 
78
        self.make_branch_and_tree('.')
 
79
        self.run_bzr('commit --lossy --unchanged -m message')
 
80
        self.assertEqual('', self.run_bzr('unknowns')[0])
 
81
 
 
82
    def test_commit_lossy_foreign(self):
 
83
        test_foreign.register_dummy_foreign_for_test(self)
 
84
        self.make_branch_and_tree('.',
 
85
            format=test_foreign.DummyForeignVcsDirFormat())
 
86
        self.run_bzr('commit --lossy --unchanged -m message')
 
87
        output = self.run_bzr('revision-info')[0]
 
88
        self.assertTrue(output.startswith('1 dummy-'))
 
89
 
61
90
    def test_commit_with_path(self):
62
91
        """Commit tree with path of root specified"""
63
92
        a_tree = self.make_branch_and_tree('a')
77
106
        self.run_bzr('resolved b/a_file')
78
107
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
79
108
 
80
 
 
81
109
    def test_10_verbose_commit(self):
82
110
        """Add one file and examine verbose commit output"""
83
111
        tree = self.make_branch_and_tree('.')
111
139
    def test_unicode_commit_message_is_filename(self):
112
140
        """Unicode commit message same as a filename (Bug #563646).
113
141
        """
 
142
        self.requireFeature(UnicodeFilenameFeature)
114
143
        file_name = u'\N{euro sign}'
115
144
        self.run_bzr(['init'])
116
145
        open(file_name, 'w').write('hello world')
129
158
        # by ui.text.show_warning
130
159
        default_get_terminal_enc = osutils.get_terminal_encoding
131
160
        try:
132
 
            osutils.get_terminal_encoding = lambda: 'ascii'
 
161
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
133
162
            file_name = u'foo\u1234'
134
163
            open(file_name, 'w').write('hello world')
135
164
            self.run_bzr(['add'])
306
335
        tree.add('foo.c')
307
336
        self.run_bzr('commit -m ""', retcode=3)
308
337
 
309
 
    def test_unsupported_encoding_commit_message(self):
310
 
        if sys.platform == 'win32':
311
 
            raise tests.TestNotApplicable('Win32 parses arguments directly'
312
 
                ' as Unicode, so we can\'t pass invalid non-ascii')
313
 
        tree = self.make_branch_and_tree('.')
314
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
315
 
        tree.add('foo.c')
316
 
        # LANG env variable has no effect on Windows
317
 
        # but some characters anyway cannot be represented
318
 
        # in default user encoding
319
 
        char = probe_bad_non_ascii(osutils.get_user_encoding())
320
 
        if char is None:
321
 
            raise TestSkipped('Cannot find suitable non-ascii character'
322
 
                'for user_encoding (%s)' % osutils.get_user_encoding())
323
 
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
324
 
                                          retcode=1,
325
 
                                          env_changes={'LANG': 'C'})
326
 
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
327
 
                                    'unsupported by the current encoding.')
328
 
 
329
338
    def test_other_branch_commit(self):
330
339
        # this branch is to ensure consistent behaviour, whether we're run
331
340
        # inside a branch, or not.
698
707
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
699
708
 
700
709
    def test_commit_readonly_checkout(self):
701
 
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
 
710
        # https://bugs.launchpad.net/bzr/+bug/129701
702
711
        # "UnlockableTransport error trying to commit in checkout of readonly
703
712
        # branch"
704
713
        self.make_branch('master')
716
725
            f = file('fed.bat', 'w')
717
726
            f.write('@rem dummy fed')
718
727
            f.close()
719
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
728
            self.overrideEnv('BZR_EDITOR', "fed.bat")
720
729
        else:
721
730
            f = file('fed.sh', 'wb')
722
731
            f.write('#!/bin/sh\n')
723
732
            f.close()
724
733
            os.chmod('fed.sh', 0755)
725
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
734
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
726
735
 
727
736
    def setup_commit_with_template(self):
728
737
        self.setup_editor()
753
762
        os.chdir('foo')
754
763
        open('foo.txt', 'w').write('hello')
755
764
        self.run_bzr(['add'])
756
 
        osutils.set_or_unset_env('EMAIL', None)
757
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
 
765
        self.overrideEnv('EMAIL', None)
 
766
        self.overrideEnv('BZR_EMAIL', None)
 
767
        # Also, make sure that it's not inferred from mailname.
 
768
        self.overrideAttr(config, '_auto_user_id',
 
769
            lambda: (None, None))
758
770
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
759
771
        self.assertContainsRe(err, 'Unable to determine your name')
 
772
 
 
773
    def test_commit_recursive_checkout(self):
 
774
        """Ensure that a commit to a recursive checkout fails cleanly.
 
775
        """
 
776
        self.run_bzr(['init', 'test_branch'])
 
777
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
 
778
        os.chdir('test_checkout')
 
779
        self.run_bzr(['bind', '.']) # bind to self
 
780
        open('foo.txt', 'w').write('hello')
 
781
        self.run_bzr(['add'])
 
782
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
 
783
        self.assertEqual(out, '')
 
784
        self.assertContainsRe(err,
 
785
            'Branch.*test_checkout.*appears to be bound to itself')
 
786