/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('.')
61
        self.build_tree(['a', 'b'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
62
        tree.add(['a'])
63
        file_id = tree.path2id('a')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
64
        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.
65
        root_id = tree.get_root_id()
66
        # And the entry should not have been added.
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
67
        tree.unversion(['a'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
68
        tree.add(['b'], [file_id])
69
        self.assertTreeLayout([('', root_id), ('b', file_id)], tree)
70
        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.
71
                              tree.basis_tree())
72
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
73
    def test_add_one_list(self):
74
        tree = self.make_branch_and_tree('.')
75
        self.build_tree(['one'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
76
        tree.add(['one'])
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
77
        root_id = tree.get_root_id()
78
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
79
        self.assertTreeLayout(
80
            [('', 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.
81
82
    def test_add_one_new_id(self):
83
        tree = self.make_branch_and_tree('.')
84
        self.build_tree(['one'])
85
        tree.add(['one'])
86
        root_id = tree.get_root_id()
87
        one_id = tree.path2id('one')
88
89
        self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
90
91
    def test_add_unicode(self):
92
        tree = self.make_branch_and_tree('.')
93
        try:
94
            self.build_tree([u'f\xf6'])
95
        except UnicodeError:
96
            raise tests.TestSkipped('Filesystem does not support filename.')
97
        tree.add([u'f\xf6'])
98
        root_id = tree.get_root_id()
99
        foo_id = tree.path2id(u'f\xf6')
100
101
        self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
102
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
103
    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.
104
        tree = self.make_branch_and_tree('.')
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
105
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
106
            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.
107
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
108
        tree.add(['dir'], ['dir-id'])
109
        tree.add(['dir/subdir'], ['subdir-id'])
110
        tree.add(['dir/subdir/foo'], ['foo-id'])
111
        root_id = tree.get_root_id()
112
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
113
        self.assertTreeLayout([('', root_id), ('dir/', 'dir-id'),
114
                               ('dir/subdir/', 'subdir-id'),
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
115
                               ('dir/subdir/foo', 'foo-id')], tree)
116
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
117
    def test_add_subdir(self):
118
        tree = self.make_branch_and_tree('.')
119
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
120
        tree.add(['dir'])
121
        tree.add(['dir/subdir'])
122
        tree.add(['dir/subdir/foo'])
123
        root_id = tree.get_root_id()
124
125
        self.assertTreeLayout([
126
            ('', root_id),
127
            ('dir/', tree.path2id('dir')),
128
            ('dir/subdir/', tree.path2id('dir/subdir')),
129
            ('dir/subdir/foo', tree.path2id('dir/subdir/foo'))],
130
            tree)
131
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
132
    def test_add_multiple(self):
133
        tree = self.make_branch_and_tree('.')
134
        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
135
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'])
136
        root_id = tree.get_root_id()
137
138
        self.assertTreeLayout([
139
            (p, tree.path2id(p))
140
            for p in ['', 'a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo']],
141
            tree)
142
143
    def test_add_multiple_with_file_ids(self):
144
        tree = self.make_branch_and_tree('.')
145
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
146
            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
147
        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.
148
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
149
                 ['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
150
        root_id = tree.get_root_id()
151
152
        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.
153
                               ('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.
154
                               ('dir/subdir/foo', 'foo-id')], tree)
155
156
    def test_add_invalid(self):
157
        tree = self.make_branch_and_tree('.')
158
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
159
        root_id = tree.get_root_id()
160
161
        self.assertRaises(errors.NotVersionedError,
162
                          tree.add, ['dir/subdir'])
163
        self.assertTreeLayout([('', root_id)], tree)
164
165
    def test_add_after_remove(self):
166
        tree = self.make_branch_and_tree('.')
167
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
168
        root_id = tree.get_root_id()
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
169
        tree.add(['dir'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
170
        tree.commit('dir')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
171
        tree.unversion(['dir'])
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
172
        self.assertRaises(errors.NotVersionedError,
173
                          tree.add, ['dir/subdir'])
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
174
175
    def test_add_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
176
        # 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.
177
        # do anything whacky.
178
        tree = self.make_branch_and_tree('.')
179
        tree.lock_write()
180
        tree.add('')
5837.2.2 by Jelmer Vernooij
Fix more uses of Tree.__iter__
181
        self.assertEqual([tree.path2id('')], list(tree.all_file_ids()))
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
182
        # the root should have been changed to be a new unique root.
183
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
184
        tree.unlock()
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
185
186
    def test_add_previously_added(self):
187
        # adding a path that was previously added should work
188
        tree = self.make_branch_and_tree('.')
189
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
190
        tree.add(['foo'])
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
191
        tree.unversion(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
192
        tree.add(['foo'])
193
        self.assertTrue(tree.has_filename('foo'))
194
195
    def test_add_previously_added_with_file_id(self):
196
        # adding a path that was previously added should work
197
        tree = self.make_branch_and_tree('.')
198
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
199
            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
200
        self.build_tree(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
201
        tree.add(['foo'], ['foo-id'])
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
202
        tree.unversion(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
203
        tree.add(['foo'], ['foo-id'])
204
        self.assertEqual('foo-id', tree.path2id('foo'))
205
206
    def test_add_present_in_basis(self):
207
        # adding a path that was present in the basis should work.
208
        tree = self.make_branch_and_tree('.')
209
        self.build_tree(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
210
        tree.add(['foo'])
211
        tree.commit('add foo')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
212
        tree.unversion(['foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
213
        tree.add(['foo'])
214
        self.assertTrue(tree.has_filename('foo'))
215
216
    def test_add_present_in_basis_with_file_ids(self):
217
        # adding a path that was present in the basis should work.
218
        tree = self.make_branch_and_tree('.')
219
        if not tree.supports_setting_file_ids():
6819.1.3 by Jelmer Vernooij
Use self.skipTest.
220
            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
221
        self.build_tree(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
222
        tree.add(['foo'], ['foo-id'])
223
        tree.commit('add foo')
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
224
        tree.unversion(['foo'])
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
225
        tree.add(['foo'], ['foo-id'])
226
        self.assertEqual('foo-id', tree.path2id('foo'))