~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2005-05-09 03:03:55 UTC
  • Revision ID: mbp@sourcefrog.net-20050509030355-ad6ab558d1362959
- Don't give an error if the trace file can't be opened

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
 
        out,err = self.run_bzr("commit", "-m", "added")
42
 
        self.assertEqual('', out)
43
 
        self.assertEqual('added hello.txt\n'
44
 
                         'Committed revision 1.\n',
45
 
                         err)
46
 
 
47
 
    def test_empty_commit_message(self):
48
 
        self.runbzr("init")
49
 
        file('foo.c', 'wt').write('int main() {}')
50
 
        self.runbzr(['add', 'foo.c'])
51
 
        self.runbzr(["commit", "-m", ""] , retcode=3) 
52
 
 
53
 
    def test_other_branch_commit(self):
54
 
        # this branch is to ensure consistent behaviour, whether we're run
55
 
        # inside a branch, or not.
56
 
        os.mkdir('empty_branch')
57
 
        os.chdir('empty_branch')
58
 
        self.runbzr('init')
59
 
        os.mkdir('branch')
60
 
        os.chdir('branch')
61
 
        self.runbzr('init')
62
 
        file('foo.c', 'wt').write('int main() {}')
63
 
        file('bar.c', 'wt').write('int main() {}')
64
 
        os.chdir('..')
65
 
        self.runbzr(['add', 'branch/foo.c'])
66
 
        self.runbzr(['add', 'branch'])
67
 
        # can't commit files in different trees; sane error
68
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
69
 
        self.runbzr('commit -m newstuff branch/foo.c')
70
 
        self.runbzr('commit -m newstuff branch')
71
 
        self.runbzr('commit -m newstuff branch', retcode=3)
72
 
 
73
 
    def test_out_of_date_tree_commit(self):
74
 
        # check we get an error code and a clear message committing with an out
75
 
        # of date checkout
76
 
        self.make_branch_and_tree('branch')
77
 
        # make a checkout
78
 
        self.runbzr('checkout --lightweight branch checkout')
79
 
        # commit to the original branch to make the checkout out of date
80
 
        self.runbzr('commit --unchanged -m message branch')
81
 
        # now commit to the checkout should emit
82
 
        # ERROR: Out of date with the branch, 'bzr update' is suggested
83
 
        output = self.runbzr('commit --unchanged -m checkout_message '
84
 
                             'checkout', retcode=3)
85
 
        self.assertEqual(output,
86
 
                         ('',
87
 
                          "bzr: ERROR: Working tree is out of date, please run "
88
 
                          "'bzr update'.\n"))
89
 
 
90
 
    def test_local_commit_unbound(self):
91
 
        # a --local commit on an unbound branch is an error
92
 
        self.make_branch_and_tree('.')
93
 
        out, err = self.run_bzr('commit', '--local', retcode=3)
94
 
        self.assertEqualDiff('', out)
95
 
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
96
 
                             'on unbound branches.\n', err)