/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: Robert Collins
  • Date: 2007-09-04 04:12:07 UTC
  • mfrom: (2794 +trunk)
  • mto: (2592.3.126 repository)
  • mto: This revision was merged to the branch mainline in revision 2795.
  • Revision ID: robertc@robertcollins.net-20070904041207-zb3l8hfco0sp6hu8
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
20
import os
21
 
import re
22
 
import sys
23
21
 
24
22
from bzrlib import (
25
23
    ignores,
26
24
    )
27
 
from bzrlib.branch import Branch
28
25
from bzrlib.bzrdir import BzrDir
29
 
from bzrlib.errors import BzrCommandError
30
26
from bzrlib.tests.blackbox import ExternalBase
31
 
from bzrlib.workingtree import WorkingTree
32
27
 
33
28
 
34
29
class TestCommit(ExternalBase):
36
31
    def test_05_empty_commit(self):
37
32
        """Commit of tree with no versioned files should fail"""
38
33
        # If forced, it should succeed, but this is not tested here.
39
 
        self.run_bzr("init")
 
34
        self.make_branch_and_tree('.')
40
35
        self.build_tree(['hello.txt'])
41
36
        out,err = self.run_bzr('commit -m empty', retcode=3)
42
37
        self.assertEqual('', out)
45
40
 
46
41
    def test_commit_success(self):
47
42
        """Successful commit should not leave behind a bzr-commit-* file"""
48
 
        self.run_bzr("init")
 
43
        self.make_branch_and_tree('.')
49
44
        self.run_bzr('commit --unchanged -m message')
50
45
        self.assertEqual('', self.run_bzr('unknowns')[0])
51
46
 
55
50
 
56
51
    def test_commit_with_path(self):
57
52
        """Commit tree with path of root specified"""
58
 
        self.run_bzr('init a')
 
53
        a_tree = self.make_branch_and_tree('a')
59
54
        self.build_tree(['a/a_file'])
60
 
        self.run_bzr('add a/a_file')
 
55
        a_tree.add('a_file')
61
56
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
62
57
 
63
 
        self.run_bzr('branch a b')
 
58
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
64
59
        self.build_tree_contents([('b/a_file', 'changes in b')])
65
60
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
66
61
 
67
62
        self.build_tree_contents([('a/a_file', 'new contents')])
68
63
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
69
64
 
70
 
        os.chdir('b')
71
 
        self.run_bzr('merge ../a', retcode=1) # will conflict
72
 
        os.chdir('..')
 
65
        b_tree.merge_from_branch(a_tree.branch)
 
66
        self.assertEqual(len(b_tree.conflicts()), 1)
73
67
        self.run_bzr('resolved b/a_file')
74
68
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
75
69
 
76
70
 
77
71
    def test_10_verbose_commit(self):
78
72
        """Add one file and examine verbose commit output"""
79
 
        self.run_bzr("init")
 
73
        tree = self.make_branch_and_tree('.')
80
74
        self.build_tree(['hello.txt'])
81
 
        self.run_bzr("add hello.txt")
 
75
        tree.add("hello.txt")
82
76
        out,err = self.run_bzr('commit -m added')
83
77
        self.assertEqual('', out)
84
78
        self.assertEqual('added hello.txt\n'
141
135
 
142
136
    def test_verbose_commit_with_unchanged(self):
143
137
        """Unchanged files should not be listed by default in verbose output"""
144
 
        self.run_bzr("init")
 
138
        tree = self.make_branch_and_tree('.')
145
139
        self.build_tree(['hello.txt', 'unchanged.txt'])
146
 
        self.run_bzr('add unchanged.txt')
 
140
        tree.add('unchanged.txt')
147
141
        self.run_bzr('commit -m unchanged unchanged.txt')
148
 
        self.run_bzr("add hello.txt")
 
142
        tree.add("hello.txt")
149
143
        out,err = self.run_bzr('commit -m added')
150
144
        self.assertEqual('', out)
151
145
        self.assertEqual('added hello.txt\n'
189
183
            other_tree.rename_one('dirtorename', 'renameddir')
190
184
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
191
185
            other_tree.rename_one('filetorename', 'renamedfile')
192
 
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
186
            other_tree.rename_one('filetoreparent',
 
187
                                  'renameddir/reparentedfile')
193
188
            other_tree.remove(['dirtoremove', 'filetoremove'])
194
189
            self.build_tree_contents([
195
 
                ('other/newdir/', ),
 
190
                ('other/newdir/',),
196
191
                ('other/filetomodify', 'new content'),
197
192
                ('other/newfile', 'new file content')])
198
193
            other_tree.add('newfile')
219
214
            err)
220
215
 
221
216
    def test_empty_commit_message(self):
222
 
        self.run_bzr("init")
223
 
        file('foo.c', 'wt').write('int main() {}')
224
 
        self.run_bzr('add foo.c')
 
217
        tree = self.make_branch_and_tree('.')
 
218
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
219
        tree.add('foo.c')
225
220
        self.run_bzr('commit -m ""', retcode=3)
226
221
 
227
222
    def test_unsupported_encoding_commit_message(self):
236
231
    def test_other_branch_commit(self):
237
232
        # this branch is to ensure consistent behaviour, whether we're run
238
233
        # inside a branch, or not.
239
 
        os.mkdir('empty_branch')
240
 
        os.chdir('empty_branch')
241
 
        self.run_bzr('init')
242
 
        os.mkdir('branch')
243
 
        os.chdir('branch')
244
 
        self.run_bzr('init')
245
 
        file('foo.c', 'wt').write('int main() {}')
246
 
        file('bar.c', 'wt').write('int main() {}')
247
 
        os.chdir('..')
248
 
        self.run_bzr('add branch/foo.c')
249
 
        self.run_bzr('add branch')
 
234
        outer_tree = self.make_branch_and_tree('.')
 
235
        inner_tree = self.make_branch_and_tree('branch')
 
236
        self.build_tree_contents([
 
237
            ('branch/foo.c', 'int main() {}'),
 
238
            ('branch/bar.c', 'int main() {}')])
 
239
        inner_tree.add('foo.c')
 
240
        inner_tree.add('bar.c')
250
241
        # can't commit files in different trees; sane error
251
242
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
252
243
        self.run_bzr('commit -m newstuff branch/foo.c')
256
247
    def test_out_of_date_tree_commit(self):
257
248
        # check we get an error code and a clear message committing with an out
258
249
        # of date checkout
259
 
        self.make_branch_and_tree('branch')
 
250
        tree = self.make_branch_and_tree('branch')
260
251
        # make a checkout
261
 
        self.run_bzr('checkout --lightweight branch checkout')
 
252
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
262
253
        # commit to the original branch to make the checkout out of date
263
 
        self.run_bzr('commit --unchanged -m message branch')
 
254
        tree.commit('message branch', allow_pointless=True)
264
255
        # now commit to the checkout should emit
265
256
        # ERROR: Out of date with the branch, 'bzr update' is suggested
266
257
        output = self.run_bzr('commit --unchanged -m checkout_message '
267
258
                             'checkout', retcode=3)
268
259
        self.assertEqual(output,
269
260
                         ('',
270
 
                          "bzr: ERROR: Working tree is out of date, please run "
271
 
                          "'bzr update'.\n"))
 
261
                          "bzr: ERROR: Working tree is out of date, please "
 
262
                          "run 'bzr update'.\n"))
272
263
 
273
264
    def test_local_commit_unbound(self):
274
265
        # a --local commit on an unbound branch is an error
284
275
        # past. This is a user story reported to fail in bug #43959 where 
285
276
        # a merge done in a checkout (using the update command) failed to
286
277
        # commit correctly.
287
 
        self.run_bzr('init trunk')
 
278
        trunk = self.make_branch_and_tree('trunk')
288
279
 
289
 
        self.run_bzr('checkout trunk u1')
 
280
        u1 = trunk.branch.create_checkout('u1')
290
281
        self.build_tree_contents([('u1/hosts', 'initial contents')])
291
 
        self.run_bzr('add u1/hosts')
 
282
        u1.add('hosts')
292
283
        self.run_bzr('commit -m add-hosts u1')
293
284
 
294
 
        self.run_bzr('checkout trunk u2')
 
285
        u2 = trunk.branch.create_checkout('u2')
295
286
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
296
287
        self.run_bzr('commit -m checkin-from-u2 u2')
297
288