1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
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
18
18
"""Tests for the commit CLI of bzr."""
25
from testtools.matchers import DocTestMatches
27
24
from bzrlib import (
34
31
from bzrlib.bzrdir import BzrDir
35
32
from bzrlib.tests import (
36
33
probe_bad_non_ascii,
39
UnicodeFilenameFeature,
41
from bzrlib.tests import TestCaseWithTransport
44
class TestCommit(TestCaseWithTransport):
36
from bzrlib.tests.blackbox import ExternalBase
39
class TestCommit(ExternalBase):
46
41
def test_05_empty_commit(self):
47
42
"""Commit of tree with no versioned files should fail"""
50
45
self.build_tree(['hello.txt'])
51
46
out,err = self.run_bzr('commit -m empty', retcode=3)
52
47
self.assertEqual('', out)
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 '\'
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))
48
self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
49
' Use --unchanged to commit anyhow.\n')
66
51
def test_commit_success(self):
67
52
"""Successful commit should not leave behind a bzr-commit-* file"""
73
58
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
74
59
self.assertEqual('', self.run_bzr('unknowns')[0])
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])
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-'))
90
61
def test_commit_with_path(self):
91
62
"""Commit tree with path of root specified"""
92
63
a_tree = self.make_branch_and_tree('a')
106
77
self.run_bzr('resolved b/a_file')
107
78
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
109
81
def test_10_verbose_commit(self):
110
82
"""Add one file and examine verbose commit output"""
111
83
tree = self.make_branch_and_tree('.')
139
111
def test_unicode_commit_message_is_filename(self):
140
112
"""Unicode commit message same as a filename (Bug #563646).
142
self.requireFeature(UnicodeFilenameFeature)
143
114
file_name = u'\N{euro sign}'
144
115
self.run_bzr(['init'])
145
116
open(file_name, 'w').write('hello world')
158
129
# by ui.text.show_warning
159
130
default_get_terminal_enc = osutils.get_terminal_encoding
161
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
132
osutils.get_terminal_encoding = lambda: 'ascii'
162
133
file_name = u'foo\u1234'
163
134
open(file_name, 'w').write('hello world')
164
135
self.run_bzr(['add'])
335
306
tree.add('foo.c')
336
307
self.run_bzr('commit -m ""', retcode=3)
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() {}')])
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())
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,
325
env_changes={'LANG': 'C'})
326
self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
327
'unsupported by the current encoding.')
338
329
def test_other_branch_commit(self):
339
330
# this branch is to ensure consistent behaviour, whether we're run
340
331
# inside a branch, or not.
725
716
f = file('fed.bat', 'w')
726
717
f.write('@rem dummy fed')
728
self.overrideEnv('BZR_EDITOR', "fed.bat")
719
osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
730
721
f = file('fed.sh', 'wb')
731
722
f.write('#!/bin/sh\n')
733
724
os.chmod('fed.sh', 0755)
734
self.overrideEnv('BZR_EDITOR', "./fed.sh")
725
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
736
727
def setup_commit_with_template(self):
737
728
self.setup_editor()
763
754
open('foo.txt', 'w').write('hello')
764
755
self.run_bzr(['add'])
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))
756
osutils.set_or_unset_env('EMAIL', None)
757
osutils.set_or_unset_env('BZR_EMAIL', None)
770
758
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
771
759
self.assertContainsRe(err, 'Unable to determine your name')
773
def test_commit_recursive_checkout(self):
774
"""Ensure that a commit to a recursive checkout fails cleanly.
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')