~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-03 18:09:01 UTC
  • mfrom: (3159.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080103180901-w987y1ftqoh02qbm
(vila) Fix #179368 by keeping the current range hint on
        ShortReadvErrors

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
 
22
    bzrdir,
22
23
    errors,
23
24
    lockdir,
24
25
    osutils,
30
31
from bzrlib.config import BranchConfig
31
32
from bzrlib.errors import (PointlessCommit, BzrError, SigningFailed, 
32
33
                           LockContention)
33
 
from bzrlib.tests import TestCaseWithTransport
 
34
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
34
35
from bzrlib.workingtree import WorkingTree
35
36
 
36
37
 
70
71
    def renamed(self, change, old_path, new_path):
71
72
        self.calls.append(('renamed', change, old_path, new_path))
72
73
 
 
74
    def is_verbose(self):
 
75
        return True
 
76
 
73
77
 
74
78
class TestCommit(TestCaseWithTransport):
75
79
 
92
96
        eq(rev.message, 'add hello')
93
97
 
94
98
        tree1 = b.repository.revision_tree(rh[0])
 
99
        tree1.lock_read()
95
100
        text = tree1.get_file_text(file_id)
96
 
        eq(text, 'hello world')
 
101
        tree1.unlock()
 
102
        self.assertEqual('hello world', text)
97
103
 
98
104
        tree2 = b.repository.revision_tree(rh[1])
99
 
        eq(tree2.get_file_text(file_id), 'version 2')
 
105
        tree2.lock_read()
 
106
        text = tree2.get_file_text(file_id)
 
107
        tree2.unlock()
 
108
        self.assertEqual('version 2', text)
100
109
 
101
110
    def test_delete_commit(self):
102
111
        """Test a commit with a deleted file"""
165
174
        eq(b.revno(), 3)
166
175
 
167
176
        tree2 = b.repository.revision_tree('test@rev-2')
 
177
        tree2.lock_read()
 
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')
171
182
        
172
183
        tree3 = b.repository.revision_tree('test@rev-3')
 
184
        tree3.lock_read()
 
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')
175
188
 
186
199
 
187
200
        eq = self.assertEquals
188
201
        tree1 = b.repository.revision_tree('test@rev-1')
 
202
        tree1.lock_read()
 
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')
195
210
 
196
211
        tree2 = b.repository.revision_tree('test@rev-2')
 
212
        tree2.lock_read()
 
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'])
226
243
        wt.lock_read()
227
244
        try:
228
245
            self.check_inventory_shape(wt.read_working_inventory(),
229
 
                                       ['a', 'a/hello', 'b'])
 
246
                                       ['a/', 'a/hello', 'b/'])
230
247
        finally:
231
248
            wt.unlock()
232
249
 
236
253
        wt.lock_read()
237
254
        try:
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/'])
242
259
        finally:
243
260
            wt.unlock()
244
261
 
248
265
        wt.lock_read()
249
266
        try:
250
267
            self.check_inventory_shape(wt.read_working_inventory(),
251
 
                                       ['a', 'a/b/hello', 'a/b'])
 
268
                                       ['a/', 'a/b/hello', 'a/b/'])
252
269
        finally:
253
270
            wt.unlock()
254
271
 
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'),
533
550
            ],
581
598
            basis.unlock()
582
599
 
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))
 
714
 
 
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'])
 
720
        tree.commit('setup')
 
721
        self.build_tree(['a/c/d/'])
 
722
        tree.add('a/c/d')
 
723
        tree.rename_one('a/z/x', 'a/c/d/x')
 
724
        tree.commit('test', specific_files=['a/z/y'])
 
725
 
 
726
    def test_commit_no_author(self):
 
727
        """The default kwarg author in MutableTree.commit should not add
 
728
        the 'author' revision property.
 
729
        """
 
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)
 
734
 
 
735
    def test_commit_author(self):
 
736
        """Passing a non-empty author kwarg to MutableTree.commit should add
 
737
        the 'author' revision property.
 
738
        """
 
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'])
 
744
 
 
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'))