110
113
return isinstance(target, DummyForeignVcsBranch)
112
115
def lossy_push(self, stop_revision=None):
116
result = branch.BranchPushResult()
117
result.source_branch = self.source
118
result.target_branch = self.target
119
result.old_revno, result.old_revid = self.target.last_revision_info()
113
120
self.source.lock_read()
115
122
# This just handles simple cases, but that's good enough for tests
129
136
(str(rev.timestamp), str(rev.timezone),
130
137
str(self.target.revno())))
131
138
parent_revno, parent_revid= self.target.last_revision_info()
132
builder = self.target.get_commit_builder([parent_revid],
139
if parent_revid == NULL_REVISION:
142
parent_revids = [parent_revid]
143
builder = self.target.get_commit_builder(parent_revids,
133
144
self.target.get_config(), rev.timestamp,
134
145
rev.timezone, rev.committer, rev.properties,
138
149
new_ie = ie.copy()
139
150
new_ie.revision = None
140
151
builder.record_entry_contents(new_ie,
141
[self.target.repository.get_inventory(parent_revid)],
152
[self.target.repository.revision_tree(parent_revid).inventory],
143
154
(ie.kind, ie.text_size, ie.executable, ie.text_sha1))
144
155
builder.finish_inventory()
288
301
self.assertEquals(mapp, rev.mapping)
291
class ShowForeignPropertiesTests(TestCase):
292
"""Tests for the show_foreign_properties() function."""
295
super(ShowForeignPropertiesTests, self).setUp()
296
self.vcs = DummyForeignVcs()
297
foreign.foreign_vcs_registry.register("dummy",
298
self.vcs, "Dummy VCS")
301
super(ShowForeignPropertiesTests, self).tearDown()
302
foreign.foreign_vcs_registry.remove("dummy")
304
def test_show_non_foreign(self):
305
"""Test use with a native (non-foreign) bzr revision."""
306
self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
308
def test_show_imported(self):
309
rev = Revision("dummy-v1:my-foreign-revid")
310
self.assertEquals({ "dummy ding": "my/foreign\\revid" },
311
foreign.show_foreign_properties(rev))
313
def test_show_direct(self):
314
rev = foreign.ForeignRevision(("some", "foreign", "revid"),
315
DummyForeignVcsMapping(self.vcs),
317
self.assertEquals({ "dummy ding": "some/foreign\\revid" },
318
foreign.show_foreign_properties(rev))
321
304
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
322
305
"""Tests for update_workingtree_fileids()."""
372
355
dir = BzrDir.open("d")
373
356
newdir = dir.sprout("e")
374
357
self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
359
def test_lossy_push_empty(self):
360
source_tree = self.make_branch_and_tree("source")
361
target_tree = self.make_branch_and_tree("target",
362
format=DummyForeignVcsDirFormat())
363
pushresult = source_tree.branch.lossy_push(target_tree.branch)
364
self.assertEquals(NULL_REVISION, pushresult.old_revid)
365
self.assertEquals(NULL_REVISION, pushresult.new_revid)
366
self.assertEquals({}, pushresult.revidmap)
368
def test_lossy_push_simple(self):
369
source_tree = self.make_branch_and_tree("source")
370
self.build_tree(['source/a', 'source/b'])
371
source_tree.add(['a', 'b'])
372
revid1 = source_tree.commit("msg")
373
target_tree = self.make_branch_and_tree("target",
374
format=DummyForeignVcsDirFormat())
375
target_tree.branch.lock_write()
377
pushresult = source_tree.branch.lossy_push(target_tree.branch)
379
target_tree.branch.unlock()
380
self.assertEquals(NULL_REVISION, pushresult.old_revid)
381
self.assertEquals({revid1:target_tree.branch.last_revision()},
383
self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)