4
from bzrlib import errors, osutils
4
5
from bzrlib.add import smart_add, smart_add_tree
5
from bzrlib.tests import TestCaseWithTransport, TestCase
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
6
7
from bzrlib.errors import NoSuchFile
7
8
from bzrlib.inventory import InventoryFile, Inventory
8
9
from bzrlib.workingtree import WorkingTree
10
12
class TestSmartAdd(TestCaseWithTransport):
12
14
def test_add_dot_from_root(self):
113
110
"""Test smart-adding a file that does not exist."""
114
111
from bzrlib.add import smart_add
115
112
wt = self.make_branch_and_tree('.')
117
113
self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
119
115
def test_returns_and_ignores(self):
120
116
"""Correctly returns added/ignored files"""
121
117
from bzrlib.commands import run_bzr
122
118
wt = self.make_branch_and_tree('.')
124
119
# no files should be ignored by default, so we need to create
125
120
# an ignore rule - we create one for the pyc files, which means
126
121
# CVS should not be ignored.
142
137
paths = ("original/", "original/file1", "original/file2")
143
138
self.build_tree(paths)
144
139
wt = self.make_branch_and_tree('.')
146
140
smart_add_tree(wt, (u".",))
147
141
for path in paths:
148
142
self.assertNotEqual(wt.path2id(path), None)
150
144
def test_add_dot_from_subdir(self):
151
145
"""Test adding . from a subdir of the tree."""
152
from bzrlib.add import smart_add_tree
153
146
paths = ("original/", "original/file1", "original/file2")
154
147
self.build_tree(paths)
155
148
wt = self.make_branch_and_tree('.')
157
149
os.chdir("original")
158
150
smart_add_tree(wt, (u".",))
159
151
for path in paths:
162
154
def test_add_tree_from_above_tree(self):
163
155
"""Test adding a tree from above the tree."""
164
from bzrlib.add import smart_add_tree
165
156
paths = ("original/", "original/file1", "original/file2")
166
157
branch_paths = ("branch/", "branch/original/", "branch/original/file1",
167
158
"branch/original/file2")
168
159
self.build_tree(branch_paths)
169
160
tree = self.make_branch_and_tree('branch')
171
161
smart_add_tree(tree, ("branch",))
172
162
for path in paths:
173
163
self.assertNotEqual(tree.path2id(path), None)
175
165
def test_add_above_tree_preserves_tree(self):
176
166
"""Test nested trees are not affect by an add above them."""
177
from bzrlib.add import smart_add_tree
178
167
paths = ("original/", "original/file1", "original/file2")
179
168
child_paths = ("path")
180
169
full_child_paths = ("original/child", "original/child/path")
197
185
def test_add_paths(self):
198
186
"""Test smart-adding a list of paths."""
199
from bzrlib.add import smart_add_tree
200
187
paths = ("file1", "file2")
201
188
self.build_tree(paths)
202
189
wt = self.make_branch_and_tree('.')
204
190
smart_add_tree(wt, paths)
205
191
for path in paths:
206
192
self.assertNotEqual(wt.path2id(path), None)
194
def test_add_multiple_dirs(self):
195
"""Test smart adding multiple directories at once."""
196
added_paths = ['file1', 'file2',
197
'dir1/', 'dir1/file3',
198
'dir1/subdir2/', 'dir1/subdir2/file4',
199
'dir2/', 'dir2/file5',
201
not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
202
self.build_tree(added_paths)
203
self.build_tree(not_added)
205
wt = self.make_branch_and_tree('.')
206
smart_add_tree(wt, ['file1', 'file2', 'dir1', 'dir2'])
208
for path in added_paths:
209
self.assertNotEqual(None, wt.path2id(path.rstrip('/')),
210
'Failed to add path: %s' % (path,))
211
for path in not_added:
212
self.assertEqual(None, wt.path2id(path.rstrip('/')),
213
'Accidentally added path: %s' % (path,))
216
class TestAddNonNormalized(TestCaseWithTransport):
220
self.build_tree([u'a\u030a'])
222
raise TestSkipped('Filesystem cannot create unicode filenames')
224
self.wt = self.make_branch_and_tree('.')
226
def test_accessible_explicit(self):
228
orig = osutils.normalized_filename
229
osutils.normalized_filename = osutils._accessible_normalized_filename
231
smart_add_tree(self.wt, [u'a\u030a'])
232
self.assertEqual([(u'\xe5', 'file')],
233
[(path, ie.kind) for path,ie in
234
self.wt.inventory.iter_entries()])
236
osutils.normalized_filename = orig
238
def test_accessible_implicit(self):
240
orig = osutils.normalized_filename
241
osutils.normalized_filename = osutils._accessible_normalized_filename
243
smart_add_tree(self.wt, [])
244
self.assertEqual([(u'\xe5', 'file')],
245
[(path, ie.kind) for path,ie in
246
self.wt.inventory.iter_entries()])
248
osutils.normalized_filename = orig
250
def test_inaccessible_explicit(self):
252
orig = osutils.normalized_filename
253
osutils.normalized_filename = osutils._inaccessible_normalized_filename
255
self.assertRaises(errors.InvalidNormalization,
256
smart_add_tree, self.wt, [u'a\u030a'])
258
osutils.normalized_filename = orig
260
def test_inaccessible_implicit(self):
262
orig = osutils.normalized_filename
263
osutils.normalized_filename = osutils._inaccessible_normalized_filename
265
# TODO: jam 20060701 In the future, this should probably
266
# just ignore files that don't fit the normalization
267
# rules, rather than exploding
268
self.assertRaises(errors.InvalidNormalization,
269
smart_add_tree, self.wt, [])
271
osutils.normalized_filename = orig
209
274
class TestAddActions(TestCase):