4
4
from bzrlib.add import smart_add, smart_add_tree
5
5
from bzrlib.tests import TestCaseWithTransport, TestCase
6
from bzrlib.branch import Branch
7
from bzrlib.errors import NotBranchError, NoSuchFile
6
from bzrlib.errors import NoSuchFile
8
7
from bzrlib.inventory import InventoryFile, Inventory
9
8
from bzrlib.workingtree import WorkingTree
59
58
wt = self.make_branch_and_tree('.')
61
60
child_tree = self.make_branch_and_tree('original/child')
62
smart_add_tree(wt, (u".",))
61
smart_add_tree(wt, (".",))
64
63
self.assertNotEqual((path, wt.path2id(path)),
75
74
paths = ("file1", "file2")
76
75
self.build_tree(paths)
77
76
wt = self.make_branch_and_tree('.')
79
77
smart_add_tree(wt, paths)
81
79
self.assertNotEqual(wt.path2id(path), None)
81
def test_add_ignored_nested_paths(self):
82
"""Test smart-adding a list of paths which includes ignored ones."""
83
wt = self.make_branch_and_tree('.')
84
tree_shape = ("adir/", "adir/CVS/", "adir/CVS/afile", "adir/CVS/afile2")
85
add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
86
expected_paths = ("adir", "adir/CVS", "adir/CVS/afile", "adir/CVS/afile2")
87
self.build_tree(tree_shape)
88
smart_add_tree(wt, add_paths)
89
for path in expected_paths:
90
self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
92
def test_save_false(self):
93
"""Test smart-adding a path with save set to false."""
94
wt = self.make_branch_and_tree('.')
95
self.build_tree(['file'])
96
smart_add_tree(wt, ['file'], save=False)
97
self.assertNotEqual(wt.path2id('file'), None, "No id added for 'file'")
98
wt.read_working_inventory()
99
self.assertEqual(wt.path2id('file'), None)
83
101
def test_add_dry_run(self):
84
102
"""Test a dry run add, make sure nothing is added."""
98
116
branch = wt.branch
99
117
self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
101
def test_returns(self):
119
def test_returns_and_ignores(self):
102
120
"""Correctly returns added/ignored files"""
103
121
from bzrlib.commands import run_bzr
104
122
wt = self.make_branch_and_tree('.')
105
123
branch = wt.branch
124
# no files should be ignored by default, so we need to create
125
# an ignore rule - we create one for the pyc files, which means
126
# CVS should not be ignored.
106
127
self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
107
128
'inertiatic/foo.pyc'])
129
self.build_tree_contents([('.bzrignore', '*.py[oc]\n')])
108
130
added, ignored = smart_add_tree(wt, u'.')
109
self.assertSubset(('inertiatic', 'inertiatic/esp'), added)
110
self.assertSubset(('CVS', '*.py[oc]'), ignored)
111
self.assertSubset(('inertiatic/CVS',), ignored['CVS'])
131
self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
133
self.assertSubset(('*.py[oc]',), ignored)
112
134
self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
115
class TestSmartAddBranch(TestCaseWithTransport):
137
class TestSmartAddTree(TestCaseWithTransport):
116
138
"""Test smart adds with a specified branch."""
118
140
def test_add_dot_from_root(self):
187
209
class TestAddActions(TestCase):
190
from bzrlib.add import add_action_null
191
self.run_action(add_action_null, "", False)
194
self.entry = InventoryFile("id", "name", None)
195
from bzrlib.add import add_action_add
196
self.run_action(add_action_add, "", True)
198
def test_add_and_print(self):
199
from bzrlib.add import add_action_add_and_print
200
self.run_action(add_action_add_and_print, "added path\n", True)
202
def test_print(self):
203
from bzrlib.add import add_action_print
204
self.run_action(add_action_print, "added path\n", False)
206
def run_action(self, action, output, should_add):
207
from StringIO import StringIO
211
def test_quiet(self):
214
def test__print(self):
215
self.run_action("added path\n")
217
def run_action(self, output):
218
from bzrlib.add import AddAction, FastPath
219
from cStringIO import StringIO
208
220
inv = Inventory()
209
221
stdout = StringIO()
222
action = AddAction(to_file=stdout, should_print=bool(output))
211
self.apply_redirected(None, stdout, None, action, inv, None, 'path', 'file')
224
self.apply_redirected(None, stdout, None, action, inv, None, FastPath('path'), 'file')
212
225
self.assertEqual(stdout.getvalue(), output)
215
self.assertNotEqual(inv.path2id('path'), None)
217
self.assertEqual(inv.path2id('path'), None)