/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
16
17
"""Test that we can use smart_add on all Tree implementations."""
18
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
19
from cStringIO import StringIO
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
20
import os
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
21
import sys
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
22
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
23
from bzrlib import (
24
    add,
25
    errors,
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
26
    ignores,
27
    osutils,
2568.2.10 by Robert Collins
And a missing import.
28
    tests,
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
29
    workingtree,
30
    )
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
31
from bzrlib.tests import (
32
    test_smart_add,
33
    per_workingtree,
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
34
    )
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
35
36
37
class TestSmartAddTree(per_workingtree.TestCaseWithWorkingTree):
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
38
39
    def test_single_file(self):
40
        tree = self.make_branch_and_tree('tree')
41
        self.build_tree(['tree/a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
42
        tree.smart_add(['tree'])
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
43
44
        tree.lock_read()
45
        try:
46
            files = [(path, status, kind)
47
                     for path, status, kind, file_id, parent_id
48
                      in tree.list_files(include_root=True)]
49
        finally:
50
            tree.unlock()
51
        self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
52
                         files)
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
53
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
54
    def assertFilenameSkipped(self, filename):
55
        tree = self.make_branch_and_tree('tree')
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
56
        try:
57
            self.build_tree(['tree/'+filename])
58
        except errors.NoSuchFile:
59
            if sys.platform == 'win32':
60
                raise tests.TestNotApplicable('Cannot create files named %r on'
61
                    ' win32' % (filename,))
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
62
        tree.smart_add(['tree'])
63
        self.assertEqual(None, tree.path2id(filename))
64
65
    def test_path_containing_newline_skips(self):
66
        self.assertFilenameSkipped('a\nb')
67
68
    def test_path_containing_carriagereturn_skips(self):
69
        self.assertFilenameSkipped('a\rb')
70
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
71
    def test_save_false(self):
72
        """Dry-run add doesn't permanently affect the tree."""
73
        wt = self.make_branch_and_tree('.')
2585.1.1 by Aaron Bentley
Unify MutableTree.smart_add behavior by disabling quirky memory-only Inventory
74
        wt.lock_write()
75
        try:
76
            self.build_tree(['file'])
77
            wt.smart_add(['file'], save=False)
78
            # the file should not be added - no id.
79
            self.assertEqual(wt.path2id('file'), None)
80
        finally:
81
            wt.unlock()
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
82
        # and the disk state should be the same - reopen to check.
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
83
        wt = wt.bzrdir.open_workingtree()
84
        self.assertEqual(wt.path2id('file'), None)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
85
86
    def test_add_dot_from_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
87
        """Test adding . from the root of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
88
        paths = ("original/", "original/file1", "original/file2")
89
        self.build_tree(paths)
90
        wt = self.make_branch_and_tree('.')
91
        wt.smart_add((u".",))
92
        for path in paths:
93
            self.assertNotEqual(wt.path2id(path), None)
94
95
    def test_add_dot_from_subdir(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
96
        """Test adding . from a subdir of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
97
        paths = ("original/", "original/file1", "original/file2")
98
        self.build_tree(paths)
99
        wt = self.make_branch_and_tree('.')
100
        wt.smart_add((u".",))
101
        for path in paths:
102
            self.assertNotEqual(wt.path2id(path), None)
103
104
    def test_add_tree_from_above_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
105
        """Test adding a tree from above the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
106
        paths = ("original/", "original/file1", "original/file2")
107
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
108
                        "branch/original/file2")
109
        self.build_tree(branch_paths)
110
        wt = self.make_branch_and_tree('branch')
111
        wt.smart_add(("branch",))
112
        for path in paths:
113
            self.assertNotEqual(wt.path2id(path), None)
114
115
    def test_add_above_tree_preserves_tree(self):
116
        """Test nested trees are not affect by an add above them."""
117
        paths = ("original/", "original/file1", "original/file2")
118
        child_paths = ("path",)
119
        full_child_paths = ("original/child", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
        build_paths = ("original/", "original/file1", "original/file2",
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
121
                       "original/child/", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
122
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
123
        self.build_tree(build_paths)
124
        wt = self.make_branch_and_tree('.')
125
        child_tree = self.make_branch_and_tree('original/child')
126
        wt.smart_add((".",))
127
        for path in paths:
128
            self.assertNotEqual((path, wt.path2id(path)),
129
                                (path, None))
130
        for path in full_child_paths:
131
            self.assertEqual((path, wt.path2id(path)),
132
                             (path, None))
133
        for path in child_paths:
134
            self.assertEqual(child_tree.path2id(path), None)
135
136
    def test_add_paths(self):
137
        """Test smart-adding a list of paths."""
138
        paths = ("file1", "file2")
139
        self.build_tree(paths)
140
        wt = self.make_branch_and_tree('.')
141
        wt.smart_add(paths)
142
        for path in paths:
143
            self.assertNotEqual(wt.path2id(path), None)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
144
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
145
    def test_add_ignored_nested_paths(self):
146
        """Test smart-adding a list of paths which includes ignored ones."""
147
        wt = self.make_branch_and_tree('.')
148
        tree_shape = ("adir/", "adir/CVS/", "adir/CVS/afile", "adir/CVS/afile2")
149
        add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
150
        expected_paths = ("adir", "adir/CVS", "adir/CVS/afile", "adir/CVS/afile2")
151
        self.build_tree(tree_shape)
152
        wt.smart_add(add_paths)
153
        for path in expected_paths:
154
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
155
156
    def test_add_non_existant(self):
157
        """Test smart-adding a file that does not exist."""
158
        wt = self.make_branch_and_tree('.')
159
        self.assertRaises(errors.NoSuchFile, wt.smart_add, ['non-existant-file'])
160
161
    def test_returns_and_ignores(self):
162
        """Correctly returns added/ignored files"""
163
        wt = self.make_branch_and_tree('.')
164
        # The default ignore list includes '*.py[co]', but not CVS
165
        ignores._set_user_ignores(['*.py[co]'])
166
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
167
                        'inertiatic/foo.pyc'])
168
        added, ignored = wt.smart_add(u'.')
169
        self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
170
                          added)
171
        self.assertSubset(('*.py[co]',), ignored)
172
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[co]'])
173
174
    def test_add_multiple_dirs(self):
175
        """Test smart adding multiple directories at once."""
176
        added_paths = ['file1', 'file2',
177
                       'dir1/', 'dir1/file3',
178
                       'dir1/subdir2/', 'dir1/subdir2/file4',
179
                       'dir2/', 'dir2/file5',
180
                      ]
181
        not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
182
        self.build_tree(added_paths)
183
        self.build_tree(not_added)
184
185
        wt = self.make_branch_and_tree('.')
186
        wt.smart_add(['file1', 'file2', 'dir1', 'dir2'])
187
188
        for path in added_paths:
189
            self.assertNotEqual(None, wt.path2id(path.rstrip('/')),
190
                    'Failed to add path: %s' % (path,))
191
        for path in not_added:
192
            self.assertEqual(None, wt.path2id(path.rstrip('/')),
193
                    'Accidentally added path: %s' % (path,))
194
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
195
    def test_add_file_in_unknown_dir(self):
196
        # Test that parent directory addition is implicit
197
        tree = self.make_branch_and_tree('.')
198
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
199
        tree.smart_add(['dir/subdir/foo'])
200
        tree.lock_read()
201
        self.addCleanup(tree.unlock)
202
        self.assertEqual(['', 'dir', 'dir/subdir', 'dir/subdir/foo'],
203
            [path for path, ie in tree.iter_entries_by_dir()])
204
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
205
    def test_add_dir_bug_251864(self):
5504.6.3 by Martin
Address poolie's review, mention both bugs in test and add news
206
        """Added file turning into a dir should be detected on add dir
207
208
        Similar to bug 205636 but with automatic adding of directory contents.
209
        """
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
210
        tree = self.make_branch_and_tree(".")
211
        self.build_tree(["dir"]) # whoops, make a file called dir
212
        tree.smart_add(["dir"])
213
        os.remove("dir")
214
        self.build_tree(["dir/", "dir/file"])
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
215
        tree.smart_add(["dir"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
216
        tree.commit("Add dir contents")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
217
        self.addCleanup(tree.lock_read().unlock)
218
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
219
            [(t[0], t[2]) for t in tree.list_files()])
220
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
221
222
    def test_add_subdir_file_bug_205636(self):
223
        """Added file turning into a dir should be detected on add dir/file"""
224
        tree = self.make_branch_and_tree(".")
225
        self.build_tree(["dir"]) # whoops, make a file called dir
226
        tree.smart_add(["dir"])
227
        os.remove("dir")
228
        self.build_tree(["dir/", "dir/file"])
5378.1.3 by Martin
Note that TestSmartAddTree.test_add_subdir_file_bug_205636 now passes
229
        tree.smart_add(["dir/file"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
230
        tree.commit("Add file in dir")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
231
        self.addCleanup(tree.lock_read().unlock)
232
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
233
            [(t[0], t[2]) for t in tree.list_files()])
234
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
235
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
236
    def test_custom_ids(self):
237
        sio = StringIO()
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
238
        action = test_smart_add.AddCustomIDAction(to_file=sio,
239
                                                  should_print=True)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
240
        self.build_tree(['file1', 'dir1/', 'dir1/file2'])
241
242
        wt = self.make_branch_and_tree('.')
243
        wt.smart_add(['.'], action=action)
244
        # The order of adds is not strictly fixed:
245
        sio.seek(0)
246
        lines = sorted(sio.readlines())
3985.2.5 by Daniel Watkins
Reverted some irrelevant changes.
247
        self.assertEqualDiff(['added dir1 with id directory-dir1\n',
248
                              'added dir1/file2 with id file-dir1%file2\n',
249
                              'added file1 with id file-file1\n',
250
                             ], lines)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
251
        wt.lock_read()
252
        self.addCleanup(wt.unlock)
253
        self.assertEqual([('', wt.path2id('')),
254
                          ('dir1', 'directory-dir1'),
255
                          ('dir1/file2', 'file-dir1%file2'),
256
                          ('file1', 'file-file1'),
257
                         ], [(path, ie.file_id) for path, ie
258
                                in wt.inventory.iter_entries()])
259
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
260
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
261
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
262
263
    def make_tree_with_text_conflict(self):
264
        tb = self.make_branch_and_tree('base')
265
        self.build_tree_contents([('base/file', 'content in base')])
266
        tb.add('file')
267
        tb.commit('Adding file')
268
269
        t1 = tb.bzrdir.sprout('t1').open_workingtree()
270
271
        self.build_tree_contents([('base/file', 'content changed in base')])
272
        tb.commit('Changing file in base')
273
274
        self.build_tree_contents([('t1/file', 'content in t1')])
275
        t1.commit('Changing file in t1')
276
        t1.merge_from_branch(tb.branch)
277
        return t1
278
279
    def test_cant_add_generated_files_implicitly(self):
280
        t = self.make_tree_with_text_conflict()
281
        added, ignored = t.smart_add([t.basedir])
282
        self.assertEqual(([], {}), (added, ignored))
283
284
    def test_can_add_generated_files_explicitly(self):
285
        fnames = ['file.%s' % s  for s in ('BASE', 'THIS', 'OTHER')]
286
        t = self.make_tree_with_text_conflict()
287
        added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
288
        self.assertEqual((fnames, {}), (added, ignored))
289
290
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
291
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
292
293
    _test_needs_features = [tests.UnicodeFilenameFeature]
294
295
    def setUp(self):
296
        super(TestSmartAddTreeUnicode, self).setUp()
297
        self.build_tree([u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
298
        self.wt = self.make_branch_and_tree('.')
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
299
        self.overrideAttr(osutils, 'normalized_filename')
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
300
301
    def test_accessible_explicit(self):
302
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
303
        if self.workingtree_format.requires_normalized_unicode_filenames:
5013.2.6 by Vincent Ladeuil
WorkingTreeFormat2 don't support not normalized filenames.
304
            self.expectFailure(
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
305
                'Working tree format smart_add requires normalized unicode filenames',
5013.2.6 by Vincent Ladeuil
WorkingTreeFormat2 don't support not normalized filenames.
306
                self.assertRaises, errors.NoSuchFile,
307
                self.wt.smart_add, [u'a\u030a'])
308
        else:
309
            self.wt.smart_add([u'a\u030a'])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
310
        self.wt.lock_read()
311
        self.addCleanup(self.wt.unlock)
312
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
313
                         [(path, ie.kind) for path,ie in
314
                          self.wt.inventory.iter_entries()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
315
316
    def test_accessible_implicit(self):
317
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
318
        if self.workingtree_format.requires_normalized_unicode_filenames:
5013.2.6 by Vincent Ladeuil
WorkingTreeFormat2 don't support not normalized filenames.
319
            self.expectFailure(
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
320
                'Working tree format smart_add requires normalized unicode filenames',
5013.2.6 by Vincent Ladeuil
WorkingTreeFormat2 don't support not normalized filenames.
321
                self.assertRaises, errors.NoSuchFile,
322
                self.wt.smart_add, [])
323
        else:
324
            self.wt.smart_add([])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
325
        self.wt.lock_read()
326
        self.addCleanup(self.wt.unlock)
327
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
5013.2.6 by Vincent Ladeuil
WorkingTreeFormat2 don't support not normalized filenames.
328
                         [(path, ie.kind) for path,ie
329
                          in self.wt.inventory.iter_entries()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
330
331
    def test_inaccessible_explicit(self):
332
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
333
        self.assertRaises(errors.InvalidNormalization,
334
                          self.wt.smart_add, [u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
335
336
    def test_inaccessible_implicit(self):
337
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
338
        # TODO: jam 20060701 In the future, this should probably
339
        #       just ignore files that don't fit the normalization
340
        #       rules, rather than exploding
341
        self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])