4
4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import Branch
6
6
from bzrlib.errors import NotBranchError
7
from bzrlib.inventory import InventoryFile
7
from bzrlib.inventory import InventoryFile, Inventory
8
8
from bzrlib.workingtree import WorkingTree
10
10
class TestSmartAdd(TestCaseInTempDir):
15
15
paths = ("original/", "original/file1", "original/file2")
16
16
self.build_tree(paths)
17
17
branch = Branch.initialize(u".")
18
smart_add((u".",), recurse=True)
20
20
self.assertNotEqual(branch.working_tree().path2id(path), None)
45
45
def test_add_above_tree_preserves_tree(self):
46
46
"""Test nested trees are not affect by an add above them."""
47
from bzrlib.add import smart_add, add_reporter_null
47
from bzrlib.add import smart_add
49
48
paths = ("original/", "original/file1", "original/file2")
50
49
child_paths = ("path",)
51
50
full_child_paths = ("original/child", "original/child/path")
55
54
self.build_tree(build_paths)
56
55
branch = Branch.initialize(u".")
57
56
child_branch = Branch.initialize("original/child")
58
smart_add((u".",), True, add_reporter_null)
60
59
self.assertNotEqual((path, branch.working_tree().path2id(path)),
76
75
self.assertNotEqual(branch.working_tree().path2id(path), None)
77
def test_add_dry_run(self):
78
"""Test a dry run add, make sure nothing is added."""
79
from bzrlib.commands import run_bzr
81
b = Branch.initialize(u'.')
83
self.build_tree(['inertiatic/', 'inertiatic/esp'])
84
eq(list(t.unknowns()), ['inertiatic'])
85
self.capture('add --dry-run .')
86
eq(list(t.unknowns()), ['inertiatic'])
78
88
class TestSmartAddBranch(TestCaseInTempDir):
79
89
"""Test smart adds with a specified branch."""
147
157
for path in paths:
148
158
self.assertNotEqual(tree.path2id(path), None)
150
class TestAddCallbacks(TestCaseInTempDir):
153
super(TestAddCallbacks, self).setUp()
160
class TestAddActions(TestCaseInTempDir):
163
from bzrlib.add import add_action_null
164
self.run_action(add_action_null, "", False)
154
167
self.entry = InventoryFile("id", "name", None)
156
def test_null_callback(self):
157
from bzrlib.add import add_reporter_null
158
add_reporter_null('path', 'file', self.entry)
160
def test_print_callback(self):
161
from bzrlib.add import add_reporter_print
168
from bzrlib.add import add_action_add
169
self.run_action(add_action_add, "", True)
171
def test_add_and_print(self):
172
from bzrlib.add import add_action_add_and_print
173
self.run_action(add_action_add_and_print, "added path\n", True)
175
def test_print(self):
176
from bzrlib.add import add_action_print
177
self.run_action(add_action_print, "added path\n", False)
179
def run_action(self, action, output, should_add):
162
180
from StringIO import StringIO
163
182
stdout = StringIO()
164
self.apply_redirected(None, stdout, None, add_reporter_print,
165
'path', 'file', self.entry)
166
self.assertEqual(stdout.getvalue(), "added path\n")
184
self.apply_redirected(None, stdout, None, action, inv, 'path', 'file')
185
self.assertEqual(stdout.getvalue(), output)
188
self.assertNotEqual(inv.path2id('path'), None)
190
self.assertEqual(inv.path2id('path'), None)