/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
1
# Copyright (C) 2005, 2006 Canonical Ltd
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
from cStringIO import StringIO
19
import os
20
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
21
from bzrlib import (
22
    branch,
23
    bzrdir,
24
    errors,
2922.2.1 by John Arbash Meinel
Add failing tests exposing part of bug #114615
25
    osutils,
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
26
    revision as _mod_revision,
27
    ui,
28
    uncommit,
29
    workingtree,
30
    )
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
31
from bzrlib.errors import (NotBranchError, NotVersionedError, 
32
                           UnsupportedOperation)
33
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
34
from bzrlib.tests import TestSkipped, TestCase
35
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
36
from bzrlib.trace import mutter
37
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
38
                                WorkingTree)
39
40
41
class CapturingUIFactory(ui.UIFactory):
42
    """A UI Factory for testing - capture the updates made through it."""
43
44
    def __init__(self):
45
        super(CapturingUIFactory, self).__init__()
46
        self._calls = []
47
        self.depth = 0
48
49
    def clear(self):
50
        """See progress.ProgressBar.clear()."""
51
52
    def clear_term(self):
53
        """See progress.ProgressBar.clear_term()."""
54
55
    def finished(self):
56
        """See progress.ProgressBar.finished()."""
57
        self.depth -= 1
58
59
    def note(self, fmt_string, *args, **kwargs):
60
        """See progress.ProgressBar.note()."""
61
62
    def progress_bar(self):
63
        return self
64
    
65
    def nested_progress_bar(self):
66
        self.depth += 1
67
        return self
68
69
    def update(self, message, count=None, total=None):
70
        """See progress.ProgressBar.update()."""
71
        if self.depth == 1:
2531.1.3 by Ian Clatworthy
Fix whitespace and improve tests to cover actual progress messages
72
            self._calls.append(("update", count, total, message))
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
73
74
75
class TestCapturingUI(TestCase):
76
77
    def test_nested_ignore_depth_beyond_one(self):
78
        # we only want to capture the first level out progress, not
79
        # want sub-components might do. So we have nested bars ignored.
80
        factory = CapturingUIFactory()
81
        pb1 = factory.nested_progress_bar()
82
        pb1.update('foo', 0, 1)
83
        pb2 = factory.nested_progress_bar()
84
        pb2.update('foo', 0, 1)
85
        pb2.finished()
86
        pb1.finished()
2531.1.3 by Ian Clatworthy
Fix whitespace and improve tests to cover actual progress messages
87
        self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
88
89
90
class TestCommit(TestCaseWithWorkingTree):
91
2922.2.1 by John Arbash Meinel
Add failing tests exposing part of bug #114615
92
    def test_autodelete_renamed(self):
93
        tree_a = self.make_branch_and_tree('a')
94
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
95
        tree_a.add(['dir', 'dir/f1', 'dir/f2'], ['dir-id', 'f1-id', 'f2-id'])
96
        rev_id1 = tree_a.commit('init')
97
        # Start off by renaming entries,
98
        # but then actually auto delete the whole tree
99
        # https://bugs.launchpad.net/bzr/+bug/114615
100
        tree_a.rename_one('dir/f1', 'dir/a')
101
        tree_a.rename_one('dir/f2', 'dir/z')
102
        osutils.rmtree('a/dir')
103
        tree_a.commit('autoremoved')
104
105
        tree_a.lock_read()
106
        try:
107
            root_id = tree_a.inventory.root.file_id
108
            paths = [(path, ie.file_id)
109
                     for path, ie in tree_a.iter_entries_by_dir()]
110
        finally:
111
            tree_a.unlock()
112
        # The only paths left should be the root
113
        self.assertEqual([('', root_id)], paths)
114
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
115
    def test_commit_sets_last_revision(self):
116
        tree = self.make_branch_and_tree('tree')
2825.5.2 by Robert Collins
Review feedback, and fix pointless commits with nested trees to raise PointlessCommit appropriately.
117
        committed_id = tree.commit('foo', rev_id='foo')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
118
        self.assertEqual(['foo'], tree.get_parent_ids())
1773.1.1 by Robert Collins
Teach WorkingTree.commit to return the committed revision id.
119
        # the commit should have returned the same id we asked for.
120
        self.assertEqual('foo', committed_id)
121
122
    def test_commit_returns_revision_id(self):
123
        tree = self.make_branch_and_tree('.')
2825.5.2 by Robert Collins
Review feedback, and fix pointless commits with nested trees to raise PointlessCommit appropriately.
124
        committed_id = tree.commit('message')
1773.1.1 by Robert Collins
Teach WorkingTree.commit to return the committed revision id.
125
        self.assertTrue(tree.branch.repository.has_revision(committed_id))
126
        self.assertNotEqual(None, committed_id)
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
127
128
    def test_commit_local_unbound(self):
129
        # using the library api to do a local commit on unbound branches is 
130
        # also an error
131
        tree = self.make_branch_and_tree('tree')
132
        self.assertRaises(errors.LocalRequiresBoundBranch,
133
                          tree.commit,
134
                          'foo',
135
                          local=True)
2374.2.1 by John Arbash Meinel
(broken) merge a test case showing that commiting a merge of a kind change fails.
136
137
    def test_commit_merged_kind_change(self):
138
        """Test merging a kind change.
139
140
        Test making a kind change in a working tree, and then merging that
141
        from another. When committed it should commit the new kind.
142
        """
143
        wt = self.make_branch_and_tree('.')
144
        self.build_tree(['a'])
145
        wt.add(['a'])
146
        wt.commit('commit one')
147
        wt2 = wt.bzrdir.sprout('to').open_workingtree()
148
        os.remove('a')
149
        os.mkdir('a')
150
        wt.commit('changed kind')
151
        wt2.merge_from_branch(wt.branch)
152
        wt2.commit('merged kind change')
153
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
154
    def test_local_commit_ignores_master(self):
155
        # a --local commit does not require access to the master branch
156
        # at all, or even for it to exist.
157
        # we test this by setting up a bound branch and then corrupting
158
        # the master.
159
        master = self.make_branch('master')
160
        tree = self.make_branch_and_tree('tree')
161
        try:
162
            tree.branch.bind(master)
163
        except errors.UpgradeRequired:
164
            # older format.
165
            return
1955.3.14 by John Arbash Meinel
Correctly fix the workingtree put() test fixes
166
        master.bzrdir.transport.put_bytes('branch-format', 'garbage')
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
167
        del master
168
        # check its corrupted.
169
        self.assertRaises(errors.UnknownFormatError,
170
                          bzrdir.BzrDir.open,
171
                          'master')
172
        tree.commit('foo', rev_id='foo', local=True)
173
 
174
    def test_local_commit_does_not_push_to_master(self):
175
        # a --local commit does not require access to the master branch
176
        # at all, or even for it to exist.
177
        # we test that even when its available it does not push to it.
178
        master = self.make_branch('master')
179
        tree = self.make_branch_and_tree('tree')
180
        try:
181
            tree.branch.bind(master)
182
        except errors.UpgradeRequired:
183
            # older format.
184
            return
185
        tree.commit('foo', rev_id='foo', local=True)
186
        self.failIf(master.repository.has_revision('foo'))
2598.5.7 by Aaron Bentley
Updates from review
187
        self.assertEqual(_mod_revision.NULL_REVISION,
188
                         (_mod_revision.ensure_null(master.last_revision())))
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
189
190
    def test_record_initial_ghost(self):
191
        """The working tree needs to record ghosts during commit."""
192
        wt = self.make_branch_and_tree('.')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
193
        wt.set_parent_ids(['non:existent@rev--ision--0--2'],
194
            allow_leftmost_as_ghost=True)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
195
        rev_id = wt.commit('commit against a ghost first parent.')
196
        rev = wt.branch.repository.get_revision(rev_id)
197
        self.assertEqual(rev.parent_ids, ['non:existent@rev--ision--0--2'])
198
        # parent_sha1s is not populated now, WTF. rbc 20051003
199
        self.assertEqual(len(rev.parent_sha1s), 0)
200
201
    def test_record_two_ghosts(self):
202
        """The working tree should preserve all the parents during commit."""
203
        wt = self.make_branch_and_tree('.')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
204
        wt.set_parent_ids([
205
                'foo@azkhazan-123123-abcabc',
206
                'wibble@fofof--20050401--1928390812',
207
            ],
208
            allow_leftmost_as_ghost=True)
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
209
        rev_id = wt.commit("commit from ghost base with one merge")
210
        # the revision should have been committed with two parents
211
        rev = wt.branch.repository.get_revision(rev_id)
212
        self.assertEqual(['foo@azkhazan-123123-abcabc',
213
            'wibble@fofof--20050401--1928390812'],
214
            rev.parent_ids)
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
215
1988.3.1 by Robert Collins
Add test case to ensure that the working tree inventory and disk state is correctly update when commit is removing directory entries.
216
    def test_commit_deleted_subtree_and_files_updates_workingtree(self):
217
        """The working trees inventory may be adjusted by commit."""
218
        wt = self.make_branch_and_tree('.')
219
        wt.lock_write()
220
        self.build_tree(['a', 'b/', 'b/c', 'd'])
221
        wt.add(['a', 'b', 'b/c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
222
        this_dir = self.get_transport()
223
        this_dir.delete_tree('b')
224
        this_dir.delete('d')
225
        # now we have a tree with a through d in the inventory, but only
226
        # a present on disk. After commit b-id, c-id and d-id should be
227
        # missing from the inventory, within the same tree transaction.
228
        wt.commit('commit stuff')
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.assertFalse(wt.has_or_had_id('d-id'))
233
        self.assertTrue(wt.has_filename('a'))
234
        self.assertFalse(wt.has_filename('b'))
235
        self.assertFalse(wt.has_filename('b/c'))
236
        self.assertFalse(wt.has_filename('d'))
237
        wt.unlock()
238
        # the changes should have persisted to disk - reopen the workingtree
239
        # to be sure.
240
        wt = wt.bzrdir.open_workingtree()
241
        wt.lock_read()
242
        self.assertTrue(wt.has_id('a-id'))
243
        self.assertFalse(wt.has_or_had_id('b-id'))
244
        self.assertFalse(wt.has_or_had_id('c-id'))
245
        self.assertFalse(wt.has_or_had_id('d-id'))
246
        self.assertTrue(wt.has_filename('a'))
247
        self.assertFalse(wt.has_filename('b'))
248
        self.assertFalse(wt.has_filename('b/c'))
249
        self.assertFalse(wt.has_filename('d'))
250
        wt.unlock()
1731.2.4 by Aaron Bentley
Ensure subsume works with Knit2 repos
251
2363.2.2 by John Arbash Meinel
Simplify the test even further....
252
    def test_commit_deleted_subtree_with_removed(self):
2363.2.1 by John Arbash Meinel
(broken) Add a simplified test which exposes the bug.
253
        wt = self.make_branch_and_tree('.')
254
        self.build_tree(['a', 'b/', 'b/c', 'd'])
255
        wt.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
256
        wt.commit('first')
2363.2.2 by John Arbash Meinel
Simplify the test even further....
257
        wt.remove('b/c')
2363.2.1 by John Arbash Meinel
(broken) Add a simplified test which exposes the bug.
258
        this_dir = self.get_transport()
259
        this_dir.delete_tree('b')
260
        wt.lock_write()
261
        wt.commit('commit deleted rename')
262
        self.assertTrue(wt.has_id('a-id'))
263
        self.assertFalse(wt.has_or_had_id('b-id'))
264
        self.assertFalse(wt.has_or_had_id('c-id'))
265
        self.assertTrue(wt.has_filename('a'))
266
        self.assertFalse(wt.has_filename('b'))
267
        self.assertFalse(wt.has_filename('b/c'))
268
        wt.unlock()
269
1731.2.4 by Aaron Bentley
Ensure subsume works with Knit2 repos
270
    def test_commit_move_new(self):
271
        wt = self.make_branch_and_tree('first')
272
        wt.commit('first')
273
        wt2 = wt.bzrdir.sprout('second').open_workingtree()
274
        self.build_tree(['second/name1'])
275
        wt2.add('name1', 'name1-id')
276
        wt2.commit('second')
277
        wt.merge_from_branch(wt2.branch)
278
        wt.rename_one('name1', 'name2')
279
        wt.commit('third')
280
        wt.path2id('name1-id')
2255.2.218 by Robert Collins
Make the nested tree commit smoke test be more rigourous.
281
282
    def test_nested_commit(self):
283
        """Commit in multiply-nested trees"""
284
        tree = self.make_branch_and_tree('.')
285
        if not tree.supports_tree_reference():
286
            # inapplicable test.
287
            return
288
        subtree = self.make_branch_and_tree('subtree')
289
        subsubtree = self.make_branch_and_tree('subtree/subtree')
290
        subtree.add(['subtree'])
291
        tree.add(['subtree'])
292
        # use allow_pointless=False to ensure that the deepest tree, which
293
        # has no commits made to it, does not get a pointless commit.
294
        rev_id = tree.commit('added reference', allow_pointless=False)
295
        tree.lock_read()
296
        self.addCleanup(tree.unlock)
297
        # the deepest subtree has not changed, so no commit should take place.
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
298
        self.assertEqual('null:', subsubtree.last_revision())
2255.2.218 by Robert Collins
Make the nested tree commit smoke test be more rigourous.
299
        # the intermediate tree should have committed a pointer to the current
300
        # subtree revision.
301
        sub_basis = subtree.basis_tree()
302
        sub_basis.lock_read()
303
        self.addCleanup(sub_basis.unlock)
304
        self.assertEqual(subsubtree.last_revision(),
2255.2.227 by Robert Collins
Make all test_commit tests pass.
305
            sub_basis.get_reference_revision(sub_basis.path2id('subtree')))
2255.2.218 by Robert Collins
Make the nested tree commit smoke test be more rigourous.
306
        # the intermediate tree has changed, so should have had a commit
307
        # take place.
308
        self.assertNotEqual(None, subtree.last_revision())
309
        # the outer tree should have committed a pointer to the current
310
        # subtree revision.
311
        basis = tree.basis_tree()
312
        basis.lock_read()
313
        self.addCleanup(basis.unlock)
314
        self.assertEqual(subtree.last_revision(),
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
315
            basis.get_reference_revision(basis.path2id('subtree')))
2255.2.218 by Robert Collins
Make the nested tree commit smoke test be more rigourous.
316
        # the outer tree must have have changed too.
317
        self.assertNotEqual(None, rev_id)
1988.3.1 by Robert Collins
Add test case to ensure that the working tree inventory and disk state is correctly update when commit is removing directory entries.
318
        
2255.2.220 by Robert Collins
Fix failing detection of changes restricted to subtrees causing spurious pointless commit errors.
319
    def test_nested_commit_second_commit_detects_changes(self):
320
        """Commit with a nested tree picks up the correct child revid."""
321
        tree = self.make_branch_and_tree('.')
322
        if not tree.supports_tree_reference():
323
            # inapplicable test.
324
            return
325
        subtree = self.make_branch_and_tree('subtree')
326
        tree.add(['subtree'])
327
        self.build_tree(['subtree/file'])
328
        subtree.add(['file'], ['file-id'])
329
        rev_id = tree.commit('added reference', allow_pointless=False)
330
        child_revid = subtree.last_revision()
331
        # now change the child tree
332
        self.build_tree_contents([('subtree/file', 'new-content')])
333
        # and commit in the parent should commit the child and grab its revid,
334
        # we test with allow_pointless=False here so that we are simulating
335
        # what users will see.
336
        rev_id2 = tree.commit('changed subtree only', allow_pointless=False)
337
        # the child tree has changed, so should have had a commit
338
        # take place.
339
        self.assertNotEqual(None, subtree.last_revision())
340
        self.assertNotEqual(child_revid, subtree.last_revision())
341
        # the outer tree should have committed a pointer to the current
342
        # subtree revision.
343
        basis = tree.basis_tree()
344
        basis.lock_read()
345
        self.addCleanup(basis.unlock)
346
        self.assertEqual(subtree.last_revision(),
2255.2.226 by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet.
347
            basis.get_reference_revision(basis.path2id('subtree')))
2255.2.220 by Robert Collins
Fix failing detection of changes restricted to subtrees causing spurious pointless commit errors.
348
        self.assertNotEqual(rev_id, rev_id2)
349
2825.5.2 by Robert Collins
Review feedback, and fix pointless commits with nested trees to raise PointlessCommit appropriately.
350
    def test_nested_pointless_commits_are_pointless(self):
351
        tree = self.make_branch_and_tree('.')
352
        if not tree.supports_tree_reference():
353
            # inapplicable test.
354
            return
355
        subtree = self.make_branch_and_tree('subtree')
356
        tree.add(['subtree'])
357
        # record the reference.
358
        rev_id = tree.commit('added reference')
359
        child_revid = subtree.last_revision()
360
        # now do a no-op commit with allow_pointless=False
361
        self.assertRaises(errors.PointlessCommit, tree.commit, '',
362
            allow_pointless=False)
363
        self.assertEqual(child_revid, subtree.last_revision())
364
        self.assertEqual(rev_id, tree.last_revision())
365
1988.3.1 by Robert Collins
Add test case to ensure that the working tree inventory and disk state is correctly update when commit is removing directory entries.
366
1740.3.10 by Jelmer Vernooij
Fix some minor issues pointed out by j-a-m.
367
class TestCommitProgress(TestCaseWithWorkingTree):
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
368
    
369
    def restoreDefaults(self):
370
        ui.ui_factory = self.old_ui_factory
371
372
    def test_commit_progress_steps(self):
373
        # during commit we one progress update for every entry in the 
374
        # inventory, and then one for the inventory, and one for the
375
        # inventory, and one for the revision insertions.
376
        # first we need a test commit to do. Lets setup a branch with 
377
        # 3 files, and alter one in a selected-file commit. This exercises
378
        # a number of cases quickly. We should also test things like 
379
        # selective commits which excludes newly added files.
380
        tree = self.make_branch_and_tree('.')
381
        self.build_tree(['a', 'b', 'c'])
382
        tree.add(['a', 'b', 'c'])
383
        tree.commit('first post')
384
        f = file('b', 'wt')
385
        f.write('new content')
386
        f.close()
387
        # set a progress bar that captures the calls so we can see what is 
388
        # emitted
389
        self.old_ui_factory = ui.ui_factory
390
        self.addCleanup(self.restoreDefaults)
391
        factory = CapturingUIFactory()
392
        ui.ui_factory = factory
393
        # TODO RBC 20060421 it would be nice to merge the reporter output
394
        # into the factory for this test - just make the test ui factory
395
        # pun as a reporter. Then we can check the ordering is right.
396
        tree.commit('second post', specific_files=['b'])
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
397
        # 5 steps, the first of which is reported 2 times, once per dir
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
398
        self.assertEqual(
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
399
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
400
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
401
             ('update', 2, 5, 'Saving data locally - Stage'),
2659.3.9 by NamNguyen
branch.py:
402
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
403
             ('update', 4, 5, 'Updating the working tree - Stage'),
2659.3.9 by NamNguyen
branch.py:
404
             ('update', 5, 5, 'Running post_commit hooks - Stage')],
1666.1.19 by Robert Collins
Introduce a progress bar during commit.
405
            factory._calls
406
           )
2553.1.2 by Robert Collins
Show hook names during commit.
407
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
408
    def test_commit_progress_shows_post_hook_names(self):
2553.1.2 by Robert Collins
Show hook names during commit.
409
        tree = self.make_branch_and_tree('.')
410
        # set a progress bar that captures the calls so we can see what is 
411
        # emitted
412
        self.old_ui_factory = ui.ui_factory
413
        self.addCleanup(self.restoreDefaults)
414
        factory = CapturingUIFactory()
415
        ui.ui_factory = factory
416
        def a_hook(_, _2, _3, _4, _5, _6):
417
            pass
418
        branch.Branch.hooks.install_hook('post_commit', a_hook)
419
        branch.Branch.hooks.name_hook(a_hook, 'hook name')
420
        tree.commit('first post')
421
        self.assertEqual(
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
422
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
423
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
424
             ('update', 2, 5, 'Saving data locally - Stage'),
2659.3.9 by NamNguyen
branch.py:
425
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
426
             ('update', 4, 5, 'Updating the working tree - Stage'),
2659.3.9 by NamNguyen
branch.py:
427
             ('update', 5, 5, 'Running post_commit hooks - Stage'),
428
             ('update', 5, 5, 'Running post_commit hooks [hook name] - Stage'),
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
429
             ],
430
            factory._calls
431
           )
432
433
    def test_commit_progress_shows_pre_hook_names(self):
434
        tree = self.make_branch_and_tree('.')
435
        # set a progress bar that captures the calls so we can see what is 
436
        # emitted
437
        self.old_ui_factory = ui.ui_factory
438
        self.addCleanup(self.restoreDefaults)
439
        factory = CapturingUIFactory()
440
        ui.ui_factory = factory
2659.3.3 by NamNguyen
Changed ``pre_commit`` hook signature.
441
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
442
            pass
443
        branch.Branch.hooks.install_hook('pre_commit', a_hook)
444
        branch.Branch.hooks.name_hook(a_hook, 'hook name')
445
        tree.commit('first post')
446
        self.assertEqual(
447
            [('update', 1, 5, 'Collecting changes [Directory 0] - Stage'),
448
             ('update', 1, 5, 'Collecting changes [Directory 1] - Stage'),
449
             ('update', 2, 5, 'Saving data locally - Stage'),
2659.3.9 by NamNguyen
branch.py:
450
             ('update', 3, 5, 'Running pre_commit hooks - Stage'),
451
             ('update', 3, 5, 'Running pre_commit hooks [hook name] - Stage'),
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
452
             ('update', 4, 5, 'Updating the working tree - Stage'),
2659.3.9 by NamNguyen
branch.py:
453
             ('update', 5, 5, 'Running post_commit hooks - Stage'),
2659.3.1 by NamNguyen
``Branch.hooks`` now supports ``pre_commit`` hook.
454
             ],
455
            factory._calls
456
           )