90
96
self._format = _format
91
97
self._base = a_bzrdir.transport.base
92
98
self._ignore_fallbacks = False
93
self.bzrdir = a_bzrdir
94
99
foreign.ForeignBranch.__init__(self,
95
100
DummyForeignVcsMapping(DummyForeignVcs()))
96
101
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
100
class InterToDummyVcsBranch(branch.GenericInterBranch,
101
foreign.InterToForeignBranch):
104
def is_compatible(source, target):
105
return isinstance(target, DummyForeignVcsBranch)
107
def push(self, overwrite=False, stop_revision=None):
108
raise errors.NoRoundtrippingSupport(self.source, self.target)
110
def lossy_push(self, stop_revision=None):
111
result = branch.BranchPushResult()
112
result.source_branch = self.source
113
result.target_branch = self.target
114
result.old_revno, result.old_revid = self.target.last_revision_info()
115
self.source.lock_read()
104
def dpull(self, source, stop_revision=None):
117
107
# This just handles simple cases, but that's good enough for tests
118
my_history = self.target.revision_history()
119
their_history = self.source.revision_history()
108
my_history = self.revision_history()
109
their_history = source.revision_history()
120
110
if their_history[:min(len(my_history), len(their_history))] != my_history:
121
raise errors.DivergedBranches(self.target, self.source)
111
raise errors.DivergedBranches(self, source)
122
112
todo = their_history[len(my_history):]
124
114
for revid in todo:
125
rev = self.source.repository.get_revision(revid)
126
tree = self.source.repository.revision_tree(revid)
115
rev = source.repository.get_revision(revid)
116
tree = source.repository.revision_tree(revid)
127
117
def get_file_with_stat(file_id, path=None):
128
118
return (tree.get_file(file_id), None)
129
119
tree.get_file_with_stat = get_file_with_stat
130
new_revid = self.target.mapping.revision_id_foreign_to_bzr(
131
(str(rev.timestamp), str(rev.timezone),
132
str(self.target.revno())))
133
parent_revno, parent_revid= self.target.last_revision_info()
134
if parent_revid == revision.NULL_REVISION:
137
parent_revids = [parent_revid]
138
builder = self.target.get_commit_builder(parent_revids,
139
self.target.get_config(), rev.timestamp,
120
new_revid = self.mapping.revision_id_foreign_to_bzr(
121
(str(rev.timestamp), str(rev.timezone), str(self.revno())))
122
parent_revno, parent_revid= self.last_revision_info()
123
builder = self.get_commit_builder([parent_revid],
124
self.get_config(), rev.timestamp,
140
125
rev.timezone, rev.committer, rev.properties,
244
226
self._control_files = lockable_files.LockableFiles(self.transport,
245
227
"lock", lockable_files.TransportLock)
247
def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
249
raise errors.NoColocatedBranchSupport(self)
229
def open_branch(self, ignore_fallbacks=True):
250
230
return self._format.get_branch_format().open(self, _found=True)
252
232
def cloning_metadir(self, stacked=False):
253
233
"""Produce a metadir suitable for cloning with."""
254
return bzrdir.format_registry.make_bzrdir("default")
234
return format_registry.make_bzrdir("default")
256
236
def sprout(self, url, revision_id=None, force_new_repo=False,
257
237
recurse='down', possible_transports=None,
265
245
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
268
def register_dummy_foreign_for_test(testcase):
269
bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
270
testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
271
DummyForeignVcsDirFormat)
272
# We need to register the optimiser to make the dummy appears really
273
# different from a regular bzr repository.
274
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
275
testcase.addCleanup(branch.InterBranch.unregister_optimiser,
276
InterToDummyVcsBranch)
279
class ForeignVcsRegistryTests(tests.TestCase):
248
class ForeignVcsRegistryTests(TestCase):
280
249
"""Tests for the ForeignVcsRegistry class."""
282
251
def test_parse_revision_id_no_dash(self):
309
278
self.assertEquals(mapp, rev.mapping)
312
class WorkingTreeFileUpdateTests(tests.TestCaseWithTransport):
313
"""Tests for update_workingtree_fileids()."""
315
def test_update_workingtree(self):
281
class ShowForeignPropertiesTests(TestCase):
282
"""Tests for the show_foreign_properties() function."""
285
super(ShowForeignPropertiesTests, self).setUp()
286
self.vcs = DummyForeignVcs()
287
foreign.foreign_vcs_registry.register("dummy",
288
self.vcs, "Dummy VCS")
291
super(ShowForeignPropertiesTests, self).tearDown()
292
foreign.foreign_vcs_registry.remove("dummy")
294
def test_show_non_foreign(self):
295
"""Test use with a native (non-foreign) bzr revision."""
296
self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
298
def test_show_imported(self):
299
rev = Revision("dummy-v1:my-foreign-revid")
300
self.assertEquals({ "dummy ding": "my/foreign\\revid" },
301
foreign.show_foreign_properties(rev))
303
def test_show_direct(self):
304
rev = foreign.ForeignRevision(("some", "foreign", "revid"),
305
DummyForeignVcsMapping(self.vcs),
307
self.assertEquals({ "dummy ding": "some/foreign\\revid" },
308
foreign.show_foreign_properties(rev))
311
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
312
"""Tests for _determine_fileid_renames()."""
314
def test_det_renames_same(self):
316
a.add_path("bla", "directory", "bla-a")
318
b.add_path("bla", "directory", "bla-a")
320
'': ('TREE_ROOT', 'TREE_ROOT'),
321
'bla': ('bla-a', 'bla-a')},
322
foreign._determine_fileid_renames(a, b))
324
def test_det_renames_simple(self):
326
a.add_path("bla", "directory", "bla-a")
328
b.add_path("bla", "directory", "bla-b")
330
'': ('TREE_ROOT', 'TREE_ROOT'),
331
'bla': ('bla-a', 'bla-b'),
332
}, foreign._determine_fileid_renames(a, b))
334
def test_det_renames_root(self):
336
a.add_path("", "directory", "bla-a")
338
b.add_path("", "directory", "bla-b")
340
{"": ("bla-a", "bla-b")},
341
foreign._determine_fileid_renames(a, b))
343
def test_update_workinginv(self):
345
a.add_path("bla", "directory", "bla-a")
347
b.add_path("bla", "directory", "bla-b")
316
348
wt = self.make_branch_and_tree('br1')
317
349
self.build_tree_contents([('br1/bla', 'original contents\n')])
318
350
wt.add('bla', 'bla-a')
320
root_id = wt.get_root_id()
321
target = wt.bzrdir.sprout('br2').open_workingtree()
322
target.unversion(['bla-a'])
323
target.add('bla', 'bla-b')
324
target.commit('bla-b')
325
target_basis = target.basis_tree()
326
target_basis.lock_read()
327
self.addCleanup(target_basis.unlock)
328
foreign.update_workingtree_fileids(wt, target_basis)
351
foreign.update_workinginv_fileids(wt, a, b)
331
self.assertEquals(set([root_id, "bla-b"]), set(wt.inventory))
354
self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory))
336
class DummyForeignVcsTests(tests.TestCaseWithTransport):
359
class DummyForeignVcsTests(TestCaseWithTransport):
337
360
"""Very basic test for DummyForeignVcs."""
363
BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
364
self.addCleanup(self.unregister)
340
365
super(DummyForeignVcsTests, self).setUp()
341
register_dummy_foreign_for_test(self)
367
def unregister(self):
369
BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
343
373
def test_create(self):
344
374
"""Test we can create dummies."""
345
375
self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
346
dir = bzrdir.BzrDir.open("d")
376
dir = BzrDir.open("d")
347
377
self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string())
348
378
dir.open_repository()
349
379
dir.open_branch()
352
382
def test_sprout(self):
353
383
"""Test we can clone dummies and that the format is not preserved."""
354
384
self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat())
355
dir = bzrdir.BzrDir.open("d")
385
dir = BzrDir.open("d")
356
386
newdir = dir.sprout("e")
357
self.assertNotEquals("A Dummy VCS Dir",
358
newdir._format.get_format_string())
360
def test_push_not_supported(self):
361
source_tree = self.make_branch_and_tree("source")
362
target_tree = self.make_branch_and_tree("target",
363
format=DummyForeignVcsDirFormat())
364
self.assertRaises(errors.NoRoundtrippingSupport,
365
source_tree.branch.push, target_tree.branch)
367
def test_lossy_push_empty(self):
368
source_tree = self.make_branch_and_tree("source")
369
target_tree = self.make_branch_and_tree("target",
370
format=DummyForeignVcsDirFormat())
371
pushresult = source_tree.branch.lossy_push(target_tree.branch)
372
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
373
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
374
self.assertEquals({}, pushresult.revidmap)
376
def test_lossy_push_simple(self):
377
source_tree = self.make_branch_and_tree("source")
378
self.build_tree(['source/a', 'source/b'])
379
source_tree.add(['a', 'b'])
380
revid1 = source_tree.commit("msg")
381
target_tree = self.make_branch_and_tree("target",
382
format=DummyForeignVcsDirFormat())
383
target_tree.branch.lock_write()
385
pushresult = source_tree.branch.lossy_push(target_tree.branch)
387
target_tree.branch.unlock()
388
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
389
self.assertEquals({revid1:target_tree.branch.last_revision()},
391
self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)
387
self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())