~bzr-pqm/bzr/bzr.dev

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