42
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
43
from bzrlib.transport import get_transport
46
class TestCaseWithInterRepository(TestCaseWithBzrDir):
49
super(TestCaseWithInterRepository, self).setUp()
51
def make_branch(self, relpath, format=None):
52
repo = self.make_repository(relpath, format=format)
53
return repo.bzrdir.create_branch()
55
def make_bzrdir(self, relpath, format=None):
57
url = self.get_url(relpath)
58
segments = url.split('/')
59
if segments and segments[-1] not in ('', '.'):
60
parent = '/'.join(segments[:-1])
61
t = get_transport(parent)
67
format = self.repository_format._matchingbzrdir
68
return format.initialize(url)
69
except UninitializableFormat:
70
raise TestSkipped("Format %s is not initializable." % format)
72
def make_repository(self, relpath, format=None):
73
made_control = self.make_bzrdir(relpath, format=format)
74
return self.repository_format.initialize(made_control)
76
def make_to_repository(self, relpath):
77
made_control = self.make_bzrdir(relpath,
78
self.repository_format_to._matchingbzrdir)
79
return self.repository_format_to.initialize(made_control)
37
from bzrlib.tests.interrepository_implementations import (
38
TestCaseWithInterRepository,
82
42
def check_old_format_lock_error(repository_format):
130
90
## self.assertEqual(self.interrepo_class, interrepo.__class__)
133
def test_fetch(self):
134
tree_a = self.make_branch_and_tree('a')
135
self.build_tree(['a/foo'])
136
tree_a.add('foo', 'file1')
137
tree_a.commit('rev1', rev_id='rev1')
138
def check_push_rev1(repo):
139
# ensure the revision is missing.
140
self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
141
# fetch with a limit of NULL_REVISION and an explicit progress bar.
142
repo.fetch(tree_a.branch.repository,
143
revision_id=NULL_REVISION,
144
pb=bzrlib.progress.DummyProgress())
145
# nothing should have been pushed
146
self.assertFalse(repo.has_revision('rev1'))
147
# fetch with a default limit (grab everything)
148
repo.fetch(tree_a.branch.repository)
149
# check that b now has all the data from a's first commit.
150
rev = repo.get_revision('rev1')
151
tree = repo.revision_tree('rev1')
153
self.addCleanup(tree.unlock)
154
tree.get_file_text('file1')
156
if tree.inventory[file_id].kind == "file":
157
tree.get_file(file_id).read()
159
# makes a target version repo
160
repo_b = self.make_to_repository('b')
161
check_push_rev1(repo_b)
163
def test_fetch_missing_basis_text(self):
164
"""If fetching a delta, we should die if a basis is not present."""
165
tree = self.make_branch_and_tree('tree')
166
self.build_tree(['tree/a'])
167
tree.add(['a'], ['a-id'])
168
tree.commit('one', rev_id='rev-one')
169
self.build_tree_contents([('tree/a', 'new contents\n')])
170
tree.commit('two', rev_id='rev-two')
172
to_repo = self.make_to_repository('to_repo')
173
# We build a broken revision so that we can test the fetch code dies
174
# properly. So copy the inventory and revision, but not the text.
177
to_repo.start_write_group()
178
inv = tree.branch.repository.get_inventory('rev-one')
179
to_repo.add_inventory('rev-one', inv, [])
180
rev = tree.branch.repository.get_revision('rev-one')
181
to_repo.add_revision('rev-one', rev, inv=inv)
182
to_repo.commit_write_group()
186
# Implementations can either copy the missing basis text, or raise an
189
to_repo.fetch(tree.branch.repository, 'rev-two')
190
except errors.RevisionNotPresent, e:
191
# If an exception is raised, the revision should not be in the
193
self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),
194
to_repo.revision_tree, 'rev-two')
196
# If not exception is raised, then the basis text should be
200
rt = to_repo.revision_tree('rev-one')
201
self.assertEqual('contents of tree/a\n',
202
rt.get_file_text('a-id'))
206
def test_fetch_missing_revision_same_location_fails(self):
207
repo_a = self.make_repository('.')
208
repo_b = repository.Repository.open('.')
210
self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
211
except errors.LockError, e:
212
check_old_format_lock_error(self.repository_format)
214
def test_fetch_same_location_trivial_works(self):
215
repo_a = self.make_repository('.')
216
repo_b = repository.Repository.open('.')
219
except errors.LockError, e:
220
check_old_format_lock_error(self.repository_format)
222
def test_fetch_missing_text_other_location_fails(self):
223
source_tree = self.make_branch_and_tree('source')
224
source = source_tree.branch.repository
225
target = self.make_to_repository('target')
227
# start by adding a file so the data knit for the file exists in
228
# repositories that have specific files for each fileid.
229
self.build_tree(['source/id'])
230
source_tree.add(['id'], ['id'])
231
source_tree.commit('a', rev_id='a')
232
# now we manually insert a revision with an inventory referencing
233
# 'id' at revision 'b', but we do not insert revision b.
234
# this should ensure that the new versions of files are being checked
235
# for during pull operations
236
inv = source.get_inventory('a')
238
source.start_write_group()
239
inv['id'].revision = 'b'
240
inv.revision_id = 'b'
241
sha1 = source.add_inventory('b', inv, ['a'])
242
rev = Revision(timestamp=0,
244
committer="Foo Bar <foo@example.com>",
248
rev.parent_ids = ['a']
249
source.add_revision('b', rev)
250
source.commit_write_group()
252
self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
253
self.assertFalse(target.has_revision('b'))
255
def test_fetch_funky_file_id(self):
256
from_tree = self.make_branch_and_tree('tree')
257
if sys.platform == 'win32':
258
from_repo = from_tree.branch.repository
259
check_repo_format_for_funky_id_on_win32(from_repo)
260
self.build_tree(['tree/filename'])
261
from_tree.add('filename', 'funky-chars<>%&;"\'')
262
from_tree.commit('commit filename')
263
to_repo = self.make_to_repository('to')
264
to_repo.fetch(from_tree.branch.repository, from_tree.get_parent_ids()[0])
267
94
class TestCaseWithComplexRepository(TestCaseWithInterRepository):
324
151
self.assertFalse(repo_a.has_revision('pizza'))
325
152
self.assertFalse(repo_b.has_revision('pizza'))
326
153
# Asking specifically for an absent revision errors.
327
self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
328
revision_id='pizza', find_ghosts=True)
329
self.assertRaises(NoSuchRevision, repo_b.search_missing_revision_ids, repo_a,
330
revision_id='pizza', find_ghosts=False)
154
self.assertRaises(errors.NoSuchRevision,
155
repo_b.search_missing_revision_ids, repo_a, revision_id='pizza',
157
self.assertRaises(errors.NoSuchRevision,
158
repo_b.search_missing_revision_ids, repo_a, revision_id='pizza',
332
161
def test_search_missing_revision_ids_revision_limited(self):
333
162
# revision ids in repository A that are not referenced by the
403
232
# rev must not be corrupt now
404
233
self.assertEqual([None, 'ghost', 'references', 'tip'],
405
234
missing_ghost.get_ancestry('tip'))
408
class TestFetchDependentData(TestCaseWithInterRepository):
410
def test_reference(self):
411
from_tree = self.make_branch_and_tree('tree')
412
to_repo = self.make_to_repository('to')
413
if (not from_tree.supports_tree_reference() or
414
not from_tree.branch.repository._format.supports_tree_reference or
415
not to_repo._format.supports_tree_reference):
416
raise TestNotApplicable("Need subtree support.")
417
subtree = self.make_branch_and_tree('tree/subtree')
418
subtree.commit('subrev 1')
419
from_tree.add_reference(subtree)
420
tree_rev = from_tree.commit('foo')
421
# now from_tree has a last-modified of subtree of the rev id of the
422
# commit for foo, and a reference revision of the rev id of the commit
424
to_repo.fetch(from_tree.branch.repository, tree_rev)
425
# to_repo should have a file_graph for from_tree.path2id('subtree') and
429
file_vf = to_repo.weave_store.get_weave(
430
from_tree.path2id('subtree'), to_repo.get_transaction())
431
self.assertEqual([tree_rev], file_vf.get_ancestry([tree_rev]))