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