198
198
self.assertFalse(wt.has_filename('b/c'))
199
199
self.assertFalse(wt.has_filename('d'))
202
def test_commit_deleted_subtree_with_removed(self):
203
wt = self.make_branch_and_tree('.')
204
self.build_tree(['a', 'b/', 'b/c', 'd'])
205
wt.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
208
this_dir = self.get_transport()
209
this_dir.delete_tree('b')
211
wt.commit('commit deleted rename')
212
self.assertTrue(wt.has_id('a-id'))
213
self.assertFalse(wt.has_or_had_id('b-id'))
214
self.assertFalse(wt.has_or_had_id('c-id'))
215
self.assertTrue(wt.has_filename('a'))
216
self.assertFalse(wt.has_filename('b'))
217
self.assertFalse(wt.has_filename('b/c'))
220
def test_commit_move_new(self):
221
wt = self.make_branch_and_tree('first')
223
wt2 = wt.bzrdir.sprout('second').open_workingtree()
224
self.build_tree(['second/name1'])
225
wt2.add('name1', 'name1-id')
227
wt.merge_from_branch(wt2.branch)
228
wt.rename_one('name1', 'name2')
230
wt.path2id('name1-id')
232
def test_nested_commit(self):
233
"""Commit in multiply-nested trees"""
234
tree = self.make_branch_and_tree('.')
235
if not tree.supports_tree_reference():
238
subtree = self.make_branch_and_tree('subtree')
239
subsubtree = self.make_branch_and_tree('subtree/subtree')
240
subtree.add(['subtree'])
241
tree.add(['subtree'])
242
# use allow_pointless=False to ensure that the deepest tree, which
243
# has no commits made to it, does not get a pointless commit.
244
rev_id = tree.commit('added reference', allow_pointless=False)
246
self.addCleanup(tree.unlock)
247
# the deepest subtree has not changed, so no commit should take place.
248
self.assertEqual(None, subsubtree.last_revision())
249
# the intermediate tree should have committed a pointer to the current
251
sub_basis = subtree.basis_tree()
252
sub_basis.lock_read()
253
self.addCleanup(sub_basis.unlock)
254
self.assertEqual(subsubtree.last_revision(),
255
sub_basis.get_reference_revision(sub_basis.path2id('subtree')))
256
# the intermediate tree has changed, so should have had a commit
258
self.assertNotEqual(None, subtree.last_revision())
259
# the outer tree should have committed a pointer to the current
261
basis = tree.basis_tree()
263
self.addCleanup(basis.unlock)
264
self.assertEqual(subtree.last_revision(),
265
basis.get_reference_revision(basis.path2id('subtree')))
266
# the outer tree must have have changed too.
267
self.assertNotEqual(None, rev_id)
269
def test_nested_commit_second_commit_detects_changes(self):
270
"""Commit with a nested tree picks up the correct child revid."""
271
tree = self.make_branch_and_tree('.')
272
if not tree.supports_tree_reference():
275
subtree = self.make_branch_and_tree('subtree')
276
tree.add(['subtree'])
277
self.build_tree(['subtree/file'])
278
subtree.add(['file'], ['file-id'])
279
rev_id = tree.commit('added reference', allow_pointless=False)
280
child_revid = subtree.last_revision()
281
# now change the child tree
282
self.build_tree_contents([('subtree/file', 'new-content')])
283
# and commit in the parent should commit the child and grab its revid,
284
# we test with allow_pointless=False here so that we are simulating
285
# what users will see.
286
rev_id2 = tree.commit('changed subtree only', allow_pointless=False)
287
# the child tree has changed, so should have had a commit
289
self.assertNotEqual(None, subtree.last_revision())
290
self.assertNotEqual(child_revid, subtree.last_revision())
291
# the outer tree should have committed a pointer to the current
293
basis = tree.basis_tree()
295
self.addCleanup(basis.unlock)
296
self.assertEqual(subtree.last_revision(),
297
basis.get_reference_revision(basis.path2id('subtree')))
298
self.assertNotEqual(rev_id, rev_id2)
203
301
class TestCommitProgress(TestCaseWithWorkingTree):