/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
1
# Copyright (C) 2006, 2007 Canonical Ltd
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
17
"""Tests for interface conformance of 'WorkingTree.move'"""
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
18
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
19
import os
20
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
21
from bzrlib import (
22
    errors,
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
23
    osutils,
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
24
    )
25
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
26
from bzrlib.workingtree_4 import DirStateWorkingTreeFormat
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
28
29
30
class TestMove(TestCaseWithWorkingTree):
31
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
32
    def get_tree_layout(self, tree):
33
        """Get the (path, file_id) pairs for the current tree."""
34
        tree.lock_read()
35
        try:
36
            return [(path, ie.file_id) for path, ie
37
                    in tree.iter_entries_by_dir()]
38
        finally:
39
            tree.unlock()
40
41
    def assertTreeLayout(self, expected, tree):
42
        """Check that the tree has the correct layout."""
43
        actual = self.get_tree_layout(tree)
44
        self.assertEqual(expected, actual)
45
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
46
    def test_move_correct_call_named(self):
47
        """tree.move has the deprecated parameter 'to_name'.
48
        It has been replaced by 'to_dir' for consistency.
49
        Test the new API using named parameter
50
        """
51
        self.build_tree(['a1', 'sub1/'])
52
        tree = self.make_branch_and_tree('.')
53
        tree.add(['a1', 'sub1'])
54
        tree.commit('initial commit')
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
55
        self.assertEqual([('a1', 'sub1/a1')],
56
            tree.move(['a1'], to_dir='sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
57
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
58
59
    def test_move_correct_call_unnamed(self):
60
        """tree.move has the deprecated parameter 'to_name'.
61
        It has been replaced by 'to_dir' for consistency.
62
        Test the new API using unnamed parameter
63
        """
64
        self.build_tree(['a1', 'sub1/'])
65
        tree = self.make_branch_and_tree('.')
66
        tree.add(['a1', 'sub1'])
67
        tree.commit('initial commit')
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
68
        self.assertEqual([('a1', 'sub1/a1')],
69
            tree.move(['a1'], 'sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
70
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
71
72
    def test_move_deprecated_wrong_call(self):
73
        """tree.move has the deprecated parameter 'to_name'.
74
        It has been replaced by 'to_dir' for consistency.
75
        Test the new API using wrong parameter
76
        """
77
        self.build_tree(['a1', 'sub1/'])
78
        tree = self.make_branch_and_tree('.')
79
        tree.add(['a1', 'sub1'])
80
        tree.commit('initial commit')
81
        self.assertRaises(TypeError, tree.move, ['a1'],
82
                          to_this_parameter_does_not_exist='sub1',
83
                          after=False)
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
84
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
85
86
    def test_move_deprecated_call(self):
87
        """tree.move has the deprecated parameter 'to_name'.
88
        It has been replaced by 'to_dir' for consistency.
89
        Test the new API using deprecated parameter
90
        """
91
        self.build_tree(['a1', 'sub1/'])
92
        tree = self.make_branch_and_tree('.')
93
        tree.add(['a1', 'sub1'])
94
        tree.commit('initial commit')
95
96
        try:
97
            self.callDeprecated(['The parameter to_name was deprecated'
98
                                 ' in version 0.13. Use to_dir instead'],
99
                                tree.move, ['a1'], to_name='sub1',
100
                                after=False)
101
        except TypeError:
3907.2.3 by Ian Clatworthy
DirStateWorkingTree and DirStateWorkingTreeFormat base classes introduced
102
            # WorkingTreeFormat4 and later don't have to maintain api
103
            # compatibility since it was deprecated before they were introduced.
104
            if not isinstance(self.workingtree_format,
105
                DirStateWorkingTreeFormat):
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
106
                raise
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
107
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
108
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
109
    def test_move_target_not_dir(self):
110
        tree = self.make_branch_and_tree('.')
111
        self.build_tree(['a'])
112
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
113
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
114
115
        self.assertRaises(errors.BzrMoveFailedError,
116
                          tree.move, ['a'], 'not-a-dir')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
117
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
118
119
    def test_move_non_existent(self):
120
        tree = self.make_branch_and_tree('.')
121
        self.build_tree(['a/'])
122
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
123
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
124
        self.assertRaises(errors.BzrMoveFailedError,
125
                          tree.move, ['not-a-file'], 'a')
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
126
        self.assertRaises(errors.BzrMoveFailedError,
127
                          tree.move, ['not-a-file'], '')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
128
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
129
130
    def test_move_target_not_versioned(self):
131
        tree = self.make_branch_and_tree('.')
132
        self.build_tree(['a/', 'b'])
133
        tree.add(['b'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
134
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
135
        self.assertRaises(errors.BzrMoveFailedError,
136
                          tree.move, ['b'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
137
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
138
139
    def test_move_unversioned(self):
140
        tree = self.make_branch_and_tree('.')
141
        self.build_tree(['a/', 'b'])
142
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
143
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
144
        self.assertRaises(errors.BzrMoveFailedError,
145
                          tree.move, ['b'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
146
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
147
148
    def test_move_multi_unversioned(self):
149
        tree = self.make_branch_and_tree('.')
150
        self.build_tree(['a/', 'b', 'c', 'd'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
151
        tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id'])
152
        tree.commit('initial', rev_id='rev-1')
153
        root_id = tree.get_root_id()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
154
        self.assertRaises(errors.BzrMoveFailedError,
155
                          tree.move, ['c', 'b', 'd'], 'a')
156
        self.assertRaises(errors.BzrMoveFailedError,
157
                          tree.move, ['b', 'c', 'd'], 'a')
158
        self.assertRaises(errors.BzrMoveFailedError,
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
159
                          tree.move, ['d', 'c', 'b'], 'a')
160
        if osutils.lexists('a/c'):
161
            # If 'c' was actually moved, then 'd' should have also been moved
162
            self.assertTreeLayout([('', root_id), ('a', 'a-id'),
163
                                   ('a/c', 'c-id'),  ('a/d', 'd-id')], tree)
164
        else:
165
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
166
                                   ('d', 'd-id')], tree)
167
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
168
                               ('d', 'd-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
169
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
170
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
171
    def test_move_over_deleted(self):
172
        tree = self.make_branch_and_tree('.')
173
        self.build_tree(['a/', 'a/b', 'b'])
174
        tree.add(['a', 'a/b', 'b'], ['a-id', 'ab-id', 'b-id'])
175
        tree.commit('initial', rev_id='rev-1')
176
177
        root_id = tree.get_root_id()
178
        tree.remove(['a/b'], keep_files=False)
179
        self.assertEqual([('b', 'a/b')], tree.move(['b'], 'a'))
180
        self.assertTreeLayout([('', root_id),
181
                               ('a', 'a-id'),
182
                               ('a/b', 'b-id'),
183
                              ], tree)
184
        tree._validate()
185
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
186
    def test_move_subdir(self):
187
        tree = self.make_branch_and_tree('.')
188
        self.build_tree(['a', 'b/', 'b/c'])
189
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
190
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
191
        root_id = tree.get_root_id()
192
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
193
                               ('b/c', 'c-id')], tree)
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
194
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
195
                               ('b/c', 'c-id')], tree.basis_tree())
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
196
        a_contents = tree.get_file_text('a-id')
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
197
        self.assertEqual([('a', 'b/a')],
198
            tree.move(['a'], 'b'))
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
199
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
200
                               ('b/c', 'c-id')], tree)
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
201
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
202
                               ('b/c', 'c-id')], tree.basis_tree())
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
203
        self.failIfExists('a')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
204
        self.assertFileEqual(a_contents, 'b/a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
205
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
206
207
    def test_move_parent_dir(self):
208
        tree = self.make_branch_and_tree('.')
209
        self.build_tree(['a', 'b/', 'b/c'])
210
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
211
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
212
        root_id = tree.get_root_id()
213
        c_contents = tree.get_file_text('c-id')
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
214
        self.assertEqual([('b/c', 'c')],
215
            tree.move(['b/c'], ''))
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
216
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
217
                               ('c', 'c-id')], tree)
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
218
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
219
                               ('b/c', 'c-id')], tree.basis_tree())
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
220
        self.failIfExists('b/c')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
221
        self.assertFileEqual(c_contents, 'c')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
222
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
223
224
    def test_move_fail_consistent(self):
225
        tree = self.make_branch_and_tree('.')
226
        self.build_tree(['a', 'b/', 'b/a', 'c'])
227
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
228
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
229
        root_id = tree.get_root_id()
230
        # Target already exists
231
        self.assertRaises(errors.RenameFailedFilesExist,
232
                          tree.move, ['c', 'a'], 'b')
233
        # 'c' may or may not have been moved, but either way the tree should
234
        # maintain a consistent state.
235
        if osutils.lexists('c'):
236
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
237
                                   ('c', 'c-id')], tree)
238
        else:
239
            self.failUnlessExists('b/c')
240
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
241
                                   ('b/c', 'c-id')], tree)
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
242
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
243
                               ('c', 'c-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
244
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
245
246
    def test_move_onto_self(self):
247
        tree = self.make_branch_and_tree('.')
248
        self.build_tree(['b/', 'b/a'])
249
        tree.add(['b', 'b/a'], ['b-id', 'a-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
250
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
251
252
        self.assertRaises(errors.BzrMoveFailedError,
253
                          tree.move, ['b/a'], 'b')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
254
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
255
256
    def test_move_onto_self_root(self):
257
        tree = self.make_branch_and_tree('.')
258
        self.build_tree(['a'])
259
        tree.add(['a'], ['a-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
260
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
261
262
        self.assertRaises(errors.BzrMoveFailedError,
263
                          tree.move, ['a'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
264
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
265
266
    def test_move_after(self):
267
        tree = self.make_branch_and_tree('.')
268
        self.build_tree(['a', 'b/'])
269
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
270
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
271
        root_id = tree.get_root_id()
272
        os.rename('a', 'b/a')
273
274
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
275
                              tree)
276
        # We don't need after=True as long as source is missing and target
277
        # exists.
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
278
        self.assertEqual([('a', 'b/a')],
279
            tree.move(['a'], 'b'))
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
280
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
281
                              tree)
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
282
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
283
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
284
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
285
286
    def test_move_after_with_after(self):
287
        tree = self.make_branch_and_tree('.')
288
        self.build_tree(['a', 'b/'])
289
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
290
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
291
        root_id = tree.get_root_id()
292
        os.rename('a', 'b/a')
293
294
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
295
                              tree)
296
        # Passing after=True should work as well
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
297
        self.assertEqual([('a', 'b/a')],
298
            tree.move(['a'], 'b', after=True))
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
299
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
300
                              tree)
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
301
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
302
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
303
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
304
305
    def test_move_after_no_target(self):
306
        tree = self.make_branch_and_tree('.')
307
        self.build_tree(['a', 'b/'])
308
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
309
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
310
        root_id = tree.get_root_id()
311
312
        # Passing after when the file hasn't been move raises an exception
313
        self.assertRaises(errors.BzrMoveFailedError,
314
                          tree.move, ['a'], 'b', after=True)
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
315
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
316
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
317
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
318
319
    def test_move_after_source_and_dest(self):
320
        tree = self.make_branch_and_tree('.')
321
        self.build_tree(['a', 'b/', 'b/a'])
322
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
323
        tree.commit('initial', rev_id='rev-1')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
324
        root_id = tree.get_root_id()
325
326
        # TODO: jam 20070225 I would usually use 'rb', but assertFileEqual
327
        #       uses 'r'.
328
        a_file = open('a', 'r')
329
        try:
330
            a_text = a_file.read()
331
        finally:
332
            a_file.close()
333
        ba_file = open('b/a', 'r')
334
        try:
335
            ba_text = ba_file.read()
336
        finally:
337
            ba_file.close()
338
339
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
340
                              tree)
341
        self.assertRaises(errors.RenameFailedFilesExist,
342
                          tree.move, ['a'], 'b', after=False)
343
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
344
                              tree)
345
        self.assertFileEqual(a_text, 'a')
346
        self.assertFileEqual(ba_text, 'b/a')
347
        # But you can pass after=True
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
348
        self.assertEqual([('a', 'b/a')],
349
            tree.move(['a'], 'b', after=True))
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
350
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
351
                              tree)
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
352
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
353
                              tree.basis_tree())
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
354
        # But it shouldn't actually move anything
355
        self.assertFileEqual(a_text, 'a')
356
        self.assertFileEqual(ba_text, 'b/a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
357
        tree._validate()
2255.2.146 by John Arbash Meinel
Implement move_directory by factoring out move_one
358
359
    def test_move_directory(self):
360
        tree = self.make_branch_and_tree('.')
361
        self.build_tree(['a/', 'a/b', 'a/c/', 'a/c/d', 'e/'])
362
        tree.add(['a', 'a/b', 'a/c', 'a/c/d', 'e'],
363
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
364
        tree.commit('initial', rev_id='rev-1')
365
        root_id = tree.get_root_id()
366
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
367
        self.assertEqual([('a', 'e/a')],
368
            tree.move(['a'], 'e'))
2255.2.146 by John Arbash Meinel
Implement move_directory by factoring out move_one
369
        self.assertTreeLayout([('', root_id), ('e', 'e-id'), ('e/a', 'a-id'),
370
                               ('e/a/b', 'b-id'), ('e/a/c', 'c-id'),
371
                               ('e/a/c/d', 'd-id')], tree)
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
372
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('e', 'e-id'),
373
                               ('a/b', 'b-id'), ('a/c', 'c-id'),
374
                               ('a/c/d', 'd-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
375
        tree._validate()
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
376
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
377
    def test_move_directory_into_parent(self):
378
        tree = self.make_branch_and_tree('.')
379
        self.build_tree(['c/', 'c/b/', 'c/b/d/'])
380
        tree.add(['c', 'c/b', 'c/b/d'],
381
                 ['c-id', 'b-id', 'd-id'])
382
        tree.commit('initial', rev_id='rev-1')
383
        root_id = tree.get_root_id()
384
385
        self.assertEqual([('c/b', 'b')],
386
                         tree.move(['c/b'], ''))
387
        self.assertTreeLayout([('', root_id),
388
                               ('b', 'b-id'),
389
                               ('c', 'c-id'),
390
                               ('b/d', 'd-id'),
391
                              ], tree)
392
        tree._validate()
393
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
394
    def test_move_directory_with_children_in_subdir(self):
395
        tree = self.make_branch_and_tree('.')
396
        self.build_tree(['a/', 'a/b', 'a/c/', 'd/'])
397
        tree.add(['a', 'a/b', 'a/c', 'd'],
398
                 ['a-id', 'b-id', 'c-id', 'd-id'])
399
        tree.commit('initial', rev_id='rev-1')
400
        root_id = tree.get_root_id()
401
402
403
        tree.rename_one('a/b', 'a/c/b')
404
        self.assertTreeLayout([('', root_id),
405
                               ('a', 'a-id'),
406
                               ('d', 'd-id'),
407
                               ('a/c', 'c-id'),
408
                               ('a/c/b', 'b-id'),
409
                              ], tree)
410
        self.assertEqual([('a', 'd/a')],
411
                         tree.move(['a'], 'd'))
412
        self.assertTreeLayout([('', root_id),
413
                               ('d', 'd-id'),
414
                               ('d/a', 'a-id'),
415
                               ('d/a/c', 'c-id'),
416
                               ('d/a/c/b', 'b-id'),
417
                              ], tree)
418
        tree._validate()
419
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
420
    def test_move_directory_with_deleted_children(self):
421
        tree = self.make_branch_and_tree('.')
422
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'b/'])
423
        tree.add(['a', 'b', 'a/b', 'a/c', 'a/d'],
424
                 ['a-id', 'b-id', 'ab-id', 'ac-id', 'ad-id'])
425
        tree.commit('initial', rev_id='rev-1')
426
        root_id = tree.get_root_id()
427
428
        tree.remove(['a/b', 'a/d'])
429
430
        self.assertEqual([('a', 'b/a')],
431
                         tree.move(['a'], 'b'))
432
        self.assertTreeLayout([('', root_id),
433
                               ('b', 'b-id'),
434
                               ('b/a', 'a-id'),
435
                               ('b/a/c', 'ac-id'),
436
                              ], tree)
437
        tree._validate()
438
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
439
    def test_move_directory_with_new_children(self):
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
440
        tree = self.make_branch_and_tree('.')
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
441
        self.build_tree(['a/', 'a/c', 'b/'])
442
        tree.add(['a', 'b', 'a/c'], ['a-id', 'b-id', 'ac-id'])
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
443
        tree.commit('initial', rev_id='rev-1')
444
        root_id = tree.get_root_id()
445
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
446
        self.build_tree(['a/b', 'a/d'])
447
        tree.add(['a/b', 'a/d'], ['ab-id', 'ad-id'])
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
448
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
449
        self.assertEqual([('a', 'b/a')],
450
                         tree.move(['a'], 'b'))
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
451
        self.assertTreeLayout([('', root_id),
452
                               ('b', 'b-id'),
453
                               ('b/a', 'a-id'),
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
454
                               ('b/a/b', 'ab-id'),
455
                               ('b/a/c', 'ac-id'),
456
                               ('b/a/d', 'ad-id'),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
457
                              ], tree)
458
        tree._validate()
459
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
460
    def test_move_directory_with_moved_children(self):
461
        tree = self.make_branch_and_tree('.')
462
        self.build_tree(['a/', 'a/b', 'a/c', 'd', 'e/'])
463
        tree.add(['a', 'a/b', 'a/c', 'd', 'e'],
464
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
465
        tree.commit('initial', rev_id='rev-1')
466
        root_id = tree.get_root_id()
467
468
        self.assertEqual([('a/b', 'b')],
469
                         tree.move(['a/b'], ''))
470
        self.assertTreeLayout([('', root_id),
471
                               ('a', 'a-id'),
472
                               ('b', 'b-id'),
473
                               ('d', 'd-id'),
474
                               ('e', 'e-id'),
475
                               ('a/c', 'c-id'),
476
                              ], tree)
477
        self.assertEqual([('d', 'a/d')],
478
                         tree.move(['d'], 'a'))
479
        self.assertTreeLayout([('', root_id),
480
                               ('a', 'a-id'),
481
                               ('b', 'b-id'),
482
                               ('e', 'e-id'),
483
                               ('a/c', 'c-id'),
484
                               ('a/d', 'd-id'),
485
                              ], tree)
486
        self.assertEqual([('a', 'e/a')],
487
                         tree.move(['a'], 'e'))
488
        self.assertTreeLayout([('', root_id),
489
                               ('b', 'b-id'),
490
                               ('e', 'e-id'),
491
                               ('e/a', 'a-id'),
492
                               ('e/a/c', 'c-id'),
493
                               ('e/a/d', 'd-id'),
494
                              ], tree)
495
        tree._validate()
496
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
497
    def test_move_directory_with_renamed_child(self):
498
        tree = self.make_branch_and_tree('.')
499
        self.build_tree(['a/', 'a/b', 'a/c', 'd/'])
500
        tree.add(['a', 'a/b', 'a/c', 'd'],
501
                 ['a-id', 'b-id', 'c-id', 'd-id'])
502
        tree.commit('initial', rev_id='rev-1')
503
        root_id = tree.get_root_id()
504
505
        tree.rename_one('a/b', 'a/d')
506
        self.assertTreeLayout([('', root_id),
507
                               ('a', 'a-id'),
508
                               ('d', 'd-id'),
509
                               ('a/c', 'c-id'),
510
                               ('a/d', 'b-id'),
511
                              ], tree)
512
        self.assertEqual([('a', 'd/a')],
513
                         tree.move(['a'], 'd'))
514
        self.assertTreeLayout([('', root_id),
515
                               ('d', 'd-id'),
516
                               ('d/a', 'a-id'),
517
                               ('d/a/c', 'c-id'),
518
                               ('d/a/d', 'b-id'),
519
                              ], tree)
520
        tree._validate()
521
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
522
    def test_move_directory_with_swapped_children(self):
523
        tree = self.make_branch_and_tree('.')
524
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'e/'])
525
        tree.add(['a', 'a/b', 'a/c', 'a/d', 'e'],
526
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
527
        tree.commit('initial', rev_id='rev-1')
528
        root_id = tree.get_root_id()
529
530
        tree.rename_one('a/b', 'a/bb')
531
        tree.rename_one('a/d', 'a/b')
532
        tree.rename_one('a/bb', 'a/d')
533
        self.assertTreeLayout([('', root_id),
534
                               ('a', 'a-id'),
535
                               ('e', 'e-id'),
536
                               ('a/b', 'd-id'),
537
                               ('a/c', 'c-id'),
538
                               ('a/d', 'b-id'),
539
                              ], tree)
540
        self.assertEqual([('a', 'e/a')],
541
                         tree.move(['a'], 'e'))
542
        self.assertTreeLayout([('', root_id),
543
                               ('e', 'e-id'),
544
                               ('e/a', 'a-id'),
545
                               ('e/a/b', 'd-id'),
546
                               ('e/a/c', 'c-id'),
547
                               ('e/a/d', 'b-id'),
548
                              ], tree)
549
        tree._validate()
550
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
551
    def test_move_moved(self):
552
        """Moving a moved entry works as expected."""
553
        tree = self.make_branch_and_tree('.')
554
        self.build_tree(['a/', 'a/b', 'c/'])
555
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
556
        tree.commit('initial', rev_id='rev-1')
557
        root_id = tree.get_root_id()
558
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
559
        self.assertEqual([('a/b', 'c/b')],
560
            tree.move(['a/b'], 'c'))
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
561
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
562
                               ('c/b', 'b-id')], tree)
563
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
564
                               ('a/b', 'b-id')], tree.basis_tree())
565
2255.7.46 by Robert Collins
Fix WorkingTree4.move to return the moved paths, and update the tree implementation tests for move to check them.
566
        self.assertEqual([('c/b', 'b')],
567
            tree.move(['c/b'], ''))
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
568
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
569
                               ('c', 'c-id')], tree)
570
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
571
                               ('a/b', 'b-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
572
        tree._validate()