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, Inventory
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".")
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".")
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
48
paths = ("original/", "original/file1", "original/file2")
49
child_paths = ("path",)
50
full_child_paths = ("original/child", "original/child/path")
51
build_paths = ("original/", "original/file1", "original/file2",
52
"original/child/", "original/child/path")
54
self.build_tree(build_paths)
55
branch = Branch.initialize(u".")
56
child_branch = Branch.initialize("original/child")
59
self.assertNotEqual((path, branch.working_tree().path2id(path)),
61
for path in full_child_paths:
62
self.assertEqual((path, branch.working_tree().path2id(path)),
64
for path in child_paths:
65
self.assertEqual(child_branch.working_tree().path2id(path), None)
67
def test_add_paths(self):
68
"""Test smart-adding a list of paths."""
69
from bzrlib.add import smart_add
70
paths = ("file1", "file2")
71
self.build_tree(paths)
72
branch = Branch.initialize(u".")
75
self.assertNotEqual(branch.working_tree().path2id(path), None)
77
def test_add_dry_run(self):
78
"""Test a dry run add, make sure nothing is added."""
79
from bzrlib.commands import run_bzr
81
b = Branch.initialize(u'.')
83
self.build_tree(['inertiatic/', 'inertiatic/esp'])
84
eq(list(t.unknowns()), ['inertiatic'])
85
self.capture('add --dry-run .')
86
eq(list(t.unknowns()), ['inertiatic'])
88
class TestSmartAddBranch(TestCaseInTempDir):
89
"""Test smart adds with a specified branch."""
91
def test_add_dot_from_root(self):
92
"""Test adding . from the root of the tree."""
93
from bzrlib.add import smart_add_tree
94
paths = ("original/", "original/file1", "original/file2")
95
self.build_tree(paths)
96
Branch.initialize(u".")
98
smart_add_tree(tree, (u".",))
100
self.assertNotEqual(tree.path2id(path), None)
102
def test_add_dot_from_subdir(self):
103
"""Test adding . from a subdir of the tree."""
104
from bzrlib.add import smart_add_tree
105
paths = ("original/", "original/file1", "original/file2")
106
self.build_tree(paths)
107
Branch.initialize(u".")
110
smart_add_tree(tree, (u".",))
112
self.assertNotEqual(tree.path2id(path), None)
114
def test_add_tree_from_above_tree(self):
115
"""Test adding a tree from above the tree."""
116
from bzrlib.add import smart_add_tree
117
paths = ("original/", "original/file1", "original/file2")
118
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
119
"branch/original/file2")
120
self.build_tree(branch_paths)
121
Branch.initialize("branch")
122
tree = WorkingTree("branch")
123
smart_add_tree(tree, ("branch",))
125
self.assertNotEqual(tree.path2id(path), None)
127
def test_add_above_tree_preserves_tree(self):
128
"""Test nested trees are not affect by an add above them."""
129
from bzrlib.add import smart_add_tree
130
paths = ("original/", "original/file1", "original/file2")
131
child_paths = ("path")
132
full_child_paths = ("original/child", "original/child/path")
133
build_paths = ("original/", "original/file1", "original/file2",
134
"original/child/", "original/child/path")
135
self.build_tree(build_paths)
136
Branch.initialize(u".")
138
child_branch = Branch.initialize("original/child")
139
smart_add_tree(tree, (u".",))
141
self.assertNotEqual((path, tree.path2id(path)),
143
for path in full_child_paths:
144
self.assertEqual((path, tree.path2id(path)),
146
for path in child_paths:
147
self.assertEqual(child_branch.working_tree().path2id(path), None)
149
def test_add_paths(self):
150
"""Test smart-adding a list of paths."""
151
from bzrlib.add import smart_add_tree
152
paths = ("file1", "file2")
153
self.build_tree(paths)
154
Branch.initialize(u".")
156
smart_add_tree(tree, paths)
158
self.assertNotEqual(tree.path2id(path), None)
160
class TestAddActions(TestCaseInTempDir):
163
from bzrlib.add import add_action_null
164
self.run_action(add_action_null, "", False)
167
self.entry = InventoryFile("id", "name", None)
168
from bzrlib.add import add_action_add
169
self.run_action(add_action_add, "", True)
171
def test_add_and_print(self):
172
from bzrlib.add import add_action_add_and_print
173
self.run_action(add_action_add_and_print, "added path\n", True)
175
def test_print(self):
176
from bzrlib.add import add_action_print
177
self.run_action(add_action_print, "added path\n", False)
179
def run_action(self, action, output, should_add):
180
from StringIO import StringIO
184
self.apply_redirected(None, stdout, None, action, inv, 'path', 'file')
185
self.assertEqual(stdout.getvalue(), output)
188
self.assertNotEqual(inv.path2id('path'), None)
190
self.assertEqual(inv.path2id('path'), None)