~ubuntu-branches/ubuntu/lucid/bzr/lucid-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2006-03-20 08:31:00 UTC
  • mfrom: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060320083100-ovdi2ssuw0epcx8s
Tags: 0.8~200603200831-0ubuntu1
* Snapshot uploaded to Dapper at Martin Pool's request.

* Disable testsuite for upload.  Fakeroot and the testsuite don't
  play along.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
 
 
19
"""Tests for the commit CLI of bzr."""
 
20
 
 
21
from cStringIO import StringIO
 
22
import os
 
23
import re
 
24
import shutil
 
25
import sys
 
26
 
 
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
 
32
 
 
33
 
 
34
class TestCommit(ExternalBase):
 
35
 
 
36
    def test_empty_commit(self):
 
37
        self.runbzr("init")
 
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")       
 
42
 
 
43
    def test_empty_commit_message(self):
 
44
        self.runbzr("init")
 
45
        file('foo.c', 'wt').write('int main() {}')
 
46
        self.runbzr(['add', 'foo.c'])
 
47
        self.runbzr(["commit", "-m", ""] , retcode=3) 
 
48
 
 
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')
 
54
        self.runbzr('init')
 
55
        os.mkdir('branch')
 
56
        os.chdir('branch')
 
57
        self.runbzr('init')
 
58
        file('foo.c', 'wt').write('int main() {}')
 
59
        file('bar.c', 'wt').write('int main() {}')
 
60
        os.chdir('..')
 
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)
 
68
 
 
69
    def test_out_of_date_tree_commit(self):
 
70
        # check we get an error code and a clear message committing with an out
 
71
        # of date checkout
 
72
        self.make_branch_and_tree('branch')
 
73
        # make a checkout
 
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,
 
82
                         ('',
 
83
                          "bzr: ERROR: Working tree is out of date, please run "
 
84
                          "'bzr update'.\n"))
 
85
 
 
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)