1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006-2011 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
24
27
from bzrlib import (
31
34
from bzrlib.bzrdir import BzrDir
32
35
from bzrlib.tests import (
33
36
probe_bad_non_ascii,
39
UnicodeFilenameFeature,
36
from bzrlib.tests.blackbox import ExternalBase
39
class TestCommit(ExternalBase):
41
from bzrlib.tests import TestCaseWithTransport
44
class TestCommit(TestCaseWithTransport):
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')
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
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))
51
65
def test_commit_success(self):
52
66
"""Successful commit should not leave behind a bzr-commit-* file"""
58
72
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
59
73
self.assertEqual('', self.run_bzr('unknowns')[0])
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])
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-'))
61
89
def test_commit_with_path(self):
62
90
"""Commit tree with path of root specified"""
63
91
a_tree = self.make_branch_and_tree('a')
77
105
self.run_bzr('resolved b/a_file')
78
106
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
81
108
def test_10_verbose_commit(self):
82
109
"""Add one file and examine verbose commit output"""
83
110
tree = self.make_branch_and_tree('.')
111
138
def test_unicode_commit_message_is_filename(self):
112
139
"""Unicode commit message same as a filename (Bug #563646).
141
self.requireFeature(UnicodeFilenameFeature)
114
142
file_name = u'\N{euro sign}'
115
143
self.run_bzr(['init'])
116
144
open(file_name, 'w').write('hello world')
129
157
# by ui.text.show_warning
130
158
default_get_terminal_enc = osutils.get_terminal_encoding
132
osutils.get_terminal_encoding = lambda: 'ascii'
160
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
133
161
file_name = u'foo\u1234'
134
162
open(file_name, 'w').write('hello world')
135
163
self.run_bzr(['add'])
306
334
tree.add('foo.c')
307
335
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.')
329
337
def test_other_branch_commit(self):
330
338
# this branch is to ensure consistent behaviour, whether we're run
331
339
# inside a branch, or not.
698
706
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
700
708
def test_commit_readonly_checkout(self):
701
# https://bugs.edge.launchpad.net/bzr/+bug/129701
709
# https://bugs.launchpad.net/bzr/+bug/129701
702
710
# "UnlockableTransport error trying to commit in checkout of readonly
704
712
self.make_branch('master')
716
724
f = file('fed.bat', 'w')
717
725
f.write('@rem dummy fed')
719
osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
727
self.overrideEnv('BZR_EDITOR', "fed.bat")
721
729
f = file('fed.sh', 'wb')
722
730
f.write('#!/bin/sh\n')
724
732
os.chmod('fed.sh', 0755)
725
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
733
self.overrideEnv('BZR_EDITOR', "./fed.sh")
727
735
def setup_commit_with_template(self):
728
736
self.setup_editor()
754
762
open('foo.txt', 'w').write('hello')
755
763
self.run_bzr(['add'])
756
osutils.set_or_unset_env('EMAIL', None)
757
osutils.set_or_unset_env('BZR_EMAIL', None)
764
self.overrideEnv('EMAIL', None)
765
self.overrideEnv('BZR_EMAIL', None)
766
# Also, make sure that it's not inferred from mailname.
767
self.overrideAttr(config, '_auto_user_id',
768
lambda: (None, None))
758
769
out, err = self.run_bzr(['commit', '-m', 'initial'], 3)
759
770
self.assertContainsRe(err, 'Unable to determine your name')
772
def test_commit_recursive_checkout(self):
773
"""Ensure that a commit to a recursive checkout fails cleanly.
775
self.run_bzr(['init', 'test_branch'])
776
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
777
os.chdir('test_checkout')
778
self.run_bzr(['bind', '.']) # bind to self
779
open('foo.txt', 'w').write('hello')
780
self.run_bzr(['add'])
781
out, err = self.run_bzr(['commit', '-m', 'addedfoo'], 3)
782
self.assertEqual(out, '')
783
self.assertContainsRe(err,
784
'Branch.*test_checkout.*appears to be bound to itself')