~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_commit_builder.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Tests for repository commit builder."""
18
18
 
19
19
from bzrlib import inventory
20
 
from bzrlib.errors import UnsupportedOperation
 
20
from bzrlib.errors import NonAsciiRevisionId, CannotSetRevisionId
21
21
from bzrlib.repository import CommitBuilder
22
22
from bzrlib import tests
23
23
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
32
32
 
33
33
    def record_root(self, builder, tree):
34
34
        if builder.record_root_entry is True:
35
 
            ie = tree.inventory.root
 
35
            tree.lock_read()
 
36
            try:
 
37
                ie = tree.inventory.root
 
38
            finally:
 
39
                tree.unlock()
36
40
            parent_tree = tree.branch.repository.revision_tree(None)
37
41
            parent_invs = []
38
42
            builder.record_entry_contents(ie, parent_invs, '', tree)
54
58
 
55
59
    def test_commit_with_revision_id(self):
56
60
        tree = self.make_branch_and_tree(".")
 
61
        # use a unicode revision id to test more corner cases.
 
62
        # The repository layer is meant to handle this.
 
63
        revision_id = u'\xc8abc'.encode('utf8')
57
64
        try:
58
 
            builder = tree.branch.get_commit_builder([], revision_id="foo")
59
 
        except UnsupportedOperation:
 
65
            try:
 
66
                builder = tree.branch.get_commit_builder([],
 
67
                    revision_id=revision_id)
 
68
            except NonAsciiRevisionId:
 
69
                revision_id = 'abc'
 
70
                builder = tree.branch.get_commit_builder([],
 
71
                    revision_id=revision_id)
 
72
        except CannotSetRevisionId:
60
73
            # This format doesn't support supplied revision ids
61
74
            return
62
75
        self.record_root(builder, tree)
63
76
        builder.finish_inventory()
64
 
        self.assertEqual("foo", builder.commit('foo bar'))
65
 
        self.assertTrue(tree.branch.repository.has_revision("foo"))
66
 
        # the revision id must be set on the inventory when saving it. This does not
67
 
        # precisely test that - a repository that wants to can add it on deserialisation,
68
 
        # but thats all the current contract guarantees anyway.
69
 
        self.assertEqual('foo', tree.branch.repository.get_inventory('foo').revision_id)
 
77
        self.assertEqual(revision_id, builder.commit('foo bar'))
 
78
        self.assertTrue(tree.branch.repository.has_revision(revision_id))
 
79
        # the revision id must be set on the inventory when saving it. This
 
80
        # does not precisely test that - a repository that wants to can add it
 
81
        # on deserialisation, but thats all the current contract guarantees
 
82
        # anyway.
 
83
        self.assertEqual(revision_id,
 
84
            tree.branch.repository.get_inventory(revision_id).revision_id)
70
85
 
71
86
    def test_commit_without_root(self):
72
87
        """This should cause a deprecation warning, not an assertion failure"""
73
88
        tree = self.make_branch_and_tree(".")
74
 
        if tree.branch.repository._format.rich_root_data:
 
89
        if tree.branch.repository.supports_rich_root():
75
90
            raise tests.TestSkipped('Format requires root')
76
91
        self.build_tree(['foo'])
77
92
        tree.add('foo', 'foo-id')
78
 
        entry = tree.inventory['foo-id']
79
 
        builder = tree.branch.get_commit_builder([])
80
 
        self.callDeprecated(['Root entry should be supplied to'
81
 
            ' record_entry_contents, as of bzr 0.10.'],
82
 
            builder.record_entry_contents, entry, [], 'foo', tree)
83
 
        builder.finish_inventory()
84
 
        rev_id = builder.commit('foo bar')
 
93
        tree.lock_write()
 
94
        try:
 
95
            entry = tree.inventory['foo-id']
 
96
            builder = tree.branch.get_commit_builder([])
 
97
            self.callDeprecated(['Root entry should be supplied to'
 
98
                ' record_entry_contents, as of bzr 0.10.'],
 
99
                builder.record_entry_contents, entry, [], 'foo', tree)
 
100
            builder.finish_inventory()
 
101
            rev_id = builder.commit('foo bar')
 
102
        finally:
 
103
            tree.unlock()
85
104
 
86
105
    def test_commit(self):
87
106
        tree = self.make_branch_and_tree(".")
107
126
        # the RevisionTree api.
108
127
        self.assertEqual(rev_id, rev_tree.get_revision_id())
109
128
        self.assertEqual([], rev_tree.get_parent_ids())
 
129
 
 
130
    def test_root_entry_has_revision(self):
 
131
        # test the root revision created and put in the basis
 
132
        # has the right rev id.
 
133
        tree = self.make_branch_and_tree('.')
 
134
        rev_id = tree.commit('message')
 
135
        basis_tree = tree.basis_tree()
 
136
        basis_tree.lock_read()
 
137
        self.addCleanup(basis_tree.unlock)
 
138
        self.assertEqual(rev_id, basis_tree.inventory.root.revision)
 
139