4
from bzrlib.tests import TestCaseInTempDir, TestCase
5
from bzrlib.branch import Branch
6
from bzrlib.errors import NotBranchError
7
from bzrlib.inventory import InventoryFile
8
from bzrlib.workingtree import WorkingTree
10
class TestSmartAdd(TestCaseInTempDir):
12
def test_add_dot_from_root(self):
13
"""Test adding . from the root of the tree."""
14
from bzrlib.add import smart_add
15
paths = ("original/", "original/file1", "original/file2")
16
self.build_tree(paths)
17
branch = Branch.initialize(u".")
18
smart_add((u".",), recurse=True)
20
self.assertNotEqual(branch.working_tree().path2id(path), None)
22
def test_add_dot_from_subdir(self):
23
"""Test adding . from a subdir of the tree."""
24
from bzrlib.add import smart_add
25
paths = ("original/", "original/file1", "original/file2")
26
self.build_tree(paths)
27
branch = Branch.initialize(u".")
29
smart_add((u".",), recurse=True)
31
self.assertNotEqual(branch.working_tree().path2id(path), None)
33
def test_add_tree_from_above_tree(self):
34
"""Test adding a tree from above the tree."""
35
from bzrlib.add import smart_add
36
paths = ("original/", "original/file1", "original/file2")
37
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
38
"branch/original/file2")
39
self.build_tree(branch_paths)
40
branch = Branch.initialize("branch")
41
smart_add(("branch",))
43
self.assertNotEqual(branch.working_tree().path2id(path), None)
45
def test_add_above_tree_preserves_tree(self):
46
"""Test nested trees are not affect by an add above them."""
47
from bzrlib.add import smart_add, add_reporter_null
49
paths = ("original/", "original/file1", "original/file2")
50
child_paths = ("path",)
51
full_child_paths = ("original/child", "original/child/path")
52
build_paths = ("original/", "original/file1", "original/file2",
53
"original/child/", "original/child/path")
55
self.build_tree(build_paths)
56
branch = Branch.initialize(u".")
57
child_branch = Branch.initialize("original/child")
58
smart_add((u".",), True, add_reporter_null)
60
self.assertNotEqual((path, branch.working_tree().path2id(path)),
62
for path in full_child_paths:
63
self.assertEqual((path, branch.working_tree().path2id(path)),
65
for path in child_paths:
66
self.assertEqual(child_branch.working_tree().path2id(path), None)
68
def test_add_paths(self):
69
"""Test smart-adding a list of paths."""
70
from bzrlib.add import smart_add
71
paths = ("file1", "file2")
72
self.build_tree(paths)
73
branch = Branch.initialize(u".")
76
self.assertNotEqual(branch.working_tree().path2id(path), None)
78
class TestSmartAddBranch(TestCaseInTempDir):
79
"""Test smart adds with a specified branch."""
81
def test_add_dot_from_root(self):
82
"""Test adding . from the root of the tree."""
83
from bzrlib.add import smart_add_tree
84
paths = ("original/", "original/file1", "original/file2")
85
self.build_tree(paths)
86
Branch.initialize(u".")
88
smart_add_tree(tree, (u".",))
90
self.assertNotEqual(tree.path2id(path), None)
92
def test_add_dot_from_subdir(self):
93
"""Test adding . from a subdir of the tree."""
94
from bzrlib.add import smart_add_tree
95
paths = ("original/", "original/file1", "original/file2")
96
self.build_tree(paths)
97
Branch.initialize(u".")
100
smart_add_tree(tree, (u".",))
102
self.assertNotEqual(tree.path2id(path), None)
104
def test_add_tree_from_above_tree(self):
105
"""Test adding a tree from above the tree."""
106
from bzrlib.add import smart_add_tree
107
paths = ("original/", "original/file1", "original/file2")
108
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
109
"branch/original/file2")
110
self.build_tree(branch_paths)
111
Branch.initialize("branch")
112
tree = WorkingTree("branch")
113
smart_add_tree(tree, ("branch",))
115
self.assertNotEqual(tree.path2id(path), None)
117
def test_add_above_tree_preserves_tree(self):
118
"""Test nested trees are not affect by an add above them."""
119
from bzrlib.add import smart_add_tree
120
paths = ("original/", "original/file1", "original/file2")
121
child_paths = ("path")
122
full_child_paths = ("original/child", "original/child/path")
123
build_paths = ("original/", "original/file1", "original/file2",
124
"original/child/", "original/child/path")
125
self.build_tree(build_paths)
126
Branch.initialize(u".")
128
child_branch = Branch.initialize("original/child")
129
smart_add_tree(tree, (u".",))
131
self.assertNotEqual((path, tree.path2id(path)),
133
for path in full_child_paths:
134
self.assertEqual((path, tree.path2id(path)),
136
for path in child_paths:
137
self.assertEqual(child_branch.working_tree().path2id(path), None)
139
def test_add_paths(self):
140
"""Test smart-adding a list of paths."""
141
from bzrlib.add import smart_add_tree
142
paths = ("file1", "file2")
143
self.build_tree(paths)
144
Branch.initialize(u".")
146
smart_add_tree(tree, paths)
148
self.assertNotEqual(tree.path2id(path), None)
150
class TestAddCallbacks(TestCaseInTempDir):
153
super(TestAddCallbacks, self).setUp()
154
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
162
from StringIO import StringIO
164
self.apply_redirected(None, stdout, None, add_reporter_print,
165
'path', 'file', self.entry)
166
self.assertEqual(stdout.getvalue(), "added path\n")