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,
38
UnicodeFilenameFeature,
36
from bzrlib.tests.blackbox import ExternalBase
39
class TestCommit(ExternalBase):
40
from bzrlib.tests import TestCaseWithTransport
43
class TestCommit(TestCaseWithTransport):
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')
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 '\'
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))
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).
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
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.')
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
704
719
self.make_branch('master')
716
731
f = file('fed.bat', 'w')
717
732
f.write('@rem dummy fed')
719
osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
734
self.overrideEnv('BZR_EDITOR', "fed.bat")
721
736
f = file('fed.sh', 'wb')
722
737
f.write('#!/bin/sh\n')
724
739
os.chmod('fed.sh', 0755)
725
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
740
self.overrideEnv('BZR_EDITOR', "./fed.sh")
727
742
def setup_commit_with_template(self):
728
743
self.setup_editor()
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')
779
def test_commit_recursive_checkout(self):
780
"""Ensure that a commit to a recursive checkout fails cleanly.
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')