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