198
198
self.assertFalse(wt.has_filename('b/c'))
199
199
self.assertFalse(wt.has_filename('d'))
202
def test_commit_move_new(self):
203
wt = self.make_branch_and_tree('first')
205
wt2 = wt.bzrdir.sprout('second').open_workingtree()
206
self.build_tree(['second/name1'])
207
wt2.add('name1', 'name1-id')
209
wt.merge_from_branch(wt2.branch)
210
wt.rename_one('name1', 'name2')
212
wt.path2id('name1-id')
214
def test_nested_commit(self):
215
"""Commit in multiply-nested trees"""
216
tree = self.make_branch_and_tree('.')
217
if not tree.supports_tree_reference():
220
subtree = self.make_branch_and_tree('subtree')
221
subsubtree = self.make_branch_and_tree('subtree/subtree')
222
subtree.add(['subtree'])
223
tree.add(['subtree'])
224
# use allow_pointless=False to ensure that the deepest tree, which
225
# has no commits made to it, does not get a pointless commit.
226
rev_id = tree.commit('added reference', allow_pointless=False)
228
self.addCleanup(tree.unlock)
229
# the deepest subtree has not changed, so no commit should take place.
230
self.assertEqual(None, subsubtree.last_revision())
231
# the intermediate tree should have committed a pointer to the current
233
sub_basis = subtree.basis_tree()
234
sub_basis.lock_read()
235
self.addCleanup(sub_basis.unlock)
236
self.assertEqual(subsubtree.last_revision(),
237
sub_basis.get_reference_revision(sub_basis.path2id('subtree')))
238
# the intermediate tree has changed, so should have had a commit
240
self.assertNotEqual(None, subtree.last_revision())
241
# the outer tree should have committed a pointer to the current
243
basis = tree.basis_tree()
245
self.addCleanup(basis.unlock)
246
self.assertEqual(subtree.last_revision(),
247
basis.get_reference_revision(basis.path2id('subtree')))
248
# the outer tree must have have changed too.
249
self.assertNotEqual(None, rev_id)
251
def test_nested_commit_second_commit_detects_changes(self):
252
"""Commit with a nested tree picks up the correct child revid."""
253
tree = self.make_branch_and_tree('.')
254
if not tree.supports_tree_reference():
257
subtree = self.make_branch_and_tree('subtree')
258
tree.add(['subtree'])
259
self.build_tree(['subtree/file'])
260
subtree.add(['file'], ['file-id'])
261
rev_id = tree.commit('added reference', allow_pointless=False)
262
child_revid = subtree.last_revision()
263
# now change the child tree
264
self.build_tree_contents([('subtree/file', 'new-content')])
265
# and commit in the parent should commit the child and grab its revid,
266
# we test with allow_pointless=False here so that we are simulating
267
# what users will see.
268
rev_id2 = tree.commit('changed subtree only', allow_pointless=False)
269
# the child tree has changed, so should have had a commit
271
self.assertNotEqual(None, subtree.last_revision())
272
self.assertNotEqual(child_revid, subtree.last_revision())
273
# the outer tree should have committed a pointer to the current
275
basis = tree.basis_tree()
277
self.addCleanup(basis.unlock)
278
self.assertEqual(subtree.last_revision(),
279
basis.get_reference_revision(basis.path2id('subtree')))
280
self.assertNotEqual(rev_id, rev_id2)
203
283
class TestCommitProgress(TestCaseWithWorkingTree):