~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge in InterRepository api to have it available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import sys
21
21
 
 
22
import bzrlib
22
23
import bzrlib.bzrdir as bzrdir
23
24
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
24
25
from bzrlib.commit import commit
167
168
        self.assertEqual(len(tree.list_files()), 0)
168
169
 
169
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
170
174
        tree_a = self.make_branch_and_tree('a')
171
175
        self.build_tree(['a/foo'])
172
176
        tree_a.add('foo', 'file1')
173
177
        tree_a.commit('rev1', rev_id='rev1')
174
 
        def check_push_rev1(repo):
175
 
            # ensure the revision is missing.
176
 
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
177
 
            # fetch with a limit of NULL_REVISION
178
 
            repo.fetch(tree_a.branch.repository, NULL_REVISION)
179
 
            # nothing should have been pushed
180
 
            self.assertFalse(repo.has_revision('rev1'))
181
 
            # fetch with a default limit (grab everything)
182
 
            repo.fetch(tree_a.branch.repository)
183
 
            # check that b now has all the data from a's first commit.
184
 
            rev = repo.get_revision('rev1')
185
 
            tree = repo.revision_tree('rev1')
186
 
            tree.get_file_text('file1')
187
 
            for file_id in tree:
188
 
                if tree.inventory[file_id].kind == "file":
189
 
                    tree.get_file(file_id).read()
190
 
 
191
 
        # makes a latest-version repo 
192
 
        repo_b = bzrdir.BzrDir.create_repository(self.get_url('b'))
193
 
        check_push_rev1(repo_b)
194
 
 
195
 
        # makes a this-version repo:
196
 
        repo_c = self.make_repository('c')
197
 
        check_push_rev1(repo_c)
198
 
        
199
 
    def test_fetch_missing_revision_same_location_fails(self):
200
 
        repo_a = self.make_repository('.')
201
 
        repo_b = repository.Repository.open('.')
202
 
        self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
203
 
 
204
 
    def test_fetch_same_location_trivial_works(self):
205
 
        repo_a = self.make_repository('.')
206
 
        repo_b = repository.Repository.open('.')
207
 
        repo_a.fetch(repo_b)
 
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,
 
181
                   revision_id=None,
 
182
                   pb=bzrlib.progress.DummyProgress())
208
183
 
209
184
    def test_clone_bzrdir_repository_revision(self):
210
185
        # make a repository with some revisions,
254
229
        tree_a = self.make_branch_and_tree('a')
255
230
        self.bzrdir = tree_a.branch.bzrdir
256
231
        # add a corrupt inventory 'orphan'
 
232
        # this may need some generalising for knits.
257
233
        tree_a.branch.repository.control_weaves.add_text(
258
234
            'inventory', 'orphan', [], [],
259
235
            tree_a.branch.repository.get_transaction())
267
243
        self.assertEqual(['rev1', 'rev2'],
268
244
                         self.bzrdir.open_repository().all_revision_ids())
269
245
 
270
 
    def test_missing_revision_ids(self):
271
 
        # revision ids in repository A but not B are returned, fake ones
272
 
        # are stripped. (fake meaning no revision object, but an inventory 
273
 
        # as some formats keyed off inventory data in the past.
274
 
        # make a repository to compare against that claims to have rev1
275
 
        tree_b = self.make_branch_and_tree('rev1_only')
276
 
        # add a real revision 'rev1'
277
 
        tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
278
 
        repo_a = self.bzrdir.open_repository()
279
 
        repo_b = tree_b.branch.repository
280
 
        self.assertEqual(['rev2'],
281
 
                         repo_b.missing_revision_ids(repo_a))
282
 
 
283
 
    def test_missing_revision_ids_default_format(self):
284
 
        # revision ids in repository A but not B are returned, fake ones
285
 
        # are stripped. (fake meaning no revision object, but an inventory 
286
 
        # as some formats keyed off inventory data in the past.
287
 
        # make a repository to compare against that claims to have rev1
288
 
        tree_b = bzrdir.BzrDir.create_standalone_workingtree('rev1_only')
289
 
        # add a real revision 'rev1'
290
 
        tree_b.commit('rev1', rev_id='rev1', allow_pointless=True)
291
 
        repo_a = self.bzrdir.open_repository()
292
 
        repo_b = tree_b.branch.repository
293
 
        self.assertEqual(['rev2'],
294
 
                         repo_b.missing_revision_ids(repo_a))
295
 
 
296
 
    def test_missing_revision_ids_revision_limited(self):
297
 
        # revision ids in repository A that are not referenced by the
298
 
        # requested revision are not returned.
299
 
        # make a repository to compare against that is empty
300
 
        tree_b = self.make_branch_and_tree('empty')
301
 
        repo_a = self.bzrdir.open_repository()
302
 
        repo_b = tree_b.branch.repository
303
 
        self.assertEqual(['rev1'],
304
 
                         repo_b.missing_revision_ids(repo_a, revision_id='rev1'))
305
 
 
306
246
    def test_get_ancestry_missing_revision(self):
307
 
        # get_ancestry(missing revision)-> NoSuchRevision
 
247
        # get_ancestry(revision that is in some data but not fully installed
 
248
        # -> NoSuchRevision
308
249
        self.assertRaises(errors.NoSuchRevision,
309
250
                          self.bzrdir.open_repository().get_ancestry, 'orphan')