104
101
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
108
class InterToDummyVcsBranch(branch.GenericInterBranch,
109
foreign.InterToForeignBranch):
112
def is_compatible(source, target):
113
return isinstance(target, DummyForeignVcsBranch)
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()
120
self.source.lock_read()
104
def dpull(self, source, stop_revision=None):
122
107
# This just handles simple cases, but that's good enough for tests
123
my_history = self.target.revision_history()
124
their_history = self.source.revision_history()
108
my_history = self.revision_history()
109
their_history = source.revision_history()
125
110
if their_history[:min(len(my_history), len(their_history))] != my_history:
126
raise errors.DivergedBranches(self.target, self.source)
111
raise errors.DivergedBranches(self, source)
127
112
todo = their_history[len(my_history):]
129
114
for revid in todo:
130
rev = self.source.repository.get_revision(revid)
131
tree = self.source.repository.revision_tree(revid)
115
rev = source.repository.get_revision(revid)
116
tree = source.repository.revision_tree(revid)
132
117
def get_file_with_stat(file_id, path=None):
133
118
return (tree.get_file(file_id), None)
134
119
tree.get_file_with_stat = get_file_with_stat
135
new_revid = self.target.mapping.revision_id_foreign_to_bzr(
136
(str(rev.timestamp), str(rev.timezone),
137
str(self.target.revno())))
138
parent_revno, parent_revid= self.target.last_revision_info()
139
if parent_revid == NULL_REVISION:
142
parent_revids = [parent_revid]
143
builder = self.target.get_commit_builder(parent_revids,
144
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,
145
125
rev.timezone, rev.committer, rev.properties,
159
139
revidmap[revid] = builder.commit(rev.message)
160
self.target.set_last_revision_info(parent_revno+1,
140
self.set_last_revision_info(parent_revno+1, revidmap[revid])
162
141
trace.mutter('lossily pushed revision %s -> %s',
163
142
revid, revidmap[revid])
166
result.new_revno, result.new_revid = self.target.last_revision_info()
167
result.revidmap = revidmap
171
148
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
301
278
self.assertEquals(mapp, rev.mapping)
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))
304
311
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
305
312
"""Tests for update_workingtree_fileids()."""
355
360
dir = BzrDir.open("d")
356
361
newdir = dir.sprout("e")
357
362
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)