~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
21
import re
23
22
import sys
24
23
 
25
 
from testtools.matchers import DocTestMatches
26
 
 
27
24
from bzrlib import (
28
 
    config,
 
25
    bzrdir,
29
26
    osutils,
30
27
    ignores,
31
28
    msgeditor,
 
29
    osutils,
32
30
    tests,
33
31
    )
34
32
from bzrlib.bzrdir import BzrDir
35
33
from bzrlib.tests import (
36
34
    probe_bad_non_ascii,
37
 
    test_foreign,
38
35
    TestSkipped,
39
36
    UnicodeFilenameFeature,
40
37
    )
50
47
        self.build_tree(['hello.txt'])
51
48
        out,err = self.run_bzr('commit -m empty', retcode=3)
52
49
        self.assertEqual('', out)
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
 
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
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
 
51
                                  ' Use --unchanged to commit anyhow.\n')
64
52
 
65
53
    def test_commit_success(self):
66
54
        """Successful commit should not leave behind a bzr-commit-* file"""
72
60
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
73
61
        self.assertEqual('', self.run_bzr('unknowns')[0])
74
62
 
75
 
    def test_commit_lossy_native(self):
76
 
        """A --lossy option to commit is supported."""
77
 
        self.make_branch_and_tree('.')
78
 
        self.run_bzr('commit --lossy --unchanged -m message')
79
 
        self.assertEqual('', self.run_bzr('unknowns')[0])
80
 
 
81
 
    def test_commit_lossy_foreign(self):
82
 
        test_foreign.register_dummy_foreign_for_test(self)
83
 
        self.make_branch_and_tree('.',
84
 
            format=test_foreign.DummyForeignVcsDirFormat())
85
 
        self.run_bzr('commit --lossy --unchanged -m message')
86
 
        output = self.run_bzr('revision-info')[0]
87
 
        self.assertTrue(output.startswith('1 dummy-'))
88
 
 
89
63
    def test_commit_with_path(self):
90
64
        """Commit tree with path of root specified"""
91
65
        a_tree = self.make_branch_and_tree('a')
105
79
        self.run_bzr('resolved b/a_file')
106
80
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
107
81
 
 
82
 
108
83
    def test_10_verbose_commit(self):
109
84
        """Add one file and examine verbose commit output"""
110
85
        tree = self.make_branch_and_tree('.')
334
309
        tree.add('foo.c')
335
310
        self.run_bzr('commit -m ""', retcode=3)
336
311
 
 
312
    def test_unsupported_encoding_commit_message(self):
 
313
        if sys.platform == 'win32':
 
314
            raise tests.TestNotApplicable('Win32 parses arguments directly'
 
315
                ' as Unicode, so we can\'t pass invalid non-ascii')
 
316
        tree = self.make_branch_and_tree('.')
 
317
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
318
        tree.add('foo.c')
 
319
        # LANG env variable has no effect on Windows
 
320
        # but some characters anyway cannot be represented
 
321
        # in default user encoding
 
322
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
323
        if char is None:
 
324
            raise TestSkipped('Cannot find suitable non-ascii character'
 
325
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
326
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
 
327
                                          retcode=1,
 
328
                                          env_changes={'LANG': 'C'})
 
329
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
 
330
                                    'unsupported by the current encoding.')
 
331
 
337
332
    def test_other_branch_commit(self):
338
333
        # this branch is to ensure consistent behaviour, whether we're run
339
334
        # inside a branch, or not.
724
719
            f = file('fed.bat', 'w')
725
720
            f.write('@rem dummy fed')
726
721
            f.close()
727
 
            self.overrideEnv('BZR_EDITOR', "fed.bat")
 
722
            osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
728
723
        else:
729
724
            f = file('fed.sh', 'wb')
730
725
            f.write('#!/bin/sh\n')
731
726
            f.close()
732
727
            os.chmod('fed.sh', 0755)
733
 
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
 
728
            osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
734
729
 
735
730
    def setup_commit_with_template(self):
736
731
        self.setup_editor()
754
749
            "commit tree/hello.txt", stdin="n\n")
755
750
        self.assertEqual(expected, tree.last_revision())
756
751
 
757
 
    def test_set_commit_message(self):
758
 
        msgeditor.hooks.install_named_hook("set_commit_message",
759
 
                lambda commit_obj, msg: "save me some typing\n", None)
760
 
        tree = self.make_branch_and_tree('tree')
761
 
        self.build_tree(['tree/hello.txt'])
762
 
        tree.add('hello.txt')
763
 
        out, err = self.run_bzr("commit tree/hello.txt")
764
 
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
765
 
        self.assertEqual('save me some typing\n', last_rev.message)
766
 
 
767
752
    def test_commit_without_username(self):
768
753
        """Ensure commit error if username is not set.
769
754
        """
771
756
        os.chdir('foo')
772
757
        open('foo.txt', 'w').write('hello')
773
758
        self.run_bzr(['add'])
774
 
        self.overrideEnv('EMAIL', None)
775
 
        self.overrideEnv('BZR_EMAIL', None)
776
 
        # Also, make sure that it's not inferred from mailname.
777
 
        self.overrideAttr(config, '_auto_user_id',
778
 
            lambda: (None, None))
 
759
        osutils.set_or_unset_env('EMAIL', None)
 
760
        osutils.set_or_unset_env('BZR_EMAIL', None)
779
761
        out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
780
762
        self.assertContainsRe(err, 'Unable to determine your name')
781
763
 
792
774
        self.assertEqual(out, '')
793
775
        self.assertContainsRe(err,
794
776
            'Branch.*test_checkout.*appears to be bound to itself')
 
777