/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: mbp at sourcefrog
  • Date: 2011-04-11 01:23:58 UTC
  • mfrom: (5777 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5802.
  • Revision ID: mbp@sourcefrog.net-20110411012358-gl07rdtxydlq7fh1
merge news

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,
34
37
    TestSkipped,
 
38
    UnicodeFilenameFeature,
35
39
    )
36
 
from bzrlib.tests.blackbox import ExternalBase
37
 
 
38
 
 
39
 
class TestCommit(ExternalBase):
 
40
from bzrlib.tests import TestCaseWithTransport
 
41
 
 
42
 
 
43
class TestCommit(TestCaseWithTransport):
40
44
 
41
45
    def test_05_empty_commit(self):
42
46
        """Commit of tree with no versioned files should fail"""
45
49
        self.build_tree(['hello.txt'])
46
50
        out,err = self.run_bzr('commit -m empty', retcode=3)
47
51
        self.assertEqual('', out)
48
 
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
49
 
                                  ' 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))
50
64
 
51
65
    def test_commit_success(self):
52
66
        """Successful commit should not leave behind a bzr-commit-* file"""
111
125
    def test_unicode_commit_message_is_filename(self):
112
126
        """Unicode commit message same as a filename (Bug #563646).
113
127
        """
 
128
        self.requireFeature(UnicodeFilenameFeature)
114
129
        file_name = u'\N{euro sign}'
115
130
        self.run_bzr(['init'])
116
131
        open(file_name, 'w').write('hello world')
129
144
        # by ui.text.show_warning
130
145
        default_get_terminal_enc = osutils.get_terminal_encoding
131
146
        try:
132
 
            osutils.get_terminal_encoding = lambda: 'ascii'
 
147
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
133
148
            file_name = u'foo\u1234'
134
149
            open(file_name, 'w').write('hello world')
135
150
            self.run_bzr(['add'])
698
713
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
699
714
 
700
715
    def test_commit_readonly_checkout(self):
701
 
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
 
716
        # https://bugs.launchpad.net/bzr/+bug/129701
702
717
        # "UnlockableTransport error trying to commit in checkout of readonly
703
718
        # branch"
704
719
        self.make_branch('master')
716
731
            f = file('fed.bat', 'w')
717
732
            f.write('@rem dummy fed')
718
733
            f.close()
719
 
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
734
            self.overrideEnv('BZR_EDITOR', "fed.bat")
720
735
        else:
721
736
            f = file('fed.sh', 'wb')
722
737
            f.write('#!/bin/sh\n')
723
738
            f.close()
724
739
            os.chmod('fed.sh', 0755)
725
 
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
740
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
726
741
 
727
742
    def setup_commit_with_template(self):
728
743
        self.setup_editor()
753
768
        os.chdir('foo')
754
769
        open('foo.txt', 'w').write('hello')
755
770
        self.run_bzr(['add'])
756
 
        osutils.set_or_unset_env('EMAIL', None)
757
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
 
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))
758
776
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
759
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