4
from bzrlib import errors, ignores, osutils
4
5
from bzrlib.add import smart_add, smart_add_tree
5
from bzrlib.tests import TestCaseWithTransport, TestCase
6
from bzrlib.branch import Branch
7
from bzrlib.errors import NotBranchError, NoSuchFile
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
7
from bzrlib.errors import NoSuchFile
8
8
from bzrlib.inventory import InventoryFile, Inventory
9
9
from bzrlib.workingtree import WorkingTree
11
12
class TestSmartAdd(TestCaseWithTransport):
13
14
def test_add_dot_from_root(self):
114
111
"""Test smart-adding a file that does not exist."""
115
112
from bzrlib.add import smart_add
116
113
wt = self.make_branch_and_tree('.')
118
114
self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
120
def test_returns(self):
116
def test_returns_and_ignores(self):
121
117
"""Correctly returns added/ignored files"""
122
118
from bzrlib.commands import run_bzr
123
119
wt = self.make_branch_and_tree('.')
125
self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
120
# The default ignore list includes '*.py[co]', but not CVS
121
ignores._set_user_ignores(['./.bazaar', '*.py[co]'])
122
self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
126
123
'inertiatic/foo.pyc'])
127
124
added, ignored = smart_add_tree(wt, u'.')
128
self.assertSubset(('inertiatic', 'inertiatic/esp'), added)
129
self.assertSubset(('CVS', '*.py[oc]'), ignored)
130
self.assertSubset(('inertiatic/CVS',), ignored['CVS'])
131
self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[oc]'])
134
class TestSmartAddBranch(TestCaseWithTransport):
125
self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
127
self.assertSubset(('*.py[co]',), ignored)
128
self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[co]'])
131
class TestSmartAddTree(TestCaseWithTransport):
135
132
"""Test smart adds with a specified branch."""
137
134
def test_add_dot_from_root(self):
139
136
paths = ("original/", "original/file1", "original/file2")
140
137
self.build_tree(paths)
141
138
wt = self.make_branch_and_tree('.')
143
139
smart_add_tree(wt, (u".",))
144
140
for path in paths:
145
141
self.assertNotEqual(wt.path2id(path), None)
147
143
def test_add_dot_from_subdir(self):
148
144
"""Test adding . from a subdir of the tree."""
149
from bzrlib.add import smart_add_tree
150
145
paths = ("original/", "original/file1", "original/file2")
151
146
self.build_tree(paths)
152
147
wt = self.make_branch_and_tree('.')
154
148
os.chdir("original")
155
149
smart_add_tree(wt, (u".",))
156
150
for path in paths:
159
153
def test_add_tree_from_above_tree(self):
160
154
"""Test adding a tree from above the tree."""
161
from bzrlib.add import smart_add_tree
162
155
paths = ("original/", "original/file1", "original/file2")
163
156
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
164
157
"branch/original/file2")
165
158
self.build_tree(branch_paths)
166
159
tree = self.make_branch_and_tree('branch')
168
160
smart_add_tree(tree, ("branch",))
169
161
for path in paths:
170
162
self.assertNotEqual(tree.path2id(path), None)
172
164
def test_add_above_tree_preserves_tree(self):
173
165
"""Test nested trees are not affect by an add above them."""
174
from bzrlib.add import smart_add_tree
175
166
paths = ("original/", "original/file1", "original/file2")
176
167
child_paths = ("path")
177
168
full_child_paths = ("original/child", "original/child/path")
194
184
def test_add_paths(self):
195
185
"""Test smart-adding a list of paths."""
196
from bzrlib.add import smart_add_tree
197
186
paths = ("file1", "file2")
198
187
self.build_tree(paths)
199
188
wt = self.make_branch_and_tree('.')
201
189
smart_add_tree(wt, paths)
202
190
for path in paths:
203
191
self.assertNotEqual(wt.path2id(path), None)
193
def test_add_multiple_dirs(self):
194
"""Test smart adding multiple directories at once."""
195
added_paths = ['file1', 'file2',
196
'dir1/', 'dir1/file3',
197
'dir1/subdir2/', 'dir1/subdir2/file4',
198
'dir2/', 'dir2/file5',
200
not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
201
self.build_tree(added_paths)
202
self.build_tree(not_added)
204
wt = self.make_branch_and_tree('.')
205
smart_add_tree(wt, ['file1', 'file2', 'dir1', 'dir2'])
207
for path in added_paths:
208
self.assertNotEqual(None, wt.path2id(path.rstrip('/')),
209
'Failed to add path: %s' % (path,))
210
for path in not_added:
211
self.assertEqual(None, wt.path2id(path.rstrip('/')),
212
'Accidentally added path: %s' % (path,))
215
class TestAddNonNormalized(TestCaseWithTransport):
219
self.build_tree([u'a\u030a'])
221
raise TestSkipped('Filesystem cannot create unicode filenames')
223
self.wt = self.make_branch_and_tree('.')
225
def test_accessible_explicit(self):
227
orig = osutils.normalized_filename
228
osutils.normalized_filename = osutils._accessible_normalized_filename
230
smart_add_tree(self.wt, [u'a\u030a'])
231
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
232
[(path, ie.kind) for path,ie in
233
self.wt.inventory.iter_entries()])
235
osutils.normalized_filename = orig
237
def test_accessible_implicit(self):
239
orig = osutils.normalized_filename
240
osutils.normalized_filename = osutils._accessible_normalized_filename
242
smart_add_tree(self.wt, [])
243
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
244
[(path, ie.kind) for path,ie in
245
self.wt.inventory.iter_entries()])
247
osutils.normalized_filename = orig
249
def test_inaccessible_explicit(self):
251
orig = osutils.normalized_filename
252
osutils.normalized_filename = osutils._inaccessible_normalized_filename
254
self.assertRaises(errors.InvalidNormalization,
255
smart_add_tree, self.wt, [u'a\u030a'])
257
osutils.normalized_filename = orig
259
def test_inaccessible_implicit(self):
261
orig = osutils.normalized_filename
262
osutils.normalized_filename = osutils._inaccessible_normalized_filename
264
# TODO: jam 20060701 In the future, this should probably
265
# just ignore files that don't fit the normalization
266
# rules, rather than exploding
267
self.assertRaises(errors.InvalidNormalization,
268
smart_add_tree, self.wt, [])
270
osutils.normalized_filename = orig
206
273
class TestAddActions(TestCase):