258
258
lock_and_call_current_dirstate(tree, 'lock_tree_write')
259
259
self.assertRaises(errors.ObjectNotLocked, tree.current_dirstate)
261
def test_set_parent_trees_uses_update_basis_by_delta(self):
262
builder = self.make_branch_builder('source')
263
builder.start_series()
264
self.addCleanup(builder.finish_series)
265
builder.build_snapshot('A', [], [
266
('add', ('', 'root-id', 'directory', None)),
267
('add', ('a', 'a-id', 'file', 'content\n'))])
268
builder.build_snapshot('B', ['A'], [
269
('modify', ('a-id', 'new content\nfor a\n')),
270
('add', ('b', 'b-id', 'file', 'b-content\n'))])
271
tree = self.make_workingtree('tree')
272
source_branch = builder.get_branch()
273
tree.branch.repository.fetch(source_branch.repository, 'B')
274
tree.pull(source_branch, stop_revision='A')
276
self.addCleanup(tree.unlock)
277
state = tree.current_dirstate()
279
orig_update = state.update_basis_by_delta
280
def log_update_basis_by_delta(delta, new_revid):
281
called.append(new_revid)
282
return orig_update(delta, new_revid)
283
state.update_basis_by_delta = log_update_basis_by_delta
284
basis = tree.basis_tree()
285
self.assertEqual('a-id', basis.path2id('a'))
286
self.assertEqual(None, basis.path2id('b'))
287
def fail_set_parent_trees(trees, ghosts):
288
raise AssertionError('dirstate.set_parent_trees() was called')
289
state.set_parent_trees = fail_set_parent_trees
290
repo = tree.branch.repository
291
tree.pull(source_branch, stop_revision='B')
292
self.assertEqual(['B'], called)
293
basis = tree.basis_tree()
294
self.assertEqual('a-id', basis.path2id('a'))
295
self.assertEqual('b-id', basis.path2id('b'))
297
def test_set_parent_trees_handles_missing_basis(self):
298
builder = self.make_branch_builder('source')
299
builder.start_series()
300
self.addCleanup(builder.finish_series)
301
builder.build_snapshot('A', [], [
302
('add', ('', 'root-id', 'directory', None)),
303
('add', ('a', 'a-id', 'file', 'content\n'))])
304
builder.build_snapshot('B', ['A'], [
305
('modify', ('a-id', 'new content\nfor a\n')),
306
('add', ('b', 'b-id', 'file', 'b-content\n'))])
307
builder.build_snapshot('C', ['A'], [
308
('add', ('c', 'c-id', 'file', 'c-content\n'))])
309
b_c = self.make_branch('branch_with_c')
310
b_c.pull(builder.get_branch(), stop_revision='C')
311
b_b = self.make_branch('branch_with_b')
312
b_b.pull(builder.get_branch(), stop_revision='B')
313
# This is reproducing some of what 'switch' does, just to isolate the
314
# set_parent_trees() step.
315
wt = b_b.create_checkout('tree', lightweight=True)
316
fmt = wt.bzrdir.find_branch_format()
317
fmt.set_reference(wt.bzrdir, None, b_c)
318
# Re-open with the new reference
319
wt = wt.bzrdir.open_workingtree()
320
wt.set_parent_trees([('C', b_c.repository.revision_tree('C'))])
321
self.assertEqual(None, wt.basis_tree().path2id('b'))
261
323
def test_new_dirstate_on_new_lock(self):
262
324
# until we have detection for when a dirstate can be reused, we
263
325
# want to reparse dirstate on every new lock.