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