/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.152 by Martin Pool
(broken) merge aaron's workingtree format changes
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
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
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
16
17
"""Tests for the InterTree.compare() function."""
18
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
19
import os
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
20
import shutil
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
21
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy import (
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
23
    errors,
4503.1.3 by Vincent Ladeuil
Take review comments into account.
24
    mutabletree,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
25
    tests,
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
26
    transform,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
27
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy.osutils import has_symlinks
29
from breezy.tests.per_intertree import TestCaseWithTwoTrees
30
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
31
    features,
32
    )
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
33
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
34
# TODO: test the include_root option.
35
# TODO: test that renaming a directory x->y does not emit a rename for the
36
#       child x/a->y/a.
37
# TODO: test that renaming a directory x-> does not emit a rename for the child
38
#        x/a -> y/a when a supplied_files argument gives either 'x/' or 'y/a'
39
#        -> that is, when the renamed parent is not processed by the function.
40
# TODO: test items are only emitted once when a specific_files list names a dir
41
#       whose parent is now a child.
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
42
# TODO: test comparisons between trees with different root ids. mbp 20070301
2255.2.189 by Martin Pool
Add and fix up basic comparison of subtrees.
43
#
44
# TODO: More comparisons between trees with subtrees in different states.
2255.2.236 by Martin Pool
Review cleanups: mostly updating or removing todo comments.
45
#
46
# TODO: Many tests start out by setting the tree roots ids the same, maybe
47
#       that should just be the default for these tests, by changing
48
#       make_branch_and_tree.  mbp 20070307
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
49
7067.6.2 by Jelmer Vernooij
Move key function to top-level.
50
51
def _change_key(change):
52
    """Return a valid key for sorting Tree.iter_changes entries."""
53
    (file_id, paths, content_changed, versioned, parent, name, kind,
7143.15.2 by Jelmer Vernooij
Run autopep8.
54
     executable) = change
7067.6.2 by Jelmer Vernooij
Move key function to top-level.
55
    return (file_id or b'', (paths[0] or '', paths[1] or ''), versioned,
56
            parent, name, kind, executable)
57
58
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
59
class TestCompare(TestCaseWithTwoTrees):
60
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
61
    def _make_abc_tree(self, tree):
62
        """setup an abc content tree."""
63
        files = ['a', 'b/', 'b/c']
64
        self.build_tree(files, line_endings='binary',
65
                        transport=tree.controldir.root_transport)
6855.3.1 by Jelmer Vernooij
Several more fixes.
66
        tree.set_root_id(b'root-id')
67
        tree.add(files, [b'a-id', b'b-id', b'c-id'])
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
68
69
    def get_tree_no_parents_abc_content(self, tree, converter=None):
70
        """return a test tree with a, b/, b/c contents."""
71
        self._make_abc_tree(tree)
72
        return self._convert_tree(tree, converter)
73
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
74
    def test_compare_empty_trees(self):
75
        tree1 = self.make_branch_and_tree('1')
76
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
77
        tree2.set_root_id(tree1.get_root_id())
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
78
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
79
        tree2 = self.get_tree_no_parents_no_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
80
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
81
        d = self.intertree_class(tree1, tree2).compare()
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
82
        self.assertEqual([], d.added)
83
        self.assertEqual([], d.modified)
84
        self.assertEqual([], d.removed)
85
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
86
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
87
88
    def test_empty_to_abc_content(self):
89
        tree1 = self.make_branch_and_tree('1')
90
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
91
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
92
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
93
        tree2 = self.get_tree_no_parents_abc_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
94
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
95
        d = self.intertree_class(tree1, tree2).compare()
6855.3.1 by Jelmer Vernooij
Several more fixes.
96
        self.assertEqual([('a', b'a-id', 'file'),
97
                          ('b', b'b-id', 'directory'),
98
                          ('b/c', b'c-id', 'file'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
99
                          ], d.added)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
100
        self.assertEqual([], d.modified)
101
        self.assertEqual([], d.removed)
102
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
103
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
104
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
105
    def test_dangling(self):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
106
        # This test depends on the ability for some trees to have a difference
107
        # between a 'versioned present' and 'versioned not present' (aka
108
        # dangling) file. In this test there are two trees each with a separate
109
        # dangling file, and the dangling files should be considered absent for
110
        # the test.
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
111
        tree1 = self.make_branch_and_tree('1')
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
112
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
113
        tree2.set_root_id(tree1.get_root_id())
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
114
        self.build_tree(['2/a'])
115
        tree2.add('a')
116
        os.unlink('2/a')
117
        self.build_tree(['1/b'])
118
        tree1.add('b')
119
        os.unlink('1/b')
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
120
        # the conversion to test trees here will leave the trees intact for the
121
        # default intertree, but may perform a commit for other tree types,
122
        # which may reduce the validity of the test. XXX: Think about how to
123
        # address this.
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
124
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
125
        d = self.intertree_class(tree1, tree2).compare()
126
        self.assertEqual([], d.added)
127
        self.assertEqual([], d.modified)
128
        self.assertEqual([], d.removed)
129
        self.assertEqual([], d.renamed)
130
        self.assertEqual([], d.unchanged)
131
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
132
    def test_abc_content_to_empty(self):
133
        tree1 = self.make_branch_and_tree('1')
134
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
135
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
136
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
137
        tree2 = self.get_tree_no_parents_no_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
138
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
139
        d = self.intertree_class(tree1, tree2).compare()
140
        self.assertEqual([], d.added)
141
        self.assertEqual([], d.modified)
6821.2.1 by Jelmer Vernooij
Fix tests.
142
        self.assertEqual([('a', tree1.path2id('a'), 'file'),
143
                          ('b', tree1.path2id('b'), 'directory'),
144
                          ('b/c', tree1.path2id('b/c'), 'file'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
145
                          ], d.removed)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
146
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
147
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
148
149
    def test_content_modification(self):
150
        tree1 = self.make_branch_and_tree('1')
151
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
152
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
153
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
154
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
155
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
156
        d = self.intertree_class(tree1, tree2).compare()
157
        self.assertEqual([], d.added)
7143.15.2 by Jelmer Vernooij
Run autopep8.
158
        self.assertEqual(
159
            [('a', tree1.path2id('a'), 'file', True, False)], d.modified)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
160
        self.assertEqual([], d.removed)
161
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
162
        self.assertEqual([], d.unchanged)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
163
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
164
    def test_meta_modification(self):
165
        tree1 = self.make_branch_and_tree('1')
166
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
167
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
168
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
169
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
170
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
171
        d = self.intertree_class(tree1, tree2).compare()
172
        self.assertEqual([], d.added)
7143.15.2 by Jelmer Vernooij
Run autopep8.
173
        self.assertEqual(
174
            [('b/c', tree1.path2id('b/c'), 'file', False, True)], d.modified)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
175
        self.assertEqual([], d.removed)
176
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
177
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
178
179
    def test_file_rename(self):
180
        tree1 = self.make_branch_and_tree('1')
181
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
182
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
183
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
184
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
185
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
186
        d = self.intertree_class(tree1, tree2).compare()
187
        self.assertEqual([], d.added)
188
        self.assertEqual([], d.modified)
189
        self.assertEqual([], d.removed)
7143.15.2 by Jelmer Vernooij
Run autopep8.
190
        self.assertEqual(
191
            [('a', 'd', tree1.path2id('a'), 'file', False, False)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
192
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
193
194
    def test_file_rename_and_modification(self):
195
        tree1 = self.make_branch_and_tree('1')
196
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
197
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
198
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
199
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
200
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
201
        d = self.intertree_class(tree1, tree2).compare()
202
        self.assertEqual([], d.added)
203
        self.assertEqual([], d.modified)
204
        self.assertEqual([], d.removed)
7143.15.2 by Jelmer Vernooij
Run autopep8.
205
        self.assertEqual(
206
            [('a', 'd', tree1.path2id('a'), 'file', True, False)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
207
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
208
209
    def test_file_rename_and_meta_modification(self):
210
        tree1 = self.make_branch_and_tree('1')
211
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
212
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
213
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
214
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
215
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
216
        d = self.intertree_class(tree1, tree2).compare()
217
        self.assertEqual([], d.added)
218
        self.assertEqual([], d.modified)
219
        self.assertEqual([], d.removed)
7143.15.2 by Jelmer Vernooij
Run autopep8.
220
        self.assertEqual(
221
            [('b/c', 'e', tree1.path2id('b/c'), 'file', False, True)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
222
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
223
224
    def test_empty_to_abc_content_a_only(self):
225
        tree1 = self.make_branch_and_tree('1')
226
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
227
        tree2.set_root_id(tree1.get_root_id())
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
228
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
229
        tree2 = self.get_tree_no_parents_abc_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
230
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
231
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
6821.2.1 by Jelmer Vernooij
Fix tests.
232
        self.assertEqual([('a', tree2.path2id('a'), 'file')], d.added)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
233
        self.assertEqual([], d.modified)
234
        self.assertEqual([], d.removed)
235
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
236
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
237
238
    def test_empty_to_abc_content_a_and_c_only(self):
239
        tree1 = self.make_branch_and_tree('1')
240
        tree2 = self.make_to_branch_and_tree('2')
241
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
242
        tree2 = self.get_tree_no_parents_abc_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
243
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
244
        d = self.intertree_class(tree1, tree2).compare(
245
            specific_files=['a', 'b/c'])
246
        self.assertEqual(
6821.2.1 by Jelmer Vernooij
Fix tests.
247
            [('a', tree2.path2id('a'), 'file'),
248
             (u'b', tree2.path2id('b'), 'directory'),
249
             ('b/c', tree2.path2id('b/c'), 'file')],
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
250
            d.added)
251
        self.assertEqual([], d.modified)
252
        self.assertEqual([], d.removed)
253
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
254
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
255
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
256
    def test_empty_to_abc_content_c_only(self):
257
        tree1 = self.make_branch_and_tree('1')
258
        tree2 = self.make_to_branch_and_tree('2')
259
        tree1 = self.get_tree_no_parents_no_content(tree1)
260
        tree2 = self.get_tree_no_parents_abc_content(tree2)
261
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
262
        d = self.intertree_class(tree1, tree2).compare(
263
            specific_files=['b/c'])
264
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
265
            [(u'b', b'b-id', 'directory'), ('b/c', b'c-id', 'file')], d.added)
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
266
        self.assertEqual([], d.modified)
267
        self.assertEqual([], d.removed)
268
        self.assertEqual([], d.renamed)
269
        self.assertEqual([], d.unchanged)
270
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
271
    def test_empty_to_abc_content_b_only(self):
272
        """Restricting to a dir matches the children of the dir."""
273
        tree1 = self.make_branch_and_tree('1')
274
        tree2 = self.make_to_branch_and_tree('2')
275
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
276
        tree2 = self.get_tree_no_parents_abc_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
277
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
278
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
279
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
280
            [('b', b'b-id', 'directory'), ('b/c', b'c-id', 'file')],
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
281
            d.added)
282
        self.assertEqual([], d.modified)
283
        self.assertEqual([], d.removed)
284
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
285
        self.assertEqual([], d.unchanged)
286
287
    def test_unchanged_with_renames_and_modifications(self):
288
        """want_unchanged should generate a list of unchanged entries."""
289
        tree1 = self.make_branch_and_tree('1')
290
        tree2 = self.make_to_branch_and_tree('2')
291
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
292
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
293
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
294
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
295
        self.assertEqual([], d.added)
296
        self.assertEqual([], d.modified)
297
        self.assertEqual([], d.removed)
6855.3.1 by Jelmer Vernooij
Several more fixes.
298
        self.assertEqual([('a', 'd', b'a-id', 'file', True, False)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
299
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
300
            [(u'b', b'b-id', 'directory'), (u'b/c', b'c-id', 'file')],
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
301
            d.unchanged)
302
303
    def test_extra_trees_finds_ids(self):
304
        """Ask for a delta between two trees with a path present in a third."""
305
        tree1 = self.make_branch_and_tree('1')
306
        tree2 = self.make_to_branch_and_tree('2')
307
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
308
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
309
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
310
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
311
        # the type of tree-3 does not matter - it is used as a lookup, not
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
312
        # a dispatch. XXX: For dirstate it does speak to the optimisability of
313
        # the lookup, in merged trees it can be fast-pathed. We probably want
314
        # two tests: one as is, and one with it as a pending merge.
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
315
        tree3 = self.make_branch_and_tree('3')
316
        tree3 = self.get_tree_no_parents_abc_content_6(tree3)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
317
        tree3.lock_read()
318
        self.addCleanup(tree3.unlock)
6855.3.1 by Jelmer Vernooij
Several more fixes.
319
        # tree 3 has 'e' which is b'c-id'. Tree 1 has c-id at b/c, and Tree 2
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
320
        # has c-id at b/c with its exec flag toggled.
321
        # without extra_trees, we should get no modifications from this
322
        # so do one, to be sure the test is valid.
323
        d = self.intertree_class(tree1, tree2).compare(
324
            specific_files=['e'])
325
        self.assertEqual([], d.modified)
326
        # now give it an additional lookup:
327
        d = self.intertree_class(tree1, tree2).compare(
328
            specific_files=['e'], extra_trees=[tree3])
329
        self.assertEqual([], d.added)
6855.3.1 by Jelmer Vernooij
Several more fixes.
330
        self.assertEqual([('b/c', b'c-id', 'file', False, True)], d.modified)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
331
        self.assertEqual([], d.removed)
332
        self.assertEqual([], d.renamed)
333
        self.assertEqual([], d.unchanged)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
334
335
    def test_require_versioned(self):
336
        # this does not quite robustly test, as it is passing in missing paths
337
        # rather than present-but-not-versioned paths. At the moment there is
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
338
        # no mechanism for managing the test trees (which are readonly) to
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
339
        # get present-but-not-versioned files for trees that can do that.
340
        tree1 = self.make_branch_and_tree('1')
341
        tree2 = self.make_to_branch_and_tree('2')
342
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
343
        tree2 = self.get_tree_no_parents_abc_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
344
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
345
        self.assertRaises(errors.PathsNotVersionedError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
346
                          self.intertree_class(tree1, tree2).compare,
347
                          specific_files=['d'],
348
                          require_versioned=True)
2012.1.1 by Aaron Bentley
Implement change iterator
349
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
350
    def test_default_ignores_unversioned_files(self):
351
        tree1 = self.make_branch_and_tree('tree1')
352
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
353
        tree2.set_root_id(tree1.get_root_id())
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
354
        self.build_tree(['tree1/a', 'tree1/c',
355
                         'tree2/a', 'tree2/b', 'tree2/c'])
6855.3.1 by Jelmer Vernooij
Several more fixes.
356
        tree1.add(['a', 'c'], [b'a-id', b'c-id'])
357
        tree2.add(['a', 'c'], [b'a-id', b'c-id'])
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
358
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
359
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
360
        d = self.intertree_class(tree1, tree2).compare()
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
361
        self.assertEqual([], d.added)
6855.3.1 by Jelmer Vernooij
Several more fixes.
362
        self.assertEqual([(u'a', b'a-id', 'file', True, False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
                          (u'c', b'c-id', 'file', True, False)], d.modified)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
364
        self.assertEqual([], d.removed)
365
        self.assertEqual([], d.renamed)
366
        self.assertEqual([], d.unchanged)
367
        self.assertEqual([], d.unversioned)
368
369
    def test_unversioned_paths_in_tree(self):
370
        tree1 = self.make_branch_and_tree('tree1')
371
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
372
        tree2.set_root_id(tree1.get_root_id())
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
373
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
374
        if has_symlinks():
375
            os.symlink('target', 'tree2/link')
376
            links_supported = True
377
        else:
378
            links_supported = False
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
379
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
380
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
381
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
382
        self.assertEqual([], d.added)
383
        self.assertEqual([], d.modified)
384
        self.assertEqual([], d.removed)
385
        self.assertEqual([], d.renamed)
386
        self.assertEqual([], d.unchanged)
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
387
        expected_unversioned = [(u'dir', None, 'directory'),
388
                                (u'file', None, 'file')]
389
        if links_supported:
390
            expected_unversioned.append((u'link', None, 'symlink'))
391
        self.assertEqual(expected_unversioned, d.unversioned)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
392
2012.1.1 by Aaron Bentley
Implement change iterator
393
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
394
class TestIterChanges(TestCaseWithTwoTrees):
2012.1.1 by Aaron Bentley
Implement change iterator
395
    """Test the comparison iterator"""
396
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
397
    def _make_abc_tree(self, tree):
398
        """setup an abc content tree."""
399
        files = ['a', 'b/', 'b/c']
400
        self.build_tree(files, line_endings='binary',
401
                        transport=tree.controldir.root_transport)
6855.4.1 by Jelmer Vernooij
Yet more bees.
402
        tree.set_root_id(b'root-id')
6855.3.1 by Jelmer Vernooij
Several more fixes.
403
        tree.add(files, [b'a-id', b'b-id', b'c-id'])
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
404
405
    def get_tree_no_parents_abc_content(self, tree, converter=None):
406
        """return a test tree with a, b/, b/c contents."""
407
        self._make_abc_tree(tree)
408
        return self._convert_tree(tree, converter)
409
410
    def get_tree_no_parents_abc_content_7(self, tree, converter=None):
411
        """return a test tree with a, b/, d/e contents.
412
6855.3.1 by Jelmer Vernooij
Several more fixes.
413
        This variation adds a dir 'd' (b'd-id'), renames b to d/e.
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
414
        """
415
        self._make_abc_tree(tree)
416
        self.build_tree(['d/'], transport=tree.controldir.root_transport)
6855.3.1 by Jelmer Vernooij
Several more fixes.
417
        tree.add(['d'], [b'd-id'])
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
418
        tt = transform.TreeTransform(tree)
419
        trans_id = tt.trans_id_tree_path('b')
420
        parent_trans_id = tt.trans_id_tree_path('d')
421
        tt.adjust_path('e', parent_trans_id, trans_id)
422
        tt.apply()
423
        return self._convert_tree(tree, converter)
424
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
425
    def assertEqualIterChanges(self, left_changes, right_changes):
426
        """Assert that left_changes == right_changes.
427
428
        :param left_changes: A list of the output from iter_changes.
429
        :param right_changes: A list of the output from iter_changes.
430
        """
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
431
        left_changes = self.sorted(left_changes)
432
        right_changes = self.sorted(right_changes)
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
433
        if left_changes == right_changes:
434
            return
435
        # setify to get item by item differences, but we can only do this
436
        # when all the ids are unique on both sides.
437
        left_dict = dict((item[0], item) for item in left_changes)
438
        right_dict = dict((item[0], item) for item in right_changes)
7143.15.2 by Jelmer Vernooij
Run autopep8.
439
        if (len(left_dict) != len(left_changes)
440
                or len(right_dict) != len(right_changes)):
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
441
            # Can't do a direct comparison. We could do a sequence diff, but
442
            # for now just do a regular assertEqual for now.
443
            self.assertEqual(left_changes, right_changes)
444
        keys = set(left_dict).union(set(right_dict))
445
        different = []
446
        same = []
447
        for key in keys:
448
            left_item = left_dict.get(key)
449
            right_item = right_dict.get(key)
450
            if left_item == right_item:
451
                same.append(str(left_item))
452
            else:
453
                different.append(" %s\n %s" % (left_item, right_item))
7143.15.2 by Jelmer Vernooij
Run autopep8.
454
        self.fail("iter_changes output different. Unchanged items:\n"
455
                  + "\n".join(same) + "\nChanged items:\n" + "\n".join(different))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
456
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
457
    def do_iter_changes(self, tree1, tree2, **extra_args):
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
458
        """Helper to run iter_changes from tree1 to tree2.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
459
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
460
        :param tree1, tree2:  The source and target trees. These will be locked
461
            automatically.
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
462
        :param **extra_args: Extra args to pass to iter_changes. This is not
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
463
            inspected by this test helper.
464
        """
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
465
        with tree1.lock_read(), tree2.lock_read():
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
466
            # sort order of output is not strictly defined
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
467
            return self.sorted(self.intertree_class(tree1, tree2)
7143.15.2 by Jelmer Vernooij
Run autopep8.
468
                               .iter_changes(**extra_args))
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
469
4503.1.3 by Vincent Ladeuil
Take review comments into account.
470
    def check_has_changes(self, expected, tree1, tree2):
471
        # has_changes is defined for mutable trees only
472
        if not isinstance(tree2, mutabletree.MutableTree):
473
            if isinstance(tree1, mutabletree.MutableTree):
474
                # Let's switch the trees since has_changes() is commutative
475
                # (where we can apply it)
476
                tree2, tree1 = tree1, tree2
477
            else:
478
                # Neither tree can be used
479
                return
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
480
        with tree1.lock_read(), tree2.lock_read():
481
            return tree2.has_changes(tree1)
4503.1.1 by Vincent Ladeuil
Add tree.has_changes() to quickly check iter_changes().
482
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
483
    def mutable_trees_to_locked_test_trees(self, tree1, tree2):
484
        """Convert the working trees into test trees.
485
486
        Read lock them, and add the unlock to the cleanup.
487
        """
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
488
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
489
        tree1.lock_read()
490
        self.addCleanup(tree1.unlock)
491
        tree2.lock_read()
492
        self.addCleanup(tree2.unlock)
493
        return tree1, tree2
494
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
495
    def make_tree_with_special_names(self):
496
        """Create a tree with filenames chosen to exercise the walk order."""
497
        tree1 = self.make_branch_and_tree('tree1')
498
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
499
        tree2.set_root_id(tree1.get_root_id())
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
500
        paths, path_ids = self._create_special_names(tree2, 'tree2')
6855.3.1 by Jelmer Vernooij
Several more fixes.
501
        tree2.commit('initial', rev_id=b'rev-1')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
502
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
503
        return (tree1, tree2, paths, path_ids)
504
505
    def make_trees_with_special_names(self):
506
        """Both trees will use the special names.
507
508
        But the contents will differ for each file.
509
        """
510
        tree1 = self.make_branch_and_tree('tree1')
511
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
512
        tree2.set_root_id(tree1.get_root_id())
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
513
        paths, path_ids = self._create_special_names(tree1, 'tree1')
514
        paths, path_ids = self._create_special_names(tree2, 'tree2')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
515
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
516
        return (tree1, tree2, paths, path_ids)
517
518
    def _create_special_names(self, tree, base_path):
519
        """Create a tree with paths that expose differences in sort orders."""
520
        # Each directory will have a single file named 'f' inside
521
        dirs = ['a',
522
                'a-a',
523
                'a/a',
524
                'a/a-a',
525
                'a/a/a',
526
                'a/a/a-a',
527
                'a/a/a/a',
528
                'a/a/a/a-a',
529
                'a/a/a/a/a',
7143.15.2 by Jelmer Vernooij
Run autopep8.
530
                ]
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
531
        with_slashes = []
532
        paths = []
533
        path_ids = []
534
        for d in dirs:
535
            with_slashes.append(base_path + '/' + d + '/')
536
            with_slashes.append(base_path + '/' + d + '/f')
537
            paths.append(d)
7143.15.2 by Jelmer Vernooij
Run autopep8.
538
            paths.append(d + '/f')
6855.3.1 by Jelmer Vernooij
Several more fixes.
539
            path_ids.append((d.replace('/', '_') + '-id').encode('ascii'))
540
            path_ids.append((d.replace('/', '_') + '_f-id').encode('ascii'))
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
541
        self.build_tree(with_slashes)
542
        tree.add(paths, path_ids)
543
        return paths, path_ids
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
544
2012.1.1 by Aaron Bentley
Implement change iterator
545
    def test_compare_empty_trees(self):
546
        tree1 = self.make_branch_and_tree('1')
547
        tree2 = self.make_to_branch_and_tree('2')
548
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
549
        tree2 = self.get_tree_no_parents_no_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
550
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
3254.1.2 by Aaron Bentley
Fix doiter_changes
551
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
552
        self.check_has_changes(False, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
553
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
554
    def added(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
555
        path, entry = self.get_path_entry(tree, file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
556
        return (file_id, (None, path), True, (False, True), (None, entry.parent_id),
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
557
                (None, entry.name), (None, entry.kind),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
558
                (None, entry.executable))
559
3363.14.7 by Aaron Bentley
Get more tests passing
560
    @staticmethod
561
    def get_path_entry(tree, file_id):
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
562
        with tree.lock_read():
563
            path = tree.id2path(file_id)
564
        iterator = tree.iter_entries_by_dir(specific_files=[path])
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
565
        try:
566
            return next(iterator)
567
        except StopIteration:
568
            raise KeyError(file_id)
3363.14.7 by Aaron Bentley
Get more tests passing
569
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
570
    def content_changed(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
571
        path, entry = self.get_path_entry(tree, file_id)
572
        return (file_id, (path, path), True, (True, True),
573
                (entry.parent_id, entry.parent_id),
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
574
                (entry.name, entry.name), (entry.kind, entry.kind),
575
                (entry.executable, entry.executable))
576
577
    def kind_changed(self, from_tree, to_tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
578
        from_path, old_entry = self.get_path_entry(from_tree, file_id)
579
        path, new_entry = self.get_path_entry(to_tree, file_id)
580
        return (file_id, (from_path, path), True, (True, True),
581
                (old_entry.parent_id, new_entry.parent_id),
582
                (old_entry.name, new_entry.name),
583
                (old_entry.kind, new_entry.kind),
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
584
                (old_entry.executable, new_entry.executable))
585
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
586
    def missing(self, file_id, from_path, to_path, parent_id, kind):
587
        _, from_basename = os.path.split(from_path)
588
        _, to_basename = os.path.split(to_path)
589
        # missing files have both paths, but no kind.
590
        return (file_id, (from_path, to_path), True, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
591
                (parent_id, parent_id),
592
                (from_basename, to_basename), (kind, None), (False, False))
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
593
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
594
    def deleted(self, tree, file_id):
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
595
        entry = tree.root_inventory.get_entry(file_id)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
596
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
597
        return (file_id, (path, None), True, (True, False), (entry.parent_id, None),
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
598
                (entry.name, None), (entry.kind, None),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
599
                (entry.executable, None))
600
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
601
    def renamed(self, from_tree, to_tree, file_id, content_changed):
3363.14.8 by Aaron Bentley
Fix more tests
602
        from_path, from_entry = self.get_path_entry(from_tree, file_id)
603
        to_path, to_entry = self.get_path_entry(to_tree, file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
604
        return (file_id, (from_path, to_path), content_changed, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
605
                (from_entry.parent_id, to_entry.parent_id),
606
                (from_entry.name, to_entry.name),
607
                (from_entry.kind, to_entry.kind),
608
                (from_entry.executable, to_entry.executable))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
609
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
610
    def unchanged(self, tree, file_id):
3363.14.8 by Aaron Bentley
Fix more tests
611
        path, entry = self.get_path_entry(tree, file_id)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
612
        parent = entry.parent_id
613
        name = entry.name
614
        kind = entry.kind
615
        executable = entry.executable
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
616
        return (file_id, (path, path), False, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
617
                (parent, parent), (name, name), (kind, kind),
618
                (executable, executable))
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
619
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
620
    def unversioned(self, tree, path):
621
        """Create an unversioned result."""
622
        _, basename = os.path.split(path)
3363.14.7 by Aaron Bentley
Get more tests passing
623
        kind = tree._comparison_data(None, path)[0]
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
624
        return (None, (None, path), True, (False, False), (None, None),
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
625
                (None, basename), (None, kind),
626
                (None, False))
627
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
628
    def sorted(self, changes):
7067.6.2 by Jelmer Vernooij
Move key function to top-level.
629
        return sorted(changes, key=_change_key)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
630
2012.1.1 by Aaron Bentley
Implement change iterator
631
    def test_empty_to_abc_content(self):
632
        tree1 = self.make_branch_and_tree('1')
633
        tree2 = self.make_to_branch_and_tree('2')
634
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
635
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
636
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
637
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
638
            self.added(tree2, b'root-id'),
639
            self.added(tree2, b'a-id'),
640
            self.added(tree2, b'b-id'),
641
            self.added(tree2, b'c-id'),
642
            self.deleted(tree1, b'empty-root-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
643
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
644
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
645
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
646
    def test_empty_specific_files(self):
647
        tree1 = self.make_branch_and_tree('1')
648
        tree2 = self.make_to_branch_and_tree('2')
649
        tree1 = self.get_tree_no_parents_no_content(tree1)
650
        tree2 = self.get_tree_no_parents_abc_content(tree2)
651
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
652
        self.assertEqual([],
7143.15.2 by Jelmer Vernooij
Run autopep8.
653
                         self.do_iter_changes(tree1, tree2, specific_files=[]))
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
654
655
    def test_no_specific_files(self):
656
        tree1 = self.make_branch_and_tree('1')
657
        tree2 = self.make_to_branch_and_tree('2')
658
        tree1 = self.get_tree_no_parents_no_content(tree1)
659
        tree2 = self.get_tree_no_parents_abc_content(tree2)
660
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
661
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
662
            self.added(tree2, b'root-id'),
663
            self.added(tree2, b'a-id'),
664
            self.added(tree2, b'b-id'),
665
            self.added(tree2, b'c-id'),
666
            self.deleted(tree1, b'empty-root-id')])
2796.1.2 by Aaron Bentley
Harmonize test_no_specific_files with test_empty_to_abc_content
667
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
668
        self.check_has_changes(True, tree1, tree2)
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
669
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
670
    def test_empty_to_abc_content_a_only(self):
671
        tree1 = self.make_branch_and_tree('1')
672
        tree2 = self.make_to_branch_and_tree('2')
673
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
674
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
675
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
676
        self.assertEqual(
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
677
            self.sorted([self.added(tree2, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
678
                         self.added(tree2, b'a-id'),
679
                         self.deleted(tree1, b'empty-root-id')]),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
680
            self.do_iter_changes(tree1, tree2, specific_files=['a']))
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
681
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
682
    def test_abc_content_to_empty_a_only(self):
683
        # For deletes we don't need to pickup parents.
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
684
        tree1 = self.make_branch_and_tree('1')
685
        tree2 = self.make_to_branch_and_tree('2')
686
        tree1 = self.get_tree_no_parents_abc_content(tree1)
687
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
688
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
689
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
690
            [self.deleted(tree1, b'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
691
            self.do_iter_changes(tree1, tree2, specific_files=['a']))
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
692
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
693
    def test_abc_content_to_empty_b_only(self):
694
        # When b stops being a directory we have to pick up b/c as well.
695
        tree1 = self.make_branch_and_tree('1')
696
        tree2 = self.make_to_branch_and_tree('2')
697
        tree1 = self.get_tree_no_parents_abc_content(tree1)
698
        tree2 = self.get_tree_no_parents_no_content(tree2)
699
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
700
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
701
            [self.deleted(tree1, b'b-id'), self.deleted(tree1, b'c-id')],
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
702
            self.do_iter_changes(tree1, tree2, specific_files=['b']))
703
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
704
    def test_empty_to_abc_content_a_and_c_only(self):
705
        tree1 = self.make_branch_and_tree('1')
706
        tree2 = self.make_to_branch_and_tree('2')
707
        tree1 = self.get_tree_no_parents_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
708
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
709
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
710
        expected_result = self.sorted([self.added(tree2, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
711
                                       self.added(
712
                                           tree2, b'a-id'), self.added(tree2, b'b-id'),
713
                                       self.added(tree2, b'c-id'), self.deleted(tree1, b'empty-root-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
714
        self.assertEqual(expected_result,
7143.15.2 by Jelmer Vernooij
Run autopep8.
715
                         self.do_iter_changes(tree1, tree2, specific_files=['a', 'b/c']))
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
716
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
717
    def test_abc_content_to_empty(self):
2012.1.1 by Aaron Bentley
Implement change iterator
718
        tree1 = self.make_branch_and_tree('1')
719
        tree2 = self.make_to_branch_and_tree('2')
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
720
        tree1 = self.get_tree_no_parents_abc_content(tree1)
721
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
722
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
723
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
724
            self.added(tree2, b'empty-root-id'),
725
            self.deleted(tree1, b'root-id'), self.deleted(tree1, b'a-id'),
726
            self.deleted(tree1, b'b-id'), self.deleted(tree1, b'c-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
727
        self.assertEqual(
728
            expected_results,
729
            self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
730
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
731
732
    def test_content_modification(self):
733
        tree1 = self.make_branch_and_tree('1')
734
        tree2 = self.make_to_branch_and_tree('2')
735
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
736
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
737
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
738
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
739
        self.assertEqual([(b'a-id', ('a', 'a'), True, (True, True),
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
740
                           (root_id, root_id), ('a', 'a'),
741
                           ('file', 'file'), (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
742
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
743
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
744
745
    def test_meta_modification(self):
746
        tree1 = self.make_branch_and_tree('1')
747
        tree2 = self.make_to_branch_and_tree('2')
748
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
749
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
750
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
6855.3.1 by Jelmer Vernooij
Several more fixes.
751
        self.assertEqual([(b'c-id', ('b/c', 'b/c'), False, (True, True),
752
                           (b'b-id', b'b-id'), ('c', 'c'), ('file', 'file'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
753
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
754
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
755
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
756
    def test_empty_dir(self):
757
        """an empty dir should not cause glitches to surrounding files."""
758
        tree1 = self.make_branch_and_tree('1')
759
        tree2 = self.make_to_branch_and_tree('2')
760
        tree1 = self.get_tree_no_parents_abc_content(tree1)
761
        tree2 = self.get_tree_no_parents_abc_content(tree2)
762
        # the pathname is chosen to fall between 'a' and 'b'.
763
        self.build_tree(['1/a-empty/', '2/a-empty/'])
6973.11.7 by Jelmer Vernooij
Fix more tests.
764
        tree1.add(['a-empty'], [b'a-empty'])
765
        tree2.add(['a-empty'], [b'a-empty'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
766
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
767
        expected = []
768
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
769
2012.1.1 by Aaron Bentley
Implement change iterator
770
    def test_file_rename(self):
771
        tree1 = self.make_branch_and_tree('1')
772
        tree2 = self.make_to_branch_and_tree('2')
773
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
774
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
775
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
776
        root_id = tree1.path2id('')
6821.2.1 by Jelmer Vernooij
Fix tests.
777
        self.assertEqual([(tree1.path2id('a'), ('a', 'd'), False, (True, True),
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
778
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
779
                           (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
780
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
781
782
    def test_file_rename_and_modification(self):
783
        tree1 = self.make_branch_and_tree('1')
784
        tree2 = self.make_to_branch_and_tree('2')
785
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
786
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
787
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
788
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
789
        self.assertEqual([(b'a-id', ('a', 'd'), True, (True, True),
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
790
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
791
                           (False, False))],
792
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
793
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
794
    def test_specific_content_modification_grabs_parents(self):
795
        # WHen the only direct change to a specified file is a content change,
796
        # and its in a reparented subtree, the parents are grabbed.
797
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
798
        tree1.mkdir('changing', b'parent-id')
799
        tree1.mkdir('changing/unchanging', b'mid-id')
800
        tree1.add(['changing/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
801
        tree1.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
802
            'changing/unchanging/file', b'a file', file_id=b'file-id')
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
803
        tree2 = self.make_to_branch_and_tree('2')
804
        tree2.set_root_id(tree1.get_root_id())
6855.4.1 by Jelmer Vernooij
Yet more bees.
805
        tree2.mkdir('changed', b'parent-id')
806
        tree2.mkdir('changed/unchanging', b'mid-id')
807
        tree2.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
808
        tree2.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
809
            'changed/unchanging/file', b'changed content', file_id=b'file-id')
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
810
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
811
        # parent-id has changed, as has file-id
812
        root_id = tree1.path2id('')
813
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
814
            [self.renamed(tree1, tree2, b'parent-id', False),
815
             self.renamed(tree1, tree2, b'file-id', True)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
816
            self.do_iter_changes(tree1, tree2,
817
                                 specific_files=['changed/unchanging/file']))
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
818
819
    def test_specific_content_modification_grabs_parents_root_changes(self):
820
        # WHen the only direct change to a specified file is a content change,
821
        # and its in a reparented subtree, the parents are grabbed, even if
822
        # that includes the root.
823
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
824
        tree1.set_root_id(b'old')
825
        tree1.mkdir('changed', b'parent-id')
826
        tree1.mkdir('changed/unchanging', b'mid-id')
827
        tree1.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
828
        tree1.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
829
            'changed/unchanging/file', b'a file',
830
            b'file-id')
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
831
        tree2 = self.make_to_branch_and_tree('2')
6855.4.1 by Jelmer Vernooij
Yet more bees.
832
        tree2.set_root_id(b'new')
833
        tree2.mkdir('changed', b'parent-id')
834
        tree2.mkdir('changed/unchanging', b'mid-id')
835
        tree2.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
836
        tree2.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
837
            'changed/unchanging/file', b'changed content', file_id=b'file-id')
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
838
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
839
        # old is gone, new is added, parent-id has changed(reparented), as has
840
        # file-id(content)
841
        root_id = tree1.path2id('')
842
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
843
            [self.renamed(tree1, tree2, b'parent-id', False),
844
             self.added(tree2, b'new'),
845
             self.deleted(tree1, b'old'),
846
             self.renamed(tree1, tree2, b'file-id', True)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
847
            self.do_iter_changes(tree1, tree2,
848
                                 specific_files=['changed/unchanging/file']))
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
849
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
850
    def test_specific_with_rename_under_new_dir_reports_new_dir(self):
851
        tree1 = self.make_branch_and_tree('1')
852
        tree2 = self.make_to_branch_and_tree('2')
853
        tree1 = self.get_tree_no_parents_abc_content(tree1)
854
        tree2 = self.get_tree_no_parents_abc_content_7(tree2)
855
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
7143.15.2 by Jelmer Vernooij
Run autopep8.
856
        # d(d-id) is new, e is b-id renamed.
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
857
        root_id = tree1.path2id('')
858
        self.assertEqualIterChanges(
6855.3.1 by Jelmer Vernooij
Several more fixes.
859
            [self.renamed(tree1, tree2, b'b-id', False),
860
             self.added(tree2, b'd-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
861
            self.do_iter_changes(tree1, tree2, specific_files=['d/e']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
862
863
    def test_specific_with_rename_under_dir_under_new_dir_reports_new_dir(self):
864
        tree1 = self.make_branch_and_tree('1')
865
        tree2 = self.make_to_branch_and_tree('2')
866
        tree1 = self.get_tree_no_parents_abc_content(tree1)
867
        tree2 = self.get_tree_no_parents_abc_content_7(tree2)
868
        tree2.rename_one('a', 'd/e/a')
869
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
7143.15.2 by Jelmer Vernooij
Run autopep8.
870
        # d is new, d/e is b-id renamed, d/e/a is a-id renamed
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
871
        root_id = tree1.path2id('')
872
        self.assertEqualIterChanges(
6821.2.1 by Jelmer Vernooij
Fix tests.
873
            [self.renamed(tree1, tree2, tree1.path2id('b'), False),
6855.3.1 by Jelmer Vernooij
Several more fixes.
874
             self.added(tree2, b'd-id'),
875
             self.renamed(tree1, tree2, b'a-id', False)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
876
            self.do_iter_changes(tree1, tree2, specific_files=['d/e/a']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
877
878
    def test_specific_old_parent_same_path_new_parent(self):
879
        # when a parent is new at its path, if the path was used in the source
880
        # it must be emitted as a change.
881
        tree1 = self.make_branch_and_tree('1')
6855.3.1 by Jelmer Vernooij
Several more fixes.
882
        tree1.add(['a'], [b'a-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
883
        tree1.put_file_bytes_non_atomic('a', b'a file')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
884
        tree2 = self.make_to_branch_and_tree('2')
885
        tree2.set_root_id(tree1.get_root_id())
6855.3.1 by Jelmer Vernooij
Several more fixes.
886
        tree2.mkdir('a', b'b-id')
887
        tree2.add(['a/c'], [b'c-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
888
        tree2.put_file_bytes_non_atomic('a/c', b'another file')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
889
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
890
        # a-id is gone, b-id and c-id are added.
891
        self.assertEqualIterChanges(
6855.3.1 by Jelmer Vernooij
Several more fixes.
892
            [self.deleted(tree1, b'a-id'),
893
             self.added(tree2, b'b-id'),
894
             self.added(tree2, b'c-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
895
            self.do_iter_changes(tree1, tree2, specific_files=['a/c']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
896
897
    def test_specific_old_parent_becomes_file(self):
898
        # When an old parent included because of a path conflict becomes a
899
        # non-directory, its children have to be all included in the delta.
900
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
901
        tree1.mkdir('a', b'a-old-id')
902
        tree1.mkdir('a/reparented', b'reparented-id')
903
        tree1.mkdir('a/deleted', b'deleted-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
904
        tree2 = self.make_to_branch_and_tree('2')
905
        tree2.set_root_id(tree1.get_root_id())
6855.4.1 by Jelmer Vernooij
Yet more bees.
906
        tree2.mkdir('a', b'a-new-id')
907
        tree2.mkdir('a/reparented', b'reparented-id')
908
        tree2.add(['b'], [b'a-old-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
909
        tree2.put_file_bytes_non_atomic('b', b'')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
910
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
911
        # a-old-id is kind-changed, a-new-id is added, reparented-id is renamed,
912
        # deleted-id is gone
913
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
914
            [self.kind_changed(tree1, tree2, b'a-old-id'),
915
             self.added(tree2, b'a-new-id'),
916
             self.renamed(tree1, tree2, b'reparented-id', False),
917
             self.deleted(tree1, b'deleted-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
918
            self.do_iter_changes(tree1, tree2,
919
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
920
921
    def test_specific_old_parent_is_deleted(self):
922
        # When an old parent included because of a path conflict is removed,
923
        # its children have to be all included in the delta.
924
        tree1 = self.make_branch_and_tree('1')
7045.2.9 by Jelmer Vernooij
Fix some foreign branch tests.
925
        tree1.mkdir('a', b'a-old-id')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
926
        tree1.mkdir('a/reparented', b'reparented-id')
927
        tree1.mkdir('a/deleted', b'deleted-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
928
        tree2 = self.make_to_branch_and_tree('2')
929
        tree2.set_root_id(tree1.get_root_id())
6973.13.2 by Jelmer Vernooij
Fix some more tests.
930
        tree2.mkdir('a', b'a-new-id')
931
        tree2.mkdir('a/reparented', b'reparented-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
932
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
933
        # a-old-id is gone, a-new-id is added, reparented-id is renamed,
934
        # deleted-id is gone
935
        self.assertEqualIterChanges(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
936
            [self.deleted(tree1, b'a-old-id'),
937
             self.added(tree2, b'a-new-id'),
938
             self.renamed(tree1, tree2, b'reparented-id', False),
939
             self.deleted(tree1, b'deleted-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
940
            self.do_iter_changes(tree1, tree2,
941
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
942
943
    def test_specific_old_parent_child_collides_with_unselected_new(self):
944
        # When the child of an old parent because of a path conflict becomes a
945
        # path conflict with some unselected item in the source, that item also
946
        # needs to be included (because otherwise the output of applying the
947
        # delta to the source would have two items at that path).
948
        tree1 = self.make_branch_and_tree('1')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
949
        tree1.mkdir('a', b'a-old-id')
950
        tree1.mkdir('a/reparented', b'reparented-id')
951
        tree1.mkdir('collides', b'collides-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
952
        tree2 = self.make_to_branch_and_tree('2')
953
        tree2.set_root_id(tree1.get_root_id())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
954
        tree2.mkdir('a', b'a-new-id')
955
        tree2.mkdir('a/selected', b'selected-id')
956
        tree2.mkdir('collides', b'reparented-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
957
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
958
        # a-old-id is one, a-new-id is added, reparented-id is renamed,
959
        # collides-id is gone, selected-id is new.
960
        self.assertEqualIterChanges(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
961
            [self.deleted(tree1, b'a-old-id'),
962
             self.added(tree2, b'a-new-id'),
963
             self.renamed(tree1, tree2, b'reparented-id', False),
964
             self.deleted(tree1, b'collides-id'),
965
             self.added(tree2, b'selected-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
966
            self.do_iter_changes(tree1, tree2,
967
                                 specific_files=['a/selected']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
968
969
    def test_specific_old_parent_child_dir_stops_being_dir(self):
970
        # When the child of an old parent also stops being a directory, its
971
        # children must also be included. This test checks that downward
972
        # recursion is done appropriately by starting at a child of the root of
973
        # a deleted subtree (a/reparented), and checking that a sibling
974
        # directory (a/deleted) has its children included in the delta.
975
        tree1 = self.make_branch_and_tree('1')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
976
        tree1.mkdir('a', b'a-old-id')
977
        tree1.mkdir('a/reparented', b'reparented-id-1')
978
        tree1.mkdir('a/deleted', b'deleted-id-1')
979
        tree1.mkdir('a/deleted/reparented', b'reparented-id-2')
980
        tree1.mkdir('a/deleted/deleted', b'deleted-id-2')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
981
        tree2 = self.make_to_branch_and_tree('2')
982
        tree2.set_root_id(tree1.get_root_id())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
983
        tree2.mkdir('a', b'a-new-id')
984
        tree2.mkdir('a/reparented', b'reparented-id-1')
985
        tree2.mkdir('reparented', b'reparented-id-2')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
986
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
987
        # a-old-id is gone, a-new-id is added, reparented-id-1, -2 are renamed,
988
        # deleted-id-1 and -2 are gone.
989
        self.assertEqualIterChanges(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
990
            [self.deleted(tree1, b'a-old-id'),
991
             self.added(tree2, b'a-new-id'),
992
             self.renamed(tree1, tree2, b'reparented-id-1', False),
993
             self.renamed(tree1, tree2, b'reparented-id-2', False),
994
             self.deleted(tree1, b'deleted-id-1'),
995
             self.deleted(tree1, b'deleted-id-2')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
996
            self.do_iter_changes(tree1, tree2,
997
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
998
2012.1.1 by Aaron Bentley
Implement change iterator
999
    def test_file_rename_and_meta_modification(self):
1000
        tree1 = self.make_branch_and_tree('1')
1001
        tree2 = self.make_to_branch_and_tree('2')
1002
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
1003
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1004
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
1005
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1006
        self.assertEqual([(b'c-id', ('b/c', 'e'), False, (True, True),
1007
                           (b'b-id', root_id), ('c', 'e'), ('file', 'file'),
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1008
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
1009
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
1010
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1011
    def test_file_becomes_unversionable_bug_438569(self):
1012
        # This isn't strictly a intertree problem, but its the intertree code
1013
        # path that triggers all stat cache updates on both xml and dirstate
1014
        # trees.
1015
        # In bug 438569, a file becoming a fifo causes an assert. Fifo's are
1016
        # not versionable or diffable. For now, we simply stop cold when they
7143.15.2 by Jelmer Vernooij
Run autopep8.
1017
        # are detected (because we don't know how far through the code the
1018
        # assumption 'fifo's do not exist' goes). In future we could report
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1019
        # the kind change and have commit refuse to go futher, or something
1020
        # similar. One particular reason for choosing this approach is that
7143.15.2 by Jelmer Vernooij
Run autopep8.
1021
        # there is no minikind for 'fifo' in dirstate today, so we can't
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1022
        # actually update records that way.
1023
        # To add confusion, the totally generic code path works - but it
1024
        # doesn't update persistent metadata. So this test permits InterTrees
1025
        # to either work, or fail with BadFileKindError.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1026
        self.requireFeature(features.OsFifoFeature)
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1027
        tree1 = self.make_branch_and_tree('1')
1028
        self.build_tree(['1/a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1029
        tree1.set_root_id(b'root-id')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1030
        tree1.add(['a'], [b'a-id'])
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1031
        tree2 = self.make_branch_and_tree('2')
1032
        os.mkfifo('2/a')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1033
        tree2.add(['a'], [b'a-id'], ['file'])
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1034
        try:
1035
            tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1036
        except (KeyError,):
1037
            raise tests.TestNotApplicable(
1038
                "Cannot represent a FIFO in this case %s" % self.id())
1039
        try:
1040
            self.do_iter_changes(tree1, tree2)
4634.58.2 by Robert Collins
Review feedback.
1041
        except errors.BadFileKindError:
1042
            pass
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1043
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
1044
    def test_missing_in_target(self):
1045
        """Test with the target files versioned but absent from disk."""
1046
        tree1 = self.make_branch_and_tree('1')
1047
        tree2 = self.make_to_branch_and_tree('2')
1048
        tree1 = self.get_tree_no_parents_abc_content(tree1)
1049
        tree2 = self.get_tree_no_parents_abc_content(tree2)
1050
        os.unlink('2/a')
1051
        shutil.rmtree('2/b')
1052
        # TODO ? have a symlink here?
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1053
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1054
        self.not_applicable_if_missing_in('a', tree2)
1055
        self.not_applicable_if_missing_in('b', tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1056
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1057
            self.missing(b'a-id', 'a', 'a', b'root-id', 'file'),
1058
            self.missing(b'b-id', 'b', 'b', b'root-id', 'directory'),
1059
            self.missing(b'c-id', 'b/c', 'b/c', b'b-id', 'file'),
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1060
            ])
1061
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1062
1063
    def test_missing_and_renamed(self):
1064
        tree1 = self.make_branch_and_tree('tree1')
1065
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
1066
        tree2.set_root_id(tree1.get_root_id())
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1067
        self.build_tree(['tree1/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1068
        tree1.add(['file'], [b'file-id'])
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1069
        self.build_tree(['tree2/directory/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1070
        tree2.add(['directory'], [b'file-id'])
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1071
        os.rmdir('tree2/directory')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1072
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1073
        self.not_applicable_if_missing_in('directory', tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1074
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1075
        root_id = tree1.path2id('')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1076
        expected = self.sorted([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1077
            self.missing(b'file-id', 'file', 'directory', root_id, 'file'),
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
1078
            ])
1079
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1080
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1081
    def test_only_in_source_and_missing(self):
1082
        tree1 = self.make_branch_and_tree('tree1')
1083
        tree2 = self.make_to_branch_and_tree('tree2')
1084
        tree2.set_root_id(tree1.get_root_id())
1085
        self.build_tree(['tree1/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1086
        tree1.add(['file'], [b'file-id'])
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1087
        os.unlink('tree1/file')
1088
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1089
        self.not_applicable_if_missing_in('file', tree1)
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1090
        root_id = tree1.path2id('')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1091
        expected = [(b'file-id', ('file', None), False, (True, False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1092
                     (root_id, None), ('file', None), (None, None), (False, None))]
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1093
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1094
1095
    def test_only_in_target_and_missing(self):
1096
        tree1 = self.make_branch_and_tree('tree1')
1097
        tree2 = self.make_to_branch_and_tree('tree2')
1098
        tree2.set_root_id(tree1.get_root_id())
1099
        self.build_tree(['tree2/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1100
        tree2.add(['file'], [b'file-id'])
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1101
        os.unlink('tree2/file')
1102
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1103
        self.not_applicable_if_missing_in('file', tree2)
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1104
        root_id = tree1.path2id('')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1105
        expected = [(b'file-id', (None, 'file'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1106
                     (None, root_id), (None, 'file'), (None, None), (None, False))]
3619.4.1 by Robert Collins
Improve tests for the behaviour of Tree.iter_changes for missing paths that are only present in one tree, and fix found bugs. (Robert Collins)
1107
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1108
4544.2.1 by Robert Collins
Add interface enforcement for the behaviour of iter_changes with missing subtrees with explicit paths - the whole subtree is returned.
1109
    def test_only_in_target_missing_subtree_specific_bug_367632(self):
1110
        tree1 = self.make_branch_and_tree('tree1')
1111
        tree2 = self.make_to_branch_and_tree('tree2')
1112
        tree2.set_root_id(tree1.get_root_id())
1113
        self.build_tree(['tree2/a-dir/', 'tree2/a-dir/a-file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1114
        tree2.add(['a-dir', 'a-dir/a-file'], [b'dir-id', b'file-id'])
4544.2.1 by Robert Collins
Add interface enforcement for the behaviour of iter_changes with missing subtrees with explicit paths - the whole subtree is returned.
1115
        os.unlink('tree2/a-dir/a-file')
1116
        os.rmdir('tree2/a-dir')
1117
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1118
        self.not_applicable_if_missing_in('a-dir', tree2)
1119
        root_id = tree1.path2id('')
1120
        expected = [
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1121
            (b'dir-id', (None, 'a-dir'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1122
             (None, root_id), (None, 'a-dir'), (None, None), (None, False)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1123
            (b'file-id', (None, 'a-dir/a-file'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1124
             (None, b'dir-id'), (None, 'a-file'), (None, None), (None, False))
4544.2.1 by Robert Collins
Add interface enforcement for the behaviour of iter_changes with missing subtrees with explicit paths - the whole subtree is returned.
1125
            ]
1126
        # bug 367632 showed that specifying the root broke some code paths,
1127
        # so we check this contract with and without it.
1128
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1129
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1130
                         self.do_iter_changes(tree1, tree2, specific_files=['']))
4544.2.1 by Robert Collins
Add interface enforcement for the behaviour of iter_changes with missing subtrees with explicit paths - the whole subtree is returned.
1131
2012.1.1 by Aaron Bentley
Implement change iterator
1132
    def test_unchanged_with_renames_and_modifications(self):
1133
        """want_unchanged should generate a list of unchanged entries."""
1134
        tree1 = self.make_branch_and_tree('1')
1135
        tree2 = self.make_to_branch_and_tree('2')
1136
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
1137
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1138
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1139
        self.assertEqual(sorted([self.unchanged(tree1, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1140
                                 self.unchanged(tree1, b'b-id'),
1141
                                 (b'a-id', ('a', 'd'), True, (True, True),
1142
                                  (b'root-id', b'root-id'), ('a',
1143
                                                             'd'), ('file', 'file'),
1144
                                  (False, False)), self.unchanged(tree1, b'c-id')]),
1145
                         self.do_iter_changes(tree1, tree2, include_unchanged=True))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1146
1147
    def test_compare_subtrees(self):
1148
        tree1 = self.make_branch_and_tree('1')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
1149
        if not tree1.supports_tree_reference():
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1150
            return
6855.3.1 by Jelmer Vernooij
Several more fixes.
1151
        tree1.set_root_id(b'root-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1152
        subtree1 = self.make_branch_and_tree('1/sub')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1153
        subtree1.set_root_id(b'subtree-id')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
1154
        tree1.add_reference(subtree1)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1155
1156
        tree2 = self.make_to_branch_and_tree('2')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
1157
        if not tree2.supports_tree_reference():
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1158
            return
6855.3.1 by Jelmer Vernooij
Several more fixes.
1159
        tree2.set_root_id(b'root-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1160
        subtree2 = self.make_to_branch_and_tree('2/sub')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1161
        subtree2.set_root_id(b'subtree-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1162
        tree2.add_reference(subtree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1163
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1164
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
1165
        self.assertEqual([], list(tree2.iter_changes(tree1)))
6855.3.1 by Jelmer Vernooij
Several more fixes.
1166
        subtree1.commit('commit', rev_id=b'commit-a')
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1167
        self.assertEqual([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1168
            (b'root-id',
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1169
             (u'', u''),
1170
             False,
1171
             (True, True),
1172
             (None, None),
1173
             (u'', u''),
1174
             ('directory', 'directory'),
1175
             (False, False)),
6855.3.1 by Jelmer Vernooij
Several more fixes.
1176
            (b'subtree-id',
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1177
             ('sub', 'sub',),
1178
             False,
1179
             (True, True),
6855.3.1 by Jelmer Vernooij
Several more fixes.
1180
             (b'root-id', b'root-id'),
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1181
             ('sub', 'sub'),
1182
             ('tree-reference', 'tree-reference'),
1183
             (False, False))],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1184
            list(tree2.iter_changes(tree1,
1185
                                    include_unchanged=True)))
2255.2.160 by Martin Pool
(merge) updates from dirstate branch
1186
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1187
    def test_disk_in_subtrees_skipped(self):
1188
        """subtrees are considered not-in-the-current-tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1189
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1190
        This test tests the trivial case, where the basis has no paths in the
1191
        current trees subtree.
1192
        """
1193
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1194
        tree1.set_root_id(b'root-id')
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1195
        tree2 = self.make_to_branch_and_tree('2')
1196
        if not tree2.supports_tree_reference():
1197
            return
6855.4.1 by Jelmer Vernooij
Yet more bees.
1198
        tree2.set_root_id(b'root-id')
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1199
        subtree2 = self.make_to_branch_and_tree('2/sub')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1200
        subtree2.set_root_id(b'subtree-id')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
1201
        tree2.add_reference(subtree2)
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1202
        self.build_tree(['2/sub/file'])
1203
        subtree2.add(['file'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1204
1205
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1206
        # this should filter correctly from above
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1207
        self.assertEqual([self.added(tree2, b'subtree-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1208
                         self.do_iter_changes(tree1, tree2, want_unversioned=True))
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1209
        # and when the path is named
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1210
        self.assertEqual([self.added(tree2, b'subtree-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1211
                         self.do_iter_changes(tree1, tree2, specific_files=['sub'],
1212
                                              want_unversioned=True))
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1213
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1214
    def test_default_ignores_unversioned_files(self):
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
1215
        tree1 = self.make_branch_and_tree('tree1')
1216
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
1217
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1218
        self.build_tree(['tree1/a', 'tree1/c',
1219
                         'tree2/a', 'tree2/b', 'tree2/c'])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1220
        tree1.add(['a', 'c'], [b'a-id', b'c-id'])
1221
        tree2.add(['a', 'c'], [b'a-id', b'c-id'])
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1222
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1223
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1224
1225
        # We should ignore the fact that 'b' exists in tree-2
1226
        # because the want_unversioned parameter was not given.
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1227
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1228
            self.content_changed(tree2, b'a-id'),
1229
            self.content_changed(tree2, b'c-id'),
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1230
            ])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
1231
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1232
        self.check_has_changes(True, tree1, tree2)
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
1233
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1234
    def test_unversioned_paths_in_tree(self):
1235
        tree1 = self.make_branch_and_tree('tree1')
1236
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
1237
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1238
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1239
        if has_symlinks():
1240
            os.symlink('target', 'tree2/link')
1241
            links_supported = True
1242
        else:
1243
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1244
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1245
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1246
        expected = [
1247
            self.unversioned(tree2, 'file'),
1248
            self.unversioned(tree2, 'dir'),
1249
            ]
1250
        if links_supported:
1251
            expected.append(self.unversioned(tree2, 'link'))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1252
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1253
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1254
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1255
1256
    def test_unversioned_paths_in_tree_specific_files(self):
1257
        tree1 = self.make_branch_and_tree('tree1')
1258
        tree2 = self.make_to_branch_and_tree('tree2')
1259
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1260
        if has_symlinks():
1261
            os.symlink('target', 'tree2/link')
1262
            links_supported = True
1263
        else:
1264
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1265
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1266
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1267
        expected = [
1268
            self.unversioned(tree2, 'file'),
1269
            self.unversioned(tree2, 'dir'),
1270
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1271
        specific_files = ['file', 'dir']
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1272
        if links_supported:
1273
            expected.append(self.unversioned(tree2, 'link'))
1274
            specific_files.append('link')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1275
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1276
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1277
                                                        specific_files=specific_files, require_versioned=False,
1278
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1279
1280
    def test_unversioned_paths_in_target_matching_source_old_names(self):
1281
        # its likely that naive implementations of unversioned file support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1282
        # will fail if the path was versioned, but is not any more,
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1283
        # due to a rename, not due to unversioning it.
1284
        # That is, if the old tree has a versioned file 'foo', and
1285
        # the new tree has the same file but versioned as 'bar', and also
1286
        # has an unknown file 'foo', we should get back output for
1287
        # both foo and bar.
1288
        tree1 = self.make_branch_and_tree('tree1')
1289
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.187 by Martin Pool
set common root ids in more tests
1290
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1291
        self.build_tree(['tree2/file', 'tree2/dir/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1292
                         'tree1/file', 'tree2/movedfile',
1293
                         'tree1/dir/', 'tree2/moveddir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1294
        if has_symlinks():
1295
            os.symlink('target', 'tree1/link')
1296
            os.symlink('target', 'tree2/link')
1297
            os.symlink('target', 'tree2/movedlink')
1298
            links_supported = True
1299
        else:
1300
            links_supported = False
6855.4.1 by Jelmer Vernooij
Yet more bees.
1301
        tree1.add(['file', 'dir'], [b'file-id', b'dir-id'])
1302
        tree2.add(['movedfile', 'moveddir'], [b'file-id', b'dir-id'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1303
        if links_supported:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1304
            tree1.add(['link'], [b'link-id'])
1305
            tree2.add(['movedlink'], [b'link-id'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1306
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1307
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1308
        root_id = tree1.path2id('')
1309
        expected = [
6855.4.1 by Jelmer Vernooij
Yet more bees.
1310
            self.renamed(tree1, tree2, b'dir-id', False),
1311
            self.renamed(tree1, tree2, b'file-id', True),
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1312
            self.unversioned(tree2, 'file'),
1313
            self.unversioned(tree2, 'dir'),
1314
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1315
        specific_files = ['file', 'dir']
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1316
        if links_supported:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1317
            expected.append(self.renamed(tree1, tree2, b'link-id', False))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1318
            expected.append(self.unversioned(tree2, 'link'))
1319
            specific_files.append('link')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1320
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1321
        # run once with, and once without specific files, to catch
1322
        # potentially different code paths.
1323
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1324
                                                        require_versioned=False,
1325
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1326
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1327
                                                        specific_files=specific_files, require_versioned=False,
1328
                                                        want_unversioned=True))
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1329
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1330
    def test_similar_filenames(self):
1331
        """Test when we have a few files with similar names."""
1332
        tree1 = self.make_branch_and_tree('tree1')
1333
        tree2 = self.make_branch_and_tree('tree2')
1334
        tree2.set_root_id(tree1.get_root_id())
1335
1336
        # The trees are actually identical, but they happen to contain
1337
        # similarly named files.
1338
        self.build_tree(['tree1/a/',
1339
                         'tree1/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1340
                         'tree1/a/b/c/',
1341
                         'tree1/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1342
                         'tree1/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1343
                         'tree1/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1344
                         'tree2/a/',
1345
                         'tree2/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1346
                         'tree2/a/b/c/',
1347
                         'tree2/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1348
                         'tree2/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1349
                         'tree2/a-c/e/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1350
                         ])
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1351
        tree1.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1352
                  [b'a-id', b'b-id', b'c-id', b'd-id', b'a-c-id', b'e-id'])
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1353
        tree2.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1354
                  [b'a-id', b'b-id', b'c-id', b'd-id', b'a-c-id', b'e-id'])
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1355
1356
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1357
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1358
1359
        self.assertEqual([], self.do_iter_changes(tree1, tree2,
1360
                                                  want_unversioned=True))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1361
        expected = self.sorted([
2466.5.2 by John Arbash Meinel
Extend the test a bit to make sure the include_unchanged value is correct.
1362
            self.unchanged(tree2, tree2.get_root_id()),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1363
            self.unchanged(tree2, b'a-id'),
1364
            self.unchanged(tree2, b'b-id'),
1365
            self.unchanged(tree2, b'c-id'),
1366
            self.unchanged(tree2, b'd-id'),
1367
            self.unchanged(tree2, b'a-c-id'),
1368
            self.unchanged(tree2, b'e-id'),
2466.5.2 by John Arbash Meinel
Extend the test a bit to make sure the include_unchanged value is correct.
1369
            ])
1370
        self.assertEqual(expected,
1371
                         self.do_iter_changes(tree1, tree2,
1372
                                              want_unversioned=True,
1373
                                              include_unchanged=True))
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1374
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1375
    def test_unversioned_subtree_only_emits_root(self):
1376
        tree1 = self.make_branch_and_tree('tree1')
1377
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.188 by Martin Pool
Set common root id in comparison tests
1378
        tree2.set_root_id(tree1.get_root_id())
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1379
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1380
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1381
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1382
        expected = [
1383
            self.unversioned(tree2, 'dir'),
1384
            ]
1385
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1386
                                                        want_unversioned=True))
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1387
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1388
    def make_trees_with_symlinks(self):
1389
        tree1 = self.make_branch_and_tree('tree1')
1390
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
1391
        tree2.set_root_id(tree1.get_root_id())
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1392
        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
1393
        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
1394
        os.symlink('original', 'tree1/changed')
1395
        os.symlink('original', 'tree1/removed')
1396
        os.symlink('original', 'tree1/tofile')
1397
        os.symlink('original', 'tree1/todir')
1398
        # we make the unchanged link point at unknown to catch incorrect
1399
        # symlink-following code in the specified_files test.
1400
        os.symlink('unknown', 'tree1/unchanged')
7143.15.2 by Jelmer Vernooij
Run autopep8.
1401
        os.symlink('new', 'tree2/added')
1402
        os.symlink('new', 'tree2/changed')
1403
        os.symlink('new', 'tree2/fromfile')
1404
        os.symlink('new', 'tree2/fromdir')
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1405
        os.symlink('unknown', 'tree2/unchanged')
1406
        from_paths_and_ids = [
1407
            'fromdir',
1408
            'fromfile',
1409
            'changed',
1410
            'removed',
1411
            'todir',
1412
            'tofile',
1413
            'unchanged',
1414
            ]
1415
        to_paths_and_ids = [
1416
            'added',
1417
            'fromdir',
1418
            'fromfile',
1419
            'changed',
1420
            'todir',
1421
            'tofile',
1422
            'unchanged',
1423
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1424
        tree1.add(from_paths_and_ids, [p.encode('utf-8')
1425
                                       for p in from_paths_and_ids])
1426
        tree2.add(to_paths_and_ids, [p.encode('utf-8')
1427
                                     for p in to_paths_and_ids])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1428
        return self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1429
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1430
    def test_versioned_symlinks(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1431
        self.requireFeature(features.SymlinkFeature)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1432
        tree1, tree2 = self.make_trees_with_symlinks()
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1433
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1434
        root_id = tree1.path2id('')
1435
        expected = [
1436
            self.unchanged(tree1, tree1.path2id('')),
7045.1.18 by Jelmer Vernooij
Fix another test.
1437
            self.added(tree2, b'added'),
7058.4.1 by Jelmer Vernooij
Fix another 40 tests.
1438
            self.content_changed(tree2, b'changed'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1439
            self.kind_changed(tree1, tree2, b'fromdir'),
1440
            self.kind_changed(tree1, tree2, b'fromfile'),
1441
            self.deleted(tree1, b'removed'),
1442
            self.unchanged(tree2, b'unchanged'),
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1443
            self.unversioned(tree2, 'unknown'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1444
            self.kind_changed(tree1, tree2, b'todir'),
1445
            self.kind_changed(tree1, tree2, b'tofile'),
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1446
            ]
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1447
        expected = self.sorted(expected)
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1448
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1449
                         self.do_iter_changes(tree1, tree2, include_unchanged=True,
1450
                                              want_unversioned=True))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1451
        self.check_has_changes(True, tree1, tree2)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1452
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1453
    def test_versioned_symlinks_specific_files(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1454
        self.requireFeature(features.SymlinkFeature)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1455
        tree1, tree2 = self.make_trees_with_symlinks()
1456
        root_id = tree1.path2id('')
1457
        expected = [
7045.1.18 by Jelmer Vernooij
Fix another test.
1458
            self.added(tree2, b'added'),
7058.4.1 by Jelmer Vernooij
Fix another 40 tests.
1459
            self.content_changed(tree2, b'changed'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1460
            self.kind_changed(tree1, tree2, b'fromdir'),
1461
            self.kind_changed(tree1, tree2, b'fromfile'),
1462
            self.deleted(tree1, b'removed'),
1463
            self.kind_changed(tree1, tree2, b'todir'),
1464
            self.kind_changed(tree1, tree2, b'tofile'),
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1465
            ]
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1466
        expected = self.sorted(expected)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1467
        # we should get back just the changed links. We pass in 'unchanged' to
1468
        # make sure that it is correctly not returned - and neither is the
1469
        # unknown path 'unknown' which it points at.
1470
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1471
                                                        specific_files=['added', 'changed', 'fromdir', 'fromfile',
1472
                                                                        'removed', 'unchanged', 'todir', 'tofile']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1473
        self.check_has_changes(True, tree1, tree2)
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
1474
2255.7.21 by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to
1475
    def test_tree_with_special_names(self):
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
1476
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1477
        expected = self.sorted(self.added(tree2, f_id) for f_id in path_ids)
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
1478
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1479
        self.check_has_changes(True, tree1, tree2)
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
1480
1481
    def test_trees_with_special_names(self):
1482
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1483
        expected = self.sorted(self.content_changed(tree2, f_id) for f_id in path_ids
7143.15.2 by Jelmer Vernooij
Run autopep8.
1484
                               if f_id.endswith(b'_f-id'))
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
1485
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1486
        self.check_has_changes(True, tree1, tree2)
2255.7.34 by John Arbash Meinel
Clean up test_bad_files, and fix a bug in _iter_changes when
1487
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1488
    def test_trees_with_deleted_dir(self):
2255.7.35 by John Arbash Meinel
Handle the case when a directory has been removed, and isn't the last entry.
1489
        tree1 = self.make_branch_and_tree('tree1')
1490
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
1491
        tree2.set_root_id(tree1.get_root_id())
2255.7.35 by John Arbash Meinel
Handle the case when a directory has been removed, and isn't the last entry.
1492
        self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',
1493
                         'tree1/b/d/', 'tree1/b/d/e', 'tree1/f/', 'tree1/f/g',
1494
                         'tree2/a', 'tree2/f/', 'tree2/f/g'])
1495
        tree1.add(['a', 'b', 'b/c', 'b/d/', 'b/d/e', 'f', 'f/g'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
1496
                  [b'a-id', b'b-id', b'c-id', b'd-id', b'e-id', b'f-id', b'g-id'])
1497
        tree2.add(['a', 'f', 'f/g'], [b'a-id', b'f-id', b'g-id'])
2255.7.35 by John Arbash Meinel
Handle the case when a directory has been removed, and isn't the last entry.
1498
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1499
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1500
        # We should notice that 'b' and all its children are deleted
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1501
        expected = [
6855.4.1 by Jelmer Vernooij
Yet more bees.
1502
            self.content_changed(tree2, b'a-id'),
1503
            self.content_changed(tree2, b'g-id'),
1504
            self.deleted(tree1, b'b-id'),
1505
            self.deleted(tree1, b'c-id'),
1506
            self.deleted(tree1, b'd-id'),
1507
            self.deleted(tree1, b'e-id'),
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1508
            ]
1509
        self.assertEqualIterChanges(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1510
                                    self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1511
        self.check_has_changes(True, tree1, tree2)
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1512
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1513
    def test_added_unicode(self):
1514
        tree1 = self.make_branch_and_tree('tree1')
1515
        tree2 = self.make_to_branch_and_tree('tree2')
1516
        root_id = tree1.get_root_id()
1517
        tree2.set_root_id(root_id)
1518
1519
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1520
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1521
        a_id = u'\u03b1-id'.encode('utf8')
1522
        added_id = u'\u03c9_added_id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1523
        try:
1524
            self.build_tree([u'tree1/\u03b1/',
1525
                             u'tree2/\u03b1/',
1526
                             u'tree2/\u03b1/\u03c9-added',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1527
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1528
        except UnicodeError:
1529
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1530
        tree1.add([u'\u03b1'], [a_id])
1531
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-added'], [a_id, added_id])
1532
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1533
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1534
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1535
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1536
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1537
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1538
                         self.do_iter_changes(tree1, tree2,
1539
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1540
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1541
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1542
    def test_deleted_unicode(self):
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1543
        tree1 = self.make_branch_and_tree('tree1')
1544
        tree2 = self.make_to_branch_and_tree('tree2')
1545
        root_id = tree1.get_root_id()
1546
        tree2.set_root_id(root_id)
1547
1548
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1549
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1550
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1551
        deleted_id = u'\u03c9_deleted_id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1552
        try:
1553
            self.build_tree([u'tree1/\u03b1/',
1554
                             u'tree1/\u03b1/\u03c9-deleted',
1555
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1556
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1557
        except UnicodeError:
1558
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1559
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-deleted'], [a_id, deleted_id])
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1560
        tree2.add([u'\u03b1'], [a_id])
1561
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1562
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1563
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1564
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1565
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1566
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1567
                         self.do_iter_changes(tree1, tree2,
1568
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1569
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1570
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1571
    def test_modified_unicode(self):
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1572
        tree1 = self.make_branch_and_tree('tree1')
1573
        tree2 = self.make_to_branch_and_tree('tree2')
1574
        root_id = tree1.get_root_id()
1575
        tree2.set_root_id(root_id)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1576
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1577
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1578
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1579
        a_id = u'\u03b1-id'.encode('utf8')
1580
        mod_id = u'\u03c9_mod_id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1581
        try:
1582
            self.build_tree([u'tree1/\u03b1/',
1583
                             u'tree1/\u03b1/\u03c9-modified',
1584
                             u'tree2/\u03b1/',
1585
                             u'tree2/\u03b1/\u03c9-modified',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1586
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1587
        except UnicodeError:
1588
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1589
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1590
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1591
1592
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1593
1594
        self.assertEqual([self.content_changed(tree1, mod_id)],
1595
                         self.do_iter_changes(tree1, tree2))
1596
        self.assertEqual([self.content_changed(tree1, mod_id)],
1597
                         self.do_iter_changes(tree1, tree2,
1598
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1599
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1600
1601
    def test_renamed_unicode(self):
1602
        tree1 = self.make_branch_and_tree('tree1')
1603
        tree2 = self.make_to_branch_and_tree('tree2')
1604
        root_id = tree1.get_root_id()
1605
        tree2.set_root_id(root_id)
1606
1607
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1608
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1609
        a_id = u'\u03b1-id'.encode('utf8')
1610
        rename_id = u'\u03c9_rename_id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1611
        try:
1612
            self.build_tree([u'tree1/\u03b1/',
1613
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1614
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1615
        except UnicodeError:
1616
            raise tests.TestSkipped("Could not create Unicode files.")
6855.4.1 by Jelmer Vernooij
Yet more bees.
1617
        self.build_tree_contents([(u'tree1/\u03c9-source', b'contents\n'),
1618
                                  (u'tree2/\u03b1/\u03c9-target', b'contents\n'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1619
                                  ])
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1620
        tree1.add([u'\u03b1', u'\u03c9-source'], [a_id, rename_id])
1621
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-target'], [a_id, rename_id])
1622
1623
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1624
1625
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1626
                         self.do_iter_changes(tree1, tree2))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1627
        self.assertEqualIterChanges(
1628
            [self.renamed(tree1, tree2, rename_id, False)],
1629
            self.do_iter_changes(tree1, tree2, specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1630
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1631
1632
    def test_unchanged_unicode(self):
1633
        tree1 = self.make_branch_and_tree('tree1')
1634
        tree2 = self.make_to_branch_and_tree('tree2')
1635
        root_id = tree1.get_root_id()
1636
        tree2.set_root_id(root_id)
1637
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1638
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1639
        a_id = u'\u03b1-id'.encode('utf8')
1640
        subfile_id = u'\u03c9-subfile-id'.encode('utf8')
1641
        rootfile_id = u'\u03c9-root-id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1642
        try:
1643
            self.build_tree([u'tree1/\u03b1/',
1644
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1645
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1646
        except UnicodeError:
1647
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1648
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1649
            (u'tree1/\u03b1/\u03c9-subfile', b'sub contents\n'),
1650
            (u'tree2/\u03b1/\u03c9-subfile', b'sub contents\n'),
1651
            (u'tree1/\u03c9-rootfile', b'root contents\n'),
1652
            (u'tree2/\u03c9-rootfile', b'root contents\n'),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1653
            ])
1654
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1655
                  [a_id, subfile_id, rootfile_id])
1656
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1657
                  [a_id, subfile_id, rootfile_id])
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1658
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1659
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1660
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1661
        expected = self.sorted([
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1662
            self.unchanged(tree1, root_id),
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1663
            self.unchanged(tree1, a_id),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1664
            self.unchanged(tree1, subfile_id),
1665
            self.unchanged(tree1, rootfile_id),
1666
            ])
1667
        self.assertEqual(expected,
1668
                         self.do_iter_changes(tree1, tree2,
1669
                                              include_unchanged=True))
1670
1671
        # We should also be able to select just a subset
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1672
        expected = self.sorted([
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1673
            self.unchanged(tree1, a_id),
1674
            self.unchanged(tree1, subfile_id),
1675
            ])
1676
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1677
                         self.do_iter_changes(tree1, tree2, specific_files=[u'\u03b1'],
1678
                                              include_unchanged=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1679
1680
    def test_unknown_unicode(self):
1681
        tree1 = self.make_branch_and_tree('tree1')
1682
        tree2 = self.make_to_branch_and_tree('tree2')
1683
        root_id = tree1.get_root_id()
1684
        tree2.set_root_id(root_id)
1685
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1686
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1687
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1688
        try:
1689
            self.build_tree([u'tree1/\u03b1/',
1690
                             u'tree2/\u03b1/',
1691
                             u'tree2/\u03b1/unknown_dir/',
1692
                             u'tree2/\u03b1/unknown_file',
1693
                             u'tree2/\u03b1/unknown_dir/file',
1694
                             u'tree2/\u03c9-unknown_root_file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1695
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1696
        except UnicodeError:
1697
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1698
        tree1.add([u'\u03b1'], [a_id])
1699
        tree2.add([u'\u03b1'], [a_id])
1700
1701
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1702
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1703
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1704
        expected = self.sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1705
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1706
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1707
            self.unversioned(tree2, u'\u03c9-unknown_root_file'),
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1708
            # a/unknown_dir/file should not be included because we should not
1709
            # recurse into unknown_dir
1710
            # self.unversioned(tree2, 'a/unknown_dir/file'),
1711
            ])
1712
        self.assertEqual(expected,
1713
                         self.do_iter_changes(tree1, tree2,
1714
                                              require_versioned=False,
1715
                                              want_unversioned=True))
7143.15.2 by Jelmer Vernooij
Run autopep8.
1716
        self.assertEqual([],  # Without want_unversioned we should get nothing
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1717
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1718
        self.check_has_changes(False, tree1, tree2)
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1719
1720
        # We should also be able to select just a subset
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1721
        expected = self.sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1722
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1723
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1724
            ])
1725
        self.assertEqual(expected,
1726
                         self.do_iter_changes(tree1, tree2,
1727
                                              specific_files=[u'\u03b1'],
1728
                                              require_versioned=False,
1729
                                              want_unversioned=True))
7143.15.2 by Jelmer Vernooij
Run autopep8.
1730
        self.assertEqual([],  # Without want_unversioned we should get nothing
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1731
                         self.do_iter_changes(tree1, tree2,
1732
                                              specific_files=[u'\u03b1']))
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1733
1734
    def test_unknown_empty_dir(self):
1735
        tree1 = self.make_branch_and_tree('tree1')
1736
        tree2 = self.make_to_branch_and_tree('tree2')
1737
        root_id = tree1.get_root_id()
1738
        tree2.set_root_id(root_id)
1739
2402.2.4 by John Arbash Meinel
Clean up the setup for clarity (suggested by Robert)
1740
        # Start with 2 identical trees
1741
        self.build_tree(['tree1/a/', 'tree1/b/',
1742
                         'tree2/a/', 'tree2/b/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1743
        self.build_tree_contents([('tree1/b/file', b'contents\n'),
1744
                                  ('tree2/b/file', b'contents\n')])
1745
        tree1.add(['a', 'b', 'b/file'], [b'a-id', b'b-id', b'b-file-id'])
1746
        tree2.add(['a', 'b', 'b/file'], [b'a-id', b'b-id', b'b-file-id'])
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1747
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1748
        # Now create some unknowns in tree2
1749
        # We should find both a/file and a/dir as unknown, but we shouldn't
1750
        # recurse into a/dir to find that a/dir/subfile is also unknown.
7143.15.2 by Jelmer Vernooij
Run autopep8.
1751
        self.build_tree(
1752
            ['tree2/a/file', 'tree2/a/dir/', 'tree2/a/dir/subfile'])
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1753
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1754
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1755
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1756
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
1757
        if tree2.has_versioned_directories():
1758
            expected = self.sorted([
1759
                self.unversioned(tree2, u'a/file'),
1760
                self.unversioned(tree2, u'a/dir'),
1761
                ])
1762
            self.assertEqual(expected,
1763
                             self.do_iter_changes(tree1, tree2,
1764
                                                  require_versioned=False,
1765
                                                  want_unversioned=True))
1766
        else:
1767
            expected = self.sorted([
1768
                self.unversioned(tree2, u'a/file'),
1769
                self.unversioned(tree2, u'a/dir/subfile'),
1770
                ])
1771
            self.assertEqual(expected,
1772
                             self.do_iter_changes(tree1, tree2,
1773
                                                  require_versioned=False,
1774
                                                  want_unversioned=True))
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1775
1776
    def test_rename_over_deleted(self):
1777
        tree1 = self.make_branch_and_tree('tree1')
1778
        tree2 = self.make_to_branch_and_tree('tree2')
1779
        root_id = tree1.get_root_id()
1780
        tree2.set_root_id(root_id)
1781
1782
        # The final changes should be:
1783
        #   touch a b c d
1784
        #   add a b c d
1785
        #   commit
1786
        #   rm a d
1787
        #   mv b a
1788
        #   mv c d
1789
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1790
            ('tree1/a', b'a contents\n'),
1791
            ('tree1/b', b'b contents\n'),
1792
            ('tree1/c', b'c contents\n'),
1793
            ('tree1/d', b'd contents\n'),
1794
            ('tree2/a', b'b contents\n'),
1795
            ('tree2/d', b'c contents\n'),
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1796
            ])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1797
        tree1.add(['a', 'b', 'c', 'd'], [b'a-id', b'b-id', b'c-id', b'd-id'])
1798
        tree2.add(['a', 'd'], [b'b-id', b'c-id'])
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1799
1800
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1801
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1802
        expected = self.sorted([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1803
            self.deleted(tree1, b'a-id'),
1804
            self.deleted(tree1, b'd-id'),
1805
            self.renamed(tree1, tree2, b'b-id', False),
1806
            self.renamed(tree1, tree2, b'c-id', False),
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1807
            ])
1808
        self.assertEqual(expected,
1809
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1810
        self.check_has_changes(True, tree1, tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1811
1812
    def test_deleted_and_unknown(self):
1813
        """Test a file marked removed, but still present on disk."""
1814
        tree1 = self.make_branch_and_tree('tree1')
1815
        tree2 = self.make_to_branch_and_tree('tree2')
1816
        root_id = tree1.get_root_id()
1817
        tree2.set_root_id(root_id)
1818
1819
        # The final changes should be:
1820
        # bzr add a b c
1821
        # bzr rm --keep b
1822
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1823
            ('tree1/a', b'a contents\n'),
1824
            ('tree1/b', b'b contents\n'),
1825
            ('tree1/c', b'c contents\n'),
1826
            ('tree2/a', b'a contents\n'),
1827
            ('tree2/b', b'b contents\n'),
1828
            ('tree2/c', b'c contents\n'),
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1829
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1830
        tree1.add(['a', 'b', 'c'], [b'a-id', b'b-id', b'c-id'])
1831
        tree2.add(['a', 'c'], [b'a-id', b'c-id'])
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1832
1833
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1834
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1835
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1836
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1837
            self.deleted(tree1, b'b-id'),
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1838
            self.unversioned(tree2, 'b'),
1839
            ])
1840
        self.assertEqual(expected,
1841
                         self.do_iter_changes(tree1, tree2,
1842
                                              want_unversioned=True))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1843
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1844
            self.deleted(tree1, b'b-id'),
2456.2.5 by John Arbash Meinel
Make sure the output with want_unversioned=False is reasonable.
1845
            ])
1846
        self.assertEqual(expected,
1847
                         self.do_iter_changes(tree1, tree2,
1848
                                              want_unversioned=False))
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1849
1850
    def test_renamed_and_added(self):
1851
        """Test when we have renamed a file, and put another in its place."""
1852
        tree1 = self.make_branch_and_tree('tree1')
1853
        tree2 = self.make_to_branch_and_tree('tree2')
1854
        root_id = tree1.get_root_id()
1855
        tree2.set_root_id(root_id)
1856
1857
        # The final changes are:
1858
        # bzr add b c
1859
        # bzr mv b a
1860
        # bzr mv c d
1861
        # bzr add b c
1862
1863
        self.build_tree_contents([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1864
            ('tree1/b', b'b contents\n'),
1865
            ('tree1/c', b'c contents\n'),
1866
            ('tree2/a', b'b contents\n'),
1867
            ('tree2/b', b'new b contents\n'),
1868
            ('tree2/c', b'new c contents\n'),
1869
            ('tree2/d', b'c contents\n'),
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1870
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1871
        tree1.add(['b', 'c'], [b'b1-id', b'c1-id'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
1872
        tree2.add(['a', 'b', 'c', 'd'], [
1873
                  b'b1-id', b'b2-id', b'c2-id', b'c1-id'])
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1874
1875
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1876
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1877
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1878
            self.renamed(tree1, tree2, b'b1-id', False),
1879
            self.renamed(tree1, tree2, b'c1-id', False),
1880
            self.added(tree2, b'b2-id'),
1881
            self.added(tree2, b'c2-id'),
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1882
            ])
1883
        self.assertEqual(expected,
1884
                         self.do_iter_changes(tree1, tree2,
1885
                                              want_unversioned=True))
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1886
1887
    def test_renamed_and_unknown(self):
1888
        """A file was moved on the filesystem, but not in bzr."""
1889
        tree1 = self.make_branch_and_tree('tree1')
1890
        tree2 = self.make_to_branch_and_tree('tree2')
1891
        root_id = tree1.get_root_id()
1892
        tree2.set_root_id(root_id)
1893
1894
        # The final changes are:
1895
        # bzr add a b
1896
        # mv a a2
1897
1898
        self.build_tree_contents([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1899
            ('tree1/a', b'a contents\n'),
1900
            ('tree1/b', b'b contents\n'),
1901
            ('tree2/a', b'a contents\n'),
1902
            ('tree2/b', b'b contents\n'),
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1903
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1904
        tree1.add(['a', 'b'], [b'a-id', b'b-id'])
1905
        tree2.add(['a', 'b'], [b'a-id', b'b-id'])
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1906
        os.rename('tree2/a', 'tree2/a2')
1907
1908
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1909
        self.not_applicable_if_missing_in('a', tree2)
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1910
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1911
        expected = self.sorted([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1912
            self.missing(b'a-id', 'a', 'a', tree2.get_root_id(), 'file'),
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1913
            self.unversioned(tree2, 'a2'),
1914
            ])
1915
        self.assertEqual(expected,
1916
                         self.do_iter_changes(tree1, tree2,
1917
                                              want_unversioned=True))