225
225
self.assertEqual([], w1.get_parents('a'))
226
226
self.assertEqual(['a'], w1.get_parents('b'))
227
227
self.assertEqual(['b'], w1.get_parents('c'))
229
def test_joining_ghosts(self):
230
# some versioned file formats allow lines to be added with parent
231
# information that is > than that in the format. Formats that do
232
# not support this need to raise NotImplementedError on the
233
# add_lines_with_ghosts api.
234
# files with ghost information when joined into a file which
235
# supports that must preserve it, when joined into a file which
236
# does not must discard it, and when filling a ghost for a listed
237
# ghost must reconcile it
238
source = self.get_source()
240
source.has_ghost('a')
242
except NotImplementedError:
243
source_ghosts = False
244
target = self.get_target()
246
target.has_ghost('a')
248
except NotImplementedError:
249
target_ghosts = False
251
if not source_ghosts and not target_ghosts:
254
if source_ghosts and not target_ghosts:
255
# switch source and target so source is ghostless
259
source_ghosts = False
261
# now target always supports ghosts.
263
# try filling target with ghosts and filling in reverse -
264
target.add_lines_with_ghosts('notbase', ['base'], [])
266
# legacy apis should behave
267
self.assertEqual(['notbase'], source.get_ancestry(['notbase']))
268
self.assertEqual([], source.get_parents('notbase'))
269
self.assertEqual({'notbase':[]}, source.get_graph())
270
self.assertFalse(source.has_version('base'))
272
# ghost data should have been preserved
273
self.assertEqual(['base', 'notbase'], source.get_ancestry_with_ghosts(['notbase']))
274
self.assertEqual(['base'], source.get_parents_with_ghosts('notbase'))
275
self.assertEqual({'notbase':['base']}, source.get_graph_with_ghosts())
276
self.assertTrue(source.has_ghost('base'))
278
# if we add something that is fills out what is a ghost, then
279
# when joining into a ghost aware join it should flesh out the ghosts.
280
source.add_lines('base', [], [])
281
target.join(source, version_ids=['base'])
282
self.assertEqual(['base', 'notbase'], target.get_ancestry(['notbase']))
283
self.assertEqual(['base'], target.get_parents('notbase'))
284
self.assertEqual({'base':[],
288
self.assertTrue(target.has_version('base'))
289
# we have _with_ghost apis to give us ghost information.
290
self.assertEqual(['base', 'notbase'], target.get_ancestry_with_ghosts(['notbase']))
291
self.assertEqual(['base'], target.get_parents_with_ghosts('notbase'))
292
self.assertEqual({'base':[],
295
target.get_graph_with_ghosts())
296
self.assertFalse(target.has_ghost('base'))