~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: 2007-03-07 10:45:44 UTC
  • mfrom: (2321.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070307104544-59e3e6358e4bdb29
(robertc) Merge dirstate and subtrees. (Robert Collins, Martin Pool, Aaaron Bentley, John A Meinel, James Westby)

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
        wt.move(['hello'], 'a')
224
224
        r2 = 'test@rev-2'
225
225
        wt.commit('two', rev_id=r2, allow_pointless=False)
226
 
        self.check_inventory_shape(wt.read_working_inventory(),
227
 
                                   ['a', 'a/hello', 'b'])
 
226
        wt.lock_read()
 
227
        try:
 
228
            self.check_inventory_shape(wt.read_working_inventory(),
 
229
                                       ['a', 'a/hello', 'b'])
 
230
        finally:
 
231
            wt.unlock()
228
232
 
229
233
        wt.move(['b'], 'a')
230
234
        r3 = 'test@rev-3'
231
235
        wt.commit('three', rev_id=r3, allow_pointless=False)
232
 
        self.check_inventory_shape(wt.read_working_inventory(),
233
 
                                   ['a', 'a/hello', 'a/b'])
234
 
        self.check_inventory_shape(b.repository.get_revision_inventory(r3),
235
 
                                   ['a', 'a/hello', 'a/b'])
 
236
        wt.lock_read()
 
237
        try:
 
238
            self.check_inventory_shape(wt.read_working_inventory(),
 
239
                                       ['a', 'a/hello', 'a/b'])
 
240
            self.check_inventory_shape(b.repository.get_revision_inventory(r3),
 
241
                                       ['a', 'a/hello', 'a/b'])
 
242
        finally:
 
243
            wt.unlock()
236
244
 
237
245
        wt.move(['a/hello'], 'a/b')
238
246
        r4 = 'test@rev-4'
239
247
        wt.commit('four', rev_id=r4, allow_pointless=False)
240
 
        self.check_inventory_shape(wt.read_working_inventory(),
241
 
                                   ['a', 'a/b/hello', 'a/b'])
 
248
        wt.lock_read()
 
249
        try:
 
250
            self.check_inventory_shape(wt.read_working_inventory(),
 
251
                                       ['a', 'a/b/hello', 'a/b'])
 
252
        finally:
 
253
            wt.unlock()
242
254
 
243
255
        inv = b.repository.get_revision_inventory(r4)
244
256
        eq(inv['hello-id'].revision, r4)
245
257
        eq(inv['a-id'].revision, r1)
246
258
        eq(inv['b-id'].revision, r3)
247
 
        
 
259
 
248
260
    def test_removed_commit(self):
249
261
        """Commit with a removed file"""
250
262
        wt = self.make_branch_and_tree('.')
527
539
        tree.commit('added a, b')
528
540
        tree.remove(['a', 'b'])
529
541
        tree.commit('removed a', specific_files='a')
530
 
        basis = tree.basis_tree().inventory
531
 
        self.assertIs(None, basis.path2id('a'))
532
 
        self.assertFalse(basis.path2id('b') is None)
 
542
        basis = tree.basis_tree()
 
543
        tree.lock_read()
 
544
        try:
 
545
            self.assertIs(None, basis.path2id('a'))
 
546
            self.assertFalse(basis.path2id('b') is None)
 
547
        finally:
 
548
            tree.unlock()
533
549
 
534
550
    def test_commit_saves_1ms_timestamp(self):
535
551
        """Passing in a timestamp is saved with 1ms resolution"""
554
570
        timestamp_1ms = round(timestamp, 3)
555
571
        self.assertEqual(timestamp_1ms, timestamp)
556
572
 
 
573
    def assertBasisTreeKind(self, kind, tree, file_id):
 
574
        basis = tree.basis_tree()
 
575
        basis.lock_read()
 
576
        try:
 
577
            self.assertEqual(kind, basis.kind(file_id))
 
578
        finally:
 
579
            basis.unlock()
 
580
 
557
581
    def test_commit_kind_changes(self):
558
582
        if not osutils.has_symlinks():
559
583
            raise tests.TestSkipped('Test requires symlink support')
561
585
        os.symlink('target', 'name')
562
586
        tree.add('name', 'a-file-id')
563
587
        tree.commit('Added a symlink')
564
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
588
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
565
589
 
566
590
        os.unlink('name')
567
591
        self.build_tree(['name'])
568
592
        tree.commit('Changed symlink to file')
569
 
        self.assertEqual('file', tree.basis_tree().kind('a-file-id'))
 
593
        self.assertBasisTreeKind('file', tree, 'a-file-id')
570
594
 
571
595
        os.unlink('name')
572
596
        os.symlink('target', 'name')
573
597
        tree.commit('file to symlink')
574
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
598
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
575
599
 
576
600
        os.unlink('name')
577
601
        os.mkdir('name')
578
602
        tree.commit('symlink to directory')
579
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
603
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
580
604
 
581
605
        os.rmdir('name')
582
606
        os.symlink('target', 'name')
583
607
        tree.commit('directory to symlink')
584
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
608
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
585
609
 
586
610
        # prepare for directory <-> file tests
587
611
        os.unlink('name')
588
612
        os.mkdir('name')
589
613
        tree.commit('symlink to directory')
590
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
614
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
591
615
 
592
616
        os.rmdir('name')
593
617
        self.build_tree(['name'])
594
618
        tree.commit('Changed directory to file')
595
 
        self.assertEqual('file', tree.basis_tree().kind('a-file-id'))
 
619
        self.assertBasisTreeKind('file', tree, 'a-file-id')
596
620
 
597
621
        os.unlink('name')
598
622
        os.mkdir('name')
599
623
        tree.commit('file to directory')
600
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
624
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
601
625
 
602
626
    def test_commit_unversioned_specified(self):
603
627
        """Commit should raise if specified files isn't in basis or worktree"""