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