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