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')
58
builder = tree.branch.get_commit_builder([], revision_id="foo")
59
except UnsupportedOperation:
66
builder = tree.branch.get_commit_builder([],
67
revision_id=revision_id)
68
except NonAsciiRevisionId:
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
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
83
self.assertEqual(revision_id,
84
tree.branch.repository.get_inventory(revision_id).revision_id)
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')
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')
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())
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)