/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 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
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
22
from bzrlib import errors
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
23
from bzrlib.osutils import file_kind
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
24
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees
25
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
26
# TODO: test diff unversioned dir that exists
27
# TODO: test the include_root option.
28
# TODO: test that renaming a directory x->y does not emit a rename for the
29
#       child x/a->y/a.
30
# TODO: test that renaming a directory x-> does not emit a rename for the child
31
#        x/a -> y/a when a supplied_files argument gives either 'x/' or 'y/a'
32
#        -> that is, when the renamed parent is not processed by the function.
33
# TODO: include dangling in the diff output.
34
# TODO: test items are only emitted once when a specific_files list names a dir
35
#       whose parent is now a child.
36
# TODO: test require_versioned
2255.2.151 by Robert Collins
Handle specific_files natively for WorkingTreeFormat4._iter_changes.
37
# TODO: explicitly test specific_files listing a non-dir, and listing a symlink
38
#       (it should not follow the link)
39
# TODO: test specific_files when the target tree has a file and the source a
40
#       dir with children, same id and same path. 
41
# TODO: test specific_files with a new unversioned path.
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
42
43
class TestCompare(TestCaseWithTwoTrees):
44
45
    def test_compare_empty_trees(self):
46
        tree1 = self.make_branch_and_tree('1')
47
        tree2 = self.make_to_branch_and_tree('2')
48
        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.
49
        tree2 = self.get_tree_no_parents_no_content(tree2)
50
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
51
        d = self.intertree_class(tree1, tree2).compare()
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
52
        self.assertEqual([], d.added)
53
        self.assertEqual([], d.modified)
54
        self.assertEqual([], d.removed)
55
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
56
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
57
58
    def test_empty_to_abc_content(self):
59
        tree1 = self.make_branch_and_tree('1')
60
        tree2 = self.make_to_branch_and_tree('2')
61
        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.
62
        tree2 = self.get_tree_no_parents_abc_content(tree2)
63
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
64
        d = self.intertree_class(tree1, tree2).compare()
65
        self.assertEqual([('a', 'a-id', 'file'),
66
                          ('b', 'b-id', 'directory'),
67
                          ('b/c', 'c-id', 'file'),
68
                         ], d.added)
69
        self.assertEqual([], d.modified)
70
        self.assertEqual([], d.removed)
71
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
72
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
73
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
74
    def test_dangling(self):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
75
        # This test depends on the ability for some trees to have a difference
76
        # between a 'versioned present' and 'versioned not present' (aka
77
        # dangling) file. In this test there are two trees each with a separate
78
        # dangling file, and the dangling files should be considered absent for
79
        # the test.
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
80
        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.
81
        tree2 = self.make_to_branch_and_tree('2')
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
82
        self.build_tree(['2/a'])
83
        tree2.add('a')
84
        os.unlink('2/a')
85
        self.build_tree(['1/b'])
86
        tree1.add('b')
87
        os.unlink('1/b')
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
88
        # the conversion to test trees here will leave the trees intact for the
89
        # default intertree, but may perform a commit for other tree types,
90
        # which may reduce the validity of the test. XXX: Think about how to
91
        # address this.
92
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
93
        d = self.intertree_class(tree1, tree2).compare()
94
        self.assertEqual([], d.added)
95
        self.assertEqual([], d.modified)
96
        self.assertEqual([], d.removed)
97
        self.assertEqual([], d.renamed)
98
        self.assertEqual([], d.unchanged)
99
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
100
    def test_abc_content_to_empty(self):
101
        tree1 = self.make_branch_and_tree('1')
102
        tree2 = self.make_to_branch_and_tree('2')
103
        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.
104
        tree2 = self.get_tree_no_parents_no_content(tree2)
105
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
106
        d = self.intertree_class(tree1, tree2).compare()
107
        self.assertEqual([], d.added)
108
        self.assertEqual([], d.modified)
109
        self.assertEqual([('a', 'a-id', 'file'),
110
                          ('b', 'b-id', 'directory'),
111
                          ('b/c', 'c-id', 'file'),
112
                         ], d.removed)
113
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
114
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
115
116
    def test_content_modification(self):
117
        tree1 = self.make_branch_and_tree('1')
118
        tree2 = self.make_to_branch_and_tree('2')
119
        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.
120
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
121
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
122
        d = self.intertree_class(tree1, tree2).compare()
123
        self.assertEqual([], d.added)
124
        self.assertEqual([('a', 'a-id', 'file', True, False)], d.modified)
125
        self.assertEqual([], d.removed)
126
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
127
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
128
        
129
    def test_meta_modification(self):
130
        tree1 = self.make_branch_and_tree('1')
131
        tree2 = self.make_to_branch_and_tree('2')
132
        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.
133
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
134
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
135
        d = self.intertree_class(tree1, tree2).compare()
136
        self.assertEqual([], d.added)
137
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
138
        self.assertEqual([], d.removed)
139
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
140
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
141
142
    def test_file_rename(self):
143
        tree1 = self.make_branch_and_tree('1')
144
        tree2 = self.make_to_branch_and_tree('2')
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_4(tree2)
147
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
148
        d = self.intertree_class(tree1, tree2).compare()
149
        self.assertEqual([], d.added)
150
        self.assertEqual([], d.modified)
151
        self.assertEqual([], d.removed)
152
        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=...).
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_and_modification(self):
156
        tree1 = self.make_branch_and_tree('1')
157
        tree2 = self.make_to_branch_and_tree('2')
158
        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.
159
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
160
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
161
        d = self.intertree_class(tree1, tree2).compare()
162
        self.assertEqual([], d.added)
163
        self.assertEqual([], d.modified)
164
        self.assertEqual([], d.removed)
165
        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=...).
166
        self.assertEqual([], d.unchanged)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
167
168
    def test_file_rename_and_meta_modification(self):
169
        tree1 = self.make_branch_and_tree('1')
170
        tree2 = self.make_to_branch_and_tree('2')
171
        tree1 = self.get_tree_no_parents_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
172
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
173
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
174
        d = self.intertree_class(tree1, tree2).compare()
175
        self.assertEqual([], d.added)
176
        self.assertEqual([], d.modified)
177
        self.assertEqual([], d.removed)
178
        self.assertEqual([('b/c', 'e', 'c-id', 'file', False, True)], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
179
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
180
181
    def test_empty_to_abc_content_a_only(self):
182
        tree1 = self.make_branch_and_tree('1')
183
        tree2 = self.make_to_branch_and_tree('2')
184
        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.
185
        tree2 = self.get_tree_no_parents_abc_content(tree2)
186
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
187
        d = self.intertree_class(tree1, tree2).compare(specific_files=['a'])
188
        self.assertEqual([('a', 'a-id', 'file')], d.added)
189
        self.assertEqual([], d.modified)
190
        self.assertEqual([], d.removed)
191
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
192
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
193
194
    def test_empty_to_abc_content_a_and_c_only(self):
195
        tree1 = self.make_branch_and_tree('1')
196
        tree2 = self.make_to_branch_and_tree('2')
197
        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.
198
        tree2 = self.get_tree_no_parents_abc_content(tree2)
199
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
200
        d = self.intertree_class(tree1, tree2).compare(
201
            specific_files=['a', 'b/c'])
202
        self.assertEqual(
203
            [('a', 'a-id', 'file'), ('b/c', 'c-id', 'file')],
204
            d.added)
205
        self.assertEqual([], d.modified)
206
        self.assertEqual([], d.removed)
207
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
208
        self.assertEqual([], d.unchanged)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
209
210
    def test_empty_to_abc_content_b_only(self):
211
        """Restricting to a dir matches the children of the dir."""
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)
216
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.3 by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate.
217
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
218
        self.assertEqual(
219
            [('b', 'b-id', 'directory'),('b/c', 'c-id', 'file')],
220
            d.added)
221
        self.assertEqual([], d.modified)
222
        self.assertEqual([], d.removed)
223
        self.assertEqual([], d.renamed)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
224
        self.assertEqual([], d.unchanged)
225
226
    def test_unchanged_with_renames_and_modifications(self):
227
        """want_unchanged should generate a list of unchanged entries."""
228
        tree1 = self.make_branch_and_tree('1')
229
        tree2 = self.make_to_branch_and_tree('2')
230
        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.
231
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
232
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
233
        d = self.intertree_class(tree1, tree2).compare(want_unchanged=True)
234
        self.assertEqual([], d.added)
235
        self.assertEqual([], d.modified)
236
        self.assertEqual([], d.removed)
237
        self.assertEqual([('a', 'd', 'a-id', 'file', True, False)], d.renamed)
238
        self.assertEqual(
239
            [(u'b', 'b-id', 'directory'), (u'b/c', 'c-id', 'file')],
240
            d.unchanged)
241
242
    def test_extra_trees_finds_ids(self):
243
        """Ask for a delta between two trees with a path present in a third."""
244
        tree1 = self.make_branch_and_tree('1')
245
        tree2 = self.make_to_branch_and_tree('2')
246
        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.
247
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
248
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
249
        d = self.intertree_class(tree1, tree2).compare(specific_files=['b'])
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
250
        # 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.
251
        # a dispatch. XXX: For dirstate it does speak to the optimisability of
252
        # the lookup, in merged trees it can be fast-pathed. We probably want
253
        # 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=...).
254
        tree3 = self.make_branch_and_tree('3')
255
        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.
256
        tree3.lock_read()
257
        self.addCleanup(tree3.unlock)
1852.9.4 by Robert Collins
Add minimal test for Tree.compare(extra_trees=...).
258
        # tree 3 has 'e' which is 'c-id'. Tree 1 has c-id at b/c, and Tree 2
259
        # has c-id at b/c with its exec flag toggled.
260
        # without extra_trees, we should get no modifications from this
261
        # so do one, to be sure the test is valid.
262
        d = self.intertree_class(tree1, tree2).compare(
263
            specific_files=['e'])
264
        self.assertEqual([], d.modified)
265
        # now give it an additional lookup:
266
        d = self.intertree_class(tree1, tree2).compare(
267
            specific_files=['e'], extra_trees=[tree3])
268
        self.assertEqual([], d.added)
269
        self.assertEqual([('b/c', 'c-id', 'file', False, True)], d.modified)
270
        self.assertEqual([], d.removed)
271
        self.assertEqual([], d.renamed)
272
        self.assertEqual([], d.unchanged)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
273
274
    def test_require_versioned(self):
275
        # this does not quite robustly test, as it is passing in missing paths
276
        # rather than present-but-not-versioned paths. At the moment there is
277
        # no mechanism for managing the test trees (which are readonly) to 
278
        # get present-but-not-versioned files for trees that can do that.
279
        tree1 = self.make_branch_and_tree('1')
280
        tree2 = self.make_to_branch_and_tree('2')
281
        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.
282
        tree2 = self.get_tree_no_parents_abc_content(tree2)
283
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
284
        self.assertRaises(errors.PathsNotVersionedError, 
285
            self.intertree_class(tree1, tree2).compare,
286
            specific_files=['d'],
287
            require_versioned=True)
2012.1.1 by Aaron Bentley
Implement change iterator
288
289
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
290
class TestIterChanges(TestCaseWithTwoTrees):
2012.1.1 by Aaron Bentley
Implement change iterator
291
    """Test the comparison iterator"""
292
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
293
    def do_iter_changes(self, tree1, tree2, **extra_args):
294
        """Helper to run _iter_changes from tree1 to tree2.
295
        
296
        :param tree1, tree2:  The source and target trees. These will be locked
297
            automatically.
298
        :param **extra_args: Extra args to pass to _iter_changes. This is not
299
            inspected by this test helper.
300
        """
301
        tree1.lock_read()
302
        tree2.lock_read()
303
        try:
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
304
            # sort order of output is not strictly defined
305
            return sorted(self.intertree_class(tree1, tree2)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
306
                ._iter_changes(**extra_args))
307
        finally:
308
            tree1.unlock()
309
            tree2.unlock()
310
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
311
    def make_tree_with_special_names(self):
312
        """Create a tree with filenames chosen to exercise the walk order."""
313
        tree1 = self.make_branch_and_tree('tree1')
314
        tree2 = self.make_to_branch_and_tree('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.
315
        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.
316
        tree2.commit('initial', rev_id='rev-1')
317
        tree1, tree2 = self.mutable_trees_to_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.
318
        return (tree1, tree2, paths, path_ids)
319
320
    def make_trees_with_special_names(self):
321
        """Both trees will use the special names.
322
323
        But the contents will differ for each file.
324
        """
325
        tree1 = self.make_branch_and_tree('tree1')
326
        tree2 = self.make_to_branch_and_tree('tree2')
327
        paths, path_ids = self._create_special_names(tree1, 'tree1')
328
        paths, path_ids = self._create_special_names(tree2, 'tree2')
329
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
330
        return (tree1, tree2, paths, path_ids)
331
332
    def _create_special_names(self, tree, base_path):
333
        """Create a tree with paths that expose differences in sort orders."""
334
        # Each directory will have a single file named 'f' inside
335
        dirs = ['a',
336
                'a-a',
337
                'a/a',
338
                'a/a-a',
339
                'a/a/a',
340
                'a/a/a-a',
341
                'a/a/a/a',
342
                'a/a/a/a-a',
343
                'a/a/a/a/a',
344
               ]
345
        with_slashes = []
346
        paths = []
347
        path_ids = []
348
        for d in dirs:
349
            with_slashes.append(base_path + '/' + d + '/')
350
            with_slashes.append(base_path + '/' + d + '/f')
351
            paths.append(d)
352
            paths.append(d+'/f')
353
            path_ids.append(d.replace('/', '_') + '-id')
354
            path_ids.append(d.replace('/', '_') + '_f-id')
355
        self.build_tree(with_slashes)
356
        tree.add(paths, path_ids)
357
        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.
358
2012.1.1 by Aaron Bentley
Implement change iterator
359
    def test_compare_empty_trees(self):
360
        tree1 = self.make_branch_and_tree('1')
361
        tree2 = self.make_to_branch_and_tree('2')
362
        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.
363
        tree2 = self.get_tree_no_parents_no_content(tree2)
364
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
365
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
366
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
367
    def added(self, tree, file_id):
368
        entry = tree.inventory[file_id]
369
        path = tree.id2path(file_id)
370
        return (file_id, 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.
371
                (None, entry.name), (None, entry.kind),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
372
                (None, entry.executable))
373
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.
374
    def content_changed(self, tree, file_id):
375
        entry = tree.inventory[file_id]
376
        path = tree.id2path(file_id)
377
        return (file_id, path, True, (True, True), (entry.parent_id, entry.parent_id),
378
                (entry.name, entry.name), (entry.kind, entry.kind),
379
                (entry.executable, entry.executable))
380
381
    def kind_changed(self, from_tree, to_tree, file_id):
382
        old_entry = from_tree.inventory[file_id]
383
        new_entry = to_tree.inventory[file_id]
384
        path = to_tree.id2path(file_id)
385
        return (file_id, path, True, (True, True), (old_entry.parent_id, new_entry.parent_id),
386
                (old_entry.name, new_entry.name), (old_entry.kind, new_entry.kind),
387
                (old_entry.executable, new_entry.executable))
388
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
389
    def missing(self, file_id, path, parent_id, kind):
390
        _, basename = os.path.split(path)
391
        return (file_id, path, True, (True, True), (parent_id, parent_id),
392
            (basename, basename), (kind, None), (False, False))
393
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
394
    def deleted(self, tree, file_id):
395
        entry = tree.inventory[file_id]
396
        path = tree.id2path(file_id)
397
        return (file_id, path, 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.
398
                (entry.name, None), (entry.kind, None),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
399
                (entry.executable, None))
400
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.
401
    def unchanged(self, tree, file_id):
402
        entry = tree.inventory[file_id]
403
        parent = entry.parent_id
404
        name = entry.name
405
        kind = entry.kind
406
        executable = entry.executable
407
        return (file_id, tree.id2path(file_id), False, (True, True),
408
               (parent, parent), (name, name), (kind, kind),
409
               (executable, executable))
410
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
411
    def unversioned(self, tree, path):
412
        """Create an unversioned result."""
413
        _, basename = os.path.split(path)
414
        kind = file_kind(tree.abspath(path))
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.
415
        return (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.
416
                (None, basename), (None, kind),
417
                (None, False))
418
2012.1.1 by Aaron Bentley
Implement change iterator
419
    def test_empty_to_abc_content(self):
420
        tree1 = self.make_branch_and_tree('1')
421
        tree2 = self.make_to_branch_and_tree('2')
422
        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.
423
        tree2 = self.get_tree_no_parents_abc_content(tree2)
424
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2255.2.118 by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests.
425
        tree1.lock_read()
426
        tree2.lock_read()
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
427
        expected_results = sorted([
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
428
            self.added(tree2, 'root-id'),
429
            self.added(tree2, 'a-id'),
430
            self.added(tree2, 'b-id'),
431
            self.added(tree2, 'c-id'),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
432
            self.deleted(tree1, 'empty-root-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
433
        tree1.unlock()
434
        tree2.unlock()
435
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
436
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
437
    def test_empty_to_abc_content_a_only(self):
438
        tree1 = self.make_branch_and_tree('1')
439
        tree2 = self.make_to_branch_and_tree('2')
440
        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.
441
        tree2 = self.get_tree_no_parents_abc_content(tree2)
442
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
443
        tree1.lock_read()
444
        tree2.lock_read()
445
        self.assertEqual(
446
            [self.added(tree2, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
447
            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.
448
        tree1.unlock()
449
        tree2.unlock()
450
451
    def test_abc_content_to_empty_to_abc_content_a_only(self):
452
        tree1 = self.make_branch_and_tree('1')
453
        tree2 = self.make_to_branch_and_tree('2')
454
        tree1 = self.get_tree_no_parents_abc_content(tree1)
455
        tree2 = self.get_tree_no_parents_no_content(tree2)
456
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
457
        tree1.lock_read()
458
        tree2.lock_read()
459
        self.assertEqual(
460
            [self.deleted(tree1, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
461
            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.
462
        tree1.unlock()
463
        tree2.unlock()
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
464
465
    def test_empty_to_abc_content_a_and_c_only(self):
466
        tree1 = self.make_branch_and_tree('1')
467
        tree2 = self.make_to_branch_and_tree('2')
468
        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.
469
        tree2 = self.get_tree_no_parents_abc_content(tree2)
470
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
2255.2.118 by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests.
471
        tree1.lock_read()
472
        tree2.lock_read()
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
473
        expected_result = [self.added(tree2, 'a-id'), self.added(tree2, 'c-id')]
474
        tree1.unlock()
475
        tree2.unlock()
476
        self.assertEqual(expected_result,
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
477
            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
478
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
479
    def test_abc_content_to_empty(self):
2012.1.1 by Aaron Bentley
Implement change iterator
480
        tree1 = self.make_branch_and_tree('1')
481
        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.
482
        tree1 = self.get_tree_no_parents_abc_content(tree1)
483
        tree2 = self.get_tree_no_parents_no_content(tree2)
484
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
485
        tree1.lock_read()
486
        tree2.lock_read()
2012.1.1 by Aaron Bentley
Implement change iterator
487
        def deleted(file_id):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
488
            entry = tree1.inventory[file_id]
489
            path = tree1.id2path(file_id)
490
            return (file_id, path, True, (True, False),
2012.1.1 by Aaron Bentley
Implement change iterator
491
                    (entry.parent_id, None),
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
492
                    (entry.name, None), (entry.kind, None),
2012.1.1 by Aaron Bentley
Implement change iterator
493
                    (entry.executable, None))
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
494
        expected_results = sorted([self.added(tree2, 'empty-root-id'),
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
495
                          deleted('root-id'), deleted('a-id'),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
496
                          deleted('b-id'), deleted('c-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
497
        tree1.unlock()
498
        tree2.unlock()
499
        self.assertEqual(
500
            expected_results,
501
            self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
502
503
    def test_content_modification(self):
504
        tree1 = self.make_branch_and_tree('1')
505
        tree2 = self.make_to_branch_and_tree('2')
506
        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.
507
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
508
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
509
        root_id = tree1.path2id('')
510
        self.assertEqual([('a-id', 'a', True, (True, True),
511
                          (root_id, root_id), ('a', 'a'),
512
                          ('file', 'file'), (False, False))],
513
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
514
515
    def test_meta_modification(self):
516
        tree1 = self.make_branch_and_tree('1')
517
        tree2 = self.make_to_branch_and_tree('2')
518
        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.
519
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
520
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
521
        self.assertEqual([('c-id', 'b/c', False, (True, True),
522
                          ('b-id', 'b-id'), ('c', 'c'), ('file', 'file'),
523
                          (False, True))],
524
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
525
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
526
    def test_empty_dir(self):
527
        """an empty dir should not cause glitches to surrounding files."""
528
        tree1 = self.make_branch_and_tree('1')
529
        tree2 = self.make_to_branch_and_tree('2')
530
        tree1 = self.get_tree_no_parents_abc_content(tree1)
531
        tree2 = self.get_tree_no_parents_abc_content(tree2)
532
        # the pathname is chosen to fall between 'a' and 'b'.
533
        self.build_tree(['1/a-empty/', '2/a-empty/'])
534
        tree1.add(['a-empty'], ['a-empty'])
535
        tree2.add(['a-empty'], ['a-empty'])
536
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
537
        expected = []
538
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
539
2012.1.1 by Aaron Bentley
Implement change iterator
540
    def test_file_rename(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_abc_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
544
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
545
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
546
        root_id = tree1.path2id('')
547
        self.assertEqual([('a-id', 'd', False, (True, True),
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
548
                          (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.
549
                          (False, False))],
550
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
551
552
    def test_file_rename_and_modification(self):
553
        tree1 = self.make_branch_and_tree('1')
554
        tree2 = self.make_to_branch_and_tree('2')
555
        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.
556
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
557
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
558
        root_id = tree1.path2id('')
559
        self.assertEqual([('a-id', 'd', True, (True, True),
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
560
                          (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.
561
                           (False, False))],
562
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
563
564
    def test_file_rename_and_meta_modification(self):
565
        tree1 = self.make_branch_and_tree('1')
566
        tree2 = self.make_to_branch_and_tree('2')
567
        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.
568
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
569
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
570
        root_id = tree1.path2id('')
571
        self.assertEqual([('c-id', 'e', False, (True, True),
572
                          ('b-id', root_id), ('c', 'e'), ('file', 'file'),
573
                          (False, True))],
574
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
575
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
576
    def test_missing_in_target(self):
577
        """Test with the target files versioned but absent from disk."""
578
        tree1 = self.make_branch_and_tree('1')
579
        tree2 = self.make_to_branch_and_tree('2')
580
        tree1 = self.get_tree_no_parents_abc_content(tree1)
581
        tree2 = self.get_tree_no_parents_abc_content(tree2)
582
        os.unlink('2/a')
583
        shutil.rmtree('2/b')
584
        # TODO ? have a symlink here?
585
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
586
        root_id = tree1.path2id('')
587
        expected = sorted([
588
            self.missing('a-id', 'a', root_id, 'file'),
589
            self.missing('b-id', 'b', root_id, 'directory'),
590
            self.missing('c-id', 'b/c', 'b-id', 'file'),
591
            ])
592
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
593
2012.1.1 by Aaron Bentley
Implement change iterator
594
    def test_unchanged_with_renames_and_modifications(self):
595
        """want_unchanged should generate a list of unchanged entries."""
596
        tree1 = self.make_branch_and_tree('1')
597
        tree2 = self.make_to_branch_and_tree('2')
598
        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.
599
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
600
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
601
        root_id = tree1.path2id('')
2255.2.118 by Robert Collins
Change _iter_changes tests to lock the tested trees - its an iterator interface so implicit locks dont ensure the tree is locked - callers need to lock and thus so do our tests.
602
        tree1.lock_read()
603
        self.addCleanup(tree1.unlock)
604
        tree2.lock_read()
605
        self.addCleanup(tree2.unlock)
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.
606
        self.assertEqual(sorted([self.unchanged(tree1, root_id),
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
607
            self.unchanged(tree1, 'b-id'), ('a-id', 'd', True, (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.
608
            (root_id, root_id), ('a', 'd'), ('file', 'file'),
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
609
            (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.
610
            self.do_iter_changes(tree1, tree2, include_unchanged=True))
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
611
612
    def _todo_test_unversioned_paths_in_tree(self):
613
        tree1 = self.make_branch_and_tree('tree1')
614
        tree2 = self.make_to_branch_and_tree('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.
615
        self.build_tree(['tree2/file', 'tree2/dir/'])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
616
        # try:
617
        os.symlink('target', 'tree2/link')
618
        links_supported = True
619
        # except ???:
620
        #   links_supported = False
621
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
622
        root_id = tree1.path2id('')
623
        tree1.lock_read()
624
        self.addCleanup(tree1.unlock)
625
        tree2.lock_read()
626
        self.addCleanup(tree2.unlock)
627
        expected = [
628
            self.unversioned(tree2, 'file'),
629
            self.unversioned(tree2, 'dir'),
630
            ]
631
        if links_supported:
632
            expected.append(self.unversioned(tree2, 'link'))
633
        expected = sorted(expected)
634
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
635
636
    def _todo_test_unversioned_paths_in_tree_specific_files(self):
637
        tree1 = self.make_branch_and_tree('tree1')
638
        tree2 = self.make_to_branch_and_tree('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.
639
        self.build_tree(['tree2/file', 'tree2/dir/'])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
640
        # try:
641
        os.symlink('target', 'tree2/link')
642
        links_supported = True
643
        # except ???:
644
        #   links_supported = False
645
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
646
        root_id = tree1.path2id('')
647
        tree1.lock_read()
648
        self.addCleanup(tree1.unlock)
649
        tree2.lock_read()
650
        self.addCleanup(tree2.unlock)
651
        expected = [
652
            self.unversioned(tree2, 'file'),
653
            self.unversioned(tree2, 'dir'),
654
            ]
655
        specific_files=['file', 'dir']
656
        if links_supported:
657
            expected.append(self.unversioned(tree2, 'link'))
658
            specific_files.append('link')
659
        expected = sorted(expected)
660
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
661
            specific_files=specific_files))
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.
662
663
    def make_trees_with_symlinks(self):
664
        tree1 = self.make_branch_and_tree('tree1')
665
        tree2 = self.make_to_branch_and_tree('tree2')
666
        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
667
        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
668
        # try:
669
        os.symlink('original', 'tree1/changed')
670
        os.symlink('original', 'tree1/removed')
671
        os.symlink('original', 'tree1/tofile')
672
        os.symlink('original', 'tree1/todir')
673
        # we make the unchanged link point at unknown to catch incorrect
674
        # symlink-following code in the specified_files test.
675
        os.symlink('unknown', 'tree1/unchanged')
676
        os.symlink('new',      'tree2/added')
677
        os.symlink('new',      'tree2/changed')
678
        os.symlink('new',      'tree2/fromfile')
679
        os.symlink('new',      'tree2/fromdir')
680
        os.symlink('unknown', 'tree2/unchanged')
681
        from_paths_and_ids = [
682
            'fromdir',
683
            'fromfile',
684
            'changed',
685
            'removed',
686
            'todir',
687
            'tofile',
688
            'unchanged',
689
            ]
690
        to_paths_and_ids = [
691
            'added',
692
            'fromdir',
693
            'fromfile',
694
            'changed',
695
            'todir',
696
            'tofile',
697
            'unchanged',
698
            ]
699
        tree1.add(from_paths_and_ids, from_paths_and_ids)
700
        tree2.add(to_paths_and_ids, to_paths_and_ids)
701
        # except ???:
702
        #   raise TestSkipped('OS does not support symlinks')
703
        #   links_supported = False
704
        return self.mutable_trees_to_test_trees(tree1, tree2)
705
706
    def _disabled_test_versioned_symlinks(self):
707
        tree1, tree2 = self.make_trees_with_symlinks()
708
        root_id = tree1.path2id('')
709
        tree1.lock_read()
710
        self.addCleanup(tree1.unlock)
711
        tree2.lock_read()
712
        self.addCleanup(tree2.unlock)
713
        expected = [
714
            self.unchanged(tree1, tree1.path2id('')),
715
            self.added(tree2, 'added'),
716
            self.content_changed(tree2, 'changed'),
717
            self.kind_changed(tree1, tree2, 'fromdir'),
718
            self.kind_changed(tree1, tree2, 'fromfile'),
719
            self.deleted(tree1, 'removed'),
720
            self.unchanged(tree2, 'unchanged'),
721
            self.unversioned(tree2, 'unknown'),
722
            self.kind_changed(tree1, tree2, 'todir'),
723
            self.kind_changed(tree1, tree2, 'tofile'),
724
            ]
725
        expected = sorted(expected)
726
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2, include_unchanged=True))
727
728
    def _disabled_test_versioned_symlinks_specific_files(self):
729
        tree1, tree2 = self.make_trees_with_symlinks()
730
        root_id = tree1.path2id('')
731
        tree1.lock_read()
732
        self.addCleanup(tree1.unlock)
733
        tree2.lock_read()
734
        self.addCleanup(tree2.unlock)
735
        expected = [
736
            self.added(tree2, 'added'),
737
            self.content_changed(tree2, 'changed'),
738
            self.kind_changed(tree1, tree2, 'fromdir'),
739
            self.kind_changed(tree1, tree2, 'fromfile'),
740
            self.deleted(tree1, 'removed'),
741
            self.kind_changed(tree1, tree2, 'todir'),
742
            self.kind_changed(tree1, tree2, 'tofile'),
743
            ]
744
        expected = sorted(expected)
745
        # we should get back just the changed links. We pass in 'unchanged' to
746
        # make sure that it is correctly not returned - and neither is the
747
        # unknown path 'unknown' which it points at.
748
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
749
            specific_files=['added', 'changed', 'fromdir', 'fromfile',
750
            '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.
751
2255.7.21 by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to
752
    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.
753
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
754
        tree1.lock_read()
755
        self.addCleanup(tree1.unlock)
756
        tree2.lock_read()
757
        self.addCleanup(tree2.unlock)
758
        expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
759
        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.
760
761
    def test_trees_with_special_names(self):
762
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
763
        tree1.lock_read()
764
        self.addCleanup(tree1.unlock)
765
        tree2.lock_read()
766
        self.addCleanup(tree2.unlock)
767
        expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
768
                          if f_id.endswith('_f-id'))
769
        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
770
771
    def test_trees_with_unknown(self):
772
        tree1 = self.make_branch_and_tree('tree1')
773
        tree2 = self.make_to_branch_and_tree('tree2')
774
        self.build_tree(['tree1/a', 'tree1/c',
775
                         'tree2/a', 'tree2/b', 'tree2/c'])
776
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
777
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
778
779
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
780
        tree1.lock_read()
781
        self.addCleanup(tree1.unlock)
782
        tree2.lock_read()
783
        self.addCleanup(tree2.unlock)
784
785
        # We should ignore the fact that 'b' exists in tree-2
786
        expected = sorted([
787
            self.content_changed(tree2, 'a-id'),
788
            self.content_changed(tree2, 'c-id'),
789
            ])
790
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
2255.7.35 by John Arbash Meinel
Handle the case when a directory has been removed, and isn't the last entry.
791
792
    def test_trees_with_missing_dir(self):
793
        tree1 = self.make_branch_and_tree('tree1')
794
        tree2 = self.make_to_branch_and_tree('tree2')
795
        self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',
796
                         'tree1/b/d/', 'tree1/b/d/e', 'tree1/f/', 'tree1/f/g',
797
                         'tree2/a', 'tree2/f/', 'tree2/f/g'])
798
        tree1.add(['a', 'b', 'b/c', 'b/d/', 'b/d/e', 'f', 'f/g'],
799
                  ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'f-id', 'g-id'])
800
        tree2.add(['a', 'f', 'f/g'], ['a-id', 'f-id', 'g-id'])
801
802
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
803
        tree1.lock_read()
804
        self.addCleanup(tree1.unlock)
805
        tree2.lock_read()
806
        self.addCleanup(tree2.unlock)
807
        # We should notice that 'b' and all its children are missing
808
        expected = sorted([
809
            self.content_changed(tree2, 'a-id'),
810
            self.content_changed(tree2, 'g-id'),
811
            self.deleted(tree1, 'b-id'),
812
            self.deleted(tree1, 'c-id'),
813
            self.deleted(tree1, 'd-id'),
814
            self.deleted(tree1, 'e-id'),
815
            ])
816
817
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))