/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
4503.1.1 by Vincent Ladeuil
Add tree.has_changes() to quickly check iter_changes().
480
        tree1.lock_read()
481
        try:
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
482
            tree2.lock_read()
483
            try:
484
                return tree2.has_changes(tree1)
485
            finally:
486
                tree2.unlock()
4503.1.1 by Vincent Ladeuil
Add tree.has_changes() to quickly check iter_changes().
487
        finally:
488
            tree1.unlock()
489
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
490
    def mutable_trees_to_locked_test_trees(self, tree1, tree2):
491
        """Convert the working trees into test trees.
492
493
        Read lock them, and add the unlock to the cleanup.
494
        """
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
495
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
496
        tree1.lock_read()
497
        self.addCleanup(tree1.unlock)
498
        tree2.lock_read()
499
        self.addCleanup(tree2.unlock)
500
        return tree1, tree2
501
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
502
    def make_tree_with_special_names(self):
503
        """Create a tree with filenames chosen to exercise the walk order."""
504
        tree1 = self.make_branch_and_tree('tree1')
505
        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
506
        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.
507
        paths, path_ids = self._create_special_names(tree2, 'tree2')
6855.3.1 by Jelmer Vernooij
Several more fixes.
508
        tree2.commit('initial', rev_id=b'rev-1')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
509
        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.
510
        return (tree1, tree2, paths, path_ids)
511
512
    def make_trees_with_special_names(self):
513
        """Both trees will use the special names.
514
515
        But the contents will differ for each file.
516
        """
517
        tree1 = self.make_branch_and_tree('tree1')
518
        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
519
        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.
520
        paths, path_ids = self._create_special_names(tree1, 'tree1')
521
        paths, path_ids = self._create_special_names(tree2, 'tree2')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
522
        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.
523
        return (tree1, tree2, paths, path_ids)
524
525
    def _create_special_names(self, tree, base_path):
526
        """Create a tree with paths that expose differences in sort orders."""
527
        # Each directory will have a single file named 'f' inside
528
        dirs = ['a',
529
                'a-a',
530
                'a/a',
531
                'a/a-a',
532
                'a/a/a',
533
                'a/a/a-a',
534
                'a/a/a/a',
535
                'a/a/a/a-a',
536
                'a/a/a/a/a',
7143.15.2 by Jelmer Vernooij
Run autopep8.
537
                ]
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.
538
        with_slashes = []
539
        paths = []
540
        path_ids = []
541
        for d in dirs:
542
            with_slashes.append(base_path + '/' + d + '/')
543
            with_slashes.append(base_path + '/' + d + '/f')
544
            paths.append(d)
7143.15.2 by Jelmer Vernooij
Run autopep8.
545
            paths.append(d + '/f')
6855.3.1 by Jelmer Vernooij
Several more fixes.
546
            path_ids.append((d.replace('/', '_') + '-id').encode('ascii'))
547
            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.
548
        self.build_tree(with_slashes)
549
        tree.add(paths, path_ids)
550
        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.
551
2012.1.1 by Aaron Bentley
Implement change iterator
552
    def test_compare_empty_trees(self):
553
        tree1 = self.make_branch_and_tree('1')
554
        tree2 = self.make_to_branch_and_tree('2')
555
        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.
556
        tree2 = self.get_tree_no_parents_no_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
557
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
3254.1.2 by Aaron Bentley
Fix doiter_changes
558
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
559
        self.check_has_changes(False, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
560
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
561
    def added(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
562
        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.
563
        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.
564
                (None, entry.name), (None, entry.kind),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
565
                (None, entry.executable))
566
3363.14.7 by Aaron Bentley
Get more tests passing
567
    @staticmethod
568
    def get_path_entry(tree, file_id):
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
569
        with tree.lock_read():
570
            path = tree.id2path(file_id)
571
        iterator = tree.iter_entries_by_dir(specific_files=[path])
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
572
        try:
573
            return next(iterator)
574
        except StopIteration:
575
            raise KeyError(file_id)
3363.14.7 by Aaron Bentley
Get more tests passing
576
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.
577
    def content_changed(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
578
        path, entry = self.get_path_entry(tree, file_id)
579
        return (file_id, (path, path), True, (True, True),
580
                (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.
581
                (entry.name, entry.name), (entry.kind, entry.kind),
582
                (entry.executable, entry.executable))
583
584
    def kind_changed(self, from_tree, to_tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
585
        from_path, old_entry = self.get_path_entry(from_tree, file_id)
586
        path, new_entry = self.get_path_entry(to_tree, file_id)
587
        return (file_id, (from_path, path), True, (True, True),
588
                (old_entry.parent_id, new_entry.parent_id),
589
                (old_entry.name, new_entry.name),
590
                (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.
591
                (old_entry.executable, new_entry.executable))
592
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
593
    def missing(self, file_id, from_path, to_path, parent_id, kind):
594
        _, from_basename = os.path.split(from_path)
595
        _, to_basename = os.path.split(to_path)
596
        # missing files have both paths, but no kind.
597
        return (file_id, (from_path, to_path), True, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
598
                (parent_id, parent_id),
599
                (from_basename, to_basename), (kind, None), (False, False))
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
600
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
601
    def deleted(self, tree, file_id):
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
602
        entry = tree.root_inventory.get_entry(file_id)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
603
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
604
        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.
605
                (entry.name, None), (entry.kind, None),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
606
                (entry.executable, None))
607
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
608
    def renamed(self, from_tree, to_tree, file_id, content_changed):
3363.14.8 by Aaron Bentley
Fix more tests
609
        from_path, from_entry = self.get_path_entry(from_tree, file_id)
610
        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.
611
        return (file_id, (from_path, to_path), content_changed, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
612
                (from_entry.parent_id, to_entry.parent_id),
613
                (from_entry.name, to_entry.name),
614
                (from_entry.kind, to_entry.kind),
615
                (from_entry.executable, to_entry.executable))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
616
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.
617
    def unchanged(self, tree, file_id):
3363.14.8 by Aaron Bentley
Fix more tests
618
        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.
619
        parent = entry.parent_id
620
        name = entry.name
621
        kind = entry.kind
622
        executable = entry.executable
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
623
        return (file_id, (path, path), False, (True, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
624
                (parent, parent), (name, name), (kind, kind),
625
                (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.
626
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
627
    def unversioned(self, tree, path):
628
        """Create an unversioned result."""
629
        _, basename = os.path.split(path)
3363.14.7 by Aaron Bentley
Get more tests passing
630
        kind = tree._comparison_data(None, path)[0]
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
631
        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.
632
                (None, basename), (None, kind),
633
                (None, False))
634
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
635
    def sorted(self, changes):
7067.6.2 by Jelmer Vernooij
Move key function to top-level.
636
        return sorted(changes, key=_change_key)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
637
2012.1.1 by Aaron Bentley
Implement change iterator
638
    def test_empty_to_abc_content(self):
639
        tree1 = self.make_branch_and_tree('1')
640
        tree2 = self.make_to_branch_and_tree('2')
641
        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.
642
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
643
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
644
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
645
            self.added(tree2, b'root-id'),
646
            self.added(tree2, b'a-id'),
647
            self.added(tree2, b'b-id'),
648
            self.added(tree2, b'c-id'),
649
            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.
650
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
651
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
652
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
653
    def test_empty_specific_files(self):
654
        tree1 = self.make_branch_and_tree('1')
655
        tree2 = self.make_to_branch_and_tree('2')
656
        tree1 = self.get_tree_no_parents_no_content(tree1)
657
        tree2 = self.get_tree_no_parents_abc_content(tree2)
658
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
659
        self.assertEqual([],
7143.15.2 by Jelmer Vernooij
Run autopep8.
660
                         self.do_iter_changes(tree1, tree2, specific_files=[]))
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
661
662
    def test_no_specific_files(self):
663
        tree1 = self.make_branch_and_tree('1')
664
        tree2 = self.make_to_branch_and_tree('2')
665
        tree1 = self.get_tree_no_parents_no_content(tree1)
666
        tree2 = self.get_tree_no_parents_abc_content(tree2)
667
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
668
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
669
            self.added(tree2, b'root-id'),
670
            self.added(tree2, b'a-id'),
671
            self.added(tree2, b'b-id'),
672
            self.added(tree2, b'c-id'),
673
            self.deleted(tree1, b'empty-root-id')])
2796.1.2 by Aaron Bentley
Harmonize test_no_specific_files with test_empty_to_abc_content
674
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
675
        self.check_has_changes(True, tree1, tree2)
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
676
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
677
    def test_empty_to_abc_content_a_only(self):
678
        tree1 = self.make_branch_and_tree('1')
679
        tree2 = self.make_to_branch_and_tree('2')
680
        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.
681
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
682
        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.
683
        self.assertEqual(
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
684
            self.sorted([self.added(tree2, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
685
                         self.added(tree2, b'a-id'),
686
                         self.deleted(tree1, b'empty-root-id')]),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
687
            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.
688
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
689
    def test_abc_content_to_empty_a_only(self):
690
        # 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.
691
        tree1 = self.make_branch_and_tree('1')
692
        tree2 = self.make_to_branch_and_tree('2')
693
        tree1 = self.get_tree_no_parents_abc_content(tree1)
694
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
695
        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.
696
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
697
            [self.deleted(tree1, b'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
698
            self.do_iter_changes(tree1, tree2, specific_files=['a']))
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
699
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
700
    def test_abc_content_to_empty_b_only(self):
701
        # When b stops being a directory we have to pick up b/c as well.
702
        tree1 = self.make_branch_and_tree('1')
703
        tree2 = self.make_to_branch_and_tree('2')
704
        tree1 = self.get_tree_no_parents_abc_content(tree1)
705
        tree2 = self.get_tree_no_parents_no_content(tree2)
706
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
707
        self.assertEqual(
6855.3.1 by Jelmer Vernooij
Several more fixes.
708
            [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.
709
            self.do_iter_changes(tree1, tree2, specific_files=['b']))
710
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
711
    def test_empty_to_abc_content_a_and_c_only(self):
712
        tree1 = self.make_branch_and_tree('1')
713
        tree2 = self.make_to_branch_and_tree('2')
714
        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.
715
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
716
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
717
        expected_result = self.sorted([self.added(tree2, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
718
                                       self.added(
719
                                           tree2, b'a-id'), self.added(tree2, b'b-id'),
720
                                       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.
721
        self.assertEqual(expected_result,
7143.15.2 by Jelmer Vernooij
Run autopep8.
722
                         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
723
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
724
    def test_abc_content_to_empty(self):
2012.1.1 by Aaron Bentley
Implement change iterator
725
        tree1 = self.make_branch_and_tree('1')
726
        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.
727
        tree1 = self.get_tree_no_parents_abc_content(tree1)
728
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
729
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
730
        expected_results = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
731
            self.added(tree2, b'empty-root-id'),
732
            self.deleted(tree1, b'root-id'), self.deleted(tree1, b'a-id'),
733
            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.
734
        self.assertEqual(
735
            expected_results,
736
            self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
737
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
738
739
    def test_content_modification(self):
740
        tree1 = self.make_branch_and_tree('1')
741
        tree2 = self.make_to_branch_and_tree('2')
742
        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.
743
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
744
        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.
745
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
746
        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.
747
                           (root_id, root_id), ('a', 'a'),
748
                           ('file', 'file'), (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
749
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
750
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
751
752
    def test_meta_modification(self):
753
        tree1 = self.make_branch_and_tree('1')
754
        tree2 = self.make_to_branch_and_tree('2')
755
        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.
756
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
757
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
6855.3.1 by Jelmer Vernooij
Several more fixes.
758
        self.assertEqual([(b'c-id', ('b/c', 'b/c'), False, (True, True),
759
                           (b'b-id', b'b-id'), ('c', 'c'), ('file', 'file'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
760
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
761
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
762
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
763
    def test_empty_dir(self):
764
        """an empty dir should not cause glitches to surrounding files."""
765
        tree1 = self.make_branch_and_tree('1')
766
        tree2 = self.make_to_branch_and_tree('2')
767
        tree1 = self.get_tree_no_parents_abc_content(tree1)
768
        tree2 = self.get_tree_no_parents_abc_content(tree2)
769
        # the pathname is chosen to fall between 'a' and 'b'.
770
        self.build_tree(['1/a-empty/', '2/a-empty/'])
6973.11.7 by Jelmer Vernooij
Fix more tests.
771
        tree1.add(['a-empty'], [b'a-empty'])
772
        tree2.add(['a-empty'], [b'a-empty'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
773
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
774
        expected = []
775
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
776
2012.1.1 by Aaron Bentley
Implement change iterator
777
    def test_file_rename(self):
778
        tree1 = self.make_branch_and_tree('1')
779
        tree2 = self.make_to_branch_and_tree('2')
780
        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.
781
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
782
        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.
783
        root_id = tree1.path2id('')
6821.2.1 by Jelmer Vernooij
Fix tests.
784
        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.
785
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
786
                           (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
787
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
788
789
    def test_file_rename_and_modification(self):
790
        tree1 = self.make_branch_and_tree('1')
791
        tree2 = self.make_to_branch_and_tree('2')
792
        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.
793
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
794
        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.
795
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
796
        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.
797
                           (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.
798
                           (False, False))],
799
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
800
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
801
    def test_specific_content_modification_grabs_parents(self):
802
        # WHen the only direct change to a specified file is a content change,
803
        # and its in a reparented subtree, the parents are grabbed.
804
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
805
        tree1.mkdir('changing', b'parent-id')
806
        tree1.mkdir('changing/unchanging', b'mid-id')
807
        tree1.add(['changing/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
808
        tree1.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
809
            '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.
810
        tree2 = self.make_to_branch_and_tree('2')
811
        tree2.set_root_id(tree1.get_root_id())
6855.4.1 by Jelmer Vernooij
Yet more bees.
812
        tree2.mkdir('changed', b'parent-id')
813
        tree2.mkdir('changed/unchanging', b'mid-id')
814
        tree2.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
815
        tree2.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
816
            '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.
817
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
818
        # parent-id has changed, as has file-id
819
        root_id = tree1.path2id('')
820
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
821
            [self.renamed(tree1, tree2, b'parent-id', False),
822
             self.renamed(tree1, tree2, b'file-id', True)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
823
            self.do_iter_changes(tree1, tree2,
824
                                 specific_files=['changed/unchanging/file']))
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
825
826
    def test_specific_content_modification_grabs_parents_root_changes(self):
827
        # WHen the only direct change to a specified file is a content change,
828
        # and its in a reparented subtree, the parents are grabbed, even if
829
        # that includes the root.
830
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
831
        tree1.set_root_id(b'old')
832
        tree1.mkdir('changed', b'parent-id')
833
        tree1.mkdir('changed/unchanging', b'mid-id')
834
        tree1.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
835
        tree1.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
836
            'changed/unchanging/file', b'a file',
837
            b'file-id')
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
838
        tree2 = self.make_to_branch_and_tree('2')
6855.4.1 by Jelmer Vernooij
Yet more bees.
839
        tree2.set_root_id(b'new')
840
        tree2.mkdir('changed', b'parent-id')
841
        tree2.mkdir('changed/unchanging', b'mid-id')
842
        tree2.add(['changed/unchanging/file'], [b'file-id'], ['file'])
6809.4.8 by Jelmer Vernooij
Fix some test failures.
843
        tree2.put_file_bytes_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
844
            '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.
845
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
846
        # old is gone, new is added, parent-id has changed(reparented), as has
847
        # file-id(content)
848
        root_id = tree1.path2id('')
849
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
850
            [self.renamed(tree1, tree2, b'parent-id', False),
851
             self.added(tree2, b'new'),
852
             self.deleted(tree1, b'old'),
853
             self.renamed(tree1, tree2, b'file-id', True)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
854
            self.do_iter_changes(tree1, tree2,
855
                                 specific_files=['changed/unchanging/file']))
4570.2.5 by Robert Collins
Review feedback, including finding a bug with changes at the root.
856
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
857
    def test_specific_with_rename_under_new_dir_reports_new_dir(self):
858
        tree1 = self.make_branch_and_tree('1')
859
        tree2 = self.make_to_branch_and_tree('2')
860
        tree1 = self.get_tree_no_parents_abc_content(tree1)
861
        tree2 = self.get_tree_no_parents_abc_content_7(tree2)
862
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
7143.15.2 by Jelmer Vernooij
Run autopep8.
863
        # 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.
864
        root_id = tree1.path2id('')
865
        self.assertEqualIterChanges(
6855.3.1 by Jelmer Vernooij
Several more fixes.
866
            [self.renamed(tree1, tree2, b'b-id', False),
867
             self.added(tree2, b'd-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
868
            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.
869
870
    def test_specific_with_rename_under_dir_under_new_dir_reports_new_dir(self):
871
        tree1 = self.make_branch_and_tree('1')
872
        tree2 = self.make_to_branch_and_tree('2')
873
        tree1 = self.get_tree_no_parents_abc_content(tree1)
874
        tree2 = self.get_tree_no_parents_abc_content_7(tree2)
875
        tree2.rename_one('a', 'd/e/a')
876
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
7143.15.2 by Jelmer Vernooij
Run autopep8.
877
        # 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.
878
        root_id = tree1.path2id('')
879
        self.assertEqualIterChanges(
6821.2.1 by Jelmer Vernooij
Fix tests.
880
            [self.renamed(tree1, tree2, tree1.path2id('b'), False),
6855.3.1 by Jelmer Vernooij
Several more fixes.
881
             self.added(tree2, b'd-id'),
882
             self.renamed(tree1, tree2, b'a-id', False)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
883
            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.
884
885
    def test_specific_old_parent_same_path_new_parent(self):
886
        # when a parent is new at its path, if the path was used in the source
887
        # it must be emitted as a change.
888
        tree1 = self.make_branch_and_tree('1')
6855.3.1 by Jelmer Vernooij
Several more fixes.
889
        tree1.add(['a'], [b'a-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
890
        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.
891
        tree2 = self.make_to_branch_and_tree('2')
892
        tree2.set_root_id(tree1.get_root_id())
6855.3.1 by Jelmer Vernooij
Several more fixes.
893
        tree2.mkdir('a', b'b-id')
894
        tree2.add(['a/c'], [b'c-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
895
        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.
896
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
897
        # a-id is gone, b-id and c-id are added.
898
        self.assertEqualIterChanges(
6855.3.1 by Jelmer Vernooij
Several more fixes.
899
            [self.deleted(tree1, b'a-id'),
900
             self.added(tree2, b'b-id'),
901
             self.added(tree2, b'c-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
902
            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.
903
904
    def test_specific_old_parent_becomes_file(self):
905
        # When an old parent included because of a path conflict becomes a
906
        # non-directory, its children have to be all included in the delta.
907
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
908
        tree1.mkdir('a', b'a-old-id')
909
        tree1.mkdir('a/reparented', b'reparented-id')
910
        tree1.mkdir('a/deleted', b'deleted-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
911
        tree2 = self.make_to_branch_and_tree('2')
912
        tree2.set_root_id(tree1.get_root_id())
6855.4.1 by Jelmer Vernooij
Yet more bees.
913
        tree2.mkdir('a', b'a-new-id')
914
        tree2.mkdir('a/reparented', b'reparented-id')
915
        tree2.add(['b'], [b'a-old-id'], ['file'])
6973.6.3 by Jelmer Vernooij
More fixes.
916
        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.
917
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
918
        # a-old-id is kind-changed, a-new-id is added, reparented-id is renamed,
919
        # deleted-id is gone
920
        self.assertEqualIterChanges(
6855.4.1 by Jelmer Vernooij
Yet more bees.
921
            [self.kind_changed(tree1, tree2, b'a-old-id'),
922
             self.added(tree2, b'a-new-id'),
923
             self.renamed(tree1, tree2, b'reparented-id', False),
924
             self.deleted(tree1, b'deleted-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
925
            self.do_iter_changes(tree1, tree2,
926
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
927
928
    def test_specific_old_parent_is_deleted(self):
929
        # When an old parent included because of a path conflict is removed,
930
        # its children have to be all included in the delta.
931
        tree1 = self.make_branch_and_tree('1')
7045.2.9 by Jelmer Vernooij
Fix some foreign branch tests.
932
        tree1.mkdir('a', b'a-old-id')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
933
        tree1.mkdir('a/reparented', b'reparented-id')
934
        tree1.mkdir('a/deleted', b'deleted-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
935
        tree2 = self.make_to_branch_and_tree('2')
936
        tree2.set_root_id(tree1.get_root_id())
6973.13.2 by Jelmer Vernooij
Fix some more tests.
937
        tree2.mkdir('a', b'a-new-id')
938
        tree2.mkdir('a/reparented', b'reparented-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
939
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
940
        # a-old-id is gone, a-new-id is added, reparented-id is renamed,
941
        # deleted-id is gone
942
        self.assertEqualIterChanges(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
943
            [self.deleted(tree1, b'a-old-id'),
944
             self.added(tree2, b'a-new-id'),
945
             self.renamed(tree1, tree2, b'reparented-id', False),
946
             self.deleted(tree1, b'deleted-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
947
            self.do_iter_changes(tree1, tree2,
948
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
949
950
    def test_specific_old_parent_child_collides_with_unselected_new(self):
951
        # When the child of an old parent because of a path conflict becomes a
952
        # path conflict with some unselected item in the source, that item also
953
        # needs to be included (because otherwise the output of applying the
954
        # delta to the source would have two items at that path).
955
        tree1 = self.make_branch_and_tree('1')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
956
        tree1.mkdir('a', b'a-old-id')
957
        tree1.mkdir('a/reparented', b'reparented-id')
958
        tree1.mkdir('collides', b'collides-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
959
        tree2 = self.make_to_branch_and_tree('2')
960
        tree2.set_root_id(tree1.get_root_id())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
961
        tree2.mkdir('a', b'a-new-id')
962
        tree2.mkdir('a/selected', b'selected-id')
963
        tree2.mkdir('collides', b'reparented-id')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
964
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
965
        # a-old-id is one, a-new-id is added, reparented-id is renamed,
966
        # collides-id is gone, selected-id is new.
967
        self.assertEqualIterChanges(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
968
            [self.deleted(tree1, b'a-old-id'),
969
             self.added(tree2, b'a-new-id'),
970
             self.renamed(tree1, tree2, b'reparented-id', False),
971
             self.deleted(tree1, b'collides-id'),
972
             self.added(tree2, b'selected-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
973
            self.do_iter_changes(tree1, tree2,
974
                                 specific_files=['a/selected']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
975
976
    def test_specific_old_parent_child_dir_stops_being_dir(self):
977
        # When the child of an old parent also stops being a directory, its
978
        # children must also be included. This test checks that downward
979
        # recursion is done appropriately by starting at a child of the root of
980
        # a deleted subtree (a/reparented), and checking that a sibling
981
        # directory (a/deleted) has its children included in the delta.
982
        tree1 = self.make_branch_and_tree('1')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
983
        tree1.mkdir('a', b'a-old-id')
984
        tree1.mkdir('a/reparented', b'reparented-id-1')
985
        tree1.mkdir('a/deleted', b'deleted-id-1')
986
        tree1.mkdir('a/deleted/reparented', b'reparented-id-2')
987
        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.
988
        tree2 = self.make_to_branch_and_tree('2')
989
        tree2.set_root_id(tree1.get_root_id())
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
990
        tree2.mkdir('a', b'a-new-id')
991
        tree2.mkdir('a/reparented', b'reparented-id-1')
992
        tree2.mkdir('reparented', b'reparented-id-2')
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
993
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
994
        # a-old-id is gone, a-new-id is added, reparented-id-1, -2 are renamed,
995
        # deleted-id-1 and -2 are gone.
996
        self.assertEqualIterChanges(
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
997
            [self.deleted(tree1, b'a-old-id'),
998
             self.added(tree2, b'a-new-id'),
999
             self.renamed(tree1, tree2, b'reparented-id-1', False),
1000
             self.renamed(tree1, tree2, b'reparented-id-2', False),
1001
             self.deleted(tree1, b'deleted-id-1'),
1002
             self.deleted(tree1, b'deleted-id-2')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1003
            self.do_iter_changes(tree1, tree2,
1004
                                 specific_files=['a/reparented']))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1005
2012.1.1 by Aaron Bentley
Implement change iterator
1006
    def test_file_rename_and_meta_modification(self):
1007
        tree1 = self.make_branch_and_tree('1')
1008
        tree2 = self.make_to_branch_and_tree('2')
1009
        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.
1010
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1011
        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.
1012
        root_id = tree1.path2id('')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1013
        self.assertEqual([(b'c-id', ('b/c', 'e'), False, (True, True),
1014
                           (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.
1015
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
1016
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
1017
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1018
    def test_file_becomes_unversionable_bug_438569(self):
1019
        # This isn't strictly a intertree problem, but its the intertree code
1020
        # path that triggers all stat cache updates on both xml and dirstate
1021
        # trees.
1022
        # In bug 438569, a file becoming a fifo causes an assert. Fifo's are
1023
        # not versionable or diffable. For now, we simply stop cold when they
7143.15.2 by Jelmer Vernooij
Run autopep8.
1024
        # are detected (because we don't know how far through the code the
1025
        # 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.
1026
        # the kind change and have commit refuse to go futher, or something
1027
        # similar. One particular reason for choosing this approach is that
7143.15.2 by Jelmer Vernooij
Run autopep8.
1028
        # 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.
1029
        # actually update records that way.
1030
        # To add confusion, the totally generic code path works - but it
1031
        # doesn't update persistent metadata. So this test permits InterTrees
1032
        # to either work, or fail with BadFileKindError.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1033
        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.
1034
        tree1 = self.make_branch_and_tree('1')
1035
        self.build_tree(['1/a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1036
        tree1.set_root_id(b'root-id')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1037
        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.
1038
        tree2 = self.make_branch_and_tree('2')
1039
        os.mkfifo('2/a')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1040
        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.
1041
        try:
1042
            tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
1043
        except (KeyError,):
1044
            raise tests.TestNotApplicable(
1045
                "Cannot represent a FIFO in this case %s" % self.id())
1046
        try:
1047
            self.do_iter_changes(tree1, tree2)
4634.58.2 by Robert Collins
Review feedback.
1048
        except errors.BadFileKindError:
1049
            pass
4634.58.1 by Robert Collins
Show a sensible error when a previously versionable path becomes a FIFO or other unversionable file.
1050
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
1051
    def test_missing_in_target(self):
1052
        """Test with the target files versioned but absent from disk."""
1053
        tree1 = self.make_branch_and_tree('1')
1054
        tree2 = self.make_to_branch_and_tree('2')
1055
        tree1 = self.get_tree_no_parents_abc_content(tree1)
1056
        tree2 = self.get_tree_no_parents_abc_content(tree2)
1057
        os.unlink('2/a')
1058
        shutil.rmtree('2/b')
1059
        # TODO ? have a symlink here?
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1060
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1061
        self.not_applicable_if_missing_in('a', tree2)
1062
        self.not_applicable_if_missing_in('b', tree2)
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1063
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1064
            self.missing(b'a-id', 'a', 'a', b'root-id', 'file'),
1065
            self.missing(b'b-id', 'b', 'b', b'root-id', 'directory'),
1066
            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.
1067
            ])
1068
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1069
1070
    def test_missing_and_renamed(self):
1071
        tree1 = self.make_branch_and_tree('tree1')
1072
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
1073
        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.
1074
        self.build_tree(['tree1/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1075
        tree1.add(['file'], [b'file-id'])
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1076
        self.build_tree(['tree2/directory/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1077
        tree2.add(['directory'], [b'file-id'])
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1078
        os.rmdir('tree2/directory')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1079
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1080
        self.not_applicable_if_missing_in('directory', tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1081
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1082
        root_id = tree1.path2id('')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1083
        expected = self.sorted([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1084
            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.
1085
            ])
1086
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1087
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)
1088
    def test_only_in_source_and_missing(self):
1089
        tree1 = self.make_branch_and_tree('tree1')
1090
        tree2 = self.make_to_branch_and_tree('tree2')
1091
        tree2.set_root_id(tree1.get_root_id())
1092
        self.build_tree(['tree1/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1093
        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)
1094
        os.unlink('tree1/file')
1095
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1096
        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)
1097
        root_id = tree1.path2id('')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1098
        expected = [(b'file-id', ('file', None), False, (True, False),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1099
                     (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)
1100
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1101
1102
    def test_only_in_target_and_missing(self):
1103
        tree1 = self.make_branch_and_tree('tree1')
1104
        tree2 = self.make_to_branch_and_tree('tree2')
1105
        tree2.set_root_id(tree1.get_root_id())
1106
        self.build_tree(['tree2/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1107
        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)
1108
        os.unlink('tree2/file')
1109
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1110
        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)
1111
        root_id = tree1.path2id('')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1112
        expected = [(b'file-id', (None, 'file'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1113
                     (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)
1114
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1115
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.
1116
    def test_only_in_target_missing_subtree_specific_bug_367632(self):
1117
        tree1 = self.make_branch_and_tree('tree1')
1118
        tree2 = self.make_to_branch_and_tree('tree2')
1119
        tree2.set_root_id(tree1.get_root_id())
1120
        self.build_tree(['tree2/a-dir/', 'tree2/a-dir/a-file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1121
        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.
1122
        os.unlink('tree2/a-dir/a-file')
1123
        os.rmdir('tree2/a-dir')
1124
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1125
        self.not_applicable_if_missing_in('a-dir', tree2)
1126
        root_id = tree1.path2id('')
1127
        expected = [
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1128
            (b'dir-id', (None, 'a-dir'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1129
             (None, root_id), (None, 'a-dir'), (None, None), (None, False)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1130
            (b'file-id', (None, 'a-dir/a-file'), False, (False, True),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1131
             (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.
1132
            ]
1133
        # bug 367632 showed that specifying the root broke some code paths,
1134
        # so we check this contract with and without it.
1135
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1136
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1137
                         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.
1138
2012.1.1 by Aaron Bentley
Implement change iterator
1139
    def test_unchanged_with_renames_and_modifications(self):
1140
        """want_unchanged should generate a list of unchanged entries."""
1141
        tree1 = self.make_branch_and_tree('1')
1142
        tree2 = self.make_to_branch_and_tree('2')
1143
        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.
1144
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1145
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1146
        self.assertEqual(sorted([self.unchanged(tree1, b'root-id'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1147
                                 self.unchanged(tree1, b'b-id'),
1148
                                 (b'a-id', ('a', 'd'), True, (True, True),
1149
                                  (b'root-id', b'root-id'), ('a',
1150
                                                             'd'), ('file', 'file'),
1151
                                  (False, False)), self.unchanged(tree1, b'c-id')]),
1152
                         self.do_iter_changes(tree1, tree2, include_unchanged=True))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1153
1154
    def test_compare_subtrees(self):
1155
        tree1 = self.make_branch_and_tree('1')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
1156
        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.
1157
            return
6855.3.1 by Jelmer Vernooij
Several more fixes.
1158
        tree1.set_root_id(b'root-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1159
        subtree1 = self.make_branch_and_tree('1/sub')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1160
        subtree1.set_root_id(b'subtree-id')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
1161
        tree1.add_reference(subtree1)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1162
1163
        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
1164
        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.
1165
            return
6855.3.1 by Jelmer Vernooij
Several more fixes.
1166
        tree2.set_root_id(b'root-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1167
        subtree2 = self.make_to_branch_and_tree('2/sub')
6855.3.1 by Jelmer Vernooij
Several more fixes.
1168
        subtree2.set_root_id(b'subtree-id')
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
1169
        tree2.add_reference(subtree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1170
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1171
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
1172
        self.assertEqual([], list(tree2.iter_changes(tree1)))
6855.3.1 by Jelmer Vernooij
Several more fixes.
1173
        subtree1.commit('commit', rev_id=b'commit-a')
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1174
        self.assertEqual([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1175
            (b'root-id',
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1176
             (u'', u''),
1177
             False,
1178
             (True, True),
1179
             (None, None),
1180
             (u'', u''),
1181
             ('directory', 'directory'),
1182
             (False, False)),
6855.3.1 by Jelmer Vernooij
Several more fixes.
1183
            (b'subtree-id',
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1184
             ('sub', 'sub',),
1185
             False,
1186
             (True, True),
6855.3.1 by Jelmer Vernooij
Several more fixes.
1187
             (b'root-id', b'root-id'),
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1188
             ('sub', 'sub'),
1189
             ('tree-reference', 'tree-reference'),
1190
             (False, False))],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1191
            list(tree2.iter_changes(tree1,
1192
                                    include_unchanged=True)))
2255.2.160 by Martin Pool
(merge) updates from dirstate branch
1193
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1194
    def test_disk_in_subtrees_skipped(self):
1195
        """subtrees are considered not-in-the-current-tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1196
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1197
        This test tests the trivial case, where the basis has no paths in the
1198
        current trees subtree.
1199
        """
1200
        tree1 = self.make_branch_and_tree('1')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1201
        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.
1202
        tree2 = self.make_to_branch_and_tree('2')
1203
        if not tree2.supports_tree_reference():
1204
            return
6855.4.1 by Jelmer Vernooij
Yet more bees.
1205
        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.
1206
        subtree2 = self.make_to_branch_and_tree('2/sub')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1207
        subtree2.set_root_id(b'subtree-id')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
1208
        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.
1209
        self.build_tree(['2/sub/file'])
1210
        subtree2.add(['file'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1211
1212
        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.
1213
        # this should filter correctly from above
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1214
        self.assertEqual([self.added(tree2, b'subtree-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1215
                         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.
1216
        # and when the path is named
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1217
        self.assertEqual([self.added(tree2, b'subtree-id')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1218
                         self.do_iter_changes(tree1, tree2, specific_files=['sub'],
1219
                                              want_unversioned=True))
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
1220
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1221
    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.
1222
        tree1 = self.make_branch_and_tree('tree1')
1223
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
1224
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1225
        self.build_tree(['tree1/a', 'tree1/c',
1226
                         'tree2/a', 'tree2/b', 'tree2/c'])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1227
        tree1.add(['a', 'c'], [b'a-id', b'c-id'])
1228
        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.
1229
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1230
        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.
1231
1232
        # We should ignore the fact that 'b' exists in tree-2
1233
        # because the want_unversioned parameter was not given.
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1234
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1235
            self.content_changed(tree2, b'a-id'),
1236
            self.content_changed(tree2, b'c-id'),
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1237
            ])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
1238
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1239
        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.
1240
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1241
    def test_unversioned_paths_in_tree(self):
1242
        tree1 = self.make_branch_and_tree('tree1')
1243
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
1244
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1245
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1246
        if has_symlinks():
1247
            os.symlink('target', 'tree2/link')
1248
            links_supported = True
1249
        else:
1250
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1251
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1252
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1253
        expected = [
1254
            self.unversioned(tree2, 'file'),
1255
            self.unversioned(tree2, 'dir'),
1256
            ]
1257
        if links_supported:
1258
            expected.append(self.unversioned(tree2, 'link'))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1259
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1260
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1261
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1262
1263
    def test_unversioned_paths_in_tree_specific_files(self):
1264
        tree1 = self.make_branch_and_tree('tree1')
1265
        tree2 = self.make_to_branch_and_tree('tree2')
1266
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1267
        if has_symlinks():
1268
            os.symlink('target', 'tree2/link')
1269
            links_supported = True
1270
        else:
1271
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1272
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1273
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1274
        expected = [
1275
            self.unversioned(tree2, 'file'),
1276
            self.unversioned(tree2, 'dir'),
1277
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1278
        specific_files = ['file', 'dir']
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1279
        if links_supported:
1280
            expected.append(self.unversioned(tree2, 'link'))
1281
            specific_files.append('link')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1282
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1283
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1284
                                                        specific_files=specific_files, require_versioned=False,
1285
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1286
1287
    def test_unversioned_paths_in_target_matching_source_old_names(self):
1288
        # its likely that naive implementations of unversioned file support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1289
        # 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.
1290
        # due to a rename, not due to unversioning it.
1291
        # That is, if the old tree has a versioned file 'foo', and
1292
        # the new tree has the same file but versioned as 'bar', and also
1293
        # has an unknown file 'foo', we should get back output for
1294
        # both foo and bar.
1295
        tree1 = self.make_branch_and_tree('tree1')
1296
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.187 by Martin Pool
set common root ids in more tests
1297
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1298
        self.build_tree(['tree2/file', 'tree2/dir/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1299
                         'tree1/file', 'tree2/movedfile',
1300
                         'tree1/dir/', 'tree2/moveddir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1301
        if has_symlinks():
1302
            os.symlink('target', 'tree1/link')
1303
            os.symlink('target', 'tree2/link')
1304
            os.symlink('target', 'tree2/movedlink')
1305
            links_supported = True
1306
        else:
1307
            links_supported = False
6855.4.1 by Jelmer Vernooij
Yet more bees.
1308
        tree1.add(['file', 'dir'], [b'file-id', b'dir-id'])
1309
        tree2.add(['movedfile', 'moveddir'], [b'file-id', b'dir-id'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
1310
        if links_supported:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1311
            tree1.add(['link'], [b'link-id'])
1312
            tree2.add(['movedlink'], [b'link-id'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1313
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1314
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1315
        root_id = tree1.path2id('')
1316
        expected = [
6855.4.1 by Jelmer Vernooij
Yet more bees.
1317
            self.renamed(tree1, tree2, b'dir-id', False),
1318
            self.renamed(tree1, tree2, b'file-id', True),
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1319
            self.unversioned(tree2, 'file'),
1320
            self.unversioned(tree2, 'dir'),
1321
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1322
        specific_files = ['file', 'dir']
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1323
        if links_supported:
6855.4.1 by Jelmer Vernooij
Yet more bees.
1324
            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.
1325
            expected.append(self.unversioned(tree2, 'link'))
1326
            specific_files.append('link')
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1327
        expected = self.sorted(expected)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1328
        # run once with, and once without specific files, to catch
1329
        # potentially different code paths.
1330
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1331
                                                        require_versioned=False,
1332
                                                        want_unversioned=True))
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1333
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1334
                                                        specific_files=specific_files, require_versioned=False,
1335
                                                        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.
1336
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1337
    def test_similar_filenames(self):
1338
        """Test when we have a few files with similar names."""
1339
        tree1 = self.make_branch_and_tree('tree1')
1340
        tree2 = self.make_branch_and_tree('tree2')
1341
        tree2.set_root_id(tree1.get_root_id())
1342
1343
        # The trees are actually identical, but they happen to contain
1344
        # similarly named files.
1345
        self.build_tree(['tree1/a/',
1346
                         'tree1/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1347
                         'tree1/a/b/c/',
1348
                         'tree1/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1349
                         'tree1/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1350
                         'tree1/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1351
                         'tree2/a/',
1352
                         'tree2/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1353
                         'tree2/a/b/c/',
1354
                         'tree2/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1355
                         'tree2/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1356
                         'tree2/a-c/e/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1357
                         ])
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
1358
        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.
1359
                  [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 '/'.
1360
        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.
1361
                  [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
1362
1363
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1364
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1365
1366
        self.assertEqual([], self.do_iter_changes(tree1, tree2,
1367
                                                  want_unversioned=True))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1368
        expected = self.sorted([
2466.5.2 by John Arbash Meinel
Extend the test a bit to make sure the include_unchanged value is correct.
1369
            self.unchanged(tree2, tree2.get_root_id()),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1370
            self.unchanged(tree2, b'a-id'),
1371
            self.unchanged(tree2, b'b-id'),
1372
            self.unchanged(tree2, b'c-id'),
1373
            self.unchanged(tree2, b'd-id'),
1374
            self.unchanged(tree2, b'a-c-id'),
1375
            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.
1376
            ])
1377
        self.assertEqual(expected,
1378
                         self.do_iter_changes(tree1, tree2,
1379
                                              want_unversioned=True,
1380
                                              include_unchanged=True))
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1381
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1382
    def test_unversioned_subtree_only_emits_root(self):
1383
        tree1 = self.make_branch_and_tree('tree1')
1384
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.188 by Martin Pool
Set common root id in comparison tests
1385
        tree2.set_root_id(tree1.get_root_id())
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1386
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1387
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1388
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1389
        expected = [
1390
            self.unversioned(tree2, 'dir'),
1391
            ]
1392
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1393
                                                        want_unversioned=True))
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1394
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.
1395
    def make_trees_with_symlinks(self):
1396
        tree1 = self.make_branch_and_tree('tree1')
1397
        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
1398
        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.
1399
        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
1400
        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
1401
        os.symlink('original', 'tree1/changed')
1402
        os.symlink('original', 'tree1/removed')
1403
        os.symlink('original', 'tree1/tofile')
1404
        os.symlink('original', 'tree1/todir')
1405
        # we make the unchanged link point at unknown to catch incorrect
1406
        # symlink-following code in the specified_files test.
1407
        os.symlink('unknown', 'tree1/unchanged')
7143.15.2 by Jelmer Vernooij
Run autopep8.
1408
        os.symlink('new', 'tree2/added')
1409
        os.symlink('new', 'tree2/changed')
1410
        os.symlink('new', 'tree2/fromfile')
1411
        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.
1412
        os.symlink('unknown', 'tree2/unchanged')
1413
        from_paths_and_ids = [
1414
            'fromdir',
1415
            'fromfile',
1416
            'changed',
1417
            'removed',
1418
            'todir',
1419
            'tofile',
1420
            'unchanged',
1421
            ]
1422
        to_paths_and_ids = [
1423
            'added',
1424
            'fromdir',
1425
            'fromfile',
1426
            'changed',
1427
            'todir',
1428
            'tofile',
1429
            'unchanged',
1430
            ]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1431
        tree1.add(from_paths_and_ids, [p.encode('utf-8')
1432
                                       for p in from_paths_and_ids])
1433
        tree2.add(to_paths_and_ids, [p.encode('utf-8')
1434
                                     for p in to_paths_and_ids])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1435
        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.
1436
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1437
    def test_versioned_symlinks(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1438
        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.
1439
        tree1, tree2 = self.make_trees_with_symlinks()
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1440
        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.
1441
        root_id = tree1.path2id('')
1442
        expected = [
1443
            self.unchanged(tree1, tree1.path2id('')),
7045.1.18 by Jelmer Vernooij
Fix another test.
1444
            self.added(tree2, b'added'),
7058.4.1 by Jelmer Vernooij
Fix another 40 tests.
1445
            self.content_changed(tree2, b'changed'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1446
            self.kind_changed(tree1, tree2, b'fromdir'),
1447
            self.kind_changed(tree1, tree2, b'fromfile'),
1448
            self.deleted(tree1, b'removed'),
1449
            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.
1450
            self.unversioned(tree2, 'unknown'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1451
            self.kind_changed(tree1, tree2, b'todir'),
1452
            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.
1453
            ]
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1454
        expected = self.sorted(expected)
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1455
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1456
                         self.do_iter_changes(tree1, tree2, include_unchanged=True,
1457
                                              want_unversioned=True))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1458
        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.
1459
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1460
    def test_versioned_symlinks_specific_files(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
1461
        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.
1462
        tree1, tree2 = self.make_trees_with_symlinks()
1463
        root_id = tree1.path2id('')
1464
        expected = [
7045.1.18 by Jelmer Vernooij
Fix another test.
1465
            self.added(tree2, b'added'),
7058.4.1 by Jelmer Vernooij
Fix another 40 tests.
1466
            self.content_changed(tree2, b'changed'),
7045.1.18 by Jelmer Vernooij
Fix another test.
1467
            self.kind_changed(tree1, tree2, b'fromdir'),
1468
            self.kind_changed(tree1, tree2, b'fromfile'),
1469
            self.deleted(tree1, b'removed'),
1470
            self.kind_changed(tree1, tree2, b'todir'),
1471
            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.
1472
            ]
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1473
        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.
1474
        # we should get back just the changed links. We pass in 'unchanged' to
1475
        # make sure that it is correctly not returned - and neither is the
1476
        # unknown path 'unknown' which it points at.
1477
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1478
                                                        specific_files=['added', 'changed', 'fromdir', 'fromfile',
1479
                                                                        'removed', 'unchanged', 'todir', 'tofile']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1480
        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.
1481
2255.7.21 by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to
1482
    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.
1483
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1484
        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.
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.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
1487
1488
    def test_trees_with_special_names(self):
1489
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1490
        expected = self.sorted(self.content_changed(tree2, f_id) for f_id in path_ids
7143.15.2 by Jelmer Vernooij
Run autopep8.
1491
                               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.
1492
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1493
        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
1494
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1495
    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.
1496
        tree1 = self.make_branch_and_tree('tree1')
1497
        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
1498
        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.
1499
        self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',
1500
                         'tree1/b/d/', 'tree1/b/d/e', 'tree1/f/', 'tree1/f/g',
1501
                         'tree2/a', 'tree2/f/', 'tree2/f/g'])
1502
        tree1.add(['a', 'b', 'b/c', 'b/d/', 'b/d/e', 'f', 'f/g'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
1503
                  [b'a-id', b'b-id', b'c-id', b'd-id', b'e-id', b'f-id', b'g-id'])
1504
        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.
1505
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1506
        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.
1507
        # 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.
1508
        expected = [
6855.4.1 by Jelmer Vernooij
Yet more bees.
1509
            self.content_changed(tree2, b'a-id'),
1510
            self.content_changed(tree2, b'g-id'),
1511
            self.deleted(tree1, b'b-id'),
1512
            self.deleted(tree1, b'c-id'),
1513
            self.deleted(tree1, b'd-id'),
1514
            self.deleted(tree1, b'e-id'),
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1515
            ]
1516
        self.assertEqualIterChanges(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1517
                                    self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1518
        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.
1519
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1520
    def test_added_unicode(self):
1521
        tree1 = self.make_branch_and_tree('tree1')
1522
        tree2 = self.make_to_branch_and_tree('tree2')
1523
        root_id = tree1.get_root_id()
1524
        tree2.set_root_id(root_id)
1525
1526
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1527
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1528
        a_id = u'\u03b1-id'.encode('utf8')
1529
        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.
1530
        try:
1531
            self.build_tree([u'tree1/\u03b1/',
1532
                             u'tree2/\u03b1/',
1533
                             u'tree2/\u03b1/\u03c9-added',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1534
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1535
        except UnicodeError:
1536
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1537
        tree1.add([u'\u03b1'], [a_id])
1538
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-added'], [a_id, added_id])
1539
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1540
        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.
1541
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1542
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1543
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1544
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1545
                         self.do_iter_changes(tree1, tree2,
1546
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1547
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1548
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1549
    def test_deleted_unicode(self):
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1550
        tree1 = self.make_branch_and_tree('tree1')
1551
        tree2 = self.make_to_branch_and_tree('tree2')
1552
        root_id = tree1.get_root_id()
1553
        tree2.set_root_id(root_id)
1554
1555
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1556
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1557
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1558
        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.
1559
        try:
1560
            self.build_tree([u'tree1/\u03b1/',
1561
                             u'tree1/\u03b1/\u03c9-deleted',
1562
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1563
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1564
        except UnicodeError:
1565
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1566
        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.
1567
        tree2.add([u'\u03b1'], [a_id])
1568
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1569
        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.
1570
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1571
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1572
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1573
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1574
                         self.do_iter_changes(tree1, tree2,
1575
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1576
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1577
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1578
    def test_modified_unicode(self):
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1579
        tree1 = self.make_branch_and_tree('tree1')
1580
        tree2 = self.make_to_branch_and_tree('tree2')
1581
        root_id = tree1.get_root_id()
1582
        tree2.set_root_id(root_id)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1583
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1584
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1585
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1586
        a_id = u'\u03b1-id'.encode('utf8')
1587
        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.
1588
        try:
1589
            self.build_tree([u'tree1/\u03b1/',
1590
                             u'tree1/\u03b1/\u03c9-modified',
1591
                             u'tree2/\u03b1/',
1592
                             u'tree2/\u03b1/\u03c9-modified',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1593
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1594
        except UnicodeError:
1595
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1596
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1597
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1598
1599
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1600
1601
        self.assertEqual([self.content_changed(tree1, mod_id)],
1602
                         self.do_iter_changes(tree1, tree2))
1603
        self.assertEqual([self.content_changed(tree1, mod_id)],
1604
                         self.do_iter_changes(tree1, tree2,
1605
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1606
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1607
1608
    def test_renamed_unicode(self):
1609
        tree1 = self.make_branch_and_tree('tree1')
1610
        tree2 = self.make_to_branch_and_tree('tree2')
1611
        root_id = tree1.get_root_id()
1612
        tree2.set_root_id(root_id)
1613
1614
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1615
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1616
        a_id = u'\u03b1-id'.encode('utf8')
1617
        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.
1618
        try:
1619
            self.build_tree([u'tree1/\u03b1/',
1620
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1621
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1622
        except UnicodeError:
1623
            raise tests.TestSkipped("Could not create Unicode files.")
6855.4.1 by Jelmer Vernooij
Yet more bees.
1624
        self.build_tree_contents([(u'tree1/\u03c9-source', b'contents\n'),
1625
                                  (u'tree2/\u03b1/\u03c9-target', b'contents\n'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1626
                                  ])
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1627
        tree1.add([u'\u03b1', u'\u03c9-source'], [a_id, rename_id])
1628
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-target'], [a_id, rename_id])
1629
1630
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1631
1632
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1633
                         self.do_iter_changes(tree1, tree2))
4570.2.3 by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas.
1634
        self.assertEqualIterChanges(
1635
            [self.renamed(tree1, tree2, rename_id, False)],
1636
            self.do_iter_changes(tree1, tree2, specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1637
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1638
1639
    def test_unchanged_unicode(self):
1640
        tree1 = self.make_branch_and_tree('tree1')
1641
        tree2 = self.make_to_branch_and_tree('tree2')
1642
        root_id = tree1.get_root_id()
1643
        tree2.set_root_id(root_id)
1644
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1645
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1646
        a_id = u'\u03b1-id'.encode('utf8')
1647
        subfile_id = u'\u03c9-subfile-id'.encode('utf8')
1648
        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.
1649
        try:
1650
            self.build_tree([u'tree1/\u03b1/',
1651
                             u'tree2/\u03b1/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1652
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1653
        except UnicodeError:
1654
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1655
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1656
            (u'tree1/\u03b1/\u03c9-subfile', b'sub contents\n'),
1657
            (u'tree2/\u03b1/\u03c9-subfile', b'sub contents\n'),
1658
            (u'tree1/\u03c9-rootfile', b'root contents\n'),
1659
            (u'tree2/\u03c9-rootfile', b'root contents\n'),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1660
            ])
1661
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1662
                  [a_id, subfile_id, rootfile_id])
1663
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1664
                  [a_id, subfile_id, rootfile_id])
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1665
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1666
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1667
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1668
        expected = self.sorted([
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1669
            self.unchanged(tree1, root_id),
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1670
            self.unchanged(tree1, a_id),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1671
            self.unchanged(tree1, subfile_id),
1672
            self.unchanged(tree1, rootfile_id),
1673
            ])
1674
        self.assertEqual(expected,
1675
                         self.do_iter_changes(tree1, tree2,
1676
                                              include_unchanged=True))
1677
1678
        # We should also be able to select just a subset
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1679
        expected = self.sorted([
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1680
            self.unchanged(tree1, a_id),
1681
            self.unchanged(tree1, subfile_id),
1682
            ])
1683
        self.assertEqual(expected,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1684
                         self.do_iter_changes(tree1, tree2, specific_files=[u'\u03b1'],
1685
                                              include_unchanged=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1686
1687
    def test_unknown_unicode(self):
1688
        tree1 = self.make_branch_and_tree('tree1')
1689
        tree2 = self.make_to_branch_and_tree('tree2')
1690
        root_id = tree1.get_root_id()
1691
        tree2.set_root_id(root_id)
1692
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1693
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1694
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1695
        try:
1696
            self.build_tree([u'tree1/\u03b1/',
1697
                             u'tree2/\u03b1/',
1698
                             u'tree2/\u03b1/unknown_dir/',
1699
                             u'tree2/\u03b1/unknown_file',
1700
                             u'tree2/\u03b1/unknown_dir/file',
1701
                             u'tree2/\u03c9-unknown_root_file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1702
                             ])
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1703
        except UnicodeError:
1704
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1705
        tree1.add([u'\u03b1'], [a_id])
1706
        tree2.add([u'\u03b1'], [a_id])
1707
1708
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1709
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1710
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1711
        expected = self.sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1712
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1713
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1714
            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.
1715
            # a/unknown_dir/file should not be included because we should not
1716
            # recurse into unknown_dir
1717
            # self.unversioned(tree2, 'a/unknown_dir/file'),
1718
            ])
1719
        self.assertEqual(expected,
1720
                         self.do_iter_changes(tree1, tree2,
1721
                                              require_versioned=False,
1722
                                              want_unversioned=True))
7143.15.2 by Jelmer Vernooij
Run autopep8.
1723
        self.assertEqual([],  # Without want_unversioned we should get nothing
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1724
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1725
        self.check_has_changes(False, tree1, tree2)
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1726
1727
        # We should also be able to select just a subset
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1728
        expected = self.sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1729
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1730
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1731
            ])
1732
        self.assertEqual(expected,
1733
                         self.do_iter_changes(tree1, tree2,
1734
                                              specific_files=[u'\u03b1'],
1735
                                              require_versioned=False,
1736
                                              want_unversioned=True))
7143.15.2 by Jelmer Vernooij
Run autopep8.
1737
        self.assertEqual([],  # Without want_unversioned we should get nothing
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1738
                         self.do_iter_changes(tree1, tree2,
1739
                                              specific_files=[u'\u03b1']))
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1740
1741
    def test_unknown_empty_dir(self):
1742
        tree1 = self.make_branch_and_tree('tree1')
1743
        tree2 = self.make_to_branch_and_tree('tree2')
1744
        root_id = tree1.get_root_id()
1745
        tree2.set_root_id(root_id)
1746
2402.2.4 by John Arbash Meinel
Clean up the setup for clarity (suggested by Robert)
1747
        # Start with 2 identical trees
1748
        self.build_tree(['tree1/a/', 'tree1/b/',
1749
                         'tree2/a/', 'tree2/b/'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1750
        self.build_tree_contents([('tree1/b/file', b'contents\n'),
1751
                                  ('tree2/b/file', b'contents\n')])
1752
        tree1.add(['a', 'b', 'b/file'], [b'a-id', b'b-id', b'b-file-id'])
1753
        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()
1754
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1755
        # Now create some unknowns in tree2
1756
        # We should find both a/file and a/dir as unknown, but we shouldn't
1757
        # recurse into a/dir to find that a/dir/subfile is also unknown.
7143.15.2 by Jelmer Vernooij
Run autopep8.
1758
        self.build_tree(
1759
            ['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
1760
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1761
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1762
        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()
1763
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1764
        expected = self.sorted([
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1765
            self.unversioned(tree2, u'a/file'),
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1766
            self.unversioned(tree2, u'a/dir'),
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1767
            ])
1768
        self.assertEqual(expected,
1769
                         self.do_iter_changes(tree1, tree2,
1770
                                              require_versioned=False,
1771
                                              want_unversioned=True))
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1772
1773
    def test_rename_over_deleted(self):
1774
        tree1 = self.make_branch_and_tree('tree1')
1775
        tree2 = self.make_to_branch_and_tree('tree2')
1776
        root_id = tree1.get_root_id()
1777
        tree2.set_root_id(root_id)
1778
1779
        # The final changes should be:
1780
        #   touch a b c d
1781
        #   add a b c d
1782
        #   commit
1783
        #   rm a d
1784
        #   mv b a
1785
        #   mv c d
1786
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1787
            ('tree1/a', b'a contents\n'),
1788
            ('tree1/b', b'b contents\n'),
1789
            ('tree1/c', b'c contents\n'),
1790
            ('tree1/d', b'd contents\n'),
1791
            ('tree2/a', b'b contents\n'),
1792
            ('tree2/d', b'c contents\n'),
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1793
            ])
6855.4.1 by Jelmer Vernooij
Yet more bees.
1794
        tree1.add(['a', 'b', 'c', 'd'], [b'a-id', b'b-id', b'c-id', b'd-id'])
1795
        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
1796
1797
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1798
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1799
        expected = self.sorted([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1800
            self.deleted(tree1, b'a-id'),
1801
            self.deleted(tree1, b'd-id'),
1802
            self.renamed(tree1, tree2, b'b-id', False),
1803
            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
1804
            ])
1805
        self.assertEqual(expected,
1806
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1807
        self.check_has_changes(True, tree1, tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1808
1809
    def test_deleted_and_unknown(self):
1810
        """Test a file marked removed, but still present on disk."""
1811
        tree1 = self.make_branch_and_tree('tree1')
1812
        tree2 = self.make_to_branch_and_tree('tree2')
1813
        root_id = tree1.get_root_id()
1814
        tree2.set_root_id(root_id)
1815
1816
        # The final changes should be:
1817
        # bzr add a b c
1818
        # bzr rm --keep b
1819
        self.build_tree_contents([
6855.4.1 by Jelmer Vernooij
Yet more bees.
1820
            ('tree1/a', b'a contents\n'),
1821
            ('tree1/b', b'b contents\n'),
1822
            ('tree1/c', b'c contents\n'),
1823
            ('tree2/a', b'a contents\n'),
1824
            ('tree2/b', b'b contents\n'),
1825
            ('tree2/c', b'c contents\n'),
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1826
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1827
        tree1.add(['a', 'b', 'c'], [b'a-id', b'b-id', b'c-id'])
1828
        tree2.add(['a', 'c'], [b'a-id', b'c-id'])
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1829
1830
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1831
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1832
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1833
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1834
            self.deleted(tree1, b'b-id'),
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1835
            self.unversioned(tree2, 'b'),
1836
            ])
1837
        self.assertEqual(expected,
1838
                         self.do_iter_changes(tree1, tree2,
1839
                                              want_unversioned=True))
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1840
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1841
            self.deleted(tree1, b'b-id'),
2456.2.5 by John Arbash Meinel
Make sure the output with want_unversioned=False is reasonable.
1842
            ])
1843
        self.assertEqual(expected,
1844
                         self.do_iter_changes(tree1, tree2,
1845
                                              want_unversioned=False))
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1846
1847
    def test_renamed_and_added(self):
1848
        """Test when we have renamed a file, and put another in its place."""
1849
        tree1 = self.make_branch_and_tree('tree1')
1850
        tree2 = self.make_to_branch_and_tree('tree2')
1851
        root_id = tree1.get_root_id()
1852
        tree2.set_root_id(root_id)
1853
1854
        # The final changes are:
1855
        # bzr add b c
1856
        # bzr mv b a
1857
        # bzr mv c d
1858
        # bzr add b c
1859
1860
        self.build_tree_contents([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1861
            ('tree1/b', b'b contents\n'),
1862
            ('tree1/c', b'c contents\n'),
1863
            ('tree2/a', b'b contents\n'),
1864
            ('tree2/b', b'new b contents\n'),
1865
            ('tree2/c', b'new c contents\n'),
1866
            ('tree2/d', b'c contents\n'),
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1867
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1868
        tree1.add(['b', 'c'], [b'b1-id', b'c1-id'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
1869
        tree2.add(['a', 'b', 'c', 'd'], [
1870
                  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
1871
1872
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1873
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1874
        expected = self.sorted([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1875
            self.renamed(tree1, tree2, b'b1-id', False),
1876
            self.renamed(tree1, tree2, b'c1-id', False),
1877
            self.added(tree2, b'b2-id'),
1878
            self.added(tree2, b'c2-id'),
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1879
            ])
1880
        self.assertEqual(expected,
1881
                         self.do_iter_changes(tree1, tree2,
1882
                                              want_unversioned=True))
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1883
1884
    def test_renamed_and_unknown(self):
1885
        """A file was moved on the filesystem, but not in bzr."""
1886
        tree1 = self.make_branch_and_tree('tree1')
1887
        tree2 = self.make_to_branch_and_tree('tree2')
1888
        root_id = tree1.get_root_id()
1889
        tree2.set_root_id(root_id)
1890
1891
        # The final changes are:
1892
        # bzr add a b
1893
        # mv a a2
1894
1895
        self.build_tree_contents([
6855.3.1 by Jelmer Vernooij
Several more fixes.
1896
            ('tree1/a', b'a contents\n'),
1897
            ('tree1/b', b'b contents\n'),
1898
            ('tree2/a', b'a contents\n'),
1899
            ('tree2/b', b'b contents\n'),
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1900
            ])
6855.3.1 by Jelmer Vernooij
Several more fixes.
1901
        tree1.add(['a', 'b'], [b'a-id', b'b-id'])
1902
        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
1903
        os.rename('tree2/a', 'tree2/a2')
1904
1905
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1906
        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
1907
7067.6.1 by Jelmer Vernooij
Fix sorting of iter_changes results.
1908
        expected = self.sorted([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
1909
            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
1910
            self.unversioned(tree2, 'a2'),
1911
            ])
1912
        self.assertEqual(expected,
1913
                         self.do_iter_changes(tree1, tree2,
1914
                                              want_unversioned=True))