120
122
self.assertEqual(revision_id,
121
123
tree.branch.repository.get_inventory(revision_id).revision_id)
123
def test_commit_without_root(self):
124
"""This should cause a deprecation warning, not an assertion failure"""
125
def test_commit_without_root_errors(self):
125
126
tree = self.make_branch_and_tree(".")
126
127
tree.lock_write()
128
if tree.branch.repository.supports_rich_root():
129
raise tests.TestSkipped('Format requires root')
130
129
self.build_tree(['foo'])
131
130
tree.add('foo', 'foo-id')
132
131
entry = tree.inventory['foo-id']
133
132
builder = tree.branch.get_commit_builder([])
134
self.callDeprecated(['Root entry should be supplied to'
135
' record_entry_contents, as of bzr 0.10.'],
136
builder.record_entry_contents, entry, [], 'foo', tree)
137
builder.finish_inventory()
138
rev_id = builder.commit('foo bar')
133
self.assertRaises(errors.RootMissing,
134
builder.record_entry_contents, entry, [], 'foo', tree,
135
tree.path_content_summary('foo'))
151
149
ie = inventory.make_entry('directory', '', None,
152
150
tree.inventory.root.file_id)
153
self.assertFalse(builder.record_entry_contents(
154
ie, [parent_tree.inventory], '', tree))
151
delta, version_recorded = builder.record_entry_contents(
152
ie, [parent_tree.inventory], '', tree,
153
tree.path_content_summary(''))
154
self.assertFalse(version_recorded)
155
self.assertEqual(None, delta)
226
227
def _add_commit_check_unchanged(self, tree, name):
227
228
tree.add([name], [name + 'id'])
228
229
rev1 = tree.commit('')
229
rev2 = tree.commit('')
230
rev2 = self.mini_commit(tree, name, name, False, False)
230
231
tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
231
232
self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
232
233
self.assertEqual(rev1, tree2.inventory[name + 'id'].revision)
320
321
tree.add([name], [name + 'id'])
321
322
rev1 = tree.commit('')
324
rev2 = self.mini_commit(tree, name, tree.id2path(name + 'id'))
325
tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
326
self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
327
self.assertEqual(rev2, tree2.inventory[name + 'id'].revision)
328
self.assertFileAncestry([rev1, rev2], tree, name)
330
def mini_commit(self, tree, name, new_name, records_version=True,
331
delta_against_basis=True):
332
"""Perform a miniature commit looking for record entry results.
334
:param tree: The tree to commit.
335
:param name: The path in the basis tree of the tree being committed.
336
:param new_name: The path in the tree being committed.
337
:param records_version: True if the commit of new_name is expected to
338
record a new version.
339
:param delta_against_basis: True of the commit of new_name is expected
340
to have a delta against the basis.
323
342
tree.lock_write()
325
344
# mini manual commit here so we can check the return of
326
345
# record_entry_contents.
327
builder = tree.branch.get_commit_builder([tree.last_revision()])
346
parent_ids = tree.get_parent_ids()
347
builder = tree.branch.get_commit_builder(parent_ids)
328
348
parent_tree = tree.basis_tree()
329
349
parent_tree.lock_read()
330
350
self.addCleanup(parent_tree.unlock)
331
351
parent_invs = [parent_tree.inventory]
352
for parent_id in parent_ids[1:]:
353
parent_invs.append(tree.branch.repository.revision_tree(
354
parent_id).inventory)
333
356
builder.record_entry_contents(
334
357
inventory.make_entry('directory', '', None,
335
tree.inventory.root.file_id), parent_invs, '', tree)
358
tree.inventory.root.file_id), parent_invs, '', tree,
359
tree.path_content_summary(''))
336
360
def commit_id(file_id):
337
361
old_ie = tree.inventory[file_id]
338
362
path = tree.id2path(file_id)
339
363
ie = inventory.make_entry(tree.kind(file_id), old_ie.name,
340
364
old_ie.parent_id, file_id)
341
return builder.record_entry_contents(ie, parent_invs, path, tree)
365
return builder.record_entry_contents(ie, parent_invs, path,
366
tree, tree.path_content_summary(path))
343
file_id = name + 'id'
368
file_id = tree.path2id(new_name)
344
369
parent_id = tree.inventory[file_id].parent_id
345
370
if parent_id != tree.inventory.root.file_id:
346
371
commit_id(parent_id)
347
372
# because a change of some sort is meant to have occurred,
348
373
# recording the entry must return True.
349
self.assertTrue(commit_id(file_id))
374
delta, version_recorded = commit_id(file_id)
376
self.assertTrue(version_recorded)
378
self.assertFalse(version_recorded)
379
new_entry = builder.new_inventory[file_id]
380
if delta_against_basis:
381
expected_delta = (name, new_name, file_id, new_entry)
383
expected_delta = None
384
if expected_delta != delta:
385
import pdb;pdb.set_trace()
386
self.assertEqual(expected_delta, delta)
350
387
builder.finish_inventory()
351
388
rev2 = builder.commit('')
352
389
tree.set_parent_ids([rev2])
359
tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
360
self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
361
self.assertEqual(rev2, tree2.inventory[name + 'id'].revision)
362
self.assertFileAncestry([rev1, rev2], tree, name)
364
398
def assertFileAncestry(self, ancestry, tree, name, alt_ancestry=None):
365
399
# all the changes that have occured should be in the ancestry
440
474
# change on the other side to merge back
441
475
rev2 = self._rename_in_tree(tree2, name)
442
476
tree1.merge_from_branch(tree2.branch)
443
rev3 = tree1.commit('')
477
rev3 = self.mini_commit(tree1, name, 'new_' + name, False)
444
478
tree3, = self._get_revtrees(tree1, [rev2])
445
479
self.assertEqual(rev2, tree3.inventory[name + 'id'].revision)
446
480
self.assertFileAncestry([rev1, rev2], tree1, name)