~bzr-pqm/bzr/bzr.dev

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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
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,
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
24
    tests,
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
25
    )
26
6072.2.2 by Jelmer Vernooij
Use HasLayout matcher.
27
from bzrlib.tests.matchers import HasLayout
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
28
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
29
from bzrlib.tests import (
30
    features,
31
    )
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
32
33
34
class TestMove(TestCaseWithWorkingTree):
35
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
36
    def assertTreeLayout(self, expected, tree):
37
        """Check that the tree has the correct layout."""
6072.2.2 by Jelmer Vernooij
Use HasLayout matcher.
38
        self.assertThat(tree, HasLayout(expected))
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
39
3923.2.1 by Charles Duffy
Fix bug #314251 (dirstate crash on rename via delete+add)
40
    def test_move_via_rm_and_add(self):
41
        """Move by remove and add-with-id"""
42
        self.build_tree(['a1', 'b1'])
43
        tree = self.make_branch_and_tree('.')
44
        tree.add(['a1'], ids=['a1-id'])
45
        tree.commit('initial commit')
46
        tree.remove('a1', force=True, keep_files=False)
47
        tree.add(['b1'], ids=['a1-id'])
48
        tree._validate()
49
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
50
    def test_move_correct_call_named(self):
51
        """tree.move has the deprecated parameter 'to_name'.
52
        It has been replaced by 'to_dir' for consistency.
53
        Test the new API using named parameter
54
        """
55
        self.build_tree(['a1', 'sub1/'])
56
        tree = self.make_branch_and_tree('.')
57
        tree.add(['a1', 'sub1'])
58
        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.
59
        self.assertEqual([('a1', 'sub1/a1')],
60
            tree.move(['a1'], to_dir='sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
61
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
62
63
    def test_move_correct_call_unnamed(self):
64
        """tree.move has the deprecated parameter 'to_name'.
65
        It has been replaced by 'to_dir' for consistency.
66
        Test the new API using unnamed parameter
67
        """
68
        self.build_tree(['a1', 'sub1/'])
69
        tree = self.make_branch_and_tree('.')
70
        tree.add(['a1', 'sub1'])
71
        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.
72
        self.assertEqual([('a1', 'sub1/a1')],
73
            tree.move(['a1'], 'sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
74
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
75
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
76
    def test_move_target_not_dir(self):
77
        tree = self.make_branch_and_tree('.')
78
        self.build_tree(['a'])
79
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
80
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
81
82
        self.assertRaises(errors.BzrMoveFailedError,
83
                          tree.move, ['a'], 'not-a-dir')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
84
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
85
86
    def test_move_non_existent(self):
87
        tree = self.make_branch_and_tree('.')
88
        self.build_tree(['a/'])
89
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
90
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
91
        self.assertRaises(errors.BzrMoveFailedError,
92
                          tree.move, ['not-a-file'], 'a')
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
93
        self.assertRaises(errors.BzrMoveFailedError,
94
                          tree.move, ['not-a-file'], '')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
95
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
96
97
    def test_move_target_not_versioned(self):
98
        tree = self.make_branch_and_tree('.')
99
        self.build_tree(['a/', 'b'])
100
        tree.add(['b'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
101
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
102
        self.assertRaises(errors.BzrMoveFailedError,
103
                          tree.move, ['b'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
104
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
105
106
    def test_move_unversioned(self):
107
        tree = self.make_branch_and_tree('.')
108
        self.build_tree(['a/', 'b'])
109
        tree.add(['a'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
110
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
111
        self.assertRaises(errors.BzrMoveFailedError,
112
                          tree.move, ['b'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
113
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
114
115
    def test_move_multi_unversioned(self):
116
        tree = self.make_branch_and_tree('.')
117
        self.build_tree(['a/', 'b', 'c', 'd'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
118
        tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id'])
119
        tree.commit('initial', rev_id='rev-1')
120
        root_id = tree.get_root_id()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
121
        self.assertRaises(errors.BzrMoveFailedError,
122
                          tree.move, ['c', 'b', 'd'], 'a')
123
        self.assertRaises(errors.BzrMoveFailedError,
124
                          tree.move, ['b', 'c', 'd'], 'a')
125
        self.assertRaises(errors.BzrMoveFailedError,
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
126
                          tree.move, ['d', 'c', 'b'], 'a')
127
        if osutils.lexists('a/c'):
128
            # If 'c' was actually moved, then 'd' should have also been moved
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
129
            self.assertTreeLayout([('', root_id), ('a/', 'a-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
130
                                   ('a/c', 'c-id'),  ('a/d', 'd-id')], tree)
131
        else:
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
132
            self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c', 'c-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
133
                                   ('d', 'd-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
134
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c', 'c-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
135
                               ('d', 'd-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
136
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
137
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
138
    def test_move_over_deleted(self):
139
        tree = self.make_branch_and_tree('.')
140
        self.build_tree(['a/', 'a/b', 'b'])
141
        tree.add(['a', 'a/b', 'b'], ['a-id', 'ab-id', 'b-id'])
142
        tree.commit('initial', rev_id='rev-1')
143
144
        root_id = tree.get_root_id()
145
        tree.remove(['a/b'], keep_files=False)
146
        self.assertEqual([('b', 'a/b')], tree.move(['b'], 'a'))
147
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
148
                               ('a/', 'a-id'),
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
149
                               ('a/b', 'b-id'),
150
                              ], tree)
151
        tree._validate()
152
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
153
    def test_move_subdir(self):
154
        tree = self.make_branch_and_tree('.')
155
        self.build_tree(['a', 'b/', 'b/c'])
156
        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
157
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
158
        root_id = tree.get_root_id()
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
159
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
160
                               ('b/c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
161
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
162
                               ('b/c', 'c-id')], tree.basis_tree())
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
163
        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.
164
        self.assertEqual([('a', 'b/a')],
165
            tree.move(['a'], 'b'))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
166
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id'),
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
167
                               ('b/c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
168
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
169
                               ('b/c', 'c-id')], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
170
        self.assertPathDoesNotExist('a')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
171
        self.assertFileEqual(a_contents, 'b/a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
172
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
173
174
    def test_move_parent_dir(self):
175
        tree = self.make_branch_and_tree('.')
176
        self.build_tree(['a', 'b/', 'b/c'])
177
        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
178
        tree.commit('initial', rev_id='rev-1')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
179
        root_id = tree.get_root_id()
180
        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.
181
        self.assertEqual([('b/c', 'c')],
182
            tree.move(['b/c'], ''))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
183
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
184
                               ('c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
185
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
186
                               ('b/c', 'c-id')], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
187
        self.assertPathDoesNotExist('b/c')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
188
        self.assertFileEqual(c_contents, 'c')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
189
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
190
191
    def test_move_fail_consistent(self):
192
        tree = self.make_branch_and_tree('.')
193
        self.build_tree(['a', 'b/', 'b/a', 'c'])
194
        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
195
        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.
196
        root_id = tree.get_root_id()
197
        # Target already exists
198
        self.assertRaises(errors.RenameFailedFilesExist,
199
                          tree.move, ['c', 'a'], 'b')
200
        # 'c' may or may not have been moved, but either way the tree should
201
        # maintain a consistent state.
202
        if osutils.lexists('c'):
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
203
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
204
                                   ('c', 'c-id')], tree)
205
        else:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
206
            self.assertPathExists('b/c')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
207
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
208
                                   ('b/c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
209
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
210
                               ('c', 'c-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
211
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
212
213
    def test_move_onto_self(self):
214
        tree = self.make_branch_and_tree('.')
215
        self.build_tree(['b/', 'b/a'])
216
        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
217
        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.
218
219
        self.assertRaises(errors.BzrMoveFailedError,
220
                          tree.move, ['b/a'], 'b')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
221
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
222
223
    def test_move_onto_self_root(self):
224
        tree = self.make_branch_and_tree('.')
225
        self.build_tree(['a'])
226
        tree.add(['a'], ['a-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
227
        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.
228
229
        self.assertRaises(errors.BzrMoveFailedError,
230
                          tree.move, ['a'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
231
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
232
233
    def test_move_after(self):
234
        tree = self.make_branch_and_tree('.')
235
        self.build_tree(['a', 'b/'])
236
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
237
        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.
238
        root_id = tree.get_root_id()
239
        os.rename('a', 'b/a')
240
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
241
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
242
                              tree)
243
        # We don't need after=True as long as source is missing and target
244
        # 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.
245
        self.assertEqual([('a', 'b/a')],
246
            tree.move(['a'], 'b'))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
247
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
248
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
249
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
250
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
251
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
252
253
    def test_move_after_with_after(self):
254
        tree = self.make_branch_and_tree('.')
255
        self.build_tree(['a', 'b/'])
256
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
257
        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.
258
        root_id = tree.get_root_id()
259
        os.rename('a', 'b/a')
260
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
261
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
262
                              tree)
263
        # 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.
264
        self.assertEqual([('a', 'b/a')],
265
            tree.move(['a'], 'b', after=True))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
266
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
267
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
268
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
269
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
270
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
271
272
    def test_move_after_no_target(self):
273
        tree = self.make_branch_and_tree('.')
274
        self.build_tree(['a', 'b/'])
275
        tree.add(['a', 'b'], ['a-id', 'b-id'])
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
276
        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.
277
        root_id = tree.get_root_id()
278
279
        # Passing after when the file hasn't been move raises an exception
280
        self.assertRaises(errors.BzrMoveFailedError,
281
                          tree.move, ['a'], 'b', after=True)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
282
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
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_source_and_dest(self):
287
        tree = self.make_branch_and_tree('.')
288
        self.build_tree(['a', 'b/', 'b/a'])
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
293
        # TODO: jam 20070225 I would usually use 'rb', but assertFileEqual
294
        #       uses 'r'.
295
        a_file = open('a', 'r')
296
        try:
297
            a_text = a_file.read()
298
        finally:
299
            a_file.close()
300
        ba_file = open('b/a', 'r')
301
        try:
302
            ba_text = ba_file.read()
303
        finally:
304
            ba_file.close()
305
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
306
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
307
                              tree)
308
        self.assertRaises(errors.RenameFailedFilesExist,
309
                          tree.move, ['a'], 'b', after=False)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
310
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
311
                              tree)
312
        self.assertFileEqual(a_text, 'a')
313
        self.assertFileEqual(ba_text, 'b/a')
314
        # 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.
315
        self.assertEqual([('a', 'b/a')],
316
            tree.move(['a'], 'b', after=True))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
317
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
318
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
319
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
320
                              tree.basis_tree())
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
321
        # But it shouldn't actually move anything
322
        self.assertFileEqual(a_text, 'a')
323
        self.assertFileEqual(ba_text, 'b/a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
324
        tree._validate()
2255.2.146 by John Arbash Meinel
Implement move_directory by factoring out move_one
325
326
    def test_move_directory(self):
327
        tree = self.make_branch_and_tree('.')
328
        self.build_tree(['a/', 'a/b', 'a/c/', 'a/c/d', 'e/'])
329
        tree.add(['a', 'a/b', 'a/c', 'a/c/d', 'e'],
330
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
331
        tree.commit('initial', rev_id='rev-1')
332
        root_id = tree.get_root_id()
333
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.
334
        self.assertEqual([('a', 'e/a')],
335
            tree.move(['a'], 'e'))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
336
        self.assertTreeLayout([('', root_id), ('e/', 'e-id'), ('e/a/', 'a-id'),
337
                               ('e/a/b', 'b-id'), ('e/a/c/', 'c-id'),
2255.2.146 by John Arbash Meinel
Implement move_directory by factoring out move_one
338
                               ('e/a/c/d', 'd-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
339
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('e/', 'e-id'),
340
                               ('a/b', 'b-id'), ('a/c/', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
341
                               ('a/c/d', 'd-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
342
        tree._validate()
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
343
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
344
    def test_move_directory_into_parent(self):
6039.1.3 by Jelmer Vernooij
Cope with versioned directories in test_move_directory_into_parent.
345
        if not self.workingtree_format.supports_versioned_directories:
346
            raise tests.TestNotApplicable(
347
                "test requires versioned directories")
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
348
        tree = self.make_branch_and_tree('.')
349
        self.build_tree(['c/', 'c/b/', 'c/b/d/'])
350
        tree.add(['c', 'c/b', 'c/b/d'],
351
                 ['c-id', 'b-id', 'd-id'])
352
        tree.commit('initial', rev_id='rev-1')
353
        root_id = tree.get_root_id()
354
355
        self.assertEqual([('c/b', 'b')],
356
                         tree.move(['c/b'], ''))
357
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
358
                               ('b/', 'b-id'),
359
                               ('c/', 'c-id'),
360
                               ('b/d/', 'd-id'),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
361
                              ], tree)
362
        tree._validate()
363
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
364
    def test_move_directory_with_children_in_subdir(self):
365
        tree = self.make_branch_and_tree('.')
366
        self.build_tree(['a/', 'a/b', 'a/c/', 'd/'])
367
        tree.add(['a', 'a/b', 'a/c', 'd'],
368
                 ['a-id', 'b-id', 'c-id', 'd-id'])
369
        tree.commit('initial', rev_id='rev-1')
370
        root_id = tree.get_root_id()
371
372
        tree.rename_one('a/b', 'a/c/b')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
373
        self.assertTreeLayout([('', root_id),
374
                               ('a/', 'a-id'),
375
                               ('d/', 'd-id'),
376
                               ('a/c/', 'c-id'),
377
                               ('a/c/b', 'b-id'),
378
                              ], tree)
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
379
        self.assertEqual([('a', 'd/a')],
380
                         tree.move(['a'], 'd'))
381
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
382
                               ('d/', 'd-id'),
383
                               ('d/a/', 'a-id'),
384
                               ('d/a/c/', 'c-id'),
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
385
                               ('d/a/c/b', 'b-id'),
386
                              ], tree)
387
        tree._validate()
388
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
389
    def test_move_directory_with_deleted_children(self):
390
        tree = self.make_branch_and_tree('.')
391
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'b/'])
392
        tree.add(['a', 'b', 'a/b', 'a/c', 'a/d'],
393
                 ['a-id', 'b-id', 'ab-id', 'ac-id', 'ad-id'])
394
        tree.commit('initial', rev_id='rev-1')
395
        root_id = tree.get_root_id()
396
397
        tree.remove(['a/b', 'a/d'])
398
399
        self.assertEqual([('a', 'b/a')],
400
                         tree.move(['a'], 'b'))
401
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
402
                               ('b/', 'b-id'),
403
                               ('b/a/', 'a-id'),
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
404
                               ('b/a/c', 'ac-id'),
405
                              ], tree)
406
        tree._validate()
407
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
408
    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
409
        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.
410
        self.build_tree(['a/', 'a/c', 'b/'])
411
        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
412
        tree.commit('initial', rev_id='rev-1')
413
        root_id = tree.get_root_id()
414
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
415
        self.build_tree(['a/b', 'a/d'])
416
        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
417
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
418
        self.assertEqual([('a', 'b/a')],
419
                         tree.move(['a'], 'b'))
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
420
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
421
                               ('b/', 'b-id'),
422
                               ('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.
423
                               ('b/a/b', 'ab-id'),
424
                               ('b/a/c', 'ac-id'),
425
                               ('b/a/d', 'ad-id'),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
426
                              ], tree)
427
        tree._validate()
428
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
429
    def test_move_directory_with_moved_children(self):
430
        tree = self.make_branch_and_tree('.')
431
        self.build_tree(['a/', 'a/b', 'a/c', 'd', 'e/'])
432
        tree.add(['a', 'a/b', 'a/c', 'd', 'e'],
433
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
434
        tree.commit('initial', rev_id='rev-1')
435
        root_id = tree.get_root_id()
436
437
        self.assertEqual([('a/b', 'b')],
438
                         tree.move(['a/b'], ''))
439
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
440
                               ('a/', 'a-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
441
                               ('b', 'b-id'),
442
                               ('d', 'd-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
443
                               ('e/', 'e-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
444
                               ('a/c', 'c-id'),
445
                              ], tree)
446
        self.assertEqual([('d', 'a/d')],
447
                         tree.move(['d'], 'a'))
448
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
449
                               ('a/', 'a-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
450
                               ('b', 'b-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
451
                               ('e/', 'e-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
452
                               ('a/c', 'c-id'),
453
                               ('a/d', 'd-id'),
454
                              ], tree)
455
        self.assertEqual([('a', 'e/a')],
456
                         tree.move(['a'], 'e'))
457
        self.assertTreeLayout([('', root_id),
458
                               ('b', 'b-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
459
                               ('e/', 'e-id'),
460
                               ('e/a/', 'a-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
461
                               ('e/a/c', 'c-id'),
462
                               ('e/a/d', 'd-id'),
463
                              ], tree)
464
        tree._validate()
465
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
466
    def test_move_directory_with_renamed_child(self):
467
        tree = self.make_branch_and_tree('.')
468
        self.build_tree(['a/', 'a/b', 'a/c', 'd/'])
469
        tree.add(['a', 'a/b', 'a/c', 'd'],
470
                 ['a-id', 'b-id', 'c-id', 'd-id'])
471
        tree.commit('initial', rev_id='rev-1')
472
        root_id = tree.get_root_id()
473
474
        tree.rename_one('a/b', 'a/d')
475
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
476
                               ('a/', 'a-id'),
477
                               ('d/', 'd-id'),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
478
                               ('a/c', 'c-id'),
479
                               ('a/d', 'b-id'),
480
                              ], tree)
481
        self.assertEqual([('a', 'd/a')],
482
                         tree.move(['a'], 'd'))
483
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
484
                               ('d/', 'd-id'),
485
                               ('d/a/', 'a-id'),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
486
                               ('d/a/c', 'c-id'),
487
                               ('d/a/d', 'b-id'),
488
                              ], tree)
489
        tree._validate()
490
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
491
    def test_move_directory_with_swapped_children(self):
492
        tree = self.make_branch_and_tree('.')
493
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'e/'])
494
        tree.add(['a', 'a/b', 'a/c', 'a/d', 'e'],
495
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
496
        tree.commit('initial', rev_id='rev-1')
497
        root_id = tree.get_root_id()
498
499
        tree.rename_one('a/b', 'a/bb')
500
        tree.rename_one('a/d', 'a/b')
501
        tree.rename_one('a/bb', 'a/d')
502
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
503
                               ('a/', 'a-id'),
504
                               ('e/', 'e-id'),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
505
                               ('a/b', 'd-id'),
506
                               ('a/c', 'c-id'),
507
                               ('a/d', 'b-id'),
508
                              ], tree)
509
        self.assertEqual([('a', 'e/a')],
510
                         tree.move(['a'], 'e'))
511
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
512
                               ('e/', 'e-id'),
513
                               ('e/a/', 'a-id'),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
514
                               ('e/a/b', 'd-id'),
515
                               ('e/a/c', 'c-id'),
516
                               ('e/a/d', 'b-id'),
517
                              ], tree)
518
        tree._validate()
519
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
520
    def test_move_moved(self):
521
        """Moving a moved entry works as expected."""
522
        tree = self.make_branch_and_tree('.')
523
        self.build_tree(['a/', 'a/b', 'c/'])
524
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
525
        tree.commit('initial', rev_id='rev-1')
526
        root_id = tree.get_root_id()
527
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.
528
        self.assertEqual([('a/b', 'c/b')],
529
            tree.move(['a/b'], 'c'))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
530
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
531
                               ('c/b', 'b-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
532
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
533
                               ('a/b', 'b-id')], tree.basis_tree())
534
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.
535
        self.assertEqual([('c/b', 'b')],
536
            tree.move(['c/b'], ''))
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
537
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('b', 'b-id'),
538
                               ('c/', 'c-id')], tree)
539
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
540
                               ('a/b', 'b-id')], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
541
        tree._validate()
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
542
543
    def test_move_to_unversioned_non_ascii_dir(self):
544
        """Check error when moving to unversioned non-ascii directory"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
545
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
546
        tree = self.make_branch_and_tree(".")
547
        self.build_tree(["a", u"\xA7/"])
548
        tree.add(["a"])
549
        e = self.assertRaises(errors.BzrMoveFailedError,
550
            tree.move, ["a"], u"\xA7")
551
        self.assertIsInstance(e.extra, errors.NotVersionedError)
552
        self.assertEqual(e.extra.path, u"\xA7")
553
554
    def test_move_unversioned_non_ascii(self):
555
        """Check error when moving an unversioned non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
556
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
557
        tree = self.make_branch_and_tree(".")
558
        self.build_tree([u"\xA7", "dir/"])
559
        tree.add("dir")
560
        e = self.assertRaises(errors.BzrMoveFailedError,
561
            tree.move, [u"\xA7"], "dir")
562
        self.assertIsInstance(e.extra, errors.NotVersionedError)
563
        self.assertEqual(e.extra.path, u"\xA7")