/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: Canonical.com Patch Queue Manager
  • Date: 2011-04-08 09:54:43 UTC
  • mfrom: (5745.3.4 tree-lazy-imports)
  • Revision ID: pqm@pqm.ubuntu.com-20110408095443-euiq0776jpr18w5d
(spiv) Use lazy imports in bzrlib.tree. (Jelmer Vernooij)

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
 
22
import re
21
23
import sys
22
24
 
 
25
from testtools.matchers import DocTestMatches
 
26
 
23
27
from bzrlib import (
 
28
    config,
24
29
    osutils,
25
30
    ignores,
26
31
    msgeditor,
27
 
    osutils,
28
32
    tests,
29
33
    )
30
34
from bzrlib.bzrdir import BzrDir
31
35
from bzrlib.tests import (
32
36
    probe_bad_non_ascii,
33
37
    TestSkipped,
 
38
    UnicodeFilenameFeature,
34
39
    )
35
 
from bzrlib.tests.blackbox import ExternalBase
36
 
 
37
 
 
38
 
class TestCommit(ExternalBase):
 
40
from bzrlib.tests import TestCaseWithTransport
 
41
 
 
42
 
 
43
class TestCommit(TestCaseWithTransport):
39
44
 
40
45
    def test_05_empty_commit(self):
41
46
        """Commit of tree with no versioned files should fail"""
44
49
        self.build_tree(['hello.txt'])
45
50
        out,err = self.run_bzr('commit -m empty', retcode=3)
46
51
        self.assertEqual('', out)
47
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
48
 
                                  ' Use --unchanged to commit anyhow.\n')
 
52
        # Two ugly bits here.
 
53
        # 1) We really don't want 'aborting commit write group' anymore.
 
54
        # 2) bzr: ERROR: is a really long line, so we wrap it with '\'
 
55
        self.assertThat(
 
56
            err,
 
57
            DocTestMatches("""\
 
58
Committing to: ...
 
59
aborting commit write group: PointlessCommit(No changes to commit)
 
60
bzr: ERROR: No changes to commit.\
 
61
 Please 'bzr add' the files you want to commit,\
 
62
 or use --unchanged to force an empty commit.
 
63
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
49
64
 
50
65
    def test_commit_success(self):
51
66
        """Successful commit should not leave behind a bzr-commit-* file"""
107
122
                              'modified hello\.txt\n'
108
123
                              'Committed revision 2\.\n$')
109
124
 
 
125
    def test_unicode_commit_message_is_filename(self):
 
126
        """Unicode commit message same as a filename (Bug #563646).
 
127
        """
 
128
        self.requireFeature(UnicodeFilenameFeature)
 
129
        file_name = u'\N{euro sign}'
 
130
        self.run_bzr(['init'])
 
131
        open(file_name, 'w').write('hello world')
 
132
        self.run_bzr(['add'])
 
133
        out, err = self.run_bzr(['commit', '-m', file_name])
 
134
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
135
        te = osutils.get_terminal_encoding()
 
136
        self.assertContainsRe(err.decode(te),
 
137
            u'The commit message is a file name:',
 
138
            flags=reflags)
 
139
 
 
140
        # Run same test with a filename that causes encode
 
141
        # error for the terminal encoding. We do this
 
142
        # by forcing terminal encoding of ascii for
 
143
        # osutils.get_terminal_encoding which is used
 
144
        # by ui.text.show_warning
 
145
        default_get_terminal_enc = osutils.get_terminal_encoding
 
146
        try:
 
147
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
 
148
            file_name = u'foo\u1234'
 
149
            open(file_name, 'w').write('hello world')
 
150
            self.run_bzr(['add'])
 
151
            out, err = self.run_bzr(['commit', '-m', file_name])
 
152
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
153
            te = osutils.get_terminal_encoding()
 
154
            self.assertContainsRe(err.decode(te, 'replace'),
 
155
                u'The commit message is a file name:',
 
156
                flags=reflags)
 
157
        finally:
 
158
            osutils.get_terminal_encoding = default_get_terminal_enc
 
159
 
110
160
    def test_warn_about_forgotten_commit_message(self):
111
161
        """Test that the lack of -m parameter is caught"""
112
162
        wt = self.make_branch_and_tree('.')
663
713
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
664
714
 
665
715
    def test_commit_readonly_checkout(self):
666
 
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
 
716
        # https://bugs.launchpad.net/bzr/+bug/129701
667
717
        # "UnlockableTransport error trying to commit in checkout of readonly
668
718
        # branch"
669
719
        self.make_branch('master')
681
731
            f = file('fed.bat', 'w')
682
732
            f.write('@rem dummy fed')
683
733
            f.close()
684
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
734
            self.overrideEnv('BZR_EDITOR', "fed.bat")
685
735
        else:
686
736
            f = file('fed.sh', 'wb')
687
737
            f.write('#!/bin/sh\n')
688
738
            f.close()
689
739
            os.chmod('fed.sh', 0755)
690
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
740
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
691
741
 
692
742
    def setup_commit_with_template(self):
693
743
        self.setup_editor()
710
760
        out, err = self.run_bzr_error(["empty commit message"],
711
761
            "commit tree/hello.txt", stdin="n\n")
712
762
        self.assertEqual(expected, tree.last_revision())
 
763
 
 
764
    def test_commit_without_username(self):
 
765
        """Ensure commit error if username is not set.
 
766
        """
 
767
        self.run_bzr(['init', 'foo'])
 
768
        os.chdir('foo')
 
769
        open('foo.txt', 'w').write('hello')
 
770
        self.run_bzr(['add'])
 
771
        self.overrideEnv('EMAIL', None)
 
772
        self.overrideEnv('BZR_EMAIL', None)
 
773
        # Also, make sure that it's not inferred from mailname.
 
774
        self.overrideAttr(config, '_auto_user_id',
 
775
            lambda: (None, None))
 
776
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
 
777
        self.assertContainsRe(err, 'Unable to determine your name')
 
778
 
 
779
    def test_commit_recursive_checkout(self):
 
780
        """Ensure that a commit to a recursive checkout fails cleanly.
 
781
        """
 
782
        self.run_bzr(['init', 'test_branch'])
 
783
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
 
784
        os.chdir('test_checkout')
 
785
        self.run_bzr(['bind', '.']) # bind to self
 
786
        open('foo.txt', 'w').write('hello')
 
787
        self.run_bzr(['add'])
 
788
        out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
 
789
        self.assertEqual(out, '')
 
790
        self.assertContainsRe(err,
 
791
            'Branch.*test_checkout.*appears to be bound to itself')
 
792