/brz/remove-bazaar

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