/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: James Blackwell
  • Date: 2006-05-05 01:05:04 UTC
  • mfrom: (1697 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1700.
  • Revision ID: jblack@merconline.com-20060505010504-264cb48507e53b64
mergedĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
18
17
 
19
18
"""Tests for the commit CLI of bzr."""
20
19
 
21
 
from cStringIO import StringIO
22
20
import os
23
21
import re
24
 
import shutil
25
22
import sys
26
23
 
27
24
from bzrlib.branch import Branch
28
 
import bzrlib.bzrdir as bzrdir
 
25
from bzrlib.bzrdir import BzrDir
29
26
from bzrlib.errors import BzrCommandError
30
27
from bzrlib.tests.blackbox import ExternalBase
31
28
from bzrlib.workingtree import WorkingTree
33
30
 
34
31
class TestCommit(ExternalBase):
35
32
 
36
 
    def test_empty_commit(self):
 
33
    def test_05_empty_commit(self):
 
34
        """Commit of tree with no versioned files should fail"""
 
35
        # If forced, it should succeed, but this is not tested here.
37
36
        self.runbzr("init")
38
37
        self.build_tree(['hello.txt'])
39
38
        self.runbzr("commit -m empty", retcode=3)
40
 
        self.runbzr("add hello.txt")
41
 
        self.runbzr("commit -m added")       
 
39
 
 
40
    def test_10_verbose_commit(self):
 
41
        """Add one file and examine verbose commit output"""
 
42
        self.runbzr("init")
 
43
        self.build_tree(['hello.txt'])
 
44
        self.runbzr("add hello.txt")
 
45
        out,err = self.run_bzr("commit", "-m", "added")
 
46
        self.assertEqual('', out)
 
47
        self.assertEqual('added hello.txt\n'
 
48
                         'Committed revision 1.\n',
 
49
                         err)
 
50
 
 
51
    def prepare_simple_history(self):
 
52
        """Prepare and return a working tree with one commit of one file"""
 
53
        # Commit with modified file should say so
 
54
        wt = BzrDir.create_standalone_workingtree('.')
 
55
        self.build_tree(['hello.txt', 'extra.txt'])
 
56
        wt.add(['hello.txt'])
 
57
        wt.commit(message='added')
 
58
        return wt
 
59
 
 
60
    def test_verbose_commit_modified(self):
 
61
        # Verbose commit of modified file should say so
 
62
        wt = self.prepare_simple_history()
 
63
        self.build_tree_contents([('hello.txt', 'new contents')])
 
64
        out, err = self.run_bzr("commit", "-m", "modified")
 
65
        self.assertEqual('', out)
 
66
        self.assertEqual('modified hello.txt\n'
 
67
                         'Committed revision 2.\n',
 
68
                         err)
 
69
 
 
70
    def test_verbose_commit_renamed(self):
 
71
        # Verbose commit of renamed file should say so
 
72
        wt = self.prepare_simple_history()
 
73
        wt.rename_one('hello.txt', 'gutentag.txt')
 
74
        out, err = self.run_bzr("commit", "-m", "renamed")
 
75
        self.assertEqual('', out)
 
76
        self.assertEqual('renamed gutentag.txt\n'
 
77
                         'Committed revision 2.\n',
 
78
                         err)
 
79
 
 
80
    def test_verbose_commit_moved(self):
 
81
        # Verbose commit of file moved to new directory should say so
 
82
        wt = self.prepare_simple_history()
 
83
        os.mkdir('subdir')
 
84
        wt.add(['subdir'])
 
85
        wt.rename_one('hello.txt', 'subdir/hello.txt')
 
86
        out, err = self.run_bzr("commit", "-m", "renamed")
 
87
        self.assertEqual('', out)
 
88
        self.assertEqualDiff('added subdir\n'
 
89
                             'renamed subdir/hello.txt\n'
 
90
                             'Committed revision 2.\n',
 
91
                             err)
 
92
 
 
93
    def test_verbose_commit_with_unknown(self):
 
94
        """Unknown files should not be listed by default in verbose output"""
 
95
        # Is that really the best policy?
 
96
        wt = BzrDir.create_standalone_workingtree('.')
 
97
        self.build_tree(['hello.txt', 'extra.txt'])
 
98
        wt.add(['hello.txt'])
 
99
        out,err = self.run_bzr("commit", "-m", "added")
 
100
        self.assertEqual('', out)
 
101
        self.assertEqual('added hello.txt\n'
 
102
                         'Committed revision 1.\n',
 
103
                         err)
 
104
 
 
105
    def test_16_verbose_commit_with_unchanged(self):
 
106
        """Unchanged files should not be listed by default in verbose output"""
 
107
        self.runbzr("init")
 
108
        self.build_tree(['hello.txt', 'unchanged.txt'])
 
109
        self.runbzr('add unchanged.txt')
 
110
        self.runbzr('commit -m unchanged unchanged.txt')
 
111
        self.runbzr("add hello.txt")
 
112
        out,err = self.run_bzr("commit", "-m", "added")
 
113
        self.assertEqual('', out)
 
114
        self.assertEqual('added hello.txt\n'
 
115
                         'Committed revision 2.\n',
 
116
                         err)
42
117
 
43
118
    def test_empty_commit_message(self):
44
119
        self.runbzr("init")
45
120
        file('foo.c', 'wt').write('int main() {}')
46
121
        self.runbzr(['add', 'foo.c'])
47
 
        self.runbzr(["commit", "-m", ""] , retcode=3) 
 
122
        self.runbzr(["commit", "-m", ""] , retcode=3)
48
123
 
49
124
    def test_other_branch_commit(self):
50
125
        # this branch is to ensure consistent behaviour, whether we're run