~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) 2007 Canonical Ltd
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.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
16
17
"""Tests for interface conformance of 'WorkingTree.rename_one'"""
18
19
import os
20
21
from bzrlib import (
22
    errors,
23
    osutils,
3638.3.13 by Vincent Ladeuil
Fix test_rename_to_denormalised_fails for OSX.
24
    tests,
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
25
    )
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
26
from bzrlib.tests import (
27
    features,
28
    )
6072.2.2 by Jelmer Vernooij
Use HasLayout matcher.
29
from bzrlib.tests.matchers import HasLayout
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
30
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
31
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
32
33
34
class TestRenameOne(TestCaseWithWorkingTree):
35
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.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
39
40
    def test_rename_one_target_not_dir(self):
41
        tree = self.make_branch_and_tree('.')
42
        self.build_tree(['a'])
43
        tree.add(['a'])
44
        tree.commit('initial', rev_id='rev-1')
45
46
        self.assertRaises(errors.BzrMoveFailedError,
47
                          tree.rename_one, 'a', 'not-a-dir/b')
48
49
    def test_rename_one_non_existent(self):
50
        tree = self.make_branch_and_tree('.')
51
        self.build_tree(['a/'])
52
        tree.add(['a'])
53
        tree.commit('initial', rev_id='rev-1')
54
        self.assertRaises(errors.BzrMoveFailedError,
55
                          tree.rename_one, 'not-a-file', 'a/failure')
56
        self.assertRaises(errors.BzrMoveFailedError,
57
                          tree.rename_one, 'not-a-file', 'also_not')
58
59
    def test_rename_one_target_not_versioned(self):
60
        tree = self.make_branch_and_tree('.')
61
        self.build_tree(['a/', 'b'])
62
        tree.add(['b'])
63
        tree.commit('initial', rev_id='rev-1')
64
        self.assertRaises(errors.BzrMoveFailedError,
65
                          tree.rename_one, 'b', 'a/b')
66
67
    def test_rename_one_unversioned(self):
68
        tree = self.make_branch_and_tree('.')
69
        self.build_tree(['a/', 'b'])
70
        tree.add(['a'])
71
        tree.commit('initial', rev_id='rev-1')
72
        self.assertRaises(errors.BzrMoveFailedError,
73
                          tree.rename_one, 'b', 'a/b')
74
75
    def test_rename_one_samedir(self):
76
        tree = self.make_branch_and_tree('.')
77
        self.build_tree(['a', 'b/'])
78
        tree.add(['a', 'b'], ['a-id', 'b-id'])
79
        tree.commit('initial', rev_id='rev-1')
80
        root_id = tree.get_root_id()
81
82
        a_contents = tree.get_file_text('a-id')
83
        tree.rename_one('a', 'foo')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
84
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('foo', 'a-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
85
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
86
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
87
                              tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
88
        self.assertPathDoesNotExist('a')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
89
        self.assertFileEqual(a_contents, 'foo')
90
91
    def test_rename_one_not_localdir(self):
92
        tree = self.make_branch_and_tree('tree')
93
        self.build_tree(['tree/a', 'tree/b/'])
94
        tree.add(['a', 'b'], ['a-id', 'b-id'])
95
        tree.commit('initial', rev_id='rev-1')
96
        root_id = tree.get_root_id()
97
98
        a_contents = tree.get_file_text('a-id')
99
        tree.rename_one('a', 'b/foo')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
100
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/foo', 'a-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
101
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
102
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
103
                              tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
104
        self.assertPathDoesNotExist('tree/a')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
105
        self.assertFileEqual(a_contents, 'tree/b/foo')
106
107
    def test_rename_one_subdir(self):
108
        tree = self.make_branch_and_tree('.')
109
        self.build_tree(['a', 'b/', 'b/c'])
110
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
111
        tree.commit('initial', rev_id='rev-1')
112
        root_id = tree.get_root_id()
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
113
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
114
                               ('b/c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
115
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
116
                               ('b/c', 'c-id')], tree.basis_tree())
117
        a_contents = tree.get_file_text('a-id')
118
        tree.rename_one('a', 'b/d')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
119
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/c', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
120
                               ('b/d', 'a-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
121
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
122
                               ('b/c', 'c-id')], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
123
        self.assertPathDoesNotExist('a')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
124
        self.assertFileEqual(a_contents, 'b/d')
125
126
    def test_rename_one_parent_dir(self):
127
        tree = self.make_branch_and_tree('.')
128
        self.build_tree(['a', 'b/', 'b/c'])
129
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
130
        tree.commit('initial', rev_id='rev-1')
131
        root_id = tree.get_root_id()
132
        c_contents = tree.get_file_text('c-id')
133
        tree.rename_one('b/c', 'd')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
134
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
135
                               ('d', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
136
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
137
                               ('b/c', 'c-id')], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
138
        self.assertPathDoesNotExist('b/c')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
139
        self.assertFileEqual(c_contents, 'd')
140
141
    def test_rename_one_fail_consistent(self):
142
        tree = self.make_branch_and_tree('.')
143
        self.build_tree(['a', 'b/', 'b/a', 'c'])
144
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
145
        tree.commit('initial', rev_id='rev-1')
146
        root_id = tree.get_root_id()
147
        # Target already exists
148
        self.assertRaises(errors.RenameFailedFilesExist,
149
                          tree.rename_one, 'a', 'b/a')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
150
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
151
                               ('c', 'c-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
152
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
153
                               ('c', 'c-id')], tree.basis_tree())
154
155
    def test_rename_one_onto_existing(self):
156
        tree = self.make_branch_and_tree('.')
157
        self.build_tree(['a', 'b'])
158
        tree.add(['a', 'b'], ['a-id', 'b-id'])
159
        tree.commit('initial', rev_id='rev-1')
160
161
        self.assertRaises(errors.BzrMoveFailedError,
162
                          tree.rename_one, 'a', 'b')
163
164
    def test_rename_one_onto_self(self):
165
        tree = self.make_branch_and_tree('.')
166
        self.build_tree(['b/', 'b/a'])
167
        tree.add(['b', 'b/a'], ['b-id', 'a-id'])
168
        tree.commit('initial', rev_id='rev-1')
169
170
        self.assertRaises(errors.BzrMoveFailedError,
171
                          tree.rename_one, 'b/a', 'b/a')
172
173
    def test_rename_one_onto_self_root(self):
174
        tree = self.make_branch_and_tree('.')
175
        self.build_tree(['a'])
176
        tree.add(['a'], ['a-id'])
177
        tree.commit('initial', rev_id='rev-1')
178
179
        self.assertRaises(errors.BzrMoveFailedError,
180
                          tree.rename_one, 'a', 'a')
181
182
    def test_rename_one_after(self):
183
        tree = self.make_branch_and_tree('.')
184
        self.build_tree(['a', 'b/'])
185
        tree.add(['a', 'b'], ['a-id', 'b-id'])
186
        tree.commit('initial', rev_id='rev-1')
187
        root_id = tree.get_root_id()
188
        os.rename('a', 'b/foo')
189
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
190
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
191
                              tree)
192
        # We don't need after=True as long as source is missing and target
193
        # exists.
194
        tree.rename_one('a', 'b/foo')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
195
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
196
                               ('b/foo', 'a-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
197
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
198
                              tree.basis_tree())
199
200
    def test_rename_one_after_with_after(self):
201
        tree = self.make_branch_and_tree('.')
202
        self.build_tree(['a', 'b/'])
203
        tree.add(['a', 'b'], ['a-id', 'b-id'])
204
        tree.commit('initial', rev_id='rev-1')
205
        root_id = tree.get_root_id()
206
        os.rename('a', 'b/foo')
207
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
208
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
209
                              tree)
210
        # Passing after=True should work as well
211
        tree.rename_one('a', 'b/foo', after=True)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
212
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
213
                               ('b/foo', 'a-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
214
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
215
                              tree.basis_tree())
216
5911.1.1 by Benoรฎt Pierre
Add some tests for new 'mv --after' behaviour.
217
    def test_rename_one_after_dest_versioned(self):
218
        tree = self.make_branch_and_tree('.')
219
        self.build_tree(['a'])
220
        tree.add(['a'], ['a-id'])
221
        tree.commit('initial', rev_id='rev-1')
222
        root_id = tree.get_root_id()
223
        os.rename('a', 'b')
224
        tree.add(['b'], ['b-id'])
225
226
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
227
                               tree)
228
        e = self.assertRaises(errors.BzrMoveFailedError,
229
            tree.rename_one, 'a', 'b')
230
        self.assertIsInstance(e.extra, errors.AlreadyVersionedError)
231
232
    def test_rename_one_after_with_after_dest_versioned(self):
233
        ''' using after with an already versioned file should fail '''
234
        tree = self.make_branch_and_tree('.')
235
        self.build_tree(['a', 'b'])
236
        tree.add(['a', 'b'], ['a-id', 'b-id'])
237
        tree.commit('initial', rev_id='rev-1')
238
        root_id = tree.get_root_id()
239
        os.unlink('a')
240
241
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
242
                               tree)
243
        e = self.assertRaises(errors.BzrMoveFailedError,
244
            tree.rename_one, 'a', 'b', after=True)
245
        self.assertIsInstance(e.extra, errors.AlreadyVersionedError)
246
247
    def test_rename_one_after_with_after_dest_added(self):
248
        ''' using after with a newly added file should work '''
249
        tree = self.make_branch_and_tree('.')
250
        self.build_tree(['a'])
251
        tree.add(['a'], ['a-id'])
252
        tree.commit('initial', rev_id='rev-1')
253
        root_id = tree.get_root_id()
254
        os.rename('a', 'b')
255
        tree.add(['b'], ['b-id'])
256
257
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
258
                               tree)
259
        tree.rename_one('a', 'b', after=True)
260
        self.assertTreeLayout([('', root_id), ('b', 'a-id')], tree)
261
4371.6.1 by Marius Kruger
Allow renaming of files already removed from the inventory
262
    def test_rename_one_after_source_removed(self):
5807.1.2 by Jelmer Vernooij
Skip some inventory-specific tests for non-inventory working trees.
263
        """Rename even if the source was already unversioned."""
4371.6.1 by Marius Kruger
Allow renaming of files already removed from the inventory
264
        tree = self.make_branch_and_tree('.')
265
        self.build_tree(['a', 'b/'])
266
        tree.add(['a', 'b'], ['a-id', 'b-id'])
267
        tree.commit('initial', rev_id='rev-1')
268
        root_id = tree.get_root_id()
269
        os.rename('a', 'b/foo')
270
        tree.remove(['a'])
271
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
272
        self.assertTreeLayout([('', root_id), ('b/', 'b-id')], tree)
4371.6.1 by Marius Kruger
Allow renaming of files already removed from the inventory
273
        # We don't need after=True as long as source is missing and target
274
        # exists.
275
        tree.rename_one('a', 'b/foo')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
276
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'),
4371.6.1 by Marius Kruger
Allow renaming of files already removed from the inventory
277
                               ('b/foo', 'a-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
278
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
4371.6.1 by Marius Kruger
Allow renaming of files already removed from the inventory
279
                              tree.basis_tree())
280
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
281
    def test_rename_one_after_no_target(self):
282
        tree = self.make_branch_and_tree('.')
283
        self.build_tree(['a', 'b/'])
284
        tree.add(['a', 'b'], ['a-id', 'b-id'])
285
        tree.commit('initial', rev_id='rev-1')
286
        root_id = tree.get_root_id()
287
288
        # Passing after when the file hasn't been rename_one raises an exception
289
        self.assertRaises(errors.BzrMoveFailedError,
290
                          tree.rename_one, 'a', 'b/foo', after=True)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
291
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
292
                              tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
293
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
294
                              tree.basis_tree())
295
296
    def test_rename_one_after_source_and_dest(self):
297
        tree = self.make_branch_and_tree('.')
298
        self.build_tree(['a', 'b/', 'b/foo'])
299
        tree.add(['a', 'b'], ['a-id', 'b-id'])
300
        tree.commit('initial', rev_id='rev-1')
301
        root_id = tree.get_root_id()
302
303
        # TODO: jam 20070225 I would usually use 'rb', but assertFileEqual
304
        #       uses 'r'.
305
        a_file = open('a', 'r')
306
        try:
307
            a_text = a_file.read()
308
        finally:
309
            a_file.close()
310
        foo_file = open('b/foo', 'r')
311
        try:
312
            foo_text = foo_file.read()
313
        finally:
314
            foo_file.close()
315
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
316
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
317
                              tree)
318
        self.assertRaises(errors.RenameFailedFilesExist,
319
                          tree.rename_one, 'a', 'b/foo', after=False)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
320
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
321
                              tree)
322
        self.assertFileEqual(a_text, 'a')
323
        self.assertFileEqual(foo_text, 'b/foo')
324
        # But you can pass after=True
325
        tree.rename_one('a', 'b/foo', after=True)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
326
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
327
                               ('b/foo', 'a-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
328
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
329
                              tree.basis_tree())
330
        # But it shouldn't actually move anything
331
        self.assertFileEqual(a_text, 'a')
332
        self.assertFileEqual(foo_text, 'b/foo')
333
334
    def test_rename_one_directory(self):
335
        tree = self.make_branch_and_tree('.')
336
        self.build_tree(['a/', 'a/b', 'a/c/', 'a/c/d', 'e/'])
337
        tree.add(['a', 'a/b', 'a/c', 'a/c/d', 'e'],
338
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
339
        tree.commit('initial', rev_id='rev-1')
340
        root_id = tree.get_root_id()
341
342
        tree.rename_one('a', 'e/f')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
343
        self.assertTreeLayout([('', root_id), ('e/', 'e-id'), ('e/f/', 'a-id'),
344
                               ('e/f/b', 'b-id'), ('e/f/c/', 'c-id'),
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
345
                               ('e/f/c/d', 'd-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
346
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('e/', 'e-id'),
347
                               ('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
348
                               ('a/c/d', 'd-id')], tree.basis_tree())
349
350
    def test_rename_one_moved(self):
351
        """Moving a moved entry works as expected."""
352
        tree = self.make_branch_and_tree('.')
353
        self.build_tree(['a/', 'a/b', 'c/'])
354
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
355
        tree.commit('initial', rev_id='rev-1')
356
        root_id = tree.get_root_id()
357
358
        tree.rename_one('a/b', 'c/foo')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
359
        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
360
                               ('c/foo', 'b-id')], tree)
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
361
        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
362
                               ('a/b', 'b-id')], tree.basis_tree())
363
364
        tree.rename_one('c/foo', 'bar')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
365
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('bar', 'b-id'),
366
                               ('c/', 'c-id')], tree)
367
        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
368
                               ('a/b', 'b-id')], tree.basis_tree())
2825.6.1 by Robert Collins
* ``WorkingTree.rename_one`` will now raise an error if normalisation of the
369
370
    def test_rename_to_denormalised_fails(self):
3638.3.13 by Vincent Ladeuil
Fix test_rename_to_denormalised_fails for OSX.
371
        if osutils.normalizes_filenames():
372
            raise tests.TestNotApplicable('OSX normalizes filenames')
2825.6.1 by Robert Collins
* ``WorkingTree.rename_one`` will now raise an error if normalisation of the
373
        tree = self.make_branch_and_tree('.')
374
        self.build_tree(['a'])
375
        tree.add(['a'])
376
        self.assertRaises((errors.InvalidNormalization, UnicodeEncodeError),
3201.1.2 by John Arbash Meinel
Test needs to be updated now that ยต is allowed.
377
            tree.rename_one, 'a', u'ba\u030arry')
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
378
379
    def test_rename_unversioned_non_ascii(self):
380
        """Check error when renaming an unversioned non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
381
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
382
        tree = self.make_branch_and_tree(".")
383
        self.build_tree([u"\xA7"])
384
        e = self.assertRaises(errors.BzrRenameFailedError,
385
            tree.rename_one, u"\xA7", "b")
386
        self.assertIsInstance(e.extra, errors.NotVersionedError)
387
        self.assertEqual(e.extra.path, u"\xA7")
388
389
    def test_rename_into_unversioned_non_ascii_dir(self):
390
        """Check error when renaming into unversioned non-ascii directory"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
391
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
392
        tree = self.make_branch_and_tree(".")
393
        self.build_tree(["a", u"\xA7/"])
394
        tree.add(["a"])
395
        e = self.assertRaises(errors.BzrMoveFailedError,
396
            tree.rename_one, "a", u"\xA7/a")
397
        self.assertIsInstance(e.extra, errors.NotVersionedError)
398
        self.assertEqual(e.extra.path, u"\xA7")
399
400
    def test_rename_over_already_versioned_non_ascii(self):
401
        """Check error renaming over an already versioned non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
402
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
403
        tree = self.make_branch_and_tree(".")
404
        self.build_tree(["a", u"\xA7"])
405
        tree.add(["a", u"\xA7"])
406
        e = self.assertRaises(errors.BzrMoveFailedError,
407
            tree.rename_one, "a", u"\xA7")
408
        self.assertIsInstance(e.extra, errors.AlreadyVersionedError)
409
        self.assertEqual(e.extra.path, u"\xA7")
410
411
    def test_rename_after_non_existant_non_ascii(self):
412
        """Check error renaming after move with missing non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
413
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
414
        tree = self.make_branch_and_tree(".")
415
        self.build_tree(["a"])
416
        tree.add(["a"])
417
        e = self.assertRaises(errors.BzrMoveFailedError,
418
            tree.rename_one, "a", u"\xA7", after=True)
419
        self.assertIsInstance(e.extra, errors.NoSuchFile)
420
        self.assertEqual(e.extra.path, u"\xA7")