89
91
repo = tree.branch.repository
90
92
self.assertIsInstance(repo.signatures,
91
93
versionedfile.VersionedFiles)
95
def test_exposed_versioned_files_are_marked_dirty(self):
96
repo = self.make_repository('.')
98
signatures = repo.signatures
99
revisions = repo.revisions
100
inventories = repo.inventories
102
self.assertRaises(errors.ObjectNotLocked,
104
self.assertRaises(errors.ObjectNotLocked,
106
self.assertRaises(errors.ObjectNotLocked,
108
self.assertRaises(errors.ObjectNotLocked,
109
signatures.add_lines, ('foo',), [], [])
110
self.assertRaises(errors.ObjectNotLocked,
111
revisions.add_lines, ('foo',), [], [])
112
self.assertRaises(errors.ObjectNotLocked,
113
inventories.add_lines, ('foo',), [], [])
116
class TestCaseWithComplexRepository(TestCaseWithRepository):
118
scenarios = all_repository_vf_format_scenarios()
121
super(TestCaseWithComplexRepository, self).setUp()
122
tree_a = self.make_branch_and_tree('a')
123
self.bzrdir = tree_a.branch.bzrdir
124
# add a corrupt inventory 'orphan'
125
# this may need some generalising for knits.
128
tree_a.branch.repository.start_write_group()
130
inv_file = tree_a.branch.repository.inventories
131
inv_file.add_lines(('orphan',), [], [])
133
tree_a.branch.repository.commit_write_group()
136
tree_a.branch.repository.abort_write_group()
139
# add a real revision 'rev1'
140
tree_a.commit('rev1', rev_id='rev1', allow_pointless=True)
141
# add a real revision 'rev2' based on rev1
142
tree_a.commit('rev2', rev_id='rev2', allow_pointless=True)
143
# add a reference to a ghost
144
tree_a.add_parent_tree_id('ghost1')
146
tree_a.commit('rev3', rev_id='rev3', allow_pointless=True)
147
except errors.RevisionNotPresent:
148
raise tests.TestNotApplicable(
149
"Cannot test with ghosts for this format.")
150
# add another reference to a ghost, and a second ghost.
151
tree_a.add_parent_tree_id('ghost1')
152
tree_a.add_parent_tree_id('ghost2')
153
tree_a.commit('rev4', rev_id='rev4', allow_pointless=True)
155
def test_revision_trees(self):
156
revision_ids = ['rev1', 'rev2', 'rev3', 'rev4']
157
repository = self.bzrdir.open_repository()
158
repository.lock_read()
159
self.addCleanup(repository.unlock)
160
trees1 = list(repository.revision_trees(revision_ids))
161
trees2 = [repository.revision_tree(t) for t in revision_ids]
162
self.assertEqual(len(trees1), len(trees2))
163
for tree1, tree2 in zip(trees1, trees2):
164
self.assertFalse(tree2.changes_from(tree1).has_changed())
166
def test_get_deltas_for_revisions(self):
167
repository = self.bzrdir.open_repository()
168
repository.lock_read()
169
self.addCleanup(repository.unlock)
170
revisions = [repository.get_revision(r) for r in
171
['rev1', 'rev2', 'rev3', 'rev4']]
172
deltas1 = list(repository.get_deltas_for_revisions(revisions))
173
deltas2 = [repository.get_revision_delta(r.revision_id) for r in
175
self.assertEqual(deltas1, deltas2)
177
def test_all_revision_ids(self):
178
# all_revision_ids -> all revisions
179
self.assertEqual(set(['rev1', 'rev2', 'rev3', 'rev4']),
180
set(self.bzrdir.open_repository().all_revision_ids()))
182
def test_get_ancestry_missing_revision(self):
183
# get_ancestry(revision that is in some data but not fully installed
185
self.assertRaises(errors.NoSuchRevision,
186
self.bzrdir.open_repository().get_ancestry, 'orphan')
188
def test_get_unordered_ancestry(self):
189
repo = self.bzrdir.open_repository()
190
self.assertEqual(set(repo.get_ancestry('rev3')),
191
set(repo.get_ancestry('rev3', topo_sorted=False)))
193
def test_reserved_id(self):
194
repo = self.make_repository('repository')
196
repo.start_write_group()
198
self.assertRaises(errors.ReservedId, repo.add_inventory,
199
'reserved:', None, None)
200
self.assertRaises(errors.ReservedId, repo.add_inventory_by_delta,
201
"foo", [], 'reserved:', None)
202
self.assertRaises(errors.ReservedId, repo.add_revision,
205
repo.abort_write_group()