/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'])
39
        tree.add('one', 'one-id')
40
        root_id = tree.get_root_id()
41
42
        self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
43
2255.7.16 by John Arbash Meinel
Make sure adding a duplicate file_id raises DuplicateFileId.
44
    def test_add_existing_id(self):
45
        """Adding an entry with a pre-existing id raises DuplicateFileId"""
46
        tree = self.make_branch_and_tree('.')
47
        self.build_tree(['a', 'b'])
48
        tree.add(['a'], ['an-id'])
49
        self.assertRaises(errors.DuplicateFileId,
50
                          tree.add, ['b'], ['an-id'])
51
        root_id = tree.get_root_id()
52
        # And the entry should not have been added.
53
        self.assertTreeLayout([('', root_id), ('a', 'an-id')], tree)
54
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.
55
    def test_add_old_id(self):
56
        """We can add an old id, as long as it doesn't exist now."""
57
        tree = self.make_branch_and_tree('.')
58
        self.build_tree(['a', 'b'])
59
        tree.add(['a'], ['an-id'])
60
        tree.commit('first', rev_id='rev-1')
61
        root_id = tree.get_root_id()
62
        # And the entry should not have been added.
63
        tree.unversion(['an-id'])
64
        tree.add(['b'], ['an-id'])
65
        self.assertTreeLayout([('', root_id), ('b', 'an-id')], tree)
66
        self.assertTreeLayout([('', root_id), ('a', 'an-id')],
67
                              tree.basis_tree())
68
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
69
    def test_add_one_list(self):
70
        tree = self.make_branch_and_tree('.')
71
        self.build_tree(['one'])
72
        tree.add(['one'], ['one-id'])
73
        root_id = tree.get_root_id()
74
75
        self.assertTreeLayout([('', root_id), ('one', 'one-id')], tree)
76
77
    def test_add_one_new_id(self):
78
        tree = self.make_branch_and_tree('.')
79
        self.build_tree(['one'])
80
        tree.add(['one'])
81
        root_id = tree.get_root_id()
82
        one_id = tree.path2id('one')
83
84
        self.assertTreeLayout([('', root_id), ('one', one_id)], tree)
85
86
    def test_add_unicode(self):
87
        tree = self.make_branch_and_tree('.')
88
        try:
89
            self.build_tree([u'f\xf6'])
90
        except UnicodeError:
91
            raise tests.TestSkipped('Filesystem does not support filename.')
92
        tree.add([u'f\xf6'])
93
        root_id = tree.get_root_id()
94
        foo_id = tree.path2id(u'f\xf6')
95
96
        self.assertTreeLayout([('', root_id), (u'f\xf6', foo_id)], tree)
97
98
    def test_add_subdir(self):
99
        tree = self.make_branch_and_tree('.')
100
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
101
        tree.add(['dir'], ['dir-id'])
102
        tree.add(['dir/subdir'], ['subdir-id'])
103
        tree.add(['dir/subdir/foo'], ['foo-id'])
104
        root_id = tree.get_root_id()
105
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
106
        self.assertTreeLayout([('', root_id), ('dir/', 'dir-id'),
107
                               ('dir/subdir/', 'subdir-id'),
2255.7.10 by John Arbash Meinel
Handle the case when we are adding a file to an empty directory.
108
                               ('dir/subdir/foo', 'foo-id')], tree)
109
110
    def test_add_multiple(self):
111
        tree = self.make_branch_and_tree('.')
112
        self.build_tree(['a', 'b', 'dir/', 'dir/subdir/', 'dir/subdir/foo'])
113
        tree.add(['a', 'b', 'dir', 'dir/subdir', 'dir/subdir/foo'],
114
                 ['a-id', 'b-id', 'dir-id', 'subdir-id', 'foo-id'])
115
        root_id = tree.get_root_id()
116
117
        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.
118
                               ('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.
119
                               ('dir/subdir/foo', 'foo-id')], tree)
120
121
    def test_add_invalid(self):
122
        tree = self.make_branch_and_tree('.')
123
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
124
        root_id = tree.get_root_id()
125
126
        self.assertRaises(errors.NotVersionedError,
127
                          tree.add, ['dir/subdir'])
128
        self.assertTreeLayout([('', root_id)], tree)
129
130
    def test_add_after_remove(self):
131
        tree = self.make_branch_and_tree('.')
132
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
133
        root_id = tree.get_root_id()
134
        tree.add(['dir'], ['dir-id'])
135
        tree.commit('dir', rev_id='rev-1')
136
        tree.unversion(['dir-id'])
137
        self.assertRaises(errors.NotVersionedError,
138
                          tree.add, ['dir/subdir'])
2255.7.74 by Robert Collins
Test adding of roots to trees, it was broken on WorkingTree4.
139
140
    def test_add_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
141
        # 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.
142
        # do anything whacky.
143
        tree = self.make_branch_and_tree('.')
144
        tree.lock_write()
145
        tree.add('')
5837.2.2 by Jelmer Vernooij
Fix more uses of Tree.__iter__
146
        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.
147
        # the root should have been changed to be a new unique root.
148
        self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
149
        tree.unlock()
2323.4.1 by Robert Collins
dirstate correctness: allow adding paths present in the basis.
150
151
    def test_add_previously_added(self):
152
        # adding a path that was previously added should work
153
        tree = self.make_branch_and_tree('.')
154
        self.build_tree(['foo'])
155
        tree.add(['foo'], ['foo-id'])
156
        tree.unversion(['foo-id'])
157
        tree.add(['foo'], ['foo-id'])
158
        self.assertEqual('foo-id', tree.path2id('foo'))
159
160
    def test_add_present_in_basis(self):
161
        # adding a path that was present in the basis should work.
162
        tree = self.make_branch_and_tree('.')
163
        self.build_tree(['foo'])
164
        tree.add(['foo'], ['foo-id'])
165
        tree.commit('add foo')
166
        tree.unversion(['foo-id'])
167
        tree.add(['foo'], ['foo-id'])
168
        self.assertEqual('foo-id', tree.path2id('foo'))