14
12
from bzrlib.add import smart_add
15
13
paths = ("original/", "original/file1", "original/file2")
16
14
self.build_tree(paths)
17
branch = Branch.initialize(".")
15
branch = Branch(".", init=True)
18
16
smart_add((".",), recurse=True)
20
self.assertNotEqual(branch.working_tree().path2id(path), None)
18
self.assertNotEqual(branch.inventory.path2id(path), None)
22
20
def test_add_dot_from_subdir(self):
23
21
"""Test adding . from a subdir of the tree."""
24
22
from bzrlib.add import smart_add
25
23
paths = ("original/", "original/file1", "original/file2")
26
24
self.build_tree(paths)
27
branch = Branch.initialize(".")
25
branch = Branch(".", init=True)
28
26
os.chdir("original")
29
27
smart_add((".",), recurse=True)
31
self.assertNotEqual(branch.working_tree().path2id(path), None)
29
self.assertNotEqual(branch.inventory.path2id(path), None)
33
31
def test_add_tree_from_above_tree(self):
34
32
"""Test adding a tree from above the tree."""
53
51
"original/child/", "original/child/path")
55
53
self.build_tree(build_paths)
56
branch = Branch.initialize(".")
57
child_branch = Branch.initialize("original/child")
54
branch = Branch(".", init=True)
55
child_branch = Branch("original/child", init=True)
58
56
smart_add((".",), True, add_reporter_null)
60
self.assertNotEqual((path, branch.working_tree().path2id(path)),
58
self.assertNotEqual((path, branch.inventory.path2id(path)),
62
60
for path in full_child_paths:
63
self.assertEqual((path, branch.working_tree().path2id(path)),
61
self.assertEqual((path, branch.inventory.path2id(path)),
65
63
for path in child_paths:
66
self.assertEqual(child_branch.working_tree().path2id(path), None)
64
self.assertEqual(child_branch.inventory.path2id(path), None)
68
66
def test_add_paths(self):
69
67
"""Test smart-adding a list of paths."""
70
68
from bzrlib.add import smart_add
71
69
paths = ("file1", "file2")
72
70
self.build_tree(paths)
73
branch = Branch.initialize(".")
71
branch = Branch(".", init=True)
76
self.assertNotEqual(branch.working_tree().path2id(path), None)
74
self.assertNotEqual(branch.inventory.path2id(path), None)
78
76
class TestSmartAddBranch(TestCaseInTempDir):
79
77
"""Test smart adds with a specified branch."""
81
79
def test_add_dot_from_root(self):
82
80
"""Test adding . from the root of the tree."""
83
from bzrlib.add import smart_add_tree
81
from bzrlib.add import smart_add_branch
84
82
paths = ("original/", "original/file1", "original/file2")
85
83
self.build_tree(paths)
86
Branch.initialize(".")
88
smart_add_tree(tree, (".",))
84
branch = Branch(".", init=True)
85
smart_add_branch(branch, (".",))
90
self.assertNotEqual(tree.path2id(path), None)
87
self.assertNotEqual(branch.inventory.path2id(path), None)
92
89
def test_add_dot_from_subdir(self):
93
90
"""Test adding . from a subdir of the tree."""
94
from bzrlib.add import smart_add_tree
91
from bzrlib.add import smart_add_branch
95
92
paths = ("original/", "original/file1", "original/file2")
96
93
self.build_tree(paths)
97
Branch.initialize(".")
94
branch = Branch(".", init=True)
99
95
os.chdir("original")
100
smart_add_tree(tree, (".",))
96
smart_add_branch(branch, (".",))
101
97
for path in paths:
102
self.assertNotEqual(tree.path2id(path), None)
98
self.assertNotEqual(branch.inventory.path2id(path), None)
104
100
def test_add_tree_from_above_tree(self):
105
101
"""Test adding a tree from above the tree."""
106
from bzrlib.add import smart_add_tree
102
from bzrlib.add import smart_add_branch
107
103
paths = ("original/", "original/file1", "original/file2")
108
104
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
109
105
"branch/original/file2")
110
106
self.build_tree(branch_paths)
111
Branch.initialize("branch")
112
tree = WorkingTree("branch")
113
smart_add_tree(tree, ("branch",))
107
branch = Branch("branch", init=True)
108
smart_add_branch(branch, ("branch",))
114
109
for path in paths:
115
self.assertNotEqual(tree.path2id(path), None)
110
self.assertNotEqual(branch.inventory.path2id(path), None)
117
112
def test_add_above_tree_preserves_tree(self):
118
113
"""Test nested trees are not affect by an add above them."""
119
from bzrlib.add import smart_add_tree
114
from bzrlib.add import smart_add_branch
120
115
paths = ("original/", "original/file1", "original/file2")
121
116
child_paths = ("path")
122
117
full_child_paths = ("original/child", "original/child/path")
123
118
build_paths = ("original/", "original/file1", "original/file2",
124
119
"original/child/", "original/child/path")
125
120
self.build_tree(build_paths)
126
Branch.initialize(".")
128
child_branch = Branch.initialize("original/child")
129
smart_add_tree(tree, (".",))
121
branch = Branch(".", init=True)
122
child_branch = Branch("original/child", init=True)
123
smart_add_branch(branch, (".",))
130
124
for path in paths:
131
self.assertNotEqual((path, tree.path2id(path)),
125
self.assertNotEqual((path, branch.inventory.path2id(path)),
133
127
for path in full_child_paths:
134
self.assertEqual((path, tree.path2id(path)),
128
self.assertEqual((path, branch.inventory.path2id(path)),
136
130
for path in child_paths:
137
self.assertEqual(child_branch.working_tree().path2id(path), None)
131
self.assertEqual(child_branch.inventory.path2id(path), None)
139
133
def test_add_paths(self):
140
134
"""Test smart-adding a list of paths."""
141
from bzrlib.add import smart_add_tree
135
from bzrlib.add import smart_add_branch
142
136
paths = ("file1", "file2")
143
137
self.build_tree(paths)
144
Branch.initialize(".")
146
smart_add_tree(tree, paths)
138
branch = Branch(".", init=True)
139
smart_add_branch(branch, paths)
147
140
for path in paths:
148
self.assertNotEqual(tree.path2id(path), None)
141
self.assertNotEqual(branch.inventory.path2id(path), None)
150
143
class TestAddCallbacks(TestCaseInTempDir):
146
from bzrlib.inventory import InventoryEntry
153
147
super(TestAddCallbacks, self).setUp()
154
self.entry = InventoryFile("id", "name", None)
148
self.entry = InventoryEntry("id", "name", "file", None)
156
150
def test_null_callback(self):
157
151
from bzrlib.add import add_reporter_null