/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
1
# Copyright (C) 2007 Canonical Ltd
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.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
16
17
"""Tests for interface conformance of 'WorkingTree.add'"""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
20
    errors,
6670.4.3 by Jelmer Vernooij
Fix more imports.
21
    tests,
22
    )
23
from breezy.bzr import (
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
24
    inventory,
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.tests.matchers import HasLayout
27
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
28
29
30
class TestAdd(TestCaseWithWorkingTree):
31
32
    def assertTreeLayout(self, expected, tree):
33
        """Check that the tree has the correct layout."""
6072.2.2 by Jelmer Vernooij
Use HasLayout matcher.
34
        self.assertThat(tree, HasLayout(expected))
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
35
36
    def test_add_one(self):
37
        tree = self.make_branch_and_tree('.')
38
        self.build_tree(['one'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
39
        tree.add('one')
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
40
        root_id = tree.get_root_id()
41
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
42
        self.assertTreeLayout(
43
            [('', root_id), ('one', tree.path2id('one'))], tree)
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
44
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
45
    def test_add_existing_id(self):
46
        """Adding an entry with a pre-existing id raises DuplicateFileId"""
47
        tree = self.make_branch_and_tree('.')
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
48
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
49
            self.skipTest("tree does not support setting file ids")
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
50
        self.build_tree(['a', 'b'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
51
        tree.add(['a'])
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
52
        self.assertRaises(errors.DuplicateFileId,
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
53
                          tree.add, ['b'], [tree.path2id('a')])
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
54
        root_id = tree.get_root_id()
55
        # And the entry should not have been added.
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
56
        self.assertTreeLayout([('', root_id), ('a', tree.path2id('a'))], tree)
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
57
2255.7.17 by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current.
58
    def test_add_old_id(self):
59
        """We can add an old id, as long as it doesn't exist now."""
60
        tree = self.make_branch_and_tree('.')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
61
        if not tree.supports_setting_file_ids():
62
            self.skipTest("tree does not support setting file ids")
2255.7.17 by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current.
63
        self.build_tree(['a', 'b'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
64
        tree.add(['a'])
65
        file_id = tree.path2id('a')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
66
        tree.commit('first')
2255.7.17 by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current.
67
        root_id = tree.get_root_id()
68
        # And the entry should not have been added.
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
69
        tree.unversion(['a'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
70
        tree.add(['b'], [file_id])
71
        self.assertTreeLayout([('', root_id), ('b', file_id)], tree)
72
        self.assertTreeLayout([('', root_id), ('a', file_id)],
2255.7.17 by John Arbash Meinel
Add another test that makes sure we can add as long as the file_id isn't current.
73
                              tree.basis_tree())
74
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
75
    def test_add_one_list(self):
76
        tree = self.make_branch_and_tree('.')
77
        self.build_tree(['one'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
78
        tree.add(['one'])
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
79
        root_id = tree.get_root_id()
80
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
81
        self.assertTreeLayout(
82
            [('', root_id), ('one', tree.path2id('one'))], tree)
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
83
84
    def test_add_one_new_id(self):
85
        tree = self.make_branch_and_tree('.')
86
        self.build_tree(['one'])
87
        tree.add(['one'])
88
        root_id = tree.get_root_id()
89
        one_id = tree.path2id('one')
90
91
        self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
92
93
    def test_add_unicode(self):
94
        tree = self.make_branch_and_tree('.')
95
        try:
96
            self.build_tree([u'f\xf6'])
97
        except UnicodeError:
98
            raise tests.TestSkipped('Filesystem does not support filename.')
99
        tree.add([u'f\xf6'])
100
        root_id = tree.get_root_id()
101
        foo_id = tree.path2id(u'f\xf6')
102
103
        self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
104
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
105
    def test_add_subdir_with_ids(self):
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
106
        tree = self.make_branch_and_tree('.')
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
107
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
108
            self.skipTest("tree does not support setting file ids")
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
109
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
110
        tree.add(['dir'], ['dir-id'])
111
        tree.add(['dir/subdir'], ['subdir-id'])
112
        tree.add(['dir/subdir/foo'], ['foo-id'])
113
        root_id = tree.get_root_id()
114
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
115
        self.assertTreeLayout([('', root_id), ('dir/', 'dir-id'),
116
                               ('dir/subdir/', 'subdir-id'),
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
117
                               ('dir/subdir/foo', 'foo-id')], tree)
118
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
119
    def test_add_subdir(self):
120
        tree = self.make_branch_and_tree('.')
121
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
122
        tree.add(['dir'])
123
        tree.add(['dir/subdir'])
124
        tree.add(['dir/subdir/foo'])
125
        root_id = tree.get_root_id()
126
127
        self.assertTreeLayout([
128
            ('', root_id),
129
            ('dir/', tree.path2id('dir')),
130
            ('dir/subdir/', tree.path2id('dir/subdir')),
131
            ('dir/subdir/foo', tree.path2id('dir/subdir/foo'))],
132
            tree)
133
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
134
    def test_add_multiple(self):
135
        tree = self.make_branch_and_tree('.')
136
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
137
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'])
138
        root_id = tree.get_root_id()
139
140
        self.assertTreeLayout([
141
            (p, tree.path2id(p))
142
            for p in ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']],
143
            tree)
144
145
    def test_add_multiple_with_file_ids(self):
146
        tree = self.make_branch_and_tree('.')
147
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
148
            self.skipTest("tree does not support setting file ids")
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
149
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
150
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
151
                 ['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
152
        root_id = tree.get_root_id()
153
154
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
155
                               ('dir/', 'dir-id'), ('dir/subdir/', 'subdir-id'),
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
156
                               ('dir/subdir/foo', 'foo-id')], tree)
157
158
    def test_add_invalid(self):
159
        tree = self.make_branch_and_tree('.')
160
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
161
        root_id = tree.get_root_id()
162
163
        self.assertRaises(errors.NotVersionedError,
164
                          tree.add, ['dir/subdir'])
165
        self.assertTreeLayout([('', root_id)], tree)
166
167
    def test_add_after_remove(self):
168
        tree = self.make_branch_and_tree('.')
169
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
170
        root_id = tree.get_root_id()
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
171
        tree.add(['dir'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
172
        tree.commit('dir')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
173
        tree.unversion(['dir'])
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
174
        self.assertRaises(errors.NotVersionedError,
175
                          tree.add, ['dir/subdir'])
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
176
177
    def test_add_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
178
        # adding the root should be a no-op, or at least not
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
179
        # do anything whacky.
180
        tree = self.make_branch_and_tree('.')
181
        tree.lock_write()
182
        tree.add('')
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
183
        self.assertEqual([''], list(tree.all_versioned_paths()))
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
184
        # the root should have been changed to be a new unique root.
185
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
186
        tree.unlock()
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
187
188
    def test_add_previously_added(self):
189
        # adding a path that was previously added should work
190
        tree = self.make_branch_and_tree('.')
191
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
192
        tree.add(['foo'])
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
193
        tree.unversion(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
194
        tree.add(['foo'])
195
        self.assertTrue(tree.has_filename('foo'))
196
197
    def test_add_previously_added_with_file_id(self):
198
        # adding a path that was previously added should work
199
        tree = self.make_branch_and_tree('.')
200
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
201
            self.skipTest("tree does not support setting file ids")
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
202
        self.build_tree(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
203
        tree.add(['foo'], ['foo-id'])
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
204
        tree.unversion(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
205
        tree.add(['foo'], ['foo-id'])
206
        self.assertEqual('foo-id', tree.path2id('foo'))
207
208
    def test_add_present_in_basis(self):
209
        # adding a path that was present in the basis should work.
210
        tree = self.make_branch_and_tree('.')
211
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
212
        tree.add(['foo'])
213
        tree.commit('add foo')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
214
        tree.unversion(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
215
        tree.add(['foo'])
216
        self.assertTrue(tree.has_filename('foo'))
217
218
    def test_add_present_in_basis_with_file_ids(self):
219
        # adding a path that was present in the basis should work.
220
        tree = self.make_branch_and_tree('.')
221
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
222
            self.skipTest("tree does not support setting file ids")
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
223
        self.build_tree(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
224
        tree.add(['foo'], ['foo-id'])
225
        tree.commit('add foo')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
226
        tree.unversion(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
227
        tree.add(['foo'], ['foo-id'])
228
        self.assertEqual('foo-id', tree.path2id('foo'))