125
126
repository.RepositoryFormat.find_format(opened_control))
127
128
def test_create_repository(self):
128
# a repository can be constructedzrdir can construct a repository for itself.
129
# bzrdir can construct a repository for itself.
129
130
if not self.bzrdir_format.is_supported():
130
131
# unsupported formats are not loopback testable
131
132
# because the default open will not open them and
136
137
made_repo = made_control.create_repository()
137
138
self.failUnless(isinstance(made_repo, repository.Repository))
138
139
self.assertEqual(made_control, made_repo.bzrdir)
141
def test_create_repository_shared(self):
142
# bzrdir can construct a shared repository.
143
if not self.bzrdir_format.is_supported():
144
# unsupported formats are not loopback testable
145
# because the default open will not open them and
146
# they may not be initializable.
148
t = get_transport(self.get_url())
149
made_control = self.bzrdir_format.initialize(t.base)
151
made_repo = made_control.create_repository(shared=True)
152
except errors.IncompatibleFormat:
153
# not all repository formats understand being shared, or
154
# may only be shared in some circumstances.
156
self.failUnless(isinstance(made_repo, repository.Repository))
157
self.assertEqual(made_control, made_repo.bzrdir)
158
self.assertTrue(made_repo.is_shared())
140
160
def test_revision_tree(self):
141
161
wt = self.make_branch_and_tree('.')
148
168
self.assertEqual(len(tree.list_files()), 0)
150
170
def test_fetch(self):
171
# smoke test fetch to ensure that the convenience function works.
172
# it is defined as a convenience function with the underlying
173
# functionality provided by an InterRepository
151
174
tree_a = self.make_branch_and_tree('a')
152
175
self.build_tree(['a/foo'])
153
176
tree_a.add('foo', 'file1')
154
177
tree_a.commit('rev1', rev_id='rev1')
155
def check_push_rev1(repo):
156
# ensure the revision is missing.
157
self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
158
# fetch with a limit of NULL_REVISION
159
repo.fetch(tree_a.branch.repository, NULL_REVISION)
160
# nothing should have been pushed
161
self.assertFalse(repo.has_revision('rev1'))
162
# fetch with a default limit (grab everything)
163
repo.fetch(tree_a.branch.repository)
164
# check that b now has all the data from a's first commit.
165
rev = repo.get_revision('rev1')
166
tree = repo.revision_tree('rev1')
167
tree.get_file_text('file1')
169
if tree.inventory[file_id].kind == "file":
170
tree.get_file(file_id).read()
172
# makes a latest-version repo
173
repo_b = bzrdir.BzrDir.create_repository(self.get_url('b'))
174
check_push_rev1(repo_b)
176
# makes a this-version repo:
177
repo_c = self.make_repository('c')
178
check_push_rev1(repo_c)
178
# fetch with a default limit (grab everything)
179
repo = bzrdir.BzrDir.create_repository(self.get_url('b'))
180
repo.fetch(tree_a.branch.repository,
182
pb=bzrlib.progress.DummyProgress())
180
184
def test_clone_bzrdir_repository_revision(self):
181
185
# make a repository with some revisions,
200
204
target = source.bzrdir.clone(self.get_url('target'), basis=tree.bzrdir)
201
205
self.assertTrue(target.open_repository().has_revision('2'))
207
def test_clone_shared_no_tree(self):
208
# cloning a shared repository keeps it shared
209
# and preserves the make_working_tree setting.
210
made_control = self.make_bzrdir('source')
212
made_repo = made_control.create_repository(shared=True)
213
except errors.IncompatibleFormat:
214
# not all repository formats understand being shared, or
215
# may only be shared in some circumstances.
217
made_repo.set_make_working_trees(False)
218
result = made_control.clone(self.get_url('target'))
219
self.failUnless(isinstance(made_repo, repository.Repository))
220
self.assertEqual(made_control, made_repo.bzrdir)
221
self.assertTrue(result.open_repository().is_shared())
222
self.assertFalse(result.open_repository().make_working_trees())
204
225
class TestCaseWithComplexRepository(TestCaseWithRepository):
208
229
tree_a = self.make_branch_and_tree('a')
209
230
self.bzrdir = tree_a.branch.bzrdir
210
231
# add a corrupt inventory 'orphan'
232
# this may need some generalising for knits.
211
233
tree_a.branch.repository.control_weaves.add_text(
212
234
'inventory', 'orphan', [], [],
213
235
tree_a.branch.repository.get_transaction())
221
243
self.assertEqual(['rev1', 'rev2'],
222
244
self.bzrdir.open_repository().all_revision_ids())
224
def test_missing_revision_ids(self):
225
# revision ids in repository A but not B are returned, fake ones
226
# are stripped. (fake meaning no revision object, but an inventory
227
# as some formats keyed off inventory data in the past.
228
# make a repository to compare against that claims to have rev1
229
tree_b = self.make_branch_and_tree('rev1_only')
230
# add a real revision 'rev1'
231
tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
232
repo_a = self.bzrdir.open_repository()
233
repo_b = tree_b.branch.repository
234
self.assertEqual(['rev2'],
235
repo_b.missing_revision_ids(repo_a))
237
def test_missing_revision_ids_default_format(self):
238
# revision ids in repository A but not B are returned, fake ones
239
# are stripped. (fake meaning no revision object, but an inventory
240
# as some formats keyed off inventory data in the past.
241
# make a repository to compare against that claims to have rev1
242
tree_b = bzrdir.BzrDir.create_standalone_workingtree('rev1_only')
243
# add a real revision 'rev1'
244
tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
245
repo_a = self.bzrdir.open_repository()
246
repo_b = tree_b.branch.repository
247
self.assertEqual(['rev2'],
248
repo_b.missing_revision_ids(repo_a))
250
def test_missing_revision_ids_revision_limited(self):
251
# revision ids in repository A that are not referenced by the
252
# requested revision are not returned.
253
# make a repository to compare against that is empty
254
tree_b = self.make_branch_and_tree('empty')
255
repo_a = self.bzrdir.open_repository()
256
repo_b = tree_b.branch.repository
257
self.assertEqual(['rev1'],
258
repo_b.missing_revision_ids(repo_a, revision_id='rev1'))
260
246
def test_get_ancestry_missing_revision(self):
261
# get_ancestry(missing revision)-> NoSuchRevision
247
# get_ancestry(revision that is in some data but not fully installed
262
249
self.assertRaises(errors.NoSuchRevision,
263
250
self.bzrdir.open_repository().get_ancestry, 'orphan')