88
87
branch.repository.get_revision(branch.last_revision()).parent_ids)
89
def test_build_commit_parent_ids(self):
90
"""build_commit() takes a parent_ids argument."""
91
builder = BranchBuilder(self.get_transport().clone('foo'))
92
rev_id1 = builder.build_commit(
93
parent_ids=["ghost"], allow_leftmost_as_ghost=True)
94
rev_id2 = builder.build_commit(parent_ids=[])
95
branch = builder.get_branch()
96
self.assertEqual((1, rev_id2), branch.last_revision_info())
99
branch.repository.get_revision(rev_id1).parent_ids)
91
102
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
248
259
(u'dir', 'dir-id', 'directory'),
249
260
(u'dir/a', 'a-id', 'file')], rev_tree)
262
def test_rename_out_of_unversioned_subdir(self):
263
builder = self.build_a_rev()
264
builder.build_snapshot('B-id', None,
265
[('add', ('dir', 'dir-id', 'directory', None)),
266
('rename', ('a', 'dir/a'))])
267
builder.build_snapshot('C-id', None,
268
[('rename', ('dir/a', 'a')),
269
('unversion', 'dir-id')])
270
rev_tree = builder.get_branch().repository.revision_tree('C-id')
271
self.assertTreeShape([(u'', 'a-root-id', 'directory'),
272
(u'a', 'a-id', 'file')], rev_tree)
251
274
def test_set_parent(self):
252
275
builder = self.build_a_rev()
253
276
builder.start_series()
323
346
# Because we copied the exact text into *this* tree, the 'c' file
324
347
# should look like it was not modified in the merge
325
self.assertEqual('C-id', d_tree.inventory['c-id'].revision)
348
self.assertEqual('C-id', d_tree.get_file_revision('c-id'))
350
def test_set_parent_to_null(self):
351
builder = self.build_a_rev()
352
builder.start_series()
353
self.addCleanup(builder.finish_series)
354
builder.build_snapshot('B-id', [],
355
[('add', ('', None, 'directory', None))])
356
# We should now have a graph:
359
repo = builder.get_branch().repository
360
self.assertEqual({'A-id': (_mod_revision.NULL_REVISION,),
361
'B-id': (_mod_revision.NULL_REVISION,),},
362
repo.get_parent_map(['A-id', 'B-id']))
327
365
def test_start_finish_series(self):
328
366
builder = BranchBuilder(self.get_transport().clone('foo'))
329
367
builder.start_series()
350
388
self.addCleanup(b.unlock)
351
389
self.assertEqual(('ghost',),
352
390
b.repository.get_graph().get_parent_map(['tip'])['tip'])
392
def test_unversion_root_add_new_root(self):
393
builder = BranchBuilder(self.get_transport().clone('foo'))
394
builder.start_series()
395
builder.build_snapshot('rev-1', None,
396
[('add', ('', 'TREE_ROOT', 'directory', ''))])
397
builder.build_snapshot('rev-2', None,
398
[('unversion', 'TREE_ROOT'),
399
('add', ('', 'my-root', 'directory', ''))])
400
builder.finish_series()
401
rev_tree = builder.get_branch().repository.revision_tree('rev-2')
402
self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
404
def test_empty_flush(self):
405
"""A flush with no actions before it is a no-op."""
406
builder = BranchBuilder(self.get_transport().clone('foo'))
407
builder.start_series()
408
builder.build_snapshot('rev-1', None,
409
[('add', ('', 'TREE_ROOT', 'directory', ''))])
410
builder.build_snapshot('rev-2', None, [('flush', None)])
411
builder.finish_series()
412
rev_tree = builder.get_branch().repository.revision_tree('rev-2')
413
self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
415
def test_kind_change(self):
416
"""It's possible to change the kind of an entry in a single snapshot
417
with a bit of help from the 'flush' action.
419
builder = BranchBuilder(self.get_transport().clone('foo'))
420
builder.start_series()
421
builder.build_snapshot('A-id', None,
422
[('add', (u'', 'a-root-id', 'directory', None)),
423
('add', (u'a', 'a-id', 'file', 'content\n'))])
424
builder.build_snapshot('B-id', None,
425
[('unversion', 'a-id'),
427
('add', (u'a', 'a-id', 'directory', None))])
428
builder.finish_series()
429
rev_tree = builder.get_branch().repository.revision_tree('B-id')
430
self.assertTreeShape(
431
[(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
434
def test_pivot_root(self):
435
"""It's possible (albeit awkward) to move an existing dir to the root
436
in a single snapshot by using unversion then flush then add.
438
builder = BranchBuilder(self.get_transport().clone('foo'))
439
builder.start_series()
440
builder.build_snapshot('A-id', None,
441
[('add', (u'', 'orig-root', 'directory', None)),
442
('add', (u'dir', 'dir-id', 'directory', None))])
443
builder.build_snapshot('B-id', None,
444
[('unversion', 'orig-root'), # implicitly unversions all children
446
('add', (u'', 'dir-id', 'directory', None))])
447
builder.finish_series()
448
rev_tree = builder.get_branch().repository.revision_tree('B-id')
449
self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)