~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    def update(self, message, count=None, total=None):
61
61
        """See progress.ProgressBar.update()."""
62
62
        if self.depth == 1:
63
 
            self._calls.append(("update", count, total))
 
63
            self._calls.append(("update", count, total, message))
64
64
 
65
65
 
66
66
class TestCapturingUI(TestCase):
75
75
        pb2.update('foo', 0, 1)
76
76
        pb2.finished()
77
77
        pb1.finished()
78
 
        self.assertEqual([("update", 0, 1)], factory._calls)
 
78
        self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
79
79
 
80
80
 
81
81
class TestCommit(TestCaseWithWorkingTree):
101
101
                          tree.commit,
102
102
                          'foo',
103
103
                          local=True)
104
 
 
 
104
 
 
105
    def test_commit_merged_kind_change(self):
 
106
        """Test merging a kind change.
 
107
 
 
108
        Test making a kind change in a working tree, and then merging that
 
109
        from another. When committed it should commit the new kind.
 
110
        """
 
111
        wt = self.make_branch_and_tree('.')
 
112
        self.build_tree(['a'])
 
113
        wt.add(['a'])
 
114
        wt.commit('commit one')
 
115
        wt2 = wt.bzrdir.sprout('to').open_workingtree()
 
116
        os.remove('a')
 
117
        os.mkdir('a')
 
118
        wt.commit('changed kind')
 
119
        wt2.merge_from_branch(wt.branch)
 
120
        wt2.commit('merged kind change')
 
121
 
105
122
    def test_local_commit_ignores_master(self):
106
123
        # a --local commit does not require access to the master branch
107
124
        # at all, or even for it to exist.
198
215
        self.assertFalse(wt.has_filename('b/c'))
199
216
        self.assertFalse(wt.has_filename('d'))
200
217
        wt.unlock()
 
218
 
 
219
    def test_commit_deleted_subtree_with_removed(self):
 
220
        wt = self.make_branch_and_tree('.')
 
221
        self.build_tree(['a', 'b/', 'b/c', 'd'])
 
222
        wt.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
223
        wt.commit('first')
 
224
        wt.remove('b/c')
 
225
        this_dir = self.get_transport()
 
226
        this_dir.delete_tree('b')
 
227
        wt.lock_write()
 
228
        wt.commit('commit deleted rename')
 
229
        self.assertTrue(wt.has_id('a-id'))
 
230
        self.assertFalse(wt.has_or_had_id('b-id'))
 
231
        self.assertFalse(wt.has_or_had_id('c-id'))
 
232
        self.assertTrue(wt.has_filename('a'))
 
233
        self.assertFalse(wt.has_filename('b'))
 
234
        self.assertFalse(wt.has_filename('b/c'))
 
235
        wt.unlock()
 
236
 
 
237
    def test_commit_move_new(self):
 
238
        wt = self.make_branch_and_tree('first')
 
239
        wt.commit('first')
 
240
        wt2 = wt.bzrdir.sprout('second').open_workingtree()
 
241
        self.build_tree(['second/name1'])
 
242
        wt2.add('name1', 'name1-id')
 
243
        wt2.commit('second')
 
244
        wt.merge_from_branch(wt2.branch)
 
245
        wt.rename_one('name1', 'name2')
 
246
        wt.commit('third')
 
247
        wt.path2id('name1-id')
 
248
 
 
249
    def test_nested_commit(self):
 
250
        """Commit in multiply-nested trees"""
 
251
        tree = self.make_branch_and_tree('.')
 
252
        if not tree.supports_tree_reference():
 
253
            # inapplicable test.
 
254
            return
 
255
        subtree = self.make_branch_and_tree('subtree')
 
256
        subsubtree = self.make_branch_and_tree('subtree/subtree')
 
257
        subtree.add(['subtree'])
 
258
        tree.add(['subtree'])
 
259
        # use allow_pointless=False to ensure that the deepest tree, which
 
260
        # has no commits made to it, does not get a pointless commit.
 
261
        rev_id = tree.commit('added reference', allow_pointless=False)
 
262
        tree.lock_read()
 
263
        self.addCleanup(tree.unlock)
 
264
        # the deepest subtree has not changed, so no commit should take place.
 
265
        self.assertEqual(None, subsubtree.last_revision())
 
266
        # the intermediate tree should have committed a pointer to the current
 
267
        # subtree revision.
 
268
        sub_basis = subtree.basis_tree()
 
269
        sub_basis.lock_read()
 
270
        self.addCleanup(sub_basis.unlock)
 
271
        self.assertEqual(subsubtree.last_revision(),
 
272
            sub_basis.get_reference_revision(sub_basis.path2id('subtree')))
 
273
        # the intermediate tree has changed, so should have had a commit
 
274
        # take place.
 
275
        self.assertNotEqual(None, subtree.last_revision())
 
276
        # the outer tree should have committed a pointer to the current
 
277
        # subtree revision.
 
278
        basis = tree.basis_tree()
 
279
        basis.lock_read()
 
280
        self.addCleanup(basis.unlock)
 
281
        self.assertEqual(subtree.last_revision(),
 
282
            basis.get_reference_revision(basis.path2id('subtree')))
 
283
        # the outer tree must have have changed too.
 
284
        self.assertNotEqual(None, rev_id)
201
285
        
 
286
    def test_nested_commit_second_commit_detects_changes(self):
 
287
        """Commit with a nested tree picks up the correct child revid."""
 
288
        tree = self.make_branch_and_tree('.')
 
289
        if not tree.supports_tree_reference():
 
290
            # inapplicable test.
 
291
            return
 
292
        subtree = self.make_branch_and_tree('subtree')
 
293
        tree.add(['subtree'])
 
294
        self.build_tree(['subtree/file'])
 
295
        subtree.add(['file'], ['file-id'])
 
296
        rev_id = tree.commit('added reference', allow_pointless=False)
 
297
        child_revid = subtree.last_revision()
 
298
        # now change the child tree
 
299
        self.build_tree_contents([('subtree/file', 'new-content')])
 
300
        # and commit in the parent should commit the child and grab its revid,
 
301
        # we test with allow_pointless=False here so that we are simulating
 
302
        # what users will see.
 
303
        rev_id2 = tree.commit('changed subtree only', allow_pointless=False)
 
304
        # the child tree has changed, so should have had a commit
 
305
        # take place.
 
306
        self.assertNotEqual(None, subtree.last_revision())
 
307
        self.assertNotEqual(child_revid, subtree.last_revision())
 
308
        # the outer tree should have committed a pointer to the current
 
309
        # subtree revision.
 
310
        basis = tree.basis_tree()
 
311
        basis.lock_read()
 
312
        self.addCleanup(basis.unlock)
 
313
        self.assertEqual(subtree.last_revision(),
 
314
            basis.get_reference_revision(basis.path2id('subtree')))
 
315
        self.assertNotEqual(rev_id, rev_id2)
 
316
 
202
317
 
203
318
class TestCommitProgress(TestCaseWithWorkingTree):
204
319
    
230
345
        # into the factory for this test - just make the test ui factory
231
346
        # pun as a reporter. Then we can check the ordering is right.
232
347
        tree.commit('second post', specific_files=['b'])
233
 
        # 9 steps: 1 for rev, 2 for inventory, 1 for finishing. 2 for root
234
 
        # and 6 for inventory files.
235
 
        # 2 steps don't trigger an update, as 'a' and 'c' are not 
 
348
        # 4 steps, the first of which is reported 5 times, once per file
 
349
        # 2 files don't trigger an update, as 'a' and 'c' are not 
236
350
        # committed.
237
351
        self.assertEqual(
238
 
            [("update", 0, 9),
239
 
             ("update", 1, 9),
240
 
             ("update", 2, 9),
241
 
             ("update", 3, 9),
242
 
             ("update", 4, 9),
243
 
             ("update", 5, 9),
244
 
             ("update", 6, 9),
245
 
             ("update", 7, 9)],
 
352
            [('update', 1, 4, 'Collecting changes [Entry 0/?] - Stage'),
 
353
             ('update', 1, 4, 'Collecting changes [Entry 1/4] - Stage'),
 
354
             ('update', 1, 4, 'Collecting changes [Entry 2/4] - Stage'),
 
355
             ('update', 1, 4, 'Collecting changes [Entry 3/4] - Stage'),
 
356
             ('update', 1, 4, 'Collecting changes [Entry 4/4] - Stage'),
 
357
             ('update', 2, 4, 'Saving data locally - Stage'),
 
358
             ('update', 3, 4, 'Updating the working tree - Stage'),
 
359
             ('update', 4, 4, 'Running post commit hooks - Stage')],
 
360
            factory._calls
 
361
           )
 
362
 
 
363
    def test_commit_progress_shows_hook_names(self):
 
364
        tree = self.make_branch_and_tree('.')
 
365
        # set a progress bar that captures the calls so we can see what is 
 
366
        # emitted
 
367
        self.old_ui_factory = ui.ui_factory
 
368
        self.addCleanup(self.restoreDefaults)
 
369
        factory = CapturingUIFactory()
 
370
        ui.ui_factory = factory
 
371
        def a_hook(_, _2, _3, _4, _5, _6):
 
372
            pass
 
373
        branch.Branch.hooks.install_hook('post_commit', a_hook)
 
374
        branch.Branch.hooks.name_hook(a_hook, 'hook name')
 
375
        tree.commit('first post')
 
376
        self.assertEqual(
 
377
            [('update', 1, 4, 'Collecting changes [Entry 0/?] - Stage'),
 
378
             ('update', 1, 4, 'Collecting changes [Entry 1/1] - Stage'),
 
379
             ('update', 2, 4, 'Saving data locally - Stage'),
 
380
             ('update', 3, 4, 'Updating the working tree - Stage'),
 
381
             ('update', 4, 4, 'Running post commit hooks - Stage'),
 
382
             ('update', 4, 4, 'Running post commit hooks [hook name] - Stage'),
 
383
             ],
246
384
            factory._calls
247
385
           )