~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-01-15 09:21:49 UTC
  • mfrom: (6606.2.1 autodoc-unicode)
  • Revision ID: pqm@pqm.ubuntu.com-20160115092149-z5f4sfq3jvaz0enb
(vila) Fix autodoc runner when LANG=C. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
 
from cStringIO import StringIO
19
18
import os
20
19
 
21
20
from bzrlib import (
22
21
    branch,
23
 
    bzrdir,
24
22
    conflicts,
 
23
    controldir,
25
24
    errors,
26
25
    mutabletree,
27
26
    osutils,
28
27
    revision as _mod_revision,
 
28
    tests,
 
29
    transport as _mod_transport,
29
30
    ui,
30
 
    uncommit,
31
 
    workingtree,
32
31
    )
33
 
from bzrlib.errors import (NotBranchError, NotVersionedError,
34
 
                           UnsupportedOperation)
35
 
from bzrlib.osutils import pathjoin, getcwd
36
 
from bzrlib.tests import TestCase
37
32
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
38
 
from bzrlib.trace import mutter
39
 
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
40
 
                                WorkingTree)
41
 
 
42
 
 
43
 
class CapturingUIFactory(ui.UIFactory):
44
 
    """A UI Factory for testing - capture the updates made through it."""
45
 
 
46
 
    def __init__(self):
47
 
        super(CapturingUIFactory, self).__init__()
48
 
        self._calls = []
49
 
        self.depth = 0
50
 
 
51
 
    def clear(self):
52
 
        """See progress.ProgressTask.clear()."""
53
 
 
54
 
    def clear_term(self):
55
 
        """See progress.ProgressTask.clear_term()."""
56
 
 
57
 
    def finished(self):
58
 
        """See progress.ProgressTask.finished()."""
59
 
        self.depth -= 1
60
 
 
61
 
    def note(self, fmt_string, *args, **kwargs):
62
 
        """See progress.ProgressTask.note()."""
63
 
 
64
 
    def progress_bar(self):
65
 
        return self
66
 
 
67
 
    def nested_progress_bar(self):
68
 
        self.depth += 1
69
 
        return self
70
 
 
71
 
    def update(self, message, count=None, total=None):
72
 
        """See progress.ProgressTask.update()."""
73
 
        if self.depth == 1:
74
 
            self._calls.append(("update", count, total, message))
75
 
 
76
 
 
77
 
class TestCapturingUI(TestCase):
78
 
 
79
 
    def test_nested_ignore_depth_beyond_one(self):
80
 
        # we only want to capture the first level out progress, not
81
 
        # want sub-components might do. So we have nested bars ignored.
82
 
        factory = CapturingUIFactory()
83
 
        pb1 = factory.nested_progress_bar()
84
 
        pb1.update('foo', 0, 1)
85
 
        pb2 = factory.nested_progress_bar()
86
 
        pb2.update('foo', 0, 1)
87
 
        pb2.finished()
88
 
        pb1.finished()
89
 
        self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
 
33
from bzrlib.tests.testui import ProgressRecordingUIFactory
90
34
 
91
35
 
92
36
class TestCommit(TestCaseWithWorkingTree):
204
148
        wt2 = wt.bzrdir.sprout('to').open_workingtree()
205
149
        wt2.commit('change_right')
206
150
        wt.merge_from_branch(wt2.branch)
207
 
        self.assertRaises(errors.CannotCommitSelectedFileMerge,
208
 
            wt.commit, 'test', exclude=['foo'])
 
151
        try:
 
152
            self.assertRaises(errors.CannotCommitSelectedFileMerge,
 
153
                wt.commit, 'test', exclude=['foo'])
 
154
        except errors.ExcludesUnsupported:
 
155
            raise tests.TestNotApplicable("excludes not supported by this "
 
156
                "repository format")
209
157
 
210
158
    def test_commit_exclude_exclude_changed_is_pointless(self):
211
159
        tree = self.make_branch_and_tree('.')
213
161
        tree.smart_add(['.'])
214
162
        tree.commit('setup test')
215
163
        self.build_tree_contents([('a', 'new contents for "a"\n')])
216
 
        self.assertRaises(errors.PointlessCommit, tree.commit, 'test',
217
 
            exclude=['a'], allow_pointless=False)
 
164
        try:
 
165
            self.assertRaises(errors.PointlessCommit, tree.commit, 'test',
 
166
                exclude=['a'], allow_pointless=False)
 
167
        except errors.ExcludesUnsupported:
 
168
            raise tests.TestNotApplicable("excludes not supported by this "
 
169
                "repository format")
218
170
 
219
171
    def test_commit_exclude_excludes_modified_files(self):
220
172
        tree = self.make_branch_and_tree('.')
221
173
        self.build_tree(['a', 'b', 'c'])
222
174
        tree.smart_add(['.'])
223
 
        tree.commit('test', exclude=['b', 'c'])
 
175
        try:
 
176
            tree.commit('test', exclude=['b', 'c'])
 
177
        except errors.ExcludesUnsupported:
 
178
            raise tests.TestNotApplicable("excludes not supported by this "
 
179
                "repository format")
224
180
        # If b was excluded it will still be 'added' in status.
225
181
        tree.lock_read()
226
182
        self.addCleanup(tree.unlock)
233
189
        tree = self.make_branch_and_tree('.')
234
190
        self.build_tree(['a/', 'a/b'])
235
191
        tree.smart_add(['.'])
236
 
        tree.commit('test', specific_files=['a'], exclude=['a/b'])
 
192
        try:
 
193
            tree.commit('test', specific_files=['a'], exclude=['a/b'])
 
194
        except errors.ExcludesUnsupported:
 
195
            raise tests.TestNotApplicable("excludes not supported by this "
 
196
                "repository format")
237
197
        # If a/b was excluded it will still be 'added' in status.
238
198
        tree.lock_read()
239
199
        self.addCleanup(tree.unlock)
305
265
        del master
306
266
        # check its corrupted.
307
267
        self.assertRaises(errors.UnknownFormatError,
308
 
                          bzrdir.BzrDir.open,
 
268
                          controldir.ControlDir.open,
309
269
                          'master')
310
270
        tree.commit('foo', rev_id='foo', local=True)
311
271
 
321
281
            # older format.
322
282
            return
323
283
        tree.commit('foo', rev_id='foo', local=True)
324
 
        self.failIf(master.repository.has_revision('foo'))
 
284
        self.assertFalse(master.repository.has_revision('foo'))
325
285
        self.assertEqual(_mod_revision.NULL_REVISION,
326
286
                         (_mod_revision.ensure_null(master.last_revision())))
327
287
 
357
317
        wt.lock_write()
358
318
        self.build_tree(['a', 'b/', 'b/c', 'd'])
359
319
        wt.add(['a', 'b', 'b/c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
360
 
        this_dir = self.get_transport()
 
320
        this_dir = wt.bzrdir.root_transport
361
321
        this_dir.delete_tree('b')
362
322
        this_dir.delete('d')
363
323
        # now we have a tree with a through d in the inventory, but only
393
353
        wt.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
394
354
        wt.commit('first')
395
355
        wt.remove('b/c')
396
 
        this_dir = self.get_transport()
 
356
        this_dir = wt.bzrdir.root_transport
397
357
        this_dir.delete_tree('b')
398
358
        wt.lock_write()
399
359
        wt.commit('commit deleted rename')
507
467
 
508
468
    def setUp(self):
509
469
        super(TestCommitProgress, self).setUp()
510
 
        ui.ui_factory = CapturingUIFactory()
 
470
        ui.ui_factory = ProgressRecordingUIFactory()
511
471
 
512
472
    def test_commit_progress_steps(self):
513
473
        # during commit we one progress update for every entry in the
526
486
        f.close()
527
487
        # set a progress bar that captures the calls so we can see what is
528
488
        # emitted
529
 
        factory = CapturingUIFactory()
 
489
        factory = ProgressRecordingUIFactory()
530
490
        ui.ui_factory = factory
531
491
        # TODO RBC 20060421 it would be nice to merge the reporter output
532
492
        # into the factory for this test - just make the test ui factory
547
507
        tree = self.make_branch_and_tree('.')
548
508
        # set a progress bar that captures the calls so we can see what is
549
509
        # emitted
550
 
        factory = CapturingUIFactory()
 
510
        factory = ProgressRecordingUIFactory()
551
511
        ui.ui_factory = factory
552
512
        def a_hook(_, _2, _3, _4, _5, _6):
553
513
            pass
570
530
        tree = self.make_branch_and_tree('.')
571
531
        # set a progress bar that captures the calls so we can see what is
572
532
        # emitted
573
 
        factory = CapturingUIFactory()
 
533
        factory = ProgressRecordingUIFactory()
574
534
        ui.ui_factory = factory
575
535
        def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
576
536
            pass
593
553
        """Make sure a start commit hook can modify the tree that is
594
554
        committed."""
595
555
        def start_commit_hook_adds_file(tree):
596
 
            open(tree.abspath("newfile"), 'w').write("data")
 
556
            with open(tree.abspath("newfile"), 'w') as f: f.write("data")
597
557
            tree.add(["newfile"])
598
558
        def restoreDefaults():
599
559
            mutabletree.MutableTree.hooks['start_commit'] = []
614
574
                mutabletree.PostCommitHookParams))
615
575
            self.assertTrue(isinstance(params.mutable_tree,
616
576
                mutabletree.MutableTree))
617
 
            open(tree.abspath("newfile"), 'w').write("data")
 
577
            with open(tree.abspath("newfile"), 'w') as f: f.write("data")
618
578
            params.mutable_tree.add(["newfile"])
619
579
        tree = self.make_branch_and_tree('.')
620
580
        mutabletree.MutableTree.hooks.install_named_hook(