/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.2.152 by Martin Pool
(broken) merge aaron's workingtree format changes
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
16
17
"""Tests for the InterTree.compare() function."""
18
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
19
import os
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
20
import shutil
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
21
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
22
from bzrlib import (
23
    errors,
4503.1.3 by Vincent Ladeuil
Take review comments into account.
24
    mutabletree,
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
25
    tests,
26
    workingtree_4,
27
    )
2321.3.4 by Alexander Belchenko
test intertree_implementations: skip tests with symlinks on platforms that don't have symlinks support
28
from bzrlib.osutils import file_kind, has_symlinks
3619.4.4 by Robert Collins
Review feedback.
29
from bzrlib.tests import TestNotApplicable
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
30
from bzrlib.tests.per_intertree import TestCaseWithTwoTrees
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
31
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
32
# TODO: test the include_root option.
33
# TODO: test that renaming a directory x->y does not emit a rename for the
34
#       child x/a->y/a.
35
# TODO: test that renaming a directory x-> does not emit a rename for the child
36
#        x/a -> y/a when a supplied_files argument gives either 'x/' or 'y/a'
37
#        -> that is, when the renamed parent is not processed by the function.
38
# TODO: test items are only emitted once when a specific_files list names a dir
39
#       whose parent is now a child.
2255.2.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
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
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)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
140
1852.9.2 by Robert Collins
Convert stock delta tests to intertree_implementation tests of InterTree.compare.
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
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
294
        # no mechanism for managing the test trees (which are readonly) to
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
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)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
301
        self.assertRaises(errors.PathsNotVersionedError,
1852.9.5 by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite.
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)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
336
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
337
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
338
        self.assertEqual([], d.added)
339
        self.assertEqual([], d.modified)
340
        self.assertEqual([], d.removed)
341
        self.assertEqual([], d.renamed)
342
        self.assertEqual([], d.unchanged)
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
343
        expected_unversioned = [(u'dir', None, 'directory'),
344
                                (u'file', None, 'file')]
345
        if links_supported:
346
            expected_unversioned.append((u'link', None, 'symlink'))
347
        self.assertEqual(expected_unversioned, d.unversioned)
2255.7.90 by Robert Collins
Add unversioned path reporting to TreeDelta.
348
2012.1.1 by Aaron Bentley
Implement change iterator
349
2012.1.3 by Aaron Bentley
Always generate tuples (because kind is always used, even when not different)
350
class TestIterChanges(TestCaseWithTwoTrees):
2012.1.1 by Aaron Bentley
Implement change iterator
351
    """Test the comparison iterator"""
352
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
353
    def do_iter_changes(self, tree1, tree2, **extra_args):
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
354
        """Helper to run iter_changes from tree1 to tree2.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
355
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
356
        :param tree1, tree2:  The source and target trees. These will be locked
357
            automatically.
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
358
        :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.
359
            inspected by this test helper.
360
        """
361
        tree1.lock_read()
362
        tree2.lock_read()
363
        try:
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
364
            # sort order of output is not strictly defined
365
            return sorted(self.intertree_class(tree1, tree2)
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
366
                .iter_changes(**extra_args))
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
367
        finally:
368
            tree1.unlock()
369
            tree2.unlock()
370
4503.1.3 by Vincent Ladeuil
Take review comments into account.
371
    def check_has_changes(self, expected, tree1, tree2):
372
        # has_changes is defined for mutable trees only
373
        if not isinstance(tree2, mutabletree.MutableTree):
374
            if isinstance(tree1, mutabletree.MutableTree):
375
                # Let's switch the trees since has_changes() is commutative
376
                # (where we can apply it)
377
                tree2, tree1 = tree1, tree2
378
            else:
379
                # Neither tree can be used
380
                return
4503.1.1 by Vincent Ladeuil
Add tree.has_changes() to quickly check iter_changes().
381
        tree1.lock_read()
382
        tree2.lock_read()
383
        try:
4503.1.3 by Vincent Ladeuil
Take review comments into account.
384
            return tree2.has_changes(tree1)
4503.1.1 by Vincent Ladeuil
Add tree.has_changes() to quickly check iter_changes().
385
        finally:
386
            tree1.unlock()
387
            tree2.unlock()
388
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
389
    def mutable_trees_to_locked_test_trees(self, tree1, tree2):
390
        """Convert the working trees into test trees.
391
392
        Read lock them, and add the unlock to the cleanup.
393
        """
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
394
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
395
        tree1.lock_read()
396
        self.addCleanup(tree1.unlock)
397
        tree2.lock_read()
398
        self.addCleanup(tree2.unlock)
399
        return tree1, tree2
400
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
401
    def make_tree_with_special_names(self):
402
        """Create a tree with filenames chosen to exercise the walk order."""
403
        tree1 = self.make_branch_and_tree('tree1')
404
        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
405
        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.
406
        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.
407
        tree2.commit('initial', rev_id='rev-1')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
408
        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.
409
        return (tree1, tree2, paths, path_ids)
410
411
    def make_trees_with_special_names(self):
412
        """Both trees will use the special names.
413
414
        But the contents will differ for each file.
415
        """
416
        tree1 = self.make_branch_and_tree('tree1')
417
        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
418
        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.
419
        paths, path_ids = self._create_special_names(tree1, 'tree1')
420
        paths, path_ids = self._create_special_names(tree2, 'tree2')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
421
        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.
422
        return (tree1, tree2, paths, path_ids)
423
424
    def _create_special_names(self, tree, base_path):
425
        """Create a tree with paths that expose differences in sort orders."""
426
        # Each directory will have a single file named 'f' inside
427
        dirs = ['a',
428
                'a-a',
429
                'a/a',
430
                'a/a-a',
431
                'a/a/a',
432
                'a/a/a-a',
433
                'a/a/a/a',
434
                'a/a/a/a-a',
435
                'a/a/a/a/a',
436
               ]
437
        with_slashes = []
438
        paths = []
439
        path_ids = []
440
        for d in dirs:
441
            with_slashes.append(base_path + '/' + d + '/')
442
            with_slashes.append(base_path + '/' + d + '/f')
443
            paths.append(d)
444
            paths.append(d+'/f')
445
            path_ids.append(d.replace('/', '_') + '-id')
446
            path_ids.append(d.replace('/', '_') + '_f-id')
447
        self.build_tree(with_slashes)
448
        tree.add(paths, path_ids)
449
        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.
450
2012.1.1 by Aaron Bentley
Implement change iterator
451
    def test_compare_empty_trees(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_no_content(tree1)
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
455
        tree2 = self.get_tree_no_parents_no_content(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
456
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
3254.1.2 by Aaron Bentley
Fix doiter_changes
457
        self.assertEqual([], self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
458
        self.check_has_changes(False, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
459
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
460
    def added(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
461
        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.
462
        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.
463
                (None, entry.name), (None, entry.kind),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
464
                (None, entry.executable))
465
3363.14.7 by Aaron Bentley
Get more tests passing
466
    @staticmethod
467
    def get_path_entry(tree, file_id):
468
        iterator = tree.iter_entries_by_dir(specific_file_ids=[file_id])
469
        return iterator.next()
470
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.
471
    def content_changed(self, tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
472
        path, entry = self.get_path_entry(tree, file_id)
473
        return (file_id, (path, path), True, (True, True),
474
                (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.
475
                (entry.name, entry.name), (entry.kind, entry.kind),
476
                (entry.executable, entry.executable))
477
478
    def kind_changed(self, from_tree, to_tree, file_id):
3363.14.7 by Aaron Bentley
Get more tests passing
479
        from_path, old_entry = self.get_path_entry(from_tree, file_id)
480
        path, new_entry = self.get_path_entry(to_tree, file_id)
481
        return (file_id, (from_path, path), True, (True, True),
482
                (old_entry.parent_id, new_entry.parent_id),
483
                (old_entry.name, new_entry.name),
484
                (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.
485
                (old_entry.executable, new_entry.executable))
486
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
487
    def missing(self, file_id, from_path, to_path, parent_id, kind):
488
        _, from_basename = os.path.split(from_path)
489
        _, to_basename = os.path.split(to_path)
490
        # missing files have both paths, but no kind.
491
        return (file_id, (from_path, to_path), True, (True, True),
492
            (parent_id, parent_id),
493
            (from_basename, to_basename), (kind, None), (False, False))
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
494
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
495
    def deleted(self, tree, file_id):
496
        entry = tree.inventory[file_id]
497
        path = tree.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
498
        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.
499
                (entry.name, None), (entry.kind, None),
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
500
                (entry.executable, None))
501
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
502
    def renamed(self, from_tree, to_tree, file_id, content_changed):
3363.14.8 by Aaron Bentley
Fix more tests
503
        from_path, from_entry = self.get_path_entry(from_tree, file_id)
504
        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.
505
        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.
506
            (from_entry.parent_id, to_entry.parent_id),
507
            (from_entry.name, to_entry.name),
508
            (from_entry.kind, to_entry.kind),
509
            (from_entry.executable, to_entry.executable))
510
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.
511
    def unchanged(self, tree, file_id):
3363.14.8 by Aaron Bentley
Fix more tests
512
        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.
513
        parent = entry.parent_id
514
        name = entry.name
515
        kind = entry.kind
516
        executable = entry.executable
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
517
        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.
518
               (parent, parent), (name, name), (kind, kind),
519
               (executable, executable))
520
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
521
    def unversioned(self, tree, path):
522
        """Create an unversioned result."""
523
        _, basename = os.path.split(path)
3363.14.7 by Aaron Bentley
Get more tests passing
524
        kind = tree._comparison_data(None, path)[0]
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
525
        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.
526
                (None, basename), (None, kind),
527
                (None, False))
528
2012.1.1 by Aaron Bentley
Implement change iterator
529
    def test_empty_to_abc_content(self):
530
        tree1 = self.make_branch_and_tree('1')
531
        tree2 = self.make_to_branch_and_tree('2')
532
        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.
533
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
534
        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.
535
        expected_results = sorted([
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
536
            self.added(tree2, 'root-id'),
537
            self.added(tree2, 'a-id'),
538
            self.added(tree2, 'b-id'),
539
            self.added(tree2, 'c-id'),
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
540
            self.deleted(tree1, 'empty-root-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
541
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
542
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
543
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
544
    def test_empty_specific_files(self):
545
        tree1 = self.make_branch_and_tree('1')
546
        tree2 = self.make_to_branch_and_tree('2')
547
        tree1 = self.get_tree_no_parents_no_content(tree1)
548
        tree2 = self.get_tree_no_parents_abc_content(tree2)
549
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
550
        self.assertEqual([],
551
            self.do_iter_changes(tree1, tree2, specific_files=[]))
552
553
    def test_no_specific_files(self):
554
        tree1 = self.make_branch_and_tree('1')
555
        tree2 = self.make_to_branch_and_tree('2')
556
        tree1 = self.get_tree_no_parents_no_content(tree1)
557
        tree2 = self.get_tree_no_parents_abc_content(tree2)
558
        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
559
        expected_results = sorted([
560
            self.added(tree2, 'root-id'),
561
            self.added(tree2, 'a-id'),
562
            self.added(tree2, 'b-id'),
563
            self.added(tree2, 'c-id'),
564
            self.deleted(tree1, 'empty-root-id')])
565
        self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
566
        self.check_has_changes(True, tree1, tree2)
2748.3.1 by Aaron Bentley
Start supporting [] for empty list
567
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
568
    def test_empty_to_abc_content_a_only(self):
569
        tree1 = self.make_branch_and_tree('1')
570
        tree2 = self.make_to_branch_and_tree('2')
571
        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.
572
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
573
        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.
574
        self.assertEqual(
575
            [self.added(tree2, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
576
            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.
577
578
    def test_abc_content_to_empty_to_abc_content_a_only(self):
579
        tree1 = self.make_branch_and_tree('1')
580
        tree2 = self.make_to_branch_and_tree('2')
581
        tree1 = self.get_tree_no_parents_abc_content(tree1)
582
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
583
        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.
584
        self.assertEqual(
585
            [self.deleted(tree1, 'a-id')],
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
586
            self.do_iter_changes(tree1, tree2, specific_files=['a']))
2012.1.5 by Aaron Bentley
Implement specific file id and dangling id handling
587
588
    def test_empty_to_abc_content_a_and_c_only(self):
589
        tree1 = self.make_branch_and_tree('1')
590
        tree2 = self.make_to_branch_and_tree('2')
591
        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.
592
        tree2 = self.get_tree_no_parents_abc_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
593
        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.
594
        expected_result = [self.added(tree2, 'a-id'), self.added(tree2, 'c-id')]
595
        self.assertEqual(expected_result,
2255.2.149 by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4.
596
            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
597
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
598
    def test_abc_content_to_empty(self):
2012.1.1 by Aaron Bentley
Implement change iterator
599
        tree1 = self.make_branch_and_tree('1')
600
        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.
601
        tree1 = self.get_tree_no_parents_abc_content(tree1)
602
        tree2 = self.get_tree_no_parents_no_content(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
603
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
604
        def deleted(file_id):
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
605
            entry = tree1.inventory[file_id]
606
            path = tree1.id2path(file_id)
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
607
            return (file_id, (path, None), True, (True, False),
2012.1.1 by Aaron Bentley
Implement change iterator
608
                    (entry.parent_id, None),
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
609
                    (entry.name, None), (entry.kind, None),
2012.1.1 by Aaron Bentley
Implement change iterator
610
                    (entry.executable, None))
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
611
        expected_results = sorted([
612
            self.added(tree2, 'empty-root-id'),
613
            deleted('root-id'), deleted('a-id'),
614
            deleted('b-id'), deleted('c-id')])
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
615
        self.assertEqual(
616
            expected_results,
617
            self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
618
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
619
620
    def test_content_modification(self):
621
        tree1 = self.make_branch_and_tree('1')
622
        tree2 = self.make_to_branch_and_tree('2')
623
        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.
624
        tree2 = self.get_tree_no_parents_abc_content_2(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
625
        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.
626
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
627
        self.assertEqual([('a-id', ('a', 'a'), True, (True, True),
628
                           (root_id, root_id), ('a', 'a'),
629
                           ('file', 'file'), (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
630
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
631
        self.check_has_changes(True, tree1, tree2)
2012.1.1 by Aaron Bentley
Implement change iterator
632
633
    def test_meta_modification(self):
634
        tree1 = self.make_branch_and_tree('1')
635
        tree2 = self.make_to_branch_and_tree('2')
636
        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.
637
        tree2 = self.get_tree_no_parents_abc_content_3(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
638
        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.
639
        self.assertEqual([('c-id', ('b/c', 'b/c'), False, (True, True),
640
                           ('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.
641
                          (False, True))],
642
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
643
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
644
    def test_empty_dir(self):
645
        """an empty dir should not cause glitches to surrounding files."""
646
        tree1 = self.make_branch_and_tree('1')
647
        tree2 = self.make_to_branch_and_tree('2')
648
        tree1 = self.get_tree_no_parents_abc_content(tree1)
649
        tree2 = self.get_tree_no_parents_abc_content(tree2)
650
        # the pathname is chosen to fall between 'a' and 'b'.
651
        self.build_tree(['1/a-empty/', '2/a-empty/'])
652
        tree1.add(['a-empty'], ['a-empty'])
653
        tree2.add(['a-empty'], ['a-empty'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
654
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
2255.7.6 by Robert Collins
Test for iterating changes past empty directories.
655
        expected = []
656
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
657
2012.1.1 by Aaron Bentley
Implement change iterator
658
    def test_file_rename(self):
659
        tree1 = self.make_branch_and_tree('1')
660
        tree2 = self.make_to_branch_and_tree('2')
661
        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.
662
        tree2 = self.get_tree_no_parents_abc_content_4(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
663
        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.
664
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
665
        self.assertEqual([('a-id', ('a', 'd'), False, (True, True),
666
                           (root_id, root_id), ('a', 'd'), ('file', 'file'),
667
                           (False, False))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
668
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
669
670
    def test_file_rename_and_modification(self):
671
        tree1 = self.make_branch_and_tree('1')
672
        tree2 = self.make_to_branch_and_tree('2')
673
        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.
674
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
675
        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.
676
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
677
        self.assertEqual([('a-id', ('a', 'd'), True, (True, True),
678
                           (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.
679
                           (False, False))],
680
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
681
682
    def test_file_rename_and_meta_modification(self):
683
        tree1 = self.make_branch_and_tree('1')
684
        tree2 = self.make_to_branch_and_tree('2')
685
        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.
686
        tree2 = self.get_tree_no_parents_abc_content_6(tree2)
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
687
        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.
688
        root_id = tree1.path2id('')
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
689
        self.assertEqual([('c-id', ('b/c', 'e'), False, (True, True),
690
                           ('b-id', root_id), ('c', 'e'), ('file', 'file'),
691
                           (False, True))],
2255.2.122 by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised.
692
                         self.do_iter_changes(tree1, tree2))
2012.1.1 by Aaron Bentley
Implement change iterator
693
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
694
    def test_missing_in_target(self):
695
        """Test with the target files versioned but absent from disk."""
696
        tree1 = self.make_branch_and_tree('1')
697
        tree2 = self.make_to_branch_and_tree('2')
698
        tree1 = self.get_tree_no_parents_abc_content(tree1)
699
        tree2 = self.get_tree_no_parents_abc_content(tree2)
700
        os.unlink('2/a')
701
        shutil.rmtree('2/b')
702
        # TODO ? have a symlink here?
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
703
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
704
        self.not_applicable_if_missing_in('a', tree2)
705
        self.not_applicable_if_missing_in('b', tree2)
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
706
        root_id = tree1.path2id('')
707
        expected = sorted([
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
708
            self.missing('a-id', 'a', 'a', root_id, 'file'),
709
            self.missing('b-id', 'b', 'b', root_id, 'directory'),
710
            self.missing('c-id', 'b/c', 'b/c', 'b-id', 'file'),
711
            ])
712
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
713
714
    def test_missing_and_renamed(self):
715
        tree1 = self.make_branch_and_tree('tree1')
716
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
717
        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.
718
        self.build_tree(['tree1/file'])
719
        tree1.add(['file'], ['file-id'])
720
        self.build_tree(['tree2/directory/'])
721
        tree2.add(['directory'], ['file-id'])
722
        os.rmdir('tree2/directory')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
723
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
724
        self.not_applicable_if_missing_in('directory', tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
725
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
726
        root_id = tree1.path2id('')
727
        expected = sorted([
728
            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.
729
            ])
730
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
731
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)
732
    def test_only_in_source_and_missing(self):
733
        tree1 = self.make_branch_and_tree('tree1')
734
        tree2 = self.make_to_branch_and_tree('tree2')
735
        tree2.set_root_id(tree1.get_root_id())
736
        self.build_tree(['tree1/file'])
737
        tree1.add(['file'], ['file-id'])
738
        os.unlink('tree1/file')
739
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
740
        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)
741
        root_id = tree1.path2id('')
742
        expected = [('file-id', ('file', None), False, (True, False),
743
            (root_id, None), ('file', None), (None, None), (False, None))]
744
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
745
746
    def test_only_in_target_and_missing(self):
747
        tree1 = self.make_branch_and_tree('tree1')
748
        tree2 = self.make_to_branch_and_tree('tree2')
749
        tree2.set_root_id(tree1.get_root_id())
750
        self.build_tree(['tree2/file'])
751
        tree2.add(['file'], ['file-id'])
752
        os.unlink('tree2/file')
753
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
754
        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)
755
        root_id = tree1.path2id('')
756
        expected = [('file-id', (None, 'file'), False, (False, True),
757
            (None, root_id), (None, 'file'), (None, None), (None, False))]
758
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
759
2012.1.1 by Aaron Bentley
Implement change iterator
760
    def test_unchanged_with_renames_and_modifications(self):
761
        """want_unchanged should generate a list of unchanged entries."""
762
        tree1 = self.make_branch_and_tree('1')
763
        tree2 = self.make_to_branch_and_tree('2')
764
        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.
765
        tree2 = self.get_tree_no_parents_abc_content_5(tree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
766
        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.
767
        root_id = tree1.path2id('')
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
768
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.
769
        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.
770
            self.unchanged(tree1, 'b-id'),
771
            ('a-id', ('a', 'd'), True, (True, True),
772
             (root_id, root_id), ('a', 'd'), ('file', 'file'),
2255.7.4 by Robert Collins
Test InterTree._iter_changes with missing (absent but versioned) files.
773
            (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.
774
            self.do_iter_changes(tree1, tree2, include_unchanged=True))
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
775
776
    def test_compare_subtrees(self):
777
        tree1 = self.make_branch_and_tree('1')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
778
        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.
779
            return
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
780
        tree1.set_root_id('root-id')
781
        subtree1 = self.make_branch_and_tree('1/sub')
782
        subtree1.set_root_id('subtree-id')
2255.9.2 by Martin Pool
test_compare_subtrees runs against all trees that claim to support
783
        tree1.add_reference(subtree1)
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
784
785
        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
786
        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.
787
            return
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
788
        tree2.set_root_id('root-id')
789
        subtree2 = self.make_to_branch_and_tree('2/sub')
790
        subtree2.set_root_id('subtree-id')
791
        tree2.add_reference(subtree2)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
792
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
793
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
794
        self.assertEqual([], list(tree2.iter_changes(tree1)))
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
795
        subtree1.commit('commit', rev_id='commit-a')
796
        self.assertEqual([
797
            ('root-id',
798
             (u'', u''),
799
             False,
800
             (True, True),
801
             (None, None),
802
             (u'', u''),
803
             ('directory', 'directory'),
804
             (False, False)),
805
            ('subtree-id',
806
             ('sub', 'sub',),
807
             False,
808
             (True, True),
809
             ('root-id', 'root-id'),
810
             ('sub', 'sub'),
811
             ('tree-reference', 'tree-reference'),
812
             (False, False))],
3254.1.1 by Aaron Bentley
Make Tree.iter_changes a public method
813
                         list(tree2.iter_changes(tree1,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
814
                             include_unchanged=True)))
2255.2.160 by Martin Pool
(merge) updates from dirstate branch
815
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
816
    def test_disk_in_subtrees_skipped(self):
817
        """subtrees are considered not-in-the-current-tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
818
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
819
        This test tests the trivial case, where the basis has no paths in the
820
        current trees subtree.
821
        """
822
        tree1 = self.make_branch_and_tree('1')
823
        tree1.set_root_id('root-id')
824
        tree2 = self.make_to_branch_and_tree('2')
825
        if not tree2.supports_tree_reference():
826
            return
827
        tree2.set_root_id('root-id')
828
        subtree2 = self.make_to_branch_and_tree('2/sub')
829
        subtree2.set_root_id('subtree-id')
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
830
        tree2.add_reference(subtree2)
2323.4.2 by Robert Collins
Fix the behaviour of dirstate optimised iter_changes recursing its disk iterator into subtrees inappropriately.
831
        self.build_tree(['2/sub/file'])
832
        subtree2.add(['file'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
833
834
        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.
835
        # this should filter correctly from above
836
        self.assertEqual([self.added(tree2, 'subtree-id')],
837
            self.do_iter_changes(tree1, tree2, want_unversioned=True))
838
        # and when the path is named
839
        self.assertEqual([self.added(tree2, 'subtree-id')],
840
            self.do_iter_changes(tree1, tree2, specific_files=['sub'],
841
                want_unversioned=True))
842
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
843
    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.
844
        tree1 = self.make_branch_and_tree('tree1')
845
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.186 by Martin Pool
Fix up root id for some more comparison tests
846
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
847
        self.build_tree(['tree1/a', 'tree1/c',
848
                         'tree2/a', 'tree2/b', 'tree2/c'])
849
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
850
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
851
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
852
        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.
853
854
        # We should ignore the fact that 'b' exists in tree-2
855
        # because the want_unversioned parameter was not given.
856
        expected = sorted([
857
            self.content_changed(tree2, 'a-id'),
858
            self.content_changed(tree2, 'c-id'),
859
            ])
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
860
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
861
        self.check_has_changes(True, tree1, tree2)
2255.7.2 by Robert Collins
Add a (currently) disabled test for unversioned paths in the target tree with _iter_changes.
862
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
863
    def test_unversioned_paths_in_tree(self):
864
        tree1 = self.make_branch_and_tree('tree1')
865
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.184 by Martin Pool
Fixes for some comparison tests; repr of DirStateRevisionTree
866
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
867
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
868
        if has_symlinks():
869
            os.symlink('target', 'tree2/link')
870
            links_supported = True
871
        else:
872
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
873
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
874
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
875
        expected = [
876
            self.unversioned(tree2, 'file'),
877
            self.unversioned(tree2, 'dir'),
878
            ]
879
        if links_supported:
880
            expected.append(self.unversioned(tree2, 'link'))
881
        expected = sorted(expected)
882
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
883
            want_unversioned=True))
884
885
    def test_unversioned_paths_in_tree_specific_files(self):
886
        tree1 = self.make_branch_and_tree('tree1')
887
        tree2 = self.make_to_branch_and_tree('tree2')
888
        self.build_tree(['tree2/file', 'tree2/dir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
889
        if has_symlinks():
890
            os.symlink('target', 'tree2/link')
891
            links_supported = True
892
        else:
893
            links_supported = False
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
894
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
895
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
896
        expected = [
897
            self.unversioned(tree2, 'file'),
898
            self.unversioned(tree2, 'dir'),
899
            ]
900
        specific_files=['file', 'dir']
901
        if links_supported:
902
            expected.append(self.unversioned(tree2, 'link'))
903
            specific_files.append('link')
904
        expected = sorted(expected)
905
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
906
            specific_files=specific_files, require_versioned=False,
907
            want_unversioned=True))
908
909
    def test_unversioned_paths_in_target_matching_source_old_names(self):
910
        # its likely that naive implementations of unversioned file support
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
911
        # will fail if the path was versioned, but is not any more,
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
912
        # due to a rename, not due to unversioning it.
913
        # That is, if the old tree has a versioned file 'foo', and
914
        # the new tree has the same file but versioned as 'bar', and also
915
        # has an unknown file 'foo', we should get back output for
916
        # both foo and bar.
917
        tree1 = self.make_branch_and_tree('tree1')
918
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.187 by Martin Pool
set common root ids in more tests
919
        tree2.set_root_id(tree1.get_root_id())
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
920
        self.build_tree(['tree2/file', 'tree2/dir/',
921
            'tree1/file', 'tree2/movedfile',
922
            'tree1/dir/', 'tree2/moveddir/'])
2408.1.2 by Alexander Belchenko
intertree_implementations: make usage of symlinks optional
923
        if has_symlinks():
924
            os.symlink('target', 'tree1/link')
925
            os.symlink('target', 'tree2/link')
926
            os.symlink('target', 'tree2/movedlink')
927
            links_supported = True
928
        else:
929
            links_supported = False
930
        tree1.add(['file', 'dir'], ['file-id', 'dir-id'])
931
        tree2.add(['movedfile', 'moveddir'], ['file-id', 'dir-id'])
932
        if links_supported:
933
            tree1.add(['link'], ['link-id'])
934
            tree2.add(['movedlink'], ['link-id'])
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
935
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
936
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
937
        root_id = tree1.path2id('')
938
        expected = [
939
            self.renamed(tree1, tree2, 'dir-id', False),
940
            self.renamed(tree1, tree2, 'file-id', True),
941
            self.unversioned(tree2, 'file'),
942
            self.unversioned(tree2, 'dir'),
943
            ]
944
        specific_files=['file', 'dir']
945
        if links_supported:
946
            expected.append(self.renamed(tree1, tree2, 'link-id', False))
947
            expected.append(self.unversioned(tree2, 'link'))
948
            specific_files.append('link')
949
        expected = sorted(expected)
950
        # run once with, and once without specific files, to catch
951
        # potentially different code paths.
952
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
953
            require_versioned=False,
954
            want_unversioned=True))
955
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
956
            specific_files=specific_files, require_versioned=False,
957
            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.
958
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
959
    def test_similar_filenames(self):
960
        """Test when we have a few files with similar names."""
961
        tree1 = self.make_branch_and_tree('tree1')
962
        tree2 = self.make_branch_and_tree('tree2')
963
        tree2.set_root_id(tree1.get_root_id())
964
965
        # The trees are actually identical, but they happen to contain
966
        # similarly named files.
967
        self.build_tree(['tree1/a/',
968
                         'tree1/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
969
                         'tree1/a/b/c/',
970
                         'tree1/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
971
                         'tree1/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
972
                         'tree1/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
973
                         'tree2/a/',
974
                         'tree2/a/b/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
975
                         'tree2/a/b/c/',
976
                         'tree2/a/b/c/d/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
977
                         'tree2/a-c/',
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
978
                         'tree2/a-c/e/',
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
979
                        ])
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
980
        tree1.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
981
                  ['a-id', 'b-id', 'c-id', 'd-id', 'a-c-id', 'e-id'])
982
        tree2.add(['a', 'a/b', 'a/b/c', 'a/b/c/d', 'a-c', 'a-c/e'],
983
                  ['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
984
985
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
986
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
987
988
        self.assertEqual([], self.do_iter_changes(tree1, tree2,
989
                                                  want_unversioned=True))
2466.5.2 by John Arbash Meinel
Extend the test a bit to make sure the include_unchanged value is correct.
990
        expected = sorted([
991
            self.unchanged(tree2, tree2.get_root_id()),
992
            self.unchanged(tree2, 'a-id'),
993
            self.unchanged(tree2, 'b-id'),
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
994
            self.unchanged(tree2, 'c-id'),
995
            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.
996
            self.unchanged(tree2, 'a-c-id'),
2466.5.4 by John Arbash Meinel
Fix bug #11127 by splitting paths on '/'.
997
            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.
998
            ])
999
        self.assertEqual(expected,
1000
                         self.do_iter_changes(tree1, tree2,
1001
                                              want_unversioned=True,
1002
                                              include_unchanged=True))
2466.5.1 by John Arbash Meinel
Add a (failing) test for bug 111127
1003
1004
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1005
    def test_unversioned_subtree_only_emits_root(self):
1006
        tree1 = self.make_branch_and_tree('tree1')
1007
        tree2 = self.make_to_branch_and_tree('tree2')
2255.2.188 by Martin Pool
Set common root id in comparison tests
1008
        tree2.set_root_id(tree1.get_root_id())
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1009
        self.build_tree(['tree2/dir/', 'tree2/dir/file'])
3363.14.9 by Aaron Bentley
Ensure TransformPreview is finalized
1010
        tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1011
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2255.7.87 by Robert Collins
Dont walk unversioned directories in _iter_changes.
1012
        expected = [
1013
            self.unversioned(tree2, 'dir'),
1014
            ]
1015
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1016
            want_unversioned=True))
1017
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.
1018
    def make_trees_with_symlinks(self):
1019
        tree1 = self.make_branch_and_tree('tree1')
1020
        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
1021
        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.
1022
        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
1023
        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
1024
        os.symlink('original', 'tree1/changed')
1025
        os.symlink('original', 'tree1/removed')
1026
        os.symlink('original', 'tree1/tofile')
1027
        os.symlink('original', 'tree1/todir')
1028
        # we make the unchanged link point at unknown to catch incorrect
1029
        # symlink-following code in the specified_files test.
1030
        os.symlink('unknown', 'tree1/unchanged')
1031
        os.symlink('new',      'tree2/added')
1032
        os.symlink('new',      'tree2/changed')
1033
        os.symlink('new',      'tree2/fromfile')
1034
        os.symlink('new',      'tree2/fromdir')
1035
        os.symlink('unknown', 'tree2/unchanged')
1036
        from_paths_and_ids = [
1037
            'fromdir',
1038
            'fromfile',
1039
            'changed',
1040
            'removed',
1041
            'todir',
1042
            'tofile',
1043
            'unchanged',
1044
            ]
1045
        to_paths_and_ids = [
1046
            'added',
1047
            'fromdir',
1048
            'fromfile',
1049
            'changed',
1050
            'todir',
1051
            'tofile',
1052
            'unchanged',
1053
            ]
1054
        tree1.add(from_paths_and_ids, from_paths_and_ids)
1055
        tree2.add(to_paths_and_ids, to_paths_and_ids)
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1056
        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.
1057
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1058
    def test_versioned_symlinks(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
1059
        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.
1060
        tree1, tree2 = self.make_trees_with_symlinks()
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1061
        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.
1062
        root_id = tree1.path2id('')
1063
        expected = [
1064
            self.unchanged(tree1, tree1.path2id('')),
1065
            self.added(tree2, 'added'),
1066
            self.content_changed(tree2, 'changed'),
1067
            self.kind_changed(tree1, tree2, 'fromdir'),
1068
            self.kind_changed(tree1, tree2, 'fromfile'),
1069
            self.deleted(tree1, 'removed'),
1070
            self.unchanged(tree2, 'unchanged'),
1071
            self.unversioned(tree2, 'unknown'),
1072
            self.kind_changed(tree1, tree2, 'todir'),
1073
            self.kind_changed(tree1, tree2, 'tofile'),
1074
            ]
1075
        expected = sorted(expected)
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1076
        self.assertEqual(expected,
1077
            self.do_iter_changes(tree1, tree2, include_unchanged=True,
1078
                want_unversioned=True))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1079
        self.check_has_changes(True, tree1, tree2)
2255.7.3 by Robert Collins
Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
1080
2255.7.88 by Robert Collins
Enable InterTree._iter_changes symlink tests.
1081
    def test_versioned_symlinks_specific_files(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
1082
        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.
1083
        tree1, tree2 = self.make_trees_with_symlinks()
1084
        root_id = tree1.path2id('')
1085
        expected = [
1086
            self.added(tree2, 'added'),
1087
            self.content_changed(tree2, 'changed'),
1088
            self.kind_changed(tree1, tree2, 'fromdir'),
1089
            self.kind_changed(tree1, tree2, 'fromfile'),
1090
            self.deleted(tree1, 'removed'),
1091
            self.kind_changed(tree1, tree2, 'todir'),
1092
            self.kind_changed(tree1, tree2, 'tofile'),
1093
            ]
1094
        expected = sorted(expected)
1095
        # we should get back just the changed links. We pass in 'unchanged' to
1096
        # make sure that it is correctly not returned - and neither is the
1097
        # unknown path 'unknown' which it points at.
1098
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1099
            specific_files=['added', 'changed', 'fromdir', 'fromfile',
1100
            'removed', 'unchanged', 'todir', 'tofile']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1101
        self.check_has_changes(True, tree1, tree2)
2255.7.15 by John Arbash Meinel
Try to create an intertree test that exposes the walkdir vs dirstate mismatch. No luck yet.
1102
2255.7.21 by John Arbash Meinel
Get iter_changes working again, by fixing set_parent_trees to
1103
    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.
1104
        tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1105
        expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
1106
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1107
        self.check_has_changes(True, tree1, tree2)
2255.7.22 by John Arbash Meinel
add a test that shows _iter_changes works when only contents have changed, and nothing is considered newly added.
1108
1109
    def test_trees_with_special_names(self):
1110
        tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1111
        expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1112
                          if f_id.endswith('_f-id'))
1113
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1114
        self.check_has_changes(True, tree1, tree2)
2255.7.34 by John Arbash Meinel
Clean up test_bad_files, and fix a bug in _iter_changes when
1115
2255.7.96 by Robert Collins
Change _iter_changes interface to yield both old and new paths.
1116
    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.
1117
        tree1 = self.make_branch_and_tree('tree1')
1118
        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
1119
        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.
1120
        self.build_tree(['tree1/a', 'tree1/b/', 'tree1/b/c',
1121
                         'tree1/b/d/', 'tree1/b/d/e', 'tree1/f/', 'tree1/f/g',
1122
                         'tree2/a', 'tree2/f/', 'tree2/f/g'])
1123
        tree1.add(['a', 'b', 'b/c', 'b/d/', 'b/d/e', 'f', 'f/g'],
1124
                  ['a-id', 'b-id', 'c-id', 'd-id', 'e-id', 'f-id', 'g-id'])
1125
        tree2.add(['a', 'f', 'f/g'], ['a-id', 'f-id', 'g-id'])
1126
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1127
        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.
1128
        # 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.
1129
        expected = sorted([
1130
            self.content_changed(tree2, 'a-id'),
1131
            self.content_changed(tree2, 'g-id'),
1132
            self.deleted(tree1, 'b-id'),
1133
            self.deleted(tree1, 'c-id'),
1134
            self.deleted(tree1, 'd-id'),
1135
            self.deleted(tree1, 'e-id'),
1136
            ])
1137
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1138
        self.check_has_changes(True, tree1, tree2)
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1139
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1140
    def test_added_unicode(self):
1141
        tree1 = self.make_branch_and_tree('tree1')
1142
        tree2 = self.make_to_branch_and_tree('tree2')
1143
        root_id = tree1.get_root_id()
1144
        tree2.set_root_id(root_id)
1145
1146
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1147
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1148
        a_id = u'\u03b1-id'.encode('utf8')
1149
        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.
1150
        try:
1151
            self.build_tree([u'tree1/\u03b1/',
1152
                             u'tree2/\u03b1/',
1153
                             u'tree2/\u03b1/\u03c9-added',
1154
                            ])
1155
        except UnicodeError:
1156
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1157
        tree1.add([u'\u03b1'], [a_id])
1158
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-added'], [a_id, added_id])
1159
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1160
        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.
1161
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1162
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1163
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1164
        self.assertEqual([self.added(tree2, added_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1165
                         self.do_iter_changes(tree1, tree2,
1166
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1167
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1168
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1169
    def test_deleted_unicode(self):
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1170
        tree1 = self.make_branch_and_tree('tree1')
1171
        tree2 = self.make_to_branch_and_tree('tree2')
1172
        root_id = tree1.get_root_id()
1173
        tree2.set_root_id(root_id)
1174
1175
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1176
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1177
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1178
        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.
1179
        try:
1180
            self.build_tree([u'tree1/\u03b1/',
1181
                             u'tree1/\u03b1/\u03c9-deleted',
1182
                             u'tree2/\u03b1/',
1183
                            ])
1184
        except UnicodeError:
1185
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1186
        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.
1187
        tree2.add([u'\u03b1'], [a_id])
1188
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1189
        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.
1190
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1191
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1192
                         self.do_iter_changes(tree1, tree2))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1193
        self.assertEqual([self.deleted(tree1, deleted_id)],
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1194
                         self.do_iter_changes(tree1, tree2,
1195
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1196
        self.check_has_changes(True, tree1, tree2)
2360.1.3 by John Arbash Meinel
Start splitting up the overzealous test into focused tests.
1197
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1198
    def test_modified_unicode(self):
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1199
        tree1 = self.make_branch_and_tree('tree1')
1200
        tree2 = self.make_to_branch_and_tree('tree2')
1201
        root_id = tree1.get_root_id()
1202
        tree2.set_root_id(root_id)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1203
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1204
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1205
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1206
        a_id = u'\u03b1-id'.encode('utf8')
1207
        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.
1208
        try:
1209
            self.build_tree([u'tree1/\u03b1/',
1210
                             u'tree1/\u03b1/\u03c9-modified',
1211
                             u'tree2/\u03b1/',
1212
                             u'tree2/\u03b1/\u03c9-modified',
1213
                            ])
1214
        except UnicodeError:
1215
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1216
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1217
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-modified'], [a_id, mod_id])
1218
1219
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1220
1221
        self.assertEqual([self.content_changed(tree1, mod_id)],
1222
                         self.do_iter_changes(tree1, tree2))
1223
        self.assertEqual([self.content_changed(tree1, mod_id)],
1224
                         self.do_iter_changes(tree1, tree2,
1225
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1226
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1227
1228
    def test_renamed_unicode(self):
1229
        tree1 = self.make_branch_and_tree('tree1')
1230
        tree2 = self.make_to_branch_and_tree('tree2')
1231
        root_id = tree1.get_root_id()
1232
        tree2.set_root_id(root_id)
1233
1234
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1235
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1236
        a_id = u'\u03b1-id'.encode('utf8')
1237
        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.
1238
        try:
1239
            self.build_tree([u'tree1/\u03b1/',
1240
                             u'tree2/\u03b1/',
1241
                            ])
1242
        except UnicodeError:
1243
            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.
1244
        self.build_tree_contents([(u'tree1/\u03c9-source', 'contents\n'),
1245
                                  (u'tree2/\u03b1/\u03c9-target', 'contents\n'),
1246
                                 ])
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1247
        tree1.add([u'\u03b1', u'\u03c9-source'], [a_id, rename_id])
1248
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-target'], [a_id, rename_id])
1249
1250
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1251
1252
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1253
                         self.do_iter_changes(tree1, tree2))
1254
        self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1255
                         self.do_iter_changes(tree1, tree2,
1256
                                              specific_files=[u'\u03b1']))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1257
        self.check_has_changes(True, tree1, tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1258
1259
    def test_unchanged_unicode(self):
1260
        tree1 = self.make_branch_and_tree('tree1')
1261
        tree2 = self.make_to_branch_and_tree('tree2')
1262
        root_id = tree1.get_root_id()
1263
        tree2.set_root_id(root_id)
1264
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1265
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1266
        a_id = u'\u03b1-id'.encode('utf8')
1267
        subfile_id = u'\u03c9-subfile-id'.encode('utf8')
1268
        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.
1269
        try:
1270
            self.build_tree([u'tree1/\u03b1/',
1271
                             u'tree2/\u03b1/',
1272
                            ])
1273
        except UnicodeError:
1274
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1275
        self.build_tree_contents([
1276
            (u'tree1/\u03b1/\u03c9-subfile', 'sub contents\n'),
1277
            (u'tree2/\u03b1/\u03c9-subfile', 'sub contents\n'),
1278
            (u'tree1/\u03c9-rootfile', 'root contents\n'),
1279
            (u'tree2/\u03c9-rootfile', 'root contents\n'),
1280
            ])
1281
        tree1.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1282
                  [a_id, subfile_id, rootfile_id])
1283
        tree2.add([u'\u03b1', u'\u03b1/\u03c9-subfile', u'\u03c9-rootfile'],
1284
                  [a_id, subfile_id, rootfile_id])
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1285
2360.1.4 by John Arbash Meinel
Clean up of test_compare code.
1286
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1287
2360.1.1 by John Arbash Meinel
Basic implementation test that makes sure _iter_changes handles unknown files.
1288
        expected = sorted([
1289
            self.unchanged(tree1, root_id),
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1290
            self.unchanged(tree1, a_id),
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1291
            self.unchanged(tree1, subfile_id),
1292
            self.unchanged(tree1, rootfile_id),
1293
            ])
1294
        self.assertEqual(expected,
1295
                         self.do_iter_changes(tree1, tree2,
1296
                                              include_unchanged=True))
1297
1298
        # We should also be able to select just a subset
1299
        expected = sorted([
1300
            self.unchanged(tree1, a_id),
1301
            self.unchanged(tree1, subfile_id),
1302
            ])
1303
        self.assertEqual(expected,
1304
                         self.do_iter_changes(tree1, tree2,
1305
                                              specific_files=[u'\u03b1'],
1306
                                              include_unchanged=True))
1307
1308
    def test_unknown_unicode(self):
1309
        tree1 = self.make_branch_and_tree('tree1')
1310
        tree2 = self.make_to_branch_and_tree('tree2')
1311
        root_id = tree1.get_root_id()
1312
        tree2.set_root_id(root_id)
1313
        # u'\u03b1' == GREEK SMALL LETTER ALPHA
1314
        # u'\u03c9' == GREEK SMALL LETTER OMEGA
1315
        a_id = u'\u03b1-id'.encode('utf8')
2360.1.8 by John Arbash Meinel
Update the tests to handle when fs is non-unicode.
1316
        try:
1317
            self.build_tree([u'tree1/\u03b1/',
1318
                             u'tree2/\u03b1/',
1319
                             u'tree2/\u03b1/unknown_dir/',
1320
                             u'tree2/\u03b1/unknown_file',
1321
                             u'tree2/\u03b1/unknown_dir/file',
1322
                             u'tree2/\u03c9-unknown_root_file',
1323
                            ])
1324
        except UnicodeError:
1325
            raise tests.TestSkipped("Could not create Unicode files.")
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1326
        tree1.add([u'\u03b1'], [a_id])
1327
        tree2.add([u'\u03b1'], [a_id])
1328
1329
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1330
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1331
1332
        expected = sorted([
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1333
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1334
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1335
            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.
1336
            # a/unknown_dir/file should not be included because we should not
1337
            # recurse into unknown_dir
1338
            # self.unversioned(tree2, 'a/unknown_dir/file'),
1339
            ])
1340
        self.assertEqual(expected,
1341
                         self.do_iter_changes(tree1, tree2,
1342
                                              require_versioned=False,
1343
                                              want_unversioned=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1344
        self.assertEqual([], # Without want_unversioned we should get nothing
1345
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1346
        self.check_has_changes(False, tree1, tree2)
2360.1.2 by John Arbash Meinel
Add an overzealous test, for Unicode support of _iter_changes.
1347
1348
        # We should also be able to select just a subset
1349
        expected = sorted([
1350
            self.unversioned(tree2, u'\u03b1/unknown_dir'),
1351
            self.unversioned(tree2, u'\u03b1/unknown_file'),
1352
            ])
1353
        self.assertEqual(expected,
1354
                         self.do_iter_changes(tree1, tree2,
1355
                                              specific_files=[u'\u03b1'],
1356
                                              require_versioned=False,
1357
                                              want_unversioned=True))
2360.1.5 by John Arbash Meinel
Split out the unicode tests properly.
1358
        self.assertEqual([], # Without want_unversioned we should get nothing
1359
                         self.do_iter_changes(tree1, tree2,
1360
                                              specific_files=[u'\u03b1']))
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1361
1362
    def test_unknown_empty_dir(self):
1363
        tree1 = self.make_branch_and_tree('tree1')
1364
        tree2 = self.make_to_branch_and_tree('tree2')
1365
        root_id = tree1.get_root_id()
1366
        tree2.set_root_id(root_id)
1367
2402.2.4 by John Arbash Meinel
Clean up the setup for clarity (suggested by Robert)
1368
        # Start with 2 identical trees
1369
        self.build_tree(['tree1/a/', 'tree1/b/',
1370
                         'tree2/a/', 'tree2/b/'])
1371
        self.build_tree_contents([('tree1/b/file', 'contents\n'),
1372
                                  ('tree2/b/file', 'contents\n')])
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1373
        tree1.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
1374
        tree2.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
1375
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1376
        # Now create some unknowns in tree2
1377
        # We should find both a/file and a/dir as unknown, but we shouldn't
1378
        # recurse into a/dir to find that a/dir/subfile is also unknown.
1379
        self.build_tree(['tree2/a/file', 'tree2/a/dir/', 'tree2/a/dir/subfile'])
1380
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1381
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1382
        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()
1383
1384
        expected = sorted([
1385
            self.unversioned(tree2, u'a/file'),
2402.2.2 by John Arbash Meinel
Fix _iter_changes to properly handle versioned (but empty) directories
1386
            self.unversioned(tree2, u'a/dir'),
2402.2.1 by John Arbash Meinel
Add a test which exposes the bug in WT4._iter_changes()
1387
            ])
1388
        self.assertEqual(expected,
1389
                         self.do_iter_changes(tree1, tree2,
1390
                                              require_versioned=False,
1391
                                              want_unversioned=True))
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
1392
1393
    def test_rename_over_deleted(self):
1394
        tree1 = self.make_branch_and_tree('tree1')
1395
        tree2 = self.make_to_branch_and_tree('tree2')
1396
        root_id = tree1.get_root_id()
1397
        tree2.set_root_id(root_id)
1398
1399
        # The final changes should be:
1400
        #   touch a b c d
1401
        #   add a b c d
1402
        #   commit
1403
        #   rm a d
1404
        #   mv b a
1405
        #   mv c d
1406
        self.build_tree_contents([
1407
            ('tree1/a', 'a contents\n'),
1408
            ('tree1/b', 'b contents\n'),
1409
            ('tree1/c', 'c contents\n'),
1410
            ('tree1/d', 'd contents\n'),
1411
            ('tree2/a', 'b contents\n'),
1412
            ('tree2/d', 'c contents\n'),
1413
            ])
1414
        tree1.add(['a', 'b', 'c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
1415
        tree2.add(['a', 'd'], ['b-id', 'c-id'])
1416
1417
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1418
1419
        expected = sorted([
1420
            self.deleted(tree1, 'a-id'),
1421
            self.deleted(tree1, 'd-id'),
1422
            self.renamed(tree1, tree2, 'b-id', False),
1423
            self.renamed(tree1, tree2, 'c-id', False),
1424
            ])
1425
        self.assertEqual(expected,
1426
                         self.do_iter_changes(tree1, tree2))
4503.1.3 by Vincent Ladeuil
Take review comments into account.
1427
        self.check_has_changes(True, tree1, tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1428
1429
    def test_deleted_and_unknown(self):
1430
        """Test a file marked removed, but still present on disk."""
1431
        tree1 = self.make_branch_and_tree('tree1')
1432
        tree2 = self.make_to_branch_and_tree('tree2')
1433
        root_id = tree1.get_root_id()
1434
        tree2.set_root_id(root_id)
1435
1436
        # The final changes should be:
1437
        # bzr add a b c
1438
        # bzr rm --keep b
1439
        self.build_tree_contents([
1440
            ('tree1/a', 'a contents\n'),
1441
            ('tree1/b', 'b contents\n'),
1442
            ('tree1/c', 'c contents\n'),
1443
            ('tree2/a', 'a contents\n'),
1444
            ('tree2/b', 'b contents\n'),
1445
            ('tree2/c', 'c contents\n'),
1446
            ])
1447
        tree1.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
1448
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
1449
1450
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1451
        self.not_applicable_if_cannot_represent_unversioned(tree2)
2456.2.2 by John Arbash Meinel
Add another (failing) test case.
1452
1453
        expected = sorted([
1454
            self.deleted(tree1, 'b-id'),
1455
            self.unversioned(tree2, 'b'),
1456
            ])
1457
        self.assertEqual(expected,
1458
                         self.do_iter_changes(tree1, tree2,
1459
                                              want_unversioned=True))
2456.2.5 by John Arbash Meinel
Make sure the output with want_unversioned=False is reasonable.
1460
        expected = sorted([
1461
            self.deleted(tree1, 'b-id'),
1462
            ])
1463
        self.assertEqual(expected,
1464
                         self.do_iter_changes(tree1, tree2,
1465
                                              want_unversioned=False))
2465.1.1 by John Arbash Meinel
Add a (failing) test exposing the bug in _iter_changes
1466
1467
    def test_renamed_and_added(self):
1468
        """Test when we have renamed a file, and put another in its place."""
1469
        tree1 = self.make_branch_and_tree('tree1')
1470
        tree2 = self.make_to_branch_and_tree('tree2')
1471
        root_id = tree1.get_root_id()
1472
        tree2.set_root_id(root_id)
1473
1474
        # The final changes are:
1475
        # bzr add b c
1476
        # bzr mv b a
1477
        # bzr mv c d
1478
        # bzr add b c
1479
1480
        self.build_tree_contents([
1481
            ('tree1/b', 'b contents\n'),
1482
            ('tree1/c', 'c contents\n'),
1483
            ('tree2/a', 'b contents\n'),
1484
            ('tree2/b', 'new b contents\n'),
1485
            ('tree2/c', 'new c contents\n'),
1486
            ('tree2/d', 'c contents\n'),
1487
            ])
1488
        tree1.add(['b', 'c'], ['b1-id', 'c1-id'])
1489
        tree2.add(['a', 'b', 'c', 'd'], ['b1-id', 'b2-id', 'c2-id', 'c1-id'])
1490
1491
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
1492
1493
        expected = sorted([
1494
            self.renamed(tree1, tree2, 'b1-id', False),
1495
            self.renamed(tree1, tree2, 'c1-id', False),
1496
            self.added(tree2, 'b2-id'),
1497
            self.added(tree2, 'c2-id'),
1498
            ])
1499
        self.assertEqual(expected,
1500
                         self.do_iter_changes(tree1, tree2,
1501
                                              want_unversioned=True))
2472.3.1 by John Arbash Meinel
Fix bug #111288. When we don't have a match
1502
1503
    def test_renamed_and_unknown(self):
1504
        """A file was moved on the filesystem, but not in bzr."""
1505
        tree1 = self.make_branch_and_tree('tree1')
1506
        tree2 = self.make_to_branch_and_tree('tree2')
1507
        root_id = tree1.get_root_id()
1508
        tree2.set_root_id(root_id)
1509
1510
        # The final changes are:
1511
        # bzr add a b
1512
        # mv a a2
1513
1514
        self.build_tree_contents([
1515
            ('tree1/a', 'a contents\n'),
1516
            ('tree1/b', 'b contents\n'),
1517
            ('tree2/a', 'a contents\n'),
1518
            ('tree2/b', 'b contents\n'),
1519
            ])
1520
        tree1.add(['a', 'b'], ['a-id', 'b-id'])
1521
        tree2.add(['a', 'b'], ['a-id', 'b-id'])
1522
        os.rename('tree2/a', 'tree2/a2')
1523
1524
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
4241.6.7 by Vincent Ladeuil
Add InterCHKRevisionTree
1525
        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
1526
1527
        expected = sorted([
1528
            self.missing('a-id', 'a', 'a', tree2.get_root_id(), 'file'),
1529
            self.unversioned(tree2, 'a2'),
1530
            ])
1531
        self.assertEqual(expected,
1532
                         self.do_iter_changes(tree1, tree2,
1533
                                              want_unversioned=True))