18
18
"""Tests for the commit CLI of bzr."""
24
22
from bzrlib import (
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
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.
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)
46
41
def test_commit_success(self):
47
42
"""Successful commit should not leave behind a bzr-commit-* file"""
43
self.make_branch_and_tree('.')
49
44
self.run_bzr('commit --unchanged -m message')
50
45
self.assertEqual('', self.run_bzr('unknowns')[0])
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')
61
56
self.run_bzr(['commit', '-m', 'first commit', 'a'])
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'])
67
62
self.build_tree_contents([('a/a_file', 'new contents')])
68
63
self.run_bzr(['commit', '-m', 'change in a', 'a'])
71
self.run_bzr('merge ../a', retcode=1) # will conflict
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'])
77
71
def test_10_verbose_commit(self):
78
72
"""Add one file and examine verbose commit output"""
73
tree = self.make_branch_and_tree('.')
80
74
self.build_tree(['hello.txt'])
81
self.run_bzr("add hello.txt")
82
76
out,err = self.run_bzr('commit -v -m added')
83
77
self.assertEqual('', out)
84
78
self.assertEqual('added hello.txt\n'
214
208
def test_verbose_commit_with_unchanged(self):
215
209
"""Unchanged files should not be listed by default in verbose output"""
210
tree = self.make_branch_and_tree('.')
217
211
self.build_tree(['hello.txt', 'unchanged.txt'])
218
self.run_bzr('add unchanged.txt')
212
tree.add('unchanged.txt')
219
213
self.run_bzr('commit -m unchanged unchanged.txt')
220
self.run_bzr("add hello.txt")
214
tree.add("hello.txt")
221
215
out,err = self.run_bzr('commit -v -m added')
222
216
self.assertEqual('', out)
223
217
self.assertEqual('added hello.txt\n'
261
255
other_tree.rename_one('dirtorename', 'renameddir')
262
256
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
263
257
other_tree.rename_one('filetorename', 'renamedfile')
264
other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
258
other_tree.rename_one('filetoreparent',
259
'renameddir/reparentedfile')
265
260
other_tree.remove(['dirtoremove', 'filetoremove'])
266
261
self.build_tree_contents([
268
263
('other/filetomodify', 'new content'),
269
264
('other/newfile', 'new file content')])
270
265
other_tree.add('newfile')
293
288
def test_empty_commit_message(self):
295
file('foo.c', 'wt').write('int main() {}')
296
self.run_bzr('add foo.c')
289
tree = self.make_branch_and_tree('.')
290
self.build_tree_contents([('foo.c', 'int main() {}')])
297
292
self.run_bzr('commit -m ""', retcode=3)
299
294
def test_unsupported_encoding_commit_message(self):
308
303
def test_other_branch_commit(self):
309
304
# this branch is to ensure consistent behaviour, whether we're run
310
305
# inside a branch, or not.
311
os.mkdir('empty_branch')
312
os.chdir('empty_branch')
317
file('foo.c', 'wt').write('int main() {}')
318
file('bar.c', 'wt').write('int main() {}')
320
self.run_bzr('add branch/foo.c')
321
self.run_bzr('add branch')
306
outer_tree = self.make_branch_and_tree('.')
307
inner_tree = self.make_branch_and_tree('branch')
308
self.build_tree_contents([
309
('branch/foo.c', 'int main() {}'),
310
('branch/bar.c', 'int main() {}')])
311
inner_tree.add('foo.c')
312
inner_tree.add('bar.c')
322
313
# can't commit files in different trees; sane error
323
314
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
324
315
self.run_bzr('commit -m newstuff branch/foo.c')
328
319
def test_out_of_date_tree_commit(self):
329
320
# check we get an error code and a clear message committing with an out
330
321
# of date checkout
331
self.make_branch_and_tree('branch')
322
tree = self.make_branch_and_tree('branch')
332
323
# make a checkout
333
self.run_bzr('checkout --lightweight branch checkout')
324
checkout = tree.branch.create_checkout('checkout', lightweight=True)
334
325
# commit to the original branch to make the checkout out of date
335
self.run_bzr('commit --unchanged -m message branch')
326
tree.commit('message branch', allow_pointless=True)
336
327
# now commit to the checkout should emit
337
328
# ERROR: Out of date with the branch, 'bzr update' is suggested
338
329
output = self.run_bzr('commit --unchanged -m checkout_message '
339
330
'checkout', retcode=3)
340
331
self.assertEqual(output,
342
"bzr: ERROR: Working tree is out of date, please run "
333
"bzr: ERROR: Working tree is out of date, please "
334
"run 'bzr update'.\n"))
345
336
def test_local_commit_unbound(self):
346
337
# a --local commit on an unbound branch is an error
356
347
# past. This is a user story reported to fail in bug #43959 where
357
348
# a merge done in a checkout (using the update command) failed to
358
349
# commit correctly.
359
self.run_bzr('init trunk')
350
trunk = self.make_branch_and_tree('trunk')
361
self.run_bzr('checkout trunk u1')
352
u1 = trunk.branch.create_checkout('u1')
362
353
self.build_tree_contents([('u1/hosts', 'initial contents')])
363
self.run_bzr('add u1/hosts')
364
355
self.run_bzr('commit -m add-hosts u1')
366
self.run_bzr('checkout trunk u2')
357
u2 = trunk.branch.create_checkout('u2')
367
358
self.build_tree_contents([('u2/hosts', 'altered in u2')])
368
359
self.run_bzr('commit -m checkin-from-u2 u2')