1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Tests for the commit CLI of bzr."""
21
from cStringIO import StringIO
27
from bzrlib.branch import Branch
28
import bzrlib.bzrdir as bzrdir
29
from bzrlib.errors import BzrCommandError
30
from bzrlib.tests.blackbox import ExternalBase
31
from bzrlib.workingtree import WorkingTree
34
class TestCommit(ExternalBase):
36
def test_empty_commit(self):
38
self.build_tree(['hello.txt'])
39
self.runbzr("commit -m empty", retcode=3)
40
self.runbzr("add hello.txt")
41
self.runbzr("commit -m added")
43
def test_empty_commit_message(self):
45
file('foo.c', 'wt').write('int main() {}')
46
self.runbzr(['add', 'foo.c'])
47
self.runbzr(["commit", "-m", ""] , retcode=3)
49
def test_other_branch_commit(self):
50
# this branch is to ensure consistent behaviour, whether we're run
51
# inside a branch, or not.
52
os.mkdir('empty_branch')
53
os.chdir('empty_branch')
58
file('foo.c', 'wt').write('int main() {}')
59
file('bar.c', 'wt').write('int main() {}')
61
self.runbzr(['add', 'branch/foo.c'])
62
self.runbzr(['add', 'branch'])
63
# can't commit files in different trees; sane error
64
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
65
self.runbzr('commit -m newstuff branch/foo.c')
66
self.runbzr('commit -m newstuff branch')
67
self.runbzr('commit -m newstuff branch', retcode=3)
69
def test_out_of_date_tree_commit(self):
70
# check we get an error code and a clear message committing with an out
72
self.make_branch_and_tree('branch')
74
self.runbzr('checkout --lightweight branch checkout')
75
# commit to the original branch to make the checkout out of date
76
self.runbzr('commit --unchanged -m message branch')
77
# now commit to the checkout should emit
78
# ERROR: Out of date with the branch, 'bzr update' is suggested
79
output = self.runbzr('commit --unchanged -m checkout_message '
80
'checkout', retcode=3)
81
self.assertEqual(output,
83
"bzr: ERROR: Working tree is out of date, please run "
86
def test_local_commit_unbound(self):
87
# a --local commit on an unbound branch is an error
88
self.make_branch_and_tree('.')
89
out, err = self.run_bzr('commit', '--local', retcode=3)
90
self.assertEqualDiff('', out)
91
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
92
'on unbound branches.\n', err)