4
from bzrlib import ignores
4
from bzrlib import errors, ignores, osutils
5
5
from bzrlib.add import smart_add, smart_add_tree
6
from bzrlib.tests import TestCaseWithTransport, TestCase
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
7
7
from bzrlib.errors import NoSuchFile
8
8
from bzrlib.inventory import InventoryFile, Inventory
9
9
from bzrlib.workingtree import WorkingTree
116
111
"""Test smart-adding a file that does not exist."""
117
112
from bzrlib.add import smart_add
118
113
wt = self.make_branch_and_tree('.')
120
114
self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
122
116
def test_returns_and_ignores(self):
123
117
"""Correctly returns added/ignored files"""
124
118
from bzrlib.commands import run_bzr
125
119
wt = self.make_branch_and_tree('.')
127
120
# The default ignore list includes '*.py[co]', but not CVS
128
121
ignores.set_user_ignores(['./.bazaar', '*.py[co]'])
129
122
self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
143
136
paths = ("original/", "original/file1", "original/file2")
144
137
self.build_tree(paths)
145
138
wt = self.make_branch_and_tree('.')
147
139
smart_add_tree(wt, (u".",))
148
140
for path in paths:
149
141
self.assertNotEqual(wt.path2id(path), None)
151
143
def test_add_dot_from_subdir(self):
152
144
"""Test adding . from a subdir of the tree."""
153
from bzrlib.add import smart_add_tree
154
145
paths = ("original/", "original/file1", "original/file2")
155
146
self.build_tree(paths)
156
147
wt = self.make_branch_and_tree('.')
158
148
os.chdir("original")
159
149
smart_add_tree(wt, (u".",))
160
150
for path in paths:
163
153
def test_add_tree_from_above_tree(self):
164
154
"""Test adding a tree from above the tree."""
165
from bzrlib.add import smart_add_tree
166
155
paths = ("original/", "original/file1", "original/file2")
167
156
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
168
157
"branch/original/file2")
169
158
self.build_tree(branch_paths)
170
159
tree = self.make_branch_and_tree('branch')
172
160
smart_add_tree(tree, ("branch",))
173
161
for path in paths:
174
162
self.assertNotEqual(tree.path2id(path), None)
176
164
def test_add_above_tree_preserves_tree(self):
177
165
"""Test nested trees are not affect by an add above them."""
178
from bzrlib.add import smart_add_tree
179
166
paths = ("original/", "original/file1", "original/file2")
180
167
child_paths = ("path")
181
168
full_child_paths = ("original/child", "original/child/path")
198
184
def test_add_paths(self):
199
185
"""Test smart-adding a list of paths."""
200
from bzrlib.add import smart_add_tree
201
186
paths = ("file1", "file2")
202
187
self.build_tree(paths)
203
188
wt = self.make_branch_and_tree('.')
205
189
smart_add_tree(wt, paths)
206
190
for path in paths:
207
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([(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([(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
210
273
class TestAddActions(TestCase):