~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_commit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-07 10:45:44 UTC
  • mfrom: (2321.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070307104544-59e3e6358e4bdb29
(robertc) Merge dirstate and subtrees. (Robert Collins, Martin Pool, Aaaron Bentley, John A Meinel, James Westby)

Show diffs side-by-side

added added

removed removed

Lines of Context:
198
198
        self.assertFalse(wt.has_filename('b/c'))
199
199
        self.assertFalse(wt.has_filename('d'))
200
200
        wt.unlock()
 
201
 
 
202
    def test_commit_move_new(self):
 
203
        wt = self.make_branch_and_tree('first')
 
204
        wt.commit('first')
 
205
        wt2 = wt.bzrdir.sprout('second').open_workingtree()
 
206
        self.build_tree(['second/name1'])
 
207
        wt2.add('name1', 'name1-id')
 
208
        wt2.commit('second')
 
209
        wt.merge_from_branch(wt2.branch)
 
210
        wt.rename_one('name1', 'name2')
 
211
        wt.commit('third')
 
212
        wt.path2id('name1-id')
 
213
 
 
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():
 
218
            # inapplicable test.
 
219
            return
 
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)
 
227
        tree.lock_read()
 
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
 
232
        # subtree revision.
 
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
 
239
        # take place.
 
240
        self.assertNotEqual(None, subtree.last_revision())
 
241
        # the outer tree should have committed a pointer to the current
 
242
        # subtree revision.
 
243
        basis = tree.basis_tree()
 
244
        basis.lock_read()
 
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)
201
250
        
 
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():
 
255
            # inapplicable test.
 
256
            return
 
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
 
270
        # take place.
 
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
 
274
        # subtree revision.
 
275
        basis = tree.basis_tree()
 
276
        basis.lock_read()
 
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)
 
281
 
202
282
 
203
283
class TestCommitProgress(TestCaseWithWorkingTree):
204
284