30
31
from bzrlib.config import BranchConfig
31
32
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed,
33
from bzrlib.tests import TestCaseWithTransport
34
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
34
35
from bzrlib.workingtree import WorkingTree
70
71
def renamed(self, change, old_path, new_path):
71
72
self.calls.append(('renamed', change, old_path, new_path))
74
78
class TestCommit(TestCaseWithTransport):
92
96
eq(rev.message, 'add hello')
94
98
tree1 = b.repository.revision_tree(rh[0])
95
100
text = tree1.get_file_text(file_id)
96
eq(text, 'hello world')
102
self.assertEqual('hello world', text)
98
104
tree2 = b.repository.revision_tree(rh[1])
99
eq(tree2.get_file_text(file_id), 'version 2')
106
text = tree2.get_file_text(file_id)
108
self.assertEqual('version 2', text)
101
110
def test_delete_commit(self):
102
111
"""Test a commit with a deleted file"""
167
176
tree2 = b.repository.revision_tree('test@rev-2')
178
self.addCleanup(tree2.unlock)
168
179
self.assertTrue(tree2.has_filename('hello'))
169
180
self.assertEquals(tree2.get_file_text('hello-id'), 'hello')
170
181
self.assertEquals(tree2.get_file_text('buongia-id'), 'new text')
172
183
tree3 = b.repository.revision_tree('test@rev-3')
185
self.addCleanup(tree3.unlock)
173
186
self.assertFalse(tree3.has_filename('hello'))
174
187
self.assertEquals(tree3.get_file_text('buongia-id'), 'new text')
187
200
eq = self.assertEquals
188
201
tree1 = b.repository.revision_tree('test@rev-1')
203
self.addCleanup(tree1.unlock)
189
204
eq(tree1.id2path('hello-id'), 'hello')
190
205
eq(tree1.get_file_text('hello-id'), 'contents of hello\n')
191
206
self.assertFalse(tree1.has_filename('fruity'))
194
209
eq(ie.revision, 'test@rev-1')
196
211
tree2 = b.repository.revision_tree('test@rev-2')
213
self.addCleanup(tree2.unlock)
197
214
eq(tree2.id2path('hello-id'), 'fruity')
198
215
eq(tree2.get_file_text('hello-id'), 'contents of hello\n')
199
216
self.check_inventory_shape(tree2.inventory, ['fruity'])
238
255
self.check_inventory_shape(wt.read_working_inventory(),
239
['a', 'a/hello', 'a/b'])
256
['a/', 'a/hello', 'a/b/'])
240
257
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
241
['a', 'a/hello', 'a/b'])
258
['a/', 'a/hello', 'a/b/'])
250
267
self.check_inventory_shape(wt.read_working_inventory(),
251
['a', 'a/b/hello', 'a/b'])
268
['a/', 'a/b/hello', 'a/b/'])
525
542
('change', 'added', 'newdir'),
526
543
('change', 'added', 'newfile'),
527
544
('renamed', 'renamed', 'dirtorename', 'renameddir'),
545
('renamed', 'renamed', 'filetorename', 'renamedfile'),
528
546
('renamed', 'renamed', 'dirtoreparent', 'renameddir/reparenteddir'),
529
547
('renamed', 'renamed', 'filetoreparent', 'renameddir/reparentedfile'),
530
('renamed', 'renamed', 'filetorename', 'renamedfile'),
531
548
('deleted', 'dirtoremove'),
532
549
('deleted', 'filetoremove'),
583
600
def test_commit_kind_changes(self):
584
if not osutils.has_symlinks():
585
raise tests.TestSkipped('Test requires symlink support')
601
self.requireFeature(SymlinkFeature)
586
602
tree = self.make_branch_and_tree('.')
587
603
os.symlink('target', 'name')
588
604
tree.add('name', 'a-file-id')
695
711
self.assertEqual(['bar', 'baz'], err.files)
696
712
self.assertEqual('Selected-file commit of merges is not supported'
697
713
' yet: files bar, baz', str(err))
715
def test_commit_ordering(self):
716
"""Test of corner-case commit ordering error"""
717
tree = self.make_branch_and_tree('.')
718
self.build_tree(['a/', 'a/z/', 'a/c/', 'a/z/x', 'a/z/y'])
719
tree.add(['a/', 'a/z/', 'a/c/', 'a/z/x', 'a/z/y'])
721
self.build_tree(['a/c/d/'])
723
tree.rename_one('a/z/x', 'a/c/d/x')
724
tree.commit('test', specific_files=['a/z/y'])
726
def test_commit_no_author(self):
727
"""The default kwarg author in MutableTree.commit should not add
728
the 'author' revision property.
730
tree = self.make_branch_and_tree('foo')
731
rev_id = tree.commit('commit 1')
732
rev = tree.branch.repository.get_revision(rev_id)
733
self.assertFalse('author' in rev.properties)
735
def test_commit_author(self):
736
"""Passing a non-empty author kwarg to MutableTree.commit should add
737
the 'author' revision property.
739
tree = self.make_branch_and_tree('foo')
740
rev_id = tree.commit('commit 1', author='John Doe <jdoe@example.com>')
741
rev = tree.branch.repository.get_revision(rev_id)
742
self.assertEqual('John Doe <jdoe@example.com>',
743
rev.properties['author'])
745
def test_commit_with_checkout_and_branch_sharing_repo(self):
746
repo = self.make_repository('repo', shared=True)
747
# make_branch_and_tree ignores shared repos
748
branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
749
tree2 = branch.create_checkout('repo/tree2')
750
tree2.commit('message', rev_id='rev1')
751
self.assertTrue(tree2.branch.repository.has_revision('rev1'))