339
339
recurse='down', possible_transports=None,
340
340
accelerator_tree=None, hardlink=False, stacked=False,
341
341
source_branch=None):
342
# dirstate doesn't cope with accelerator_trees well
342
# dirstate doesn't cope with accelerator_trees well
343
343
# that have a different control dir
344
return super(DummyForeignVcsDir, self).sprout(url=url,
345
revision_id=revision_id, force_new_repo=force_new_repo,
346
recurse=recurse, possible_transports=possible_transports,
347
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
344
return super(DummyForeignVcsDir, self).sprout(
346
revision_id=revision_id, force_new_repo=force_new_repo,
347
recurse=recurse, possible_transports=possible_transports,
348
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
350
351
def register_dummy_foreign_for_test(testcase):
351
352
controldir.ControlDirFormat.register_prober(DummyForeignProber)
352
353
testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
354
355
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
355
356
testcase.addCleanup(repository.format_registry.remove,
356
DummyForeignVcsRepositoryFormat())
357
DummyForeignVcsRepositoryFormat())
357
358
branch.format_registry.register(DummyForeignVcsBranchFormat())
358
359
testcase.addCleanup(branch.format_registry.remove,
359
DummyForeignVcsBranchFormat())
360
DummyForeignVcsBranchFormat())
360
361
# We need to register the optimiser to make the dummy appears really
361
362
# different from a regular bzr repository.
362
363
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
407
408
mapp = DummyForeignVcsMapping(DummyForeignVcs())
408
409
rev = foreign.ForeignRevision(("a", "foreign", "revid"),
409
410
mapp, "roundtripped-revid")
410
self.assertEquals("", rev.inventory_sha1)
411
self.assertEquals(("a", "foreign", "revid"), rev.foreign_revid)
412
self.assertEquals(mapp, rev.mapping)
411
self.assertEqual("", rev.inventory_sha1)
412
self.assertEqual(("a", "foreign", "revid"), rev.foreign_revid)
413
self.assertEqual(mapp, rev.mapping)
415
416
class WorkingTreeFileUpdateTests(tests.TestCaseWithTransport):
458
459
dir = controldir.ControlDir.open("d")
459
460
newdir = dir.sprout("e")
460
461
self.assertNotEqual("A Dummy VCS Dir",
461
newdir._format.get_format_string())
462
newdir._format.get_format_string())
463
464
def test_push_not_supported(self):
464
465
source_tree = self.make_branch_and_tree("source")
465
target_tree = self.make_branch_and_tree("target",
466
format=DummyForeignVcsDirFormat())
467
self.assertRaises(errors.NoRoundtrippingSupport,
468
source_tree.branch.push, target_tree.branch)
466
target_tree = self.make_branch_and_tree(
467
"target", format=DummyForeignVcsDirFormat())
468
self.assertRaises(errors.NoRoundtrippingSupport,
469
source_tree.branch.push, target_tree.branch)
470
471
def test_lossy_push_empty(self):
471
472
source_tree = self.make_branch_and_tree("source")
472
target_tree = self.make_branch_and_tree("target",
473
format=DummyForeignVcsDirFormat())
473
target_tree = self.make_branch_and_tree(
474
"target", format=DummyForeignVcsDirFormat())
474
475
pushresult = source_tree.branch.push(target_tree.branch, lossy=True)
475
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
476
self.assertEquals(revision.NULL_REVISION, pushresult.new_revid)
477
self.assertEquals({}, pushresult.revidmap)
476
self.assertEqual(revision.NULL_REVISION, pushresult.old_revid)
477
self.assertEqual(revision.NULL_REVISION, pushresult.new_revid)
478
self.assertEqual({}, pushresult.revidmap)
479
480
def test_lossy_push_simple(self):
480
481
source_tree = self.make_branch_and_tree("source")
481
482
self.build_tree(['source/a', 'source/b'])
482
483
source_tree.add(['a', 'b'])
483
484
revid1 = source_tree.commit("msg")
484
target_tree = self.make_branch_and_tree("target",
485
format=DummyForeignVcsDirFormat())
485
target_tree = self.make_branch_and_tree(
486
"target", format=DummyForeignVcsDirFormat())
486
487
target_tree.branch.lock_write()
488
489
pushresult = source_tree.branch.push(
489
490
target_tree.branch, lossy=True)
491
492
target_tree.branch.unlock()
492
self.assertEquals(revision.NULL_REVISION, pushresult.old_revid)
493
self.assertEquals({revid1:target_tree.branch.last_revision()},
495
self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)
493
self.assertEqual(revision.NULL_REVISION, pushresult.old_revid)
494
self.assertEqual({revid1: target_tree.branch.last_revision()},
496
self.assertEqual(pushresult.revidmap[revid1], pushresult.new_revid)