4
from bzrlib.selftest import FunctionalTestCase, TestCase
4
from bzrlib.selftest import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import Branch
6
6
from bzrlib.errors import NotBranchError, NotVersionedError
8
class TestSmartAdd(FunctionalTestCase):
8
class TestSmartAdd(TestCaseInTempDir):
10
10
def test_add_dot_from_root(self):
11
11
"""Test adding . from the root of the tree."""
13
13
paths = ("original/", "original/file1", "original/file2")
14
14
self.build_tree(paths)
15
15
branch = Branch(".", init=True)
16
smart_add((".",), False, True)
16
smart_add((".",), recurse=True)
18
18
self.assertNotEqual(branch.inventory.path2id(path), None)
24
24
self.build_tree(paths)
25
25
branch = Branch(".", init=True)
26
26
os.chdir("original")
27
smart_add((".",), False, True)
27
smart_add((".",), recurse=True)
29
29
self.assertNotEqual(branch.inventory.path2id(path), None)
36
36
"branch/original/file2")
37
37
self.build_tree(branch_paths)
38
38
branch = Branch("branch", init=True)
39
smart_add(("branch",), False, True)
39
smart_add(("branch",))
41
41
self.assertNotEqual(branch.inventory.path2id(path), None)
43
43
def test_add_above_tree_preserves_tree(self):
44
44
"""Test nested trees are not affect by an add above them."""
45
from bzrlib.add import smart_add
45
from bzrlib.add import smart_add, add_reporter_null
46
47
paths = ("original/", "original/file1", "original/file2")
47
child_paths = ("path")
48
child_paths = ("path",)
48
49
full_child_paths = ("original/child", "original/child/path")
49
50
build_paths = ("original/", "original/file1", "original/file2",
50
51
"original/child/", "original/child/path")
51
53
self.build_tree(build_paths)
52
54
branch = Branch(".", init=True)
53
55
child_branch = Branch("original/child", init=True)
54
smart_add((".",), False, True)
56
smart_add((".",), True, add_reporter_null)
56
58
self.assertNotEqual((path, branch.inventory.path2id(path)),
67
69
paths = ("file1", "file2")
68
70
self.build_tree(paths)
69
71
branch = Branch(".", init=True)
70
smart_add(paths, False, True)
72
74
self.assertNotEqual(branch.inventory.path2id(path), None)
74
class TestSmartAddBranch(FunctionalTestCase):
76
class TestSmartAddBranch(TestCaseInTempDir):
75
77
"""Test smart adds with a specified branch."""
77
79
def test_add_dot_from_root(self):
80
82
paths = ("original/", "original/file1", "original/file2")
81
83
self.build_tree(paths)
82
84
branch = Branch(".", init=True)
83
smart_add_branch(branch, (".",), False, True)
85
smart_add_branch(branch, (".",))
85
87
self.assertNotEqual(branch.inventory.path2id(path), None)
91
93
self.build_tree(paths)
92
94
branch = Branch(".", init=True)
93
95
os.chdir("original")
94
smart_add_branch(branch, (".",), False, True)
96
smart_add_branch(branch, (".",))
96
98
self.assertNotEqual(branch.inventory.path2id(path), None)
103
105
"branch/original/file2")
104
106
self.build_tree(branch_paths)
105
107
branch = Branch("branch", init=True)
106
smart_add_branch(branch, ("branch",), False, True)
108
smart_add_branch(branch, ("branch",))
107
109
for path in paths:
108
110
self.assertNotEqual(branch.inventory.path2id(path), None)
118
120
self.build_tree(build_paths)
119
121
branch = Branch(".", init=True)
120
122
child_branch = Branch("original/child", init=True)
121
smart_add_branch(branch, (".",), False, True)
123
smart_add_branch(branch, (".",))
122
124
for path in paths:
123
125
self.assertNotEqual((path, branch.inventory.path2id(path)),
134
136
paths = ("file1", "file2")
135
137
self.build_tree(paths)
136
138
branch = Branch(".", init=True)
137
smart_add_branch(branch, paths, False, True)
139
smart_add_branch(branch, paths)
138
140
for path in paths:
139
141
self.assertNotEqual(branch.inventory.path2id(path), None)
141
class TestAddCallbacks(TestCase):
143
class TestAddCallbacks(TestCaseInTempDir):
144
146
from bzrlib.inventory import InventoryEntry
146
148
self.entry = InventoryEntry("id", "name", "file", None)
148
150
def test_null_callback(self):
149
from bzrlib.add import _NullAddCallback
150
_NullAddCallback(self.entry)
151
from bzrlib.add import add_reporter_null
152
add_reporter_null('path', 'file', self.entry)
152
154
def test_print_callback(self):
153
from bzrlib.add import _PrintAddCallback
155
from bzrlib.add import add_reporter_print
154
156
from StringIO import StringIO
155
157
stdout = StringIO()
156
self.apply_redirected(None, stdout, None, _PrintAddCallback,
158
self.assertEqual(stdout.getvalue(), "added name\n")
158
self.apply_redirected(None, stdout, None, add_reporter_print,
159
'path', 'file', self.entry)
160
self.assertEqual(stdout.getvalue(), "added path\n")