/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
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.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
16
17
"""Tests for WorkingTree.paths2ids.
18
19
This API probably needs to be exposed as a tree implementation test, but these
20
initial tests are for the specific cases being refactored from
21
find_ids_across_trees.
22
"""
23
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy import errors
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
25
from breezy.tests import (
26
    features,
27
    TestNotApplicable,
28
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
29
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
30
31
2255.2.103 by Robert Collins
Document some future tests for paths2ids.
32
# TODO: This needs an additional test: do a merge, then do a
33
# paths2id(trees=left parent only), and also with (trees=all parents) to check
34
# that only the requested trees are considered - i.e. have an unversioned path
35
# in the unlisted tree, or an extra file that moves into the selected path but
36
# should not be returned
37
38
# TODO: test that supplying paths with duplication - i.e. foo, foo, foo/bar -
39
# does not result in garbage out.
40
2255.2.104 by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate.
41
# TODO: Are we meant to raise the precise unversioned paths when some are
42
# unversioned - if so, test this.
2255.2.103 by Robert Collins
Document some future tests for paths2ids.
43
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
44
class TestPaths2Ids(TestCaseWithWorkingTree):
45
2255.2.101 by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api.
46
    def assertExpectedIds(self, ids, tree, paths, trees=None,
47
        require_versioned=True):
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
48
        """Run paths2ids for tree, and check the result."""
49
        tree.lock_read()
50
        if trees:
6631.3.1 by Martin
Run 2to3 map fixer and refactor after
51
            for t in trees:
52
                t.lock_read()
2255.2.101 by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api.
53
            result = tree.paths2ids(paths, trees,
54
                require_versioned=require_versioned)
6631.3.1 by Martin
Run 2to3 map fixer and refactor after
55
            for t in trees:
56
                t.unlock()
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
57
        else:
2255.2.101 by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api.
58
            result = tree.paths2ids(paths,
59
                require_versioned=require_versioned)
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
60
        self.assertEqual(set(ids), result)
61
        tree.unlock()
62
2255.2.104 by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate.
63
    def test_paths_none_result_none(self):
64
        tree = self.make_branch_and_tree('tree')
65
        tree.lock_read()
66
        self.assertEqual(None, tree.paths2ids(None))
67
        tree.unlock()
68
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
69
    def test_find_single_root(self):
70
        tree = self.make_branch_and_tree('tree')
71
        self.assertExpectedIds([tree.path2id('')], tree, [''])
72
73
    def test_find_tree_and_clone_roots(self):
74
        tree = self.make_branch_and_tree('tree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
75
        clone = tree.controldir.clone('clone').open_workingtree()
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
76
        clone.lock_tree_write()
77
        clone_root_id = 'new-id'
78
        clone.set_root_id(clone_root_id)
79
        tree_root_id = tree.path2id('')
80
        clone.unlock()
81
        self.assertExpectedIds([tree_root_id, clone_root_id], tree, [''], [clone])
82
83
    def test_find_tree_basis_roots(self):
84
        tree = self.make_branch_and_tree('tree')
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
85
        if not tree.supports_setting_file_ids():
86
            raise TestNotApplicable('tree does not support setting file ids')
87
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
88
        tree.commit('basis')
89
        basis = tree.basis_tree()
90
        basis_root_id = basis.path2id('')
91
        tree.lock_tree_write()
92
        tree_root_id = 'new-id'
93
        tree.set_root_id(tree_root_id)
94
        tree.unlock()
95
        self.assertExpectedIds([tree_root_id, basis_root_id], tree, [''], [basis])
96
97
    def test_find_children_of_moved_directories(self):
98
        """Check the basic nasty corner case that path2ids should handle.
99
100
        This is the following situation:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
101
        basis:
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
102
          / ROOT
103
          /dir dir
104
          /dir/child-moves child-moves
105
          /dir/child-stays child-stays
106
          /dir/child-goes  child-goes
107
108
        current tree:
109
          / ROOT
110
          /child-moves child-moves
111
          /newdir newdir
112
          /newdir/dir  dir
113
          /newdir/dir/child-stays child-stays
114
          /newdir/dir/new-child   new-child
115
116
        In english: we move a directory under a directory that was a sibling,
117
        and at the same time remove, or move out of the directory, some of its
118
        children, and give it a new child previous absent or a sibling.
119
120
        current_tree.path2ids(['newdir'], [basis]) is meant to handle this
121
        correctly: that is it should return the ids:
122
          newdir because it was provided
123
          dir, because its under newdir in current
124
          child-moves because its under dir in old
125
          child-stays either because its under newdir/dir in current, or under dir in old
126
          child-goes because its under dir in old.
127
          new-child because its under dir in new
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
128
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
129
        Symmetrically, current_tree.path2ids(['dir'], [basis]) is meant to show
130
        new-child, even though its not under the path 'dir' in current, because
131
        its under a path selected by 'dir' in basis:
132
          dir because its selected in basis.
133
          child-moves because its under dir in old
134
          child-stays either because its under newdir/dir in current, or under dir in old
135
          child-goes because its under dir in old.
136
          new-child because its under dir in new.
137
        """
138
        tree = self.make_branch_and_tree('tree')
139
        self.build_tree(
140
            ['tree/dir/', 'tree/dir/child-moves', 'tree/dir/child-stays',
141
             'tree/dir/child-goes'])
142
        tree.add(['dir', 'dir/child-moves', 'dir/child-stays', 'dir/child-goes'],
143
                 ['dir', 'child-moves', 'child-stays', 'child-goes'])
144
        tree.commit('create basis')
145
        basis = tree.basis_tree()
6809.4.25 by Jelmer Vernooij
Add paths argument to .unversion.
146
        tree.unversion(['dir/child-goes'])
2255.2.100 by Robert Collins
Create a paths2ids api to replace find_ids_across_trees, with tests.
147
        tree.rename_one('dir/child-moves', 'child-moves')
148
        self.build_tree(['tree/newdir/'])
149
        tree.add(['newdir'], ['newdir'])
150
        tree.rename_one('dir/child-stays', 'child-stays')
151
        tree.rename_one('dir', 'newdir/dir')
152
        tree.rename_one('child-stays', 'newdir/dir/child-stays')
153
        self.build_tree(['tree/newdir/dir/new-child'])
154
        tree.add(['newdir/dir/new-child'], ['new-child'])
155
        self.assertExpectedIds(
156
            ['newdir', 'dir', 'child-moves', 'child-stays', 'child-goes',
157
             'new-child'], tree, ['newdir'], [basis])
158
        self.assertExpectedIds(
159
            ['dir', 'child-moves', 'child-stays', 'child-goes', 'new-child'],
160
            tree, ['dir'], [basis])
2255.2.101 by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api.
161
162
    def test_unversioned_one_tree(self):
163
        tree = self.make_branch_and_tree('tree')
164
        self.build_tree(['tree/unversioned'])
165
        self.assertExpectedIds([], tree, ['unversioned'], require_versioned=False)
166
        tree.lock_read()
167
        self.assertRaises(errors.PathsNotVersionedError, tree.paths2ids, ['unversioned'])
168
        tree.unlock()
169
2255.2.104 by Robert Collins
Add WorkingTree4.paths2ids which is inventory-usage free if the trees being examined are in the dirstate.
170
    def test_unversioned_in_one_of_multiple_trees(self):
171
        # in this test, the path is unversioned in only one tree, and thus
172
        # should not raise an error: it must be unversioned in *all* trees to
173
        # error.
174
        tree = self.make_branch_and_tree('tree')
175
        tree.commit('make basis')
176
        basis = tree.basis_tree()
177
        self.build_tree(['tree/in-one'])
178
        tree.add(['in-one'], ['in-one'])
179
        self.assertExpectedIds(['in-one'], tree, ['in-one'], [basis])
180
181
    def test_unversioned_all_of_multiple_trees(self):
182
        # in this test, the path is unversioned in every tree, and thus
183
        # should not raise an error: it must be unversioned in *all* trees to
184
        # error.
185
        tree = self.make_branch_and_tree('tree')
186
        tree.commit('make basis')
187
        basis = tree.basis_tree()
2255.2.101 by Robert Collins
Finish making Tree.ids2paths support the file_ids_across_trees api.
188
        self.assertExpectedIds([], tree, ['unversioned'], [basis],
189
            require_versioned=False)
190
        tree.lock_read()
191
        basis.lock_read()
192
        self.assertRaises(errors.PathsNotVersionedError, tree.paths2ids,
193
            ['unversioned'], [basis])
194
        self.assertRaises(errors.PathsNotVersionedError, basis.paths2ids,
195
            ['unversioned'], [tree])
196
        basis.unlock()
197
        tree.unlock()
6345.1.2 by Martin Packman
Add targetted working tree tests for places that raise PathsNotVersionedError
198
199
    def test_unversioned_non_ascii_one_tree(self):
200
        self.requireFeature(features.UnicodeFilenameFeature)
201
        tree = self.make_branch_and_tree('.')
202
        self.build_tree([u"\xa7"])
203
        self.assertExpectedIds([], tree, [u"\xa7"], require_versioned=False)
204
        self.addCleanup(tree.lock_read().unlock)
205
        e = self.assertRaises(errors.PathsNotVersionedError,
206
            tree.paths2ids, [u"\xa7"])
207
        self.assertEqual([u"\xa7"], e.paths)