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