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
18
from cStringIO import StringIO
21
20
from bzrlib import (
28
27
revision as _mod_revision,
29
transport as _mod_transport,
33
from bzrlib.errors import (NotBranchError, NotVersionedError,
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,
43
class CapturingUIFactory(ui.UIFactory):
44
"""A UI Factory for testing - capture the updates made through it."""
47
super(CapturingUIFactory, self).__init__()
52
"""See progress.ProgressTask.clear()."""
55
"""See progress.ProgressTask.clear_term()."""
58
"""See progress.ProgressTask.finished()."""
61
def note(self, fmt_string, *args, **kwargs):
62
"""See progress.ProgressTask.note()."""
64
def progress_bar(self):
67
def nested_progress_bar(self):
71
def update(self, message, count=None, total=None):
72
"""See progress.ProgressTask.update()."""
74
self._calls.append(("update", count, total, message))
77
class TestCapturingUI(TestCase):
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)
89
self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
33
from bzrlib.tests.testui import ProgressRecordingUIFactory
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'])
152
self.assertRaises(errors.CannotCommitSelectedFileMerge,
153
wt.commit, 'test', exclude=['foo'])
154
except errors.ExcludesUnsupported:
155
raise tests.TestNotApplicable("excludes not supported by this "
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)
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 "
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'])
176
tree.commit('test', exclude=['b', 'c'])
177
except errors.ExcludesUnsupported:
178
raise tests.TestNotApplicable("excludes not supported by this "
224
180
# If b was excluded it will still be 'added' in status.
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'])
193
tree.commit('test', specific_files=['a'], exclude=['a/b'])
194
except errors.ExcludesUnsupported:
195
raise tests.TestNotApplicable("excludes not supported by this "
237
197
# If a/b was excluded it will still be 'added' in status.
239
199
self.addCleanup(tree.unlock)
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())))
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')
396
this_dir = self.get_transport()
356
this_dir = wt.bzrdir.root_transport
397
357
this_dir.delete_tree('b')
399
359
wt.commit('commit deleted rename')
547
507
tree = self.make_branch_and_tree('.')
548
508
# set a progress bar that captures the calls so we can see what is
550
factory = CapturingUIFactory()
510
factory = ProgressRecordingUIFactory()
551
511
ui.ui_factory = factory
552
512
def a_hook(_, _2, _3, _4, _5, _6):
570
530
tree = self.make_branch_and_tree('.')
571
531
# set a progress bar that captures the calls so we can see what is
573
factory = CapturingUIFactory()
533
factory = ProgressRecordingUIFactory()
574
534
ui.ui_factory = factory
575
535
def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
593
553
"""Make sure a start commit hook can modify the tree that is
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(