/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.152 by Martin Pool
(broken) merge aaron's workingtree format changes
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
2255.6.4 by Aaron Bentley
merge from dirstate
22
from bzrlib import errors, tests, workingtree_4
2321.3.4 by Alexander Belchenko
test intertree_implementations: skip tests with symlinks on platforms that don't have symlinks support
23
from bzrlib.osutils import file_kind, has_symlinks
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
24
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees
25
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
26
# TODO: test the include_root option.
27
# TODO: test that renaming a directory x->y does not emit a rename for the
28
#       child x/a->y/a.
29
# TODO: test that renaming a directory x-> does not emit a rename for the child
30
#        x/a -> y/a when a supplied_files argument gives either 'x/' or 'y/a'
31
#        -> that is, when the renamed parent is not processed by the function.
32
# TODO: test items are only emitted once when a specific_files list names a dir
33
#       whose parent is now a child.
2255.2.151 by Robert Collins
Handle specific_files natively for WorkingTreeFormat4._iter_changes.
34
# TODO: test specific_files when the target tree has a file and the source a
35
#       dir with children, same id and same path. 
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
36
# 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.
37
#
38
# TODO: More comparisons between trees with subtrees in different states.
2255.2.236 by Martin Pool
Review cleanups: mostly updating or removing todo comments.
39
#
40
# TODO: Many tests start out by setting the tree roots ids the same, maybe
41
#       that should just be the default for these tests, by changing
42
#       make_branch_and_tree.  mbp 20070307
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
43
44
class TestCompare(TestCaseWithTwoTrees):
45
46
    def test_compare_empty_trees(self):
47
        tree1 = self.make_branch_and_tree('1')
48
        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
49
        tree2.set_root_id(tree1.get_root_id())
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
50
        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.
51
        tree2 = self.get_tree_no_parents_no_content(tree2)
52
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
53
        d = self.intertree_class(tree1, tree2).compare()
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
54
        self.assertEqual([], d.added)
55
        self.assertEqual([], d.modified)
56
        self.assertEqual([], d.removed)
57
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
58
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
59
60
    def test_empty_to_abc_content(self):
61
        tree1 = self.make_branch_and_tree('1')
62
        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
63
        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.
64
        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.
65
        tree2 = self.get_tree_no_parents_abc_content(tree2)
66
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
67
        d = self.intertree_class(tree1, tree2).compare()
68
        self.assertEqual([('a', 'a-id', 'file'),
69
                          ('b', 'b-id', 'directory'),
70
                          ('b/c', 'c-id', 'file'),
71
                         ], d.added)
72
        self.assertEqual([], d.modified)
73
        self.assertEqual([], d.removed)
74
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
75
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
76
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
77
    def test_dangling(self):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
78
        # This test depends on the ability for some trees to have a difference
79
        # between a 'versioned present' and 'versioned not present' (aka
80
        # dangling) file. In this test there are two trees each with a separate
81
        # dangling file, and the dangling files should be considered absent for
82
        # the test.
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
83
        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.
84
        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
85
        tree2.set_root_id(tree1.get_root_id())
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
86
        self.build_tree(['2/a'])
87
        tree2.add('a')
88
        os.unlink('2/a')
89
        self.build_tree(['1/b'])
90
        tree1.add('b')
91
        os.unlink('1/b')
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
92
        # the conversion to test trees here will leave the trees intact for the
93
        # default intertree, but may perform a commit for other tree types,
94
        # which may reduce the validity of the test. XXX: Think about how to
95
        # address this.
96
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
97
        d = self.intertree_class(tree1, tree2).compare()
98
        self.assertEqual([], d.added)
99
        self.assertEqual([], d.modified)
100
        self.assertEqual([], d.removed)
101
        self.assertEqual([], d.renamed)
102
        self.assertEqual([], d.unchanged)
103
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
104
    def test_abc_content_to_empty(self):
105
        tree1 = self.make_branch_and_tree('1')
106
        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
107
        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.
108
        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.
109
        tree2 = self.get_tree_no_parents_no_content(tree2)
110
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
111
        d = self.intertree_class(tree1, tree2).compare()
112
        self.assertEqual([], d.added)
113
        self.assertEqual([], d.modified)
114
        self.assertEqual([('a', 'a-id', 'file'),
115
                          ('b', 'b-id', 'directory'),
116
                          ('b/c', 'c-id', 'file'),
117
                         ], d.removed)
118
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
119
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
120
121
    def test_content_modification(self):
122
        tree1 = self.make_branch_and_tree('1')
123
        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
124
        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.
125
        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.
126
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
127
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
128
        d = self.intertree_class(tree1, tree2).compare()
129
        self.assertEqual([], d.added)
130
        self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
131
        self.assertEqual([], d.removed)
132
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
133
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
134
        
135
    def test_meta_modification(self):
136
        tree1 = self.make_branch_and_tree('1')
137
        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
138
        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.
139
        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.
140
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
141
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
142
        d = self.intertree_class(tree1, tree2).compare()
143
        self.assertEqual([], d.added)
144
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
145
        self.assertEqual([], d.removed)
146
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
147
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
148
149
    def test_file_rename(self):
150
        tree1 = self.make_branch_and_tree('1')
151
        tree2 = self.make_to_branch_and_tree('2')
2255.2.161 by Martin Pool
merge some of dirstate, update comparison tests to keep tree roots the same unless they're meant to differ
152
        tree2.set_root_id(tree1.get_root_id())
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
153
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
154
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
155
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
156
        d = self.intertree_class(tree1, tree2).compare()
157
        self.assertEqual([], d.added)
158
        self.assertEqual([], d.modified)
159
        self.assertEqual([], d.removed)
160
        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=...).
161
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
162
163
    def test_file_rename_and_modification(self):
164
        tree1 = self.make_branch_and_tree('1')
165
        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
166
        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.
167
        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.
168
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
169
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
170
        d = self.intertree_class(tree1, tree2).compare()
171
        self.assertEqual([], d.added)
172
        self.assertEqual([], d.modified)
173
        self.assertEqual([], d.removed)
174
        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=...).
175
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
176
177
    def test_file_rename_and_meta_modification(self):
178
        tree1 = self.make_branch_and_tree('1')
179
        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
180
        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.
181
        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.
182
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
183
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
184
        d = self.intertree_class(tree1, tree2).compare()
185
        self.assertEqual([], d.added)
186
        self.assertEqual([], d.modified)
187
        self.assertEqual([], d.removed)
188
        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=...).
189
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
190
191
    def test_empty_to_abc_content_a_only(self):
192
        tree1 = self.make_branch_and_tree('1')
193
        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
194
        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.
195
        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.
196
        tree2 = self.get_tree_no_parents_abc_content(tree2)
197
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
198
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
199
        self.assertEqual([('a', 'a-id', 'file')], d.added)
200
        self.assertEqual([], d.modified)
201
        self.assertEqual([], d.removed)
202
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
203
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
204
205
    def test_empty_to_abc_content_a_and_c_only(self):
206
        tree1 = self.make_branch_and_tree('1')
207
        tree2 = self.make_to_branch_and_tree('2')
208
        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.
209
        tree2 = self.get_tree_no_parents_abc_content(tree2)
210
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
211
        d = self.intertree_class(tree1, tree2).compare(
212
            specific_files=['a', 'b/c'])
213
        self.assertEqual(
214
            [('a', 'a-id', 'file'), ('b/c', 'c-id', 'file')],
215
            d.added)
216
        self.assertEqual([], d.modified)
217
        self.assertEqual([], d.removed)
218
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
219
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
220
221
    def test_empty_to_abc_content_b_only(self):
222
        """Restricting to a dir matches the children of the dir."""
223
        tree1 = self.make_branch_and_tree('1')
224
        tree2 = self.make_to_branch_and_tree('2')
225
        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.
226
        tree2 = self.get_tree_no_parents_abc_content(tree2)
227
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
228
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
229
        self.assertEqual(
230
            [('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')],
231
            d.added)
232
        self.assertEqual([], d.modified)
233
        self.assertEqual([], d.removed)
234
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
235
        self.assertEqual([], d.unchanged)
236
237
    def test_unchanged_with_renames_and_modifications(self):
238
        """want_unchanged should generate a list of unchanged entries."""
239
        tree1 = self.make_branch_and_tree('1')
240
        tree2 = self.make_to_branch_and_tree('2')
241
        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.
242
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
243
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
244
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
245
        self.assertEqual([], d.added)
246
        self.assertEqual([], d.modified)
247
        self.assertEqual([], d.removed)
248
        self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
249
        self.assertEqual(
250
            [(u'b', 'b-id', 'directory'), (u'b/c', 'c-id', 'file')],
251
            d.unchanged)
252
253
    def test_extra_trees_finds_ids(self):
254
        """Ask for a delta between two trees with a path present in a third."""
255
        tree1 = self.make_branch_and_tree('1')
256
        tree2 = self.make_to_branch_and_tree('2')
257
        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.
258
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
259
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
260
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
261
        # 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.
262
        # a dispatch. XXX: For dirstate it does speak to the optimisability of
263
        # the lookup, in merged trees it can be fast-pathed. We probably want
264
        # 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=...).
265
        tree3 = self.make_branch_and_tree('3')
266
        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.
267
        tree3.lock_read()
268
        self.addCleanup(tree3.unlock)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
269
        # tree 3 has 'e' which is 'c-id'. Tree 1 has c-id at b/c, and Tree 2
270
        # has c-id at b/c with its exec flag toggled.
271
        # without extra_trees, we should get no modifications from this
272
        # so do one, to be sure the test is valid.
273
        d = self.intertree_class(tree1, tree2).compare(
274
            specific_files=['e'])
275
        self.assertEqual([], d.modified)
276
        # now give it an additional lookup:
277
        d = self.intertree_class(tree1, tree2).compare(
278
            specific_files=['e'], extra_trees=[tree3])
279
        self.assertEqual([], d.added)
280
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
281
        self.assertEqual([], d.removed)
282
        self.assertEqual([], d.renamed)
283
        self.assertEqual([], d.unchanged)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
284
285
    def test_require_versioned(self):
286
        # this does not quite robustly test, as it is passing in missing paths
287
        # rather than present-but-not-versioned paths. At the moment there is
288
        # no mechanism for managing the test trees (which are readonly) to 
289
        # get present-but-not-versioned files for trees that can do that.
290
        tree1 = self.make_branch_and_tree('1')
291
        tree2 = self.make_to_branch_and_tree('2')
292
        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.
293
        tree2 = self.get_tree_no_parents_abc_content(tree2)
294
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
295
        self.assertRaises(errors.PathsNotVersionedError, 
296
            self.intertree_class(tree1, tree2).compare,
297
            specific_files=['d'],
298
            require_versioned=True)
2012.1.1 by Aaron Bentley
Implement change iterator
299
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
300
    def test_default_ignores_unversioned_files(self):
301
        tree1 = self.make_branch_and_tree('tree1')
302
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
303
        tree2.set_root_id(tree1.get_root_id())
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
304
        self.build_tree(['tree1/a', 'tree1/c',
305
                         'tree2/a', 'tree2/b', 'tree2/c'])
306
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
307
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
308
309
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
310
        d = self.intertree_class(tree1, tree2).compare()
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
311
        self.assertEqual([], d.added)
312
        self.assertEqual([(u'a', 'a-id', 'file', True, False),
313
            (u'c', 'c-id', 'file', True, False)], d.modified)
314
        self.assertEqual([], d.removed)
315
        self.assertEqual([], d.renamed)
316
        self.assertEqual([], d.unchanged)
317
        self.assertEqual([], d.unversioned)
318
319
    def test_unversioned_paths_in_tree(self):
320
        tree1 = self.make_branch_and_tree('tree1')
321
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
322
        tree2.set_root_id(tree1.get_root_id())
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
323
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
324
        if has_symlinks():
325
            os.symlink('target', 'tree2/link')
326
            links_supported = True
327
        else:
328
            links_supported = False
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
329
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
330
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
331
        self.assertEqual([], d.added)
332
        self.assertEqual([], d.modified)
333
        self.assertEqual([], d.removed)
334
        self.assertEqual([], d.renamed)
335
        self.assertEqual([], d.unchanged)
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
336
        expected_unversioned = [(u'dir', None, 'directory'),
337
                                (u'file', None, 'file')]
338
        if links_supported:
339
            expected_unversioned.append((u'link', None, 'symlink'))
340
        self.assertEqual(expected_unversioned, d.unversioned)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
341
2012.1.1 by Aaron Bentley
Implement change iterator
342
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
343
class TestIterChanges(TestCaseWithTwoTrees):
2012.1.1 by Aaron Bentley
Implement change iterator
344
    """Test the comparison iterator"""
345
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
346
    def do_iter_changes(self, tree1, tree2, **extra_args):
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
347
        """Helper to run iter_changes from tree1 to tree2.
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
348
        
349
        :param tree1, tree2:  The source and target trees. These will be locked
350
            automatically.
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
351
        :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.
352
            inspected by this test helper.
353
        """
354
        tree1.lock_read()
355
        tree2.lock_read()
356
        try:
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
357
            # sort order of output is not strictly defined
358
            return sorted(self.intertree_class(tree1, tree2)
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
359
                .iter_changes(**extra_args))
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
360
        finally:
361
            tree1.unlock()
362
            tree2.unlock()
363
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
364
    def mutable_trees_to_locked_test_trees(self, tree1, tree2):
365
        """Convert the working trees into test trees.
366
367
        Read lock them, and add the unlock to the cleanup.
368
        """
369
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
370
        tree1.lock_read()
371
        self.addCleanup(tree1.unlock)
372
        tree2.lock_read()
373
        self.addCleanup(tree2.unlock)
374
        return tree1, tree2
375
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
376
    def make_tree_with_special_names(self):
377
        """Create a tree with filenames chosen to exercise the walk order."""
378
        tree1 = self.make_branch_and_tree('tree1')
379
        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
380
        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.
381
        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.
382
        tree2.commit('initial', rev_id='rev-1')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
383
        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.
384
        return (tree1, tree2, paths, path_ids)
385
386
    def make_trees_with_special_names(self):
387
        """Both trees will use the special names.
388
389
        But the contents will differ for each file.
390
        """
391
        tree1 = self.make_branch_and_tree('tree1')
392
        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
393
        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.
394
        paths, path_ids = self._create_special_names(tree1, 'tree1')
395
        paths, path_ids = self._create_special_names(tree2, 'tree2')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
396
        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.
397
        return (tree1, tree2, paths, path_ids)
398
399
    def _create_special_names(self, tree, base_path):
400
        """Create a tree with paths that expose differences in sort orders."""
401
        # Each directory will have a single file named 'f' inside
402
        dirs = ['a',
403
                'a-a',
404
                'a/a',
405
                'a/a-a',
406
                'a/a/a',
407
                'a/a/a-a',
408
                'a/a/a/a',
409
                'a/a/a/a-a',
410
                'a/a/a/a/a',
411
               ]
412
        with_slashes = []
413
        paths = []
414
        path_ids = []
415
        for d in dirs:
416
            with_slashes.append(base_path + '/' + d + '/')
417
            with_slashes.append(base_path + '/' + d + '/f')
418
            paths.append(d)
419
            paths.append(d+'/f')
420
            path_ids.append(d.replace('/', '_') + '-id')
421
            path_ids.append(d.replace('/', '_') + '_f-id')
422
        self.build_tree(with_slashes)
423
        tree.add(paths, path_ids)
424
        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.
425
2012.1.1 by Aaron Bentley
Implement change iterator
426
    def test_compare_empty_trees(self):
427
        tree1 = self.make_branch_and_tree('1')
428
        tree2 = self.make_to_branch_and_tree('2')
429
        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.
430
        tree2 = self.get_tree_no_parents_no_content(tree2)
431
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
3254.1.2 by Aaron Bentley
Fix doiter_changes
432
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
433
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
434
    def added(self, tree, file_id):
435
        entry = tree.inventory[file_id]
436
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
437
        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.
438
                (None, entry.name), (None, entry.kind),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
439
                (None, entry.executable))
440
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.
441
    def content_changed(self, tree, file_id):
442
        entry = tree.inventory[file_id]
443
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
444
        return (file_id, (path, path), True, (True, True), (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.
445
                (entry.name, entry.name), (entry.kind, entry.kind),
446
                (entry.executable, entry.executable))
447
448
    def kind_changed(self, from_tree, to_tree, file_id):
449
        old_entry = from_tree.inventory[file_id]
450
        new_entry = to_tree.inventory[file_id]
451
        path = to_tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
452
        from_path = from_tree.id2path(file_id)
453
        return (file_id, (from_path, path), True, (True, True), (old_entry.parent_id, new_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.
454
                (old_entry.name, new_entry.name), (old_entry.kind, new_entry.kind),
455
                (old_entry.executable, new_entry.executable))
456
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
457
    def missing(self, file_id, from_path, to_path, parent_id, kind):
458
        _, from_basename = os.path.split(from_path)
459
        _, to_basename = os.path.split(to_path)
460
        # missing files have both paths, but no kind.
461
        return (file_id, (from_path, to_path), True, (True, True),
462
            (parent_id, parent_id),
463
            (from_basename, to_basename), (kind, None), (False, False))
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
464
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
465
    def deleted(self, tree, file_id):
466
        entry = tree.inventory[file_id]
467
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
468
        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.
469
                (entry.name, None), (entry.kind, None),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
470
                (entry.executable, None))
471
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
472
    def renamed(self, from_tree, to_tree, file_id, content_changed):
473
        from_entry = from_tree.inventory[file_id]
474
        to_entry = to_tree.inventory[file_id]
475
        from_path = from_tree.id2path(file_id)
476
        to_path = to_tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
477
        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.
478
            (from_entry.parent_id, to_entry.parent_id),
479
            (from_entry.name, to_entry.name),
480
            (from_entry.kind, to_entry.kind),
481
            (from_entry.executable, to_entry.executable))
482
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.
483
    def unchanged(self, tree, file_id):
484
        entry = tree.inventory[file_id]
485
        parent = entry.parent_id
486
        name = entry.name
487
        kind = entry.kind
488
        executable = entry.executable
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
489
        path = tree.id2path(file_id)
490
        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.
491
               (parent, parent), (name, name), (kind, kind),
492
               (executable, executable))
493
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
494
    def unversioned(self, tree, path):
495
        """Create an unversioned result."""
496
        _, basename = os.path.split(path)
497
        kind = file_kind(tree.abspath(path))
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
498
        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.
499
                (None, basename), (None, kind),
500
                (None, False))
501
2012.1.1 by Aaron Bentley
Implement change iterator
502
    def test_empty_to_abc_content(self):
503
        tree1 = self.make_branch_and_tree('1')
504
        tree2 = self.make_to_branch_and_tree('2')
505
        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.
506
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
507
        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.
508
        expected_results = sorted([
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
509
            self.added(tree2, 'root-id'),
510
            self.added(tree2, 'a-id'),
511
            self.added(tree2, 'b-id'),
512
            self.added(tree2, 'c-id'),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
513
            self.deleted(tree1, 'empty-root-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
514
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
515
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
516
    def test_empty_specific_files(self):
517
        tree1 = self.make_branch_and_tree('1')
518
        tree2 = self.make_to_branch_and_tree('2')
519
        tree1 = self.get_tree_no_parents_no_content(tree1)
520
        tree2 = self.get_tree_no_parents_abc_content(tree2)
521
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
522
        self.assertEqual([],
523
            self.do_iter_changes(tree1, tree2, specific_files=[]))
524
525
    def test_no_specific_files(self):
526
        tree1 = self.make_branch_and_tree('1')
527
        tree2 = self.make_to_branch_and_tree('2')
528
        tree1 = self.get_tree_no_parents_no_content(tree1)
529
        tree2 = self.get_tree_no_parents_abc_content(tree2)
530
        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
531
        expected_results = sorted([
532
            self.added(tree2, 'root-id'),
533
            self.added(tree2, 'a-id'),
534
            self.added(tree2, 'b-id'),
535
            self.added(tree2, 'c-id'),
536
            self.deleted(tree1, 'empty-root-id')])
537
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
538
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
539
    def test_empty_to_abc_content_a_only(self):
540
        tree1 = self.make_branch_and_tree('1')
541
        tree2 = self.make_to_branch_and_tree('2')
542
        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.
543
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
544
        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.
545
        self.assertEqual(
546
            [self.added(tree2, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
547
            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.
548
549
    def test_abc_content_to_empty_to_abc_content_a_only(self):
550
        tree1 = self.make_branch_and_tree('1')
551
        tree2 = self.make_to_branch_and_tree('2')
552
        tree1 = self.get_tree_no_parents_abc_content(tree1)
553
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
554
        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.
555
        self.assertEqual(
556
            [self.deleted(tree1, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
557
            self.do_iter_changes(tree1, tree2, specific_files=['a']))
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
558
559
    def test_empty_to_abc_content_a_and_c_only(self):
560
        tree1 = self.make_branch_and_tree('1')
561
        tree2 = self.make_to_branch_and_tree('2')
562
        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.
563
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
564
        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.
565
        expected_result = [self.added(tree2, 'a-id'), self.added(tree2, 'c-id')]
566
        self.assertEqual(expected_result,
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
567
            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
568
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
569
    def test_abc_content_to_empty(self):
2012.1.1 by Aaron Bentley
Implement change iterator
570
        tree1 = self.make_branch_and_tree('1')
571
        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.
572
        tree1 = self.get_tree_no_parents_abc_content(tree1)
573
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
574
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
575
        def deleted(file_id):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
576
            entry = tree1.inventory[file_id]
577
            path = tree1.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
578
            return (file_id, (path, None), True, (True, False),
2012.1.1 by Aaron Bentley
Implement change iterator
579
                    (entry.parent_id, None),
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
580
                    (entry.name, None), (entry.kind, None),
2012.1.1 by Aaron Bentley
Implement change iterator
581
                    (entry.executable, None))
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
582
        expected_results = sorted([
583
            self.added(tree2, 'empty-root-id'),
584
            deleted('root-id'), deleted('a-id'),
585
            deleted('b-id'), deleted('c-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
586
        self.assertEqual(
587
            expected_results,
588
            self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
589
590
    def test_content_modification(self):
591
        tree1 = self.make_branch_and_tree('1')
592
        tree2 = self.make_to_branch_and_tree('2')
593
        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.
594
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
595
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
596
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
597
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
598
                           (root_id, root_id), ('a', 'a'),
599
                           ('file', 'file'), (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
600
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
601
602
    def test_meta_modification(self):
603
        tree1 = self.make_branch_and_tree('1')
604
        tree2 = self.make_to_branch_and_tree('2')
605
        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.
606
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
607
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
608
        self.assertEqual([('c-id', ('b/c', 'b/c'), False, (True, True),
609
                           ('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.
610
                          (False, True))],
611
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
612
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
613
    def test_empty_dir(self):
614
        """an empty dir should not cause glitches to surrounding files."""
615
        tree1 = self.make_branch_and_tree('1')
616
        tree2 = self.make_to_branch_and_tree('2')
617
        tree1 = self.get_tree_no_parents_abc_content(tree1)
618
        tree2 = self.get_tree_no_parents_abc_content(tree2)
619
        # the pathname is chosen to fall between 'a' and 'b'.
620
        self.build_tree(['1/a-empty/', '2/a-empty/'])
621
        tree1.add(['a-empty'], ['a-empty'])
622
        tree2.add(['a-empty'], ['a-empty'])
623
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
624
        expected = []
625
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
626
2012.1.1 by Aaron Bentley
Implement change iterator
627
    def test_file_rename(self):
628
        tree1 = self.make_branch_and_tree('1')
629
        tree2 = self.make_to_branch_and_tree('2')
630
        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.
631
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
632
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
633
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
634
        self.assertEqual([('a-id', ('a', 'd'), False, (True, True),
635
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
636
                           (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
637
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
638
639
    def test_file_rename_and_modification(self):
640
        tree1 = self.make_branch_and_tree('1')
641
        tree2 = self.make_to_branch_and_tree('2')
642
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
643
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
644
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
645
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
646
        self.assertEqual([('a-id', ('a', 'd'), True, (True, True),
647
                           (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.
648
                           (False, False))],
649
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
650
651
    def test_file_rename_and_meta_modification(self):
652
        tree1 = self.make_branch_and_tree('1')
653
        tree2 = self.make_to_branch_and_tree('2')
654
        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.
655
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
656
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
657
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
658
        self.assertEqual([('c-id', ('b/c', 'e'), False, (True, True),
659
                           ('b-id', root_id), ('c', 'e'), ('file', 'file'),
660
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
661
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
662
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
663
    def test_missing_in_target(self):
664
        """Test with the target files versioned but absent from disk."""
665
        tree1 = self.make_branch_and_tree('1')
666
        tree2 = self.make_to_branch_and_tree('2')
667
        tree1 = self.get_tree_no_parents_abc_content(tree1)
668
        tree2 = self.get_tree_no_parents_abc_content(tree2)
669
        os.unlink('2/a')
670
        shutil.rmtree('2/b')
671
        # TODO ? have a symlink here?
672
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
673
        root_id = tree1.path2id('')
674
        expected = sorted([
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
675
            self.missing('a-id', 'a', 'a', root_id, 'file'),
676
            self.missing('b-id', 'b', 'b', root_id, 'directory'),
677
            self.missing('c-id', 'b/c', 'b/c', 'b-id', 'file'),
678
            ])
679
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
680
681
    def test_missing_and_renamed(self):
682
        tree1 = self.make_branch_and_tree('tree1')
683
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
684
        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.
685
        self.build_tree(['tree1/file'])
686
        tree1.add(['file'], ['file-id'])
687
        self.build_tree(['tree2/directory/'])
688
        tree2.add(['directory'], ['file-id'])
689
        os.rmdir('tree2/directory')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
690
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
691
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
692
        root_id = tree1.path2id('')
693
        expected = sorted([
694
            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.
695
            ])
696
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
697
2012.1.1 by Aaron Bentley
Implement change iterator
698
    def test_unchanged_with_renames_and_modifications(self):
699
        """want_unchanged should generate a list of unchanged entries."""
700
        tree1 = self.make_branch_and_tree('1')
701
        tree2 = self.make_to_branch_and_tree('2')
702
        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.
703
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
704
        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.
705
        root_id = tree1.path2id('')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
706
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.
707
        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.
708
            self.unchanged(tree1, 'b-id'),
709
            ('a-id', ('a', 'd'), True, (True, True),
710
             (root_id, root_id), ('a', 'd'), ('file', 'file'),
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
711
            (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.
712
            self.do_iter_changes(tree1, tree2, include_unchanged=True))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
713
714
    def test_compare_subtrees(self):
715
        tree1 = self.make_branch_and_tree('1')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
716
        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.
717
            return
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
718
        tree1.set_root_id('root-id')
719
        subtree1 = self.make_branch_and_tree('1/sub')
720
        subtree1.set_root_id('subtree-id')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
721
        tree1.add_reference(subtree1)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
722
723
        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
724
        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.
725
            return
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
726
        tree2.set_root_id('root-id')
727
        subtree2 = self.make_to_branch_and_tree('2/sub')
728
        subtree2.set_root_id('subtree-id')
729
        tree2.add_reference(subtree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
730
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
731
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
732
        self.assertEqual([], list(tree2.iter_changes(tree1)))
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
733
        subtree1.commit('commit', rev_id='commit-a')
734
        self.assertEqual([
735
            ('root-id',
736
             (u'', u''),
737
             False,
738
             (True, True),
739
             (None, None),
740
             (u'', u''),
741
             ('directory', 'directory'),
742
             (False, False)),
743
            ('subtree-id',
744
             ('sub', 'sub',),
745
             False,
746
             (True, True),
747
             ('root-id', 'root-id'),
748
             ('sub', 'sub'),
749
             ('tree-reference', 'tree-reference'),
750
             (False, False))],
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
751
                         list(tree2.iter_changes(tree1,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
752
                             include_unchanged=True)))
2255.2.160 by Martin Pool
(merge) updates from dirstate branch
753
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
754
    def test_disk_in_subtrees_skipped(self):
755
        """subtrees are considered not-in-the-current-tree.
756
        
757
        This test tests the trivial case, where the basis has no paths in the
758
        current trees subtree.
759
        """
760
        tree1 = self.make_branch_and_tree('1')
761
        tree1.set_root_id('root-id')
762
        tree2 = self.make_to_branch_and_tree('2')
763
        if not tree2.supports_tree_reference():
764
            return
765
        tree2.set_root_id('root-id')
766
        subtree2 = self.make_to_branch_and_tree('2/sub')
767
        subtree2.set_root_id('subtree-id')
768
        tree2.add(['sub'], ['subtree-id'])
769
        self.build_tree(['2/sub/file'])
770
        subtree2.add(['file'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
771
772
        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.
773
        # this should filter correctly from above
774
        self.assertEqual([self.added(tree2, 'subtree-id')],
775
            self.do_iter_changes(tree1, tree2, want_unversioned=True))
776
        # and when the path is named
777
        self.assertEqual([self.added(tree2, 'subtree-id')],
778
            self.do_iter_changes(tree1, tree2, specific_files=['sub'],
779
                want_unversioned=True))
780
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
781
    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.
782
        tree1 = self.make_branch_and_tree('tree1')
783
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
784
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
785
        self.build_tree(['tree1/a', 'tree1/c',
786
                         'tree2/a', 'tree2/b', 'tree2/c'])
787
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
788
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
789
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
790
        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.
791
792
        # We should ignore the fact that 'b' exists in tree-2
793
        # because the want_unversioned parameter was not given.
794
        expected = sorted([
795
            self.content_changed(tree2, 'a-id'),
796
            self.content_changed(tree2, 'c-id'),
797
            ])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
798
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
799
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
800
    def test_unversioned_paths_in_tree(self):
801
        tree1 = self.make_branch_and_tree('tree1')
802
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
803
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
804
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
805
        if has_symlinks():
806
            os.symlink('target', 'tree2/link')
807
            links_supported = True
808
        else:
809
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
810
        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.
811
        expected = [
812
            self.unversioned(tree2, 'file'),
813
            self.unversioned(tree2, 'dir'),
814
            ]
815
        if links_supported:
816
            expected.append(self.unversioned(tree2, 'link'))
817
        expected = sorted(expected)
818
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
819
            want_unversioned=True))
820
821
    def test_unversioned_paths_in_tree_specific_files(self):
822
        tree1 = self.make_branch_and_tree('tree1')
823
        tree2 = self.make_to_branch_and_tree('tree2')
824
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
825
        if has_symlinks():
826
            os.symlink('target', 'tree2/link')
827
            links_supported = True
828
        else:
829
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
830
        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.
831
        expected = [
832
            self.unversioned(tree2, 'file'),
833
            self.unversioned(tree2, 'dir'),
834
            ]
835
        specific_files=['file', 'dir']
836
        if links_supported:
837
            expected.append(self.unversioned(tree2, 'link'))
838
            specific_files.append('link')
839
        expected = sorted(expected)
840
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
841
            specific_files=specific_files, require_versioned=False,
842
            want_unversioned=True))
843
844
    def test_unversioned_paths_in_target_matching_source_old_names(self):
845
        # its likely that naive implementations of unversioned file support
846
        # will fail if the path was versioned, but is not any more, 
847
        # due to a rename, not due to unversioning it.
848
        # That is, if the old tree has a versioned file 'foo', and
849
        # the new tree has the same file but versioned as 'bar', and also
850
        # has an unknown file 'foo', we should get back output for
851
        # both foo and bar.
852
        tree1 = self.make_branch_and_tree('tree1')
853
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.187 by Martin Pool
set common root ids in more tests
854
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
855
        self.build_tree(['tree2/file', 'tree2/dir/',
856
            'tree1/file', 'tree2/movedfile',
857
            'tree1/dir/', 'tree2/moveddir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
858
        if has_symlinks():
859
            os.symlink('target', 'tree1/link')
860
            os.symlink('target', 'tree2/link')
861
            os.symlink('target', 'tree2/movedlink')
862
            links_supported = True
863
        else:
864
            links_supported = False
865
        tree1.add(['file', 'dir'], ['file-id', 'dir-id'])
866
        tree2.add(['movedfile', 'moveddir'], ['file-id', 'dir-id'])
867
        if links_supported:
868
            tree1.add(['link'], ['link-id'])
869
            tree2.add(['movedlink'], ['link-id'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
870
        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.
871
        root_id = tree1.path2id('')
872
        expected = [
873
            self.renamed(tree1, tree2, 'dir-id', False),
874
            self.renamed(tree1, tree2, 'file-id', True),
875
            self.unversioned(tree2, 'file'),
876
            self.unversioned(tree2, 'dir'),
877
            ]
878
        specific_files=['file', 'dir']
879
        if links_supported:
880
            expected.append(self.renamed(tree1, tree2, 'link-id', False))
881
            expected.append(self.unversioned(tree2, 'link'))
882
            specific_files.append('link')
883
        expected = sorted(expected)
884
        # run once with, and once without specific files, to catch
885
        # potentially different code paths.
886
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
887
            require_versioned=False,
888
            want_unversioned=True))
889
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
890
            specific_files=specific_files, require_versioned=False,
891
            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.
892
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
893
    def test_similar_filenames(self):
894
        """Test when we have a few files with similar names."""
895
        tree1 = self.make_branch_and_tree('tree1')
896
        tree2 = self.make_branch_and_tree('tree2')
897
        tree2.set_root_id(tree1.get_root_id())
898
899
        # The trees are actually identical, but they happen to contain
900
        # similarly named files.
901
        self.build_tree(['tree1/a/',
902
                         'tree1/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
903
                         'tree1/a/b/c/',
904
                         'tree1/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
905
                         'tree1/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
906
                         'tree1/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
907
                         'tree2/a/',
908
                         'tree2/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
909
                         'tree2/a/b/c/',
910
                         'tree2/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
911
                         'tree2/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
912
                         'tree2/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
913
                        ])
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
914
        tree1.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
915
                  ['a-id', 'b-id', 'c-id', 'd-id', 'a-c-id', 'e-id'])
916
        tree2.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
917
                  ['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
918
919
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
920
921
        self.assertEqual([], self.do_iter_changes(tree1, tree2,
922
                                                  want_unversioned=True))
2466.5.2 by John Arbash Meinel
Extend the test a bit to make sure the include_unchanged value is correct.
923
        expected = sorted([
924
            self.unchanged(tree2, tree2.get_root_id()),
925
            self.unchanged(tree2, 'a-id'),
926
            self.unchanged(tree2, 'b-id'),
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
927
            self.unchanged(tree2, 'c-id'),
928
            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.
929
            self.unchanged(tree2, 'a-c-id'),
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
930
            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.
931
            ])
932
        self.assertEqual(expected,
933
                         self.do_iter_changes(tree1, tree2,
934
                                              want_unversioned=True,
935
                                              include_unchanged=True))
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
936
937
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
938
    def test_unversioned_subtree_only_emits_root(self):
939
        tree1 = self.make_branch_and_tree('tree1')
940
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.188 by Martin Pool
Set common root id in comparison tests
941
        tree2.set_root_id(tree1.get_root_id())
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
942
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
943
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
944
        expected = [
945
            self.unversioned(tree2, 'dir'),
946
            ]
947
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
948
            want_unversioned=True))
949
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.
950
    def make_trees_with_symlinks(self):
951
        tree1 = self.make_branch_and_tree('tree1')
952
        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
953
        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.
954
        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
955
        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
956
        os.symlink('original', 'tree1/changed')
957
        os.symlink('original', 'tree1/removed')
958
        os.symlink('original', 'tree1/tofile')
959
        os.symlink('original', 'tree1/todir')
960
        # we make the unchanged link point at unknown to catch incorrect
961
        # symlink-following code in the specified_files test.
962
        os.symlink('unknown', 'tree1/unchanged')
963
        os.symlink('new',      'tree2/added')
964
        os.symlink('new',      'tree2/changed')
965
        os.symlink('new',      'tree2/fromfile')
966
        os.symlink('new',      'tree2/fromdir')
967
        os.symlink('unknown', 'tree2/unchanged')
968
        from_paths_and_ids = [
969
            'fromdir',
970
            'fromfile',
971
            'changed',
972
            'removed',
973
            'todir',
974
            'tofile',
975
            'unchanged',
976
            ]
977
        to_paths_and_ids = [
978
            'added',
979
            'fromdir',
980
            'fromfile',
981
            'changed',
982
            'todir',
983
            'tofile',
984
            'unchanged',
985
            ]
986
        tree1.add(from_paths_and_ids, from_paths_and_ids)
987
        tree2.add(to_paths_and_ids, to_paths_and_ids)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
988
        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.
989
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
990
    def test_versioned_symlinks(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
991
        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.
992
        tree1, tree2 = self.make_trees_with_symlinks()
993
        root_id = tree1.path2id('')
994
        expected = [
995
            self.unchanged(tree1, tree1.path2id('')),
996
            self.added(tree2, 'added'),
997
            self.content_changed(tree2, 'changed'),
998
            self.kind_changed(tree1, tree2, 'fromdir'),
999
            self.kind_changed(tree1, tree2, 'fromfile'),
1000
            self.deleted(tree1, 'removed'),
1001
            self.unchanged(tree2, 'unchanged'),
1002
            self.unversioned(tree2, 'unknown'),
1003
            self.kind_changed(tree1, tree2, 'todir'),
1004
            self.kind_changed(tree1, tree2, 'tofile'),
1005
            ]
1006
        expected = sorted(expected)
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1007
        self.assertEqual(expected,
1008
            self.do_iter_changes(tree1, tree2, include_unchanged=True,
1009
                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.
1010
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1011
    def test_versioned_symlinks_specific_files(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
1012
        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.
1013
        tree1, tree2 = self.make_trees_with_symlinks()
1014
        root_id = tree1.path2id('')
1015
        expected = [
1016
            self.added(tree2, 'added'),
1017
            self.content_changed(tree2, 'changed'),
1018
            self.kind_changed(tree1, tree2, 'fromdir'),
1019
            self.kind_changed(tree1, tree2, 'fromfile'),
1020
            self.deleted(tree1, 'removed'),
1021
            self.kind_changed(tree1, tree2, 'todir'),
1022
            self.kind_changed(tree1, tree2, 'tofile'),
1023
            ]
1024
        expected = sorted(expected)
1025
        # we should get back just the changed links. We pass in 'unchanged' to
1026
        # make sure that it is correctly not returned - and neither is the
1027
        # unknown path 'unknown' which it points at.
1028
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1029
            specific_files=['added', 'changed', 'fromdir', 'fromfile',
1030
            'removed', 'unchanged', 'todir', 'tofile']))
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
1031
2255.7.21 by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to
1032
    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.
1033
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1034
        expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
1035
        self.assertEqual(expected, self.do_iter_changes(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.
1036
1037
    def test_trees_with_special_names(self):
1038
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1039
        expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1040
                          if f_id.endswith('_f-id'))
1041
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
2255.7.34 by John Arbash Meinel
Clean up test_bad_files, and fix a bug in _iter_changes when
1042
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1043
    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.
1044
        tree1 = self.make_branch_and_tree('tree1')
1045
        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
1046
        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.
1047
        self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',
1048
                         'tree1/b/d/', 'tree1/b/d/e', 'tree1/f/', 'tree1/f/g',
1049
                         'tree2/a', 'tree2/f/', 'tree2/f/g'])
1050
        tree1.add(['a', 'b', 'b/c', 'b/d/', 'b/d/e', 'f', 'f/g'],
1051
                  ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'f-id', 'g-id'])
1052
        tree2.add(['a', 'f', 'f/g'], ['a-id', 'f-id', 'g-id'])
1053
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1054
        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.
1055
        # We should notice that 'b' and all its children are deleted
2255.7.35 by John Arbash Meinel
Handle the case when a directory has been removed, and isn't the last entry.
1056
        expected = sorted([
1057
            self.content_changed(tree2, 'a-id'),
1058
            self.content_changed(tree2, 'g-id'),
1059
            self.deleted(tree1, 'b-id'),
1060
            self.deleted(tree1, 'c-id'),
1061
            self.deleted(tree1, 'd-id'),
1062
            self.deleted(tree1, 'e-id'),
1063
            ])
1064
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1065
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1066
    def test_added_unicode(self):
1067
        tree1 = self.make_branch_and_tree('tree1')
1068
        tree2 = self.make_to_branch_and_tree('tree2')
1069
        root_id = tree1.get_root_id()
1070
        tree2.set_root_id(root_id)
1071
1072
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1073
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1074
        a_id = u'\u03b1-id'.encode('utf8')
1075
        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.
1076
        try:
1077
            self.build_tree([u'tree1/\u03b1/',
1078
                             u'tree2/\u03b1/',
1079
                             u'tree2/\u03b1/\u03c9-added',
1080
                            ])
1081
        except UnicodeError:
1082
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1083
        tree1.add([u'\u03b1'], [a_id])
1084
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-added'], [a_id, added_id])
1085
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1086
        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.
1087
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1088
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1089
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1090
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1091
                         self.do_iter_changes(tree1, tree2,
1092
                                              specific_files=[u'\u03b1']))
1093
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1094
    def test_deleted_unicode(self):
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1095
        tree1 = self.make_branch_and_tree('tree1')
1096
        tree2 = self.make_to_branch_and_tree('tree2')
1097
        root_id = tree1.get_root_id()
1098
        tree2.set_root_id(root_id)
1099
1100
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1101
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1102
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1103
        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.
1104
        try:
1105
            self.build_tree([u'tree1/\u03b1/',
1106
                             u'tree1/\u03b1/\u03c9-deleted',
1107
                             u'tree2/\u03b1/',
1108
                            ])
1109
        except UnicodeError:
1110
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1111
        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.
1112
        tree2.add([u'\u03b1'], [a_id])
1113
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1114
        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.
1115
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1116
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1117
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1118
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1119
                         self.do_iter_changes(tree1, tree2,
1120
                                              specific_files=[u'\u03b1']))
1121
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1122
    def test_modified_unicode(self):
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1123
        tree1 = self.make_branch_and_tree('tree1')
1124
        tree2 = self.make_to_branch_and_tree('tree2')
1125
        root_id = tree1.get_root_id()
1126
        tree2.set_root_id(root_id)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1127
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1128
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1129
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1130
        a_id = u'\u03b1-id'.encode('utf8')
1131
        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.
1132
        try:
1133
            self.build_tree([u'tree1/\u03b1/',
1134
                             u'tree1/\u03b1/\u03c9-modified',
1135
                             u'tree2/\u03b1/',
1136
                             u'tree2/\u03b1/\u03c9-modified',
1137
                            ])
1138
        except UnicodeError:
1139
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1140
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1141
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1142
1143
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1144
1145
        self.assertEqual([self.content_changed(tree1, mod_id)],
1146
                         self.do_iter_changes(tree1, tree2))
1147
        self.assertEqual([self.content_changed(tree1, mod_id)],
1148
                         self.do_iter_changes(tree1, tree2,
1149
                                              specific_files=[u'\u03b1']))
1150
1151
    def test_renamed_unicode(self):
1152
        tree1 = self.make_branch_and_tree('tree1')
1153
        tree2 = self.make_to_branch_and_tree('tree2')
1154
        root_id = tree1.get_root_id()
1155
        tree2.set_root_id(root_id)
1156
1157
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1158
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1159
        a_id = u'\u03b1-id'.encode('utf8')
1160
        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.
1161
        try:
1162
            self.build_tree([u'tree1/\u03b1/',
1163
                             u'tree2/\u03b1/',
1164
                            ])
1165
        except UnicodeError:
1166
            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.
1167
        self.build_tree_contents([(u'tree1/\u03c9-source', 'contents\n'),
1168
                                  (u'tree2/\u03b1/\u03c9-target', 'contents\n'),
1169
                                 ])
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1170
        tree1.add([u'\u03b1', u'\u03c9-source'], [a_id, rename_id])
1171
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-target'], [a_id, rename_id])
1172
1173
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1174
1175
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1176
                         self.do_iter_changes(tree1, tree2))
1177
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1178
                         self.do_iter_changes(tree1, tree2,
1179
                                              specific_files=[u'\u03b1']))
1180
1181
    def test_unchanged_unicode(self):
1182
        tree1 = self.make_branch_and_tree('tree1')
1183
        tree2 = self.make_to_branch_and_tree('tree2')
1184
        root_id = tree1.get_root_id()
1185
        tree2.set_root_id(root_id)
1186
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1187
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1188
        a_id = u'\u03b1-id'.encode('utf8')
1189
        subfile_id = u'\u03c9-subfile-id'.encode('utf8')
1190
        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.
1191
        try:
1192
            self.build_tree([u'tree1/\u03b1/',
1193
                             u'tree2/\u03b1/',
1194
                            ])
1195
        except UnicodeError:
1196
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1197
        self.build_tree_contents([
1198
            (u'tree1/\u03b1/\u03c9-subfile', 'sub contents\n'),
1199
            (u'tree2/\u03b1/\u03c9-subfile', 'sub contents\n'),
1200
            (u'tree1/\u03c9-rootfile', 'root contents\n'),
1201
            (u'tree2/\u03c9-rootfile', 'root contents\n'),
1202
            ])
1203
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1204
                  [a_id, subfile_id, rootfile_id])
1205
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1206
                  [a_id, subfile_id, rootfile_id])
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1207
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1208
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1209
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1210
        expected = sorted([
1211
            self.unchanged(tree1, root_id),
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1212
            self.unchanged(tree1, a_id),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1213
            self.unchanged(tree1, subfile_id),
1214
            self.unchanged(tree1, rootfile_id),
1215
            ])
1216
        self.assertEqual(expected,
1217
                         self.do_iter_changes(tree1, tree2,
1218
                                              include_unchanged=True))
1219
1220
        # We should also be able to select just a subset
1221
        expected = sorted([
1222
            self.unchanged(tree1, a_id),
1223
            self.unchanged(tree1, subfile_id),
1224
            ])
1225
        self.assertEqual(expected,
1226
                         self.do_iter_changes(tree1, tree2,
1227
                                              specific_files=[u'\u03b1'],
1228
                                              include_unchanged=True))
1229
1230
    def test_unknown_unicode(self):
1231
        tree1 = self.make_branch_and_tree('tree1')
1232
        tree2 = self.make_to_branch_and_tree('tree2')
1233
        root_id = tree1.get_root_id()
1234
        tree2.set_root_id(root_id)
1235
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1236
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1237
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1238
        try:
1239
            self.build_tree([u'tree1/\u03b1/',
1240
                             u'tree2/\u03b1/',
1241
                             u'tree2/\u03b1/unknown_dir/',
1242
                             u'tree2/\u03b1/unknown_file',
1243
                             u'tree2/\u03b1/unknown_dir/file',
1244
                             u'tree2/\u03c9-unknown_root_file',
1245
                            ])
1246
        except UnicodeError:
1247
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1248
        tree1.add([u'\u03b1'], [a_id])
1249
        tree2.add([u'\u03b1'], [a_id])
1250
1251
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1252
1253
        expected = sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1254
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1255
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1256
            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.
1257
            # a/unknown_dir/file should not be included because we should not
1258
            # recurse into unknown_dir
1259
            # self.unversioned(tree2, 'a/unknown_dir/file'),
1260
            ])
1261
        self.assertEqual(expected,
1262
                         self.do_iter_changes(tree1, tree2,
1263
                                              require_versioned=False,
1264
                                              want_unversioned=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1265
        self.assertEqual([], # Without want_unversioned we should get nothing
1266
                         self.do_iter_changes(tree1, tree2))
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1267
1268
        # We should also be able to select just a subset
1269
        expected = sorted([
1270
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1271
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1272
            ])
1273
        self.assertEqual(expected,
1274
                         self.do_iter_changes(tree1, tree2,
1275
                                              specific_files=[u'\u03b1'],
1276
                                              require_versioned=False,
1277
                                              want_unversioned=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1278
        self.assertEqual([], # Without want_unversioned we should get nothing
1279
                         self.do_iter_changes(tree1, tree2,
1280
                                              specific_files=[u'\u03b1']))
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1281
1282
    def test_unknown_empty_dir(self):
1283
        tree1 = self.make_branch_and_tree('tree1')
1284
        tree2 = self.make_to_branch_and_tree('tree2')
1285
        root_id = tree1.get_root_id()
1286
        tree2.set_root_id(root_id)
1287
2402.2.4 by John Arbash Meinel
Clean up the setup for clarity (suggested by Robert)
1288
        # Start with 2 identical trees
1289
        self.build_tree(['tree1/a/', 'tree1/b/',
1290
                         'tree2/a/', 'tree2/b/'])
1291
        self.build_tree_contents([('tree1/b/file', 'contents\n'),
1292
                                  ('tree2/b/file', 'contents\n')])
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1293
        tree1.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
1294
        tree2.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
1295
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1296
        # Now create some unknowns in tree2
1297
        # We should find both a/file and a/dir as unknown, but we shouldn't
1298
        # recurse into a/dir to find that a/dir/subfile is also unknown.
1299
        self.build_tree(['tree2/a/file', 'tree2/a/dir/', 'tree2/a/dir/subfile'])
1300
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1301
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1302
1303
        expected = sorted([
1304
            self.unversioned(tree2, u'a/file'),
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1305
            self.unversioned(tree2, u'a/dir'),
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1306
            ])
1307
        self.assertEqual(expected,
1308
                         self.do_iter_changes(tree1, tree2,
1309
                                              require_versioned=False,
1310
                                              want_unversioned=True))
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1311
1312
    def test_rename_over_deleted(self):
1313
        tree1 = self.make_branch_and_tree('tree1')
1314
        tree2 = self.make_to_branch_and_tree('tree2')
1315
        root_id = tree1.get_root_id()
1316
        tree2.set_root_id(root_id)
1317
1318
        # The final changes should be:
1319
        #   touch a b c d
1320
        #   add a b c d
1321
        #   commit
1322
        #   rm a d
1323
        #   mv b a
1324
        #   mv c d
1325
        self.build_tree_contents([
1326
            ('tree1/a', 'a contents\n'),
1327
            ('tree1/b', 'b contents\n'),
1328
            ('tree1/c', 'c contents\n'),
1329
            ('tree1/d', 'd contents\n'),
1330
            ('tree2/a', 'b contents\n'),
1331
            ('tree2/d', 'c contents\n'),
1332
            ])
1333
        tree1.add(['a', 'b', 'c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
1334
        tree2.add(['a', 'd'], ['b-id', 'c-id'])
1335
1336
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1337
1338
        expected = sorted([
1339
            self.deleted(tree1, 'a-id'),
1340
            self.deleted(tree1, 'd-id'),
1341
            self.renamed(tree1, tree2, 'b-id', False),
1342
            self.renamed(tree1, tree2, 'c-id', False),
1343
            ])
1344
        self.assertEqual(expected,
1345
                         self.do_iter_changes(tree1, tree2))
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1346
1347
    def test_deleted_and_unknown(self):
1348
        """Test a file marked removed, but still present on disk."""
1349
        tree1 = self.make_branch_and_tree('tree1')
1350
        tree2 = self.make_to_branch_and_tree('tree2')
1351
        root_id = tree1.get_root_id()
1352
        tree2.set_root_id(root_id)
1353
1354
        # The final changes should be:
1355
        # bzr add a b c
1356
        # bzr rm --keep b
1357
        self.build_tree_contents([
1358
            ('tree1/a', 'a contents\n'),
1359
            ('tree1/b', 'b contents\n'),
1360
            ('tree1/c', 'c contents\n'),
1361
            ('tree2/a', 'a contents\n'),
1362
            ('tree2/b', 'b contents\n'),
1363
            ('tree2/c', 'c contents\n'),
1364
            ])
1365
        tree1.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
1366
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
1367
1368
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1369
1370
        expected = sorted([
1371
            self.deleted(tree1, 'b-id'),
1372
            self.unversioned(tree2, 'b'),
1373
            ])
1374
        self.assertEqual(expected,
1375
                         self.do_iter_changes(tree1, tree2,
1376
                                              want_unversioned=True))
2456.2.5 by John Arbash Meinel
Make sure the output with want_unversioned=False is reasonable.
1377
        expected = sorted([
1378
            self.deleted(tree1, 'b-id'),
1379
            ])
1380
        self.assertEqual(expected,
1381
                         self.do_iter_changes(tree1, tree2,
1382
                                              want_unversioned=False))
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1383
1384
    def test_renamed_and_added(self):
1385
        """Test when we have renamed a file, and put another in its place."""
1386
        tree1 = self.make_branch_and_tree('tree1')
1387
        tree2 = self.make_to_branch_and_tree('tree2')
1388
        root_id = tree1.get_root_id()
1389
        tree2.set_root_id(root_id)
1390
1391
        # The final changes are:
1392
        # bzr add b c
1393
        # bzr mv b a
1394
        # bzr mv c d
1395
        # bzr add b c
1396
1397
        self.build_tree_contents([
1398
            ('tree1/b', 'b contents\n'),
1399
            ('tree1/c', 'c contents\n'),
1400
            ('tree2/a', 'b contents\n'),
1401
            ('tree2/b', 'new b contents\n'),
1402
            ('tree2/c', 'new c contents\n'),
1403
            ('tree2/d', 'c contents\n'),
1404
            ])
1405
        tree1.add(['b', 'c'], ['b1-id', 'c1-id'])
1406
        tree2.add(['a', 'b', 'c', 'd'], ['b1-id', 'b2-id', 'c2-id', 'c1-id'])
1407
1408
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1409
1410
        expected = sorted([
1411
            self.renamed(tree1, tree2, 'b1-id', False),
1412
            self.renamed(tree1, tree2, 'c1-id', False),
1413
            self.added(tree2, 'b2-id'),
1414
            self.added(tree2, 'c2-id'),
1415
            ])
1416
        self.assertEqual(expected,
1417
                         self.do_iter_changes(tree1, tree2,
1418
                                              want_unversioned=True))
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1419
1420
    def test_renamed_and_unknown(self):
1421
        """A file was moved on the filesystem, but not in bzr."""
1422
        tree1 = self.make_branch_and_tree('tree1')
1423
        tree2 = self.make_to_branch_and_tree('tree2')
1424
        root_id = tree1.get_root_id()
1425
        tree2.set_root_id(root_id)
1426
1427
        # The final changes are:
1428
        # bzr add a b
1429
        # mv a a2
1430
1431
        self.build_tree_contents([
1432
            ('tree1/a', 'a contents\n'),
1433
            ('tree1/b', 'b contents\n'),
1434
            ('tree2/a', 'a contents\n'),
1435
            ('tree2/b', 'b contents\n'),
1436
            ])
1437
        tree1.add(['a', 'b'], ['a-id', 'b-id'])
1438
        tree2.add(['a', 'b'], ['a-id', 'b-id'])
1439
        os.rename('tree2/a', 'tree2/a2')
1440
1441
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1442
1443
        expected = sorted([
1444
            self.missing('a-id', 'a', 'a', tree2.get_root_id(), 'file'),
1445
            self.unversioned(tree2, 'a2'),
1446
            ])
1447
        self.assertEqual(expected,
1448
                         self.do_iter_changes(tree1, tree2,
1449
                                              want_unversioned=True))