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