~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from bzr.dev.

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('.')
345
357
                                                      allow_pointless=True,
346
358
                                                      rev_id='B',
347
359
                                                      working_tree=wt)
348
 
            self.assertEqual(Testament.from_revision(branch.repository,
349
 
                             'B').as_short_text(),
 
360
            def sign(text):
 
361
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
 
362
            self.assertEqual(sign(Testament.from_revision(branch.repository,
 
363
                             'B').as_short_text()),
350
364
                             branch.repository.get_signature_text('B'))
351
365
        finally:
352
366
            bzrlib.gpg.GPGStrategy = oldstrategy
527
541
        tree.commit('added a, b')
528
542
        tree.remove(['a', 'b'])
529
543
        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)
 
544
        basis = tree.basis_tree()
 
545
        tree.lock_read()
 
546
        try:
 
547
            self.assertIs(None, basis.path2id('a'))
 
548
            self.assertFalse(basis.path2id('b') is None)
 
549
        finally:
 
550
            tree.unlock()
533
551
 
534
552
    def test_commit_saves_1ms_timestamp(self):
535
553
        """Passing in a timestamp is saved with 1ms resolution"""
554
572
        timestamp_1ms = round(timestamp, 3)
555
573
        self.assertEqual(timestamp_1ms, timestamp)
556
574
 
 
575
    def assertBasisTreeKind(self, kind, tree, file_id):
 
576
        basis = tree.basis_tree()
 
577
        basis.lock_read()
 
578
        try:
 
579
            self.assertEqual(kind, basis.kind(file_id))
 
580
        finally:
 
581
            basis.unlock()
 
582
 
557
583
    def test_commit_kind_changes(self):
558
584
        if not osutils.has_symlinks():
559
585
            raise tests.TestSkipped('Test requires symlink support')
561
587
        os.symlink('target', 'name')
562
588
        tree.add('name', 'a-file-id')
563
589
        tree.commit('Added a symlink')
564
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
590
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
565
591
 
566
592
        os.unlink('name')
567
593
        self.build_tree(['name'])
568
594
        tree.commit('Changed symlink to file')
569
 
        self.assertEqual('file', tree.basis_tree().kind('a-file-id'))
 
595
        self.assertBasisTreeKind('file', tree, 'a-file-id')
570
596
 
571
597
        os.unlink('name')
572
598
        os.symlink('target', 'name')
573
599
        tree.commit('file to symlink')
574
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
600
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
575
601
 
576
602
        os.unlink('name')
577
603
        os.mkdir('name')
578
604
        tree.commit('symlink to directory')
579
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
605
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
580
606
 
581
607
        os.rmdir('name')
582
608
        os.symlink('target', 'name')
583
609
        tree.commit('directory to symlink')
584
 
        self.assertEqual('symlink', tree.basis_tree().kind('a-file-id'))
 
610
        self.assertBasisTreeKind('symlink', tree, 'a-file-id')
585
611
 
586
612
        # prepare for directory <-> file tests
587
613
        os.unlink('name')
588
614
        os.mkdir('name')
589
615
        tree.commit('symlink to directory')
590
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
616
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
591
617
 
592
618
        os.rmdir('name')
593
619
        self.build_tree(['name'])
594
620
        tree.commit('Changed directory to file')
595
 
        self.assertEqual('file', tree.basis_tree().kind('a-file-id'))
 
621
        self.assertBasisTreeKind('file', tree, 'a-file-id')
596
622
 
597
623
        os.unlink('name')
598
624
        os.mkdir('name')
599
625
        tree.commit('file to directory')
600
 
        self.assertEqual('directory', tree.basis_tree().kind('a-file-id'))
 
626
        self.assertBasisTreeKind('directory', tree, 'a-file-id')
601
627
 
602
628
    def test_commit_unversioned_specified(self):
603
629
        """Commit should raise if specified files isn't in basis or worktree"""