/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
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.tests.matchers import HasLayout
28
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
29
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
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('.')
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
44
        if tree.supports_setting_file_ids():
45
            tree.add(['a1'], ids=['a1-id'])
46
        else:
47
            tree.add(['a1'])
3923.2.1 by Charles Duffy
Fix bug #314251 (dirstate crash on rename via delete+add)
48
        tree.commit('initial commit')
49
        tree.remove('a1', force=True, keep_files=False)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
50
        if tree.supports_setting_file_ids():
51
            tree.add(['b1'], ids=['a1-id'])
52
        else:
53
            tree.add(['b1'])
3923.2.1 by Charles Duffy
Fix bug #314251 (dirstate crash on rename via delete+add)
54
        tree._validate()
55
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
56
    def test_move_correct_call_named(self):
57
        """tree.move has the deprecated parameter 'to_name'.
58
        It has been replaced by 'to_dir' for consistency.
59
        Test the new API using named parameter
60
        """
61
        self.build_tree(['a1', 'sub1/'])
62
        tree = self.make_branch_and_tree('.')
63
        tree.add(['a1', 'sub1'])
64
        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.
65
        self.assertEqual([('a1', 'sub1/a1')],
66
            tree.move(['a1'], to_dir='sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
67
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
68
69
    def test_move_correct_call_unnamed(self):
70
        """tree.move has the deprecated parameter 'to_name'.
71
        It has been replaced by 'to_dir' for consistency.
72
        Test the new API using unnamed parameter
73
        """
74
        self.build_tree(['a1', 'sub1/'])
75
        tree = self.make_branch_and_tree('.')
76
        tree.add(['a1', 'sub1'])
77
        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.
78
        self.assertEqual([('a1', 'sub1/a1')],
79
            tree.move(['a1'], 'sub1', after=False))
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
80
        tree._validate()
2255.2.137 by John Arbash Meinel
Move the WorkingTree.move() tests into their own module
81
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
82
    def test_move_target_not_dir(self):
83
        tree = self.make_branch_and_tree('.')
84
        self.build_tree(['a'])
85
        tree.add(['a'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
86
        tree.commit('initial')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
87
88
        self.assertRaises(errors.BzrMoveFailedError,
89
                          tree.move, ['a'], 'not-a-dir')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
90
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
91
92
    def test_move_non_existent(self):
93
        tree = self.make_branch_and_tree('.')
94
        self.build_tree(['a/'])
95
        tree.add(['a'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
96
        tree.commit('initial')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
97
        self.assertRaises(errors.BzrMoveFailedError,
98
                          tree.move, ['not-a-file'], 'a')
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
99
        self.assertRaises(errors.BzrMoveFailedError,
100
                          tree.move, ['not-a-file'], '')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
101
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
102
103
    def test_move_target_not_versioned(self):
104
        tree = self.make_branch_and_tree('.')
105
        self.build_tree(['a/', 'b'])
106
        tree.add(['b'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
107
        tree.commit('initial')
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
108
        if tree.has_versioned_directories():
109
            self.assertRaises(errors.BzrMoveFailedError,
110
                              tree.move, ['b'], 'a')
111
        else:
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_unversioned(self):
116
        tree = self.make_branch_and_tree('.')
117
        self.build_tree(['a/', 'b'])
118
        tree.add(['a'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
119
        tree.commit('initial')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
120
        self.assertRaises(errors.BzrMoveFailedError,
121
                          tree.move, ['b'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
122
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
123
124
    def test_move_multi_unversioned(self):
125
        tree = self.make_branch_and_tree('.')
126
        self.build_tree(['a/', 'b', 'c', 'd'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
127
        tree.add(['a', 'c', 'd'])
128
        a_id = tree.path2id('a')
129
        c_id = tree.path2id('c')
130
        d_id = tree.path2id('d')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
131
        tree.commit('initial')
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
132
        root_id = tree.get_root_id()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
133
        self.assertRaises(errors.BzrMoveFailedError,
134
                          tree.move, ['c', 'b', 'd'], 'a')
135
        self.assertRaises(errors.BzrMoveFailedError,
136
                          tree.move, ['b', 'c', 'd'], 'a')
137
        self.assertRaises(errors.BzrMoveFailedError,
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
138
                          tree.move, ['d', 'c', 'b'], 'a')
139
        if osutils.lexists('a/c'):
140
            # If 'c' was actually moved, then 'd' should have also been moved
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
141
            self.assertTreeLayout([('', root_id), ('a/', a_id),
142
                                   ('a/c', c_id),  ('a/d', d_id)], tree)
2255.2.140 by John Arbash Meinel
Update tests to ensure basis tree is not modified
143
        else:
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
144
            self.assertTreeLayout([('', root_id), ('a/', a_id), ('c', c_id),
145
                                   ('d', d_id)], tree)
146
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c', c_id),
147
                               ('d', d_id)], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
148
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
149
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
150
    def test_move_over_deleted(self):
151
        tree = self.make_branch_and_tree('.')
152
        self.build_tree(['a/', 'a/b', 'b'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
153
        tree.add(['a', 'a/b', 'b'])
154
        a_id = tree.path2id('a')
155
        ab_id = tree.path2id('a/b')
156
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
157
        tree.commit('initial')
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
158
159
        root_id = tree.get_root_id()
160
        tree.remove(['a/b'], keep_files=False)
161
        self.assertEqual([('b', 'a/b')], tree.move(['b'], 'a'))
162
        self.assertTreeLayout([('', root_id),
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
163
                               ('a/', a_id),
164
                               ('a/b', b_id),
2456.2.1 by John Arbash Meinel
(broken) Add a (failing) test that _iter_changes works correctly
165
                              ], tree)
166
        tree._validate()
167
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
168
    def test_move_subdir(self):
169
        tree = self.make_branch_and_tree('.')
170
        self.build_tree(['a', 'b/', 'b/c'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
171
        tree.add(['a', 'b', 'b/c'])
172
        a_id = tree.path2id('a')
173
        b_id = tree.path2id('b')
174
        c_id = tree.path2id('b/c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
175
        tree.commit('initial')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
176
        root_id = tree.get_root_id()
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
177
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
178
                               ('b/c', c_id)], tree)
179
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
180
                               ('b/c', c_id)], tree.basis_tree())
181
        a_contents = tree.get_file_text('a', 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.
182
        self.assertEqual([('a', 'b/a')],
183
            tree.move(['a'], 'b'))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
184
        self.assertTreeLayout([('', root_id), ('b/', b_id), ('b/a', a_id),
185
                               ('b/c', c_id)], tree)
186
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
187
                               ('b/c', c_id)], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
188
        self.assertPathDoesNotExist('a')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
189
        self.assertFileEqual(a_contents, 'b/a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
190
        tree._validate()
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
191
192
    def test_move_parent_dir(self):
193
        tree = self.make_branch_and_tree('.')
194
        self.build_tree(['a', 'b/', 'b/c'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
195
        tree.add(['a', 'b', 'b/c'])
196
        a_id = tree.path2id('a')
197
        b_id = tree.path2id('b')
198
        c_id = tree.path2id('b/c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
199
        tree.commit('initial')
2255.2.138 by John Arbash Meinel
implement several new WorkingTree.move() tests
200
        root_id = tree.get_root_id()
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
201
        c_contents = tree.get_file_text('b/c', 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.
202
        self.assertEqual([('b/c', 'c')],
203
            tree.move(['b/c'], ''))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
204
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
205
                               ('c', c_id)], tree)
206
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
207
                               ('b/c', c_id)], tree.basis_tree())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
208
        self.assertPathDoesNotExist('b/c')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
209
        self.assertFileEqual(c_contents, 'c')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
210
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
211
212
    def test_move_fail_consistent(self):
213
        tree = self.make_branch_and_tree('.')
214
        self.build_tree(['a', 'b/', 'b/a', 'c'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
215
        tree.add(['a', 'b', 'c'])
216
        a_id = tree.path2id('a')
217
        b_id = tree.path2id('b')
218
        c_id = tree.path2id('c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
219
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
220
        root_id = tree.get_root_id()
221
        # Target already exists
222
        self.assertRaises(errors.RenameFailedFilesExist,
223
                          tree.move, ['c', 'a'], 'b')
224
        # 'c' may or may not have been moved, but either way the tree should
225
        # maintain a consistent state.
226
        if osutils.lexists('c'):
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
227
            self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
228
                                   ('c', c_id)], tree)
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
229
        else:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
230
            self.assertPathExists('b/c')
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
231
            self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
232
                                   ('b/c', c_id)], tree)
233
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id),
234
                               ('c', c_id)], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
235
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
236
237
    def test_move_onto_self(self):
238
        tree = self.make_branch_and_tree('.')
239
        self.build_tree(['b/', 'b/a'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
240
        tree.add(['b', 'b/a'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
241
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
242
243
        self.assertRaises(errors.BzrMoveFailedError,
244
                          tree.move, ['b/a'], 'b')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
245
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
246
247
    def test_move_onto_self_root(self):
248
        tree = self.make_branch_and_tree('.')
249
        self.build_tree(['a'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
250
        tree.add(['a'])
251
        a_id = tree.path2id('a')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
252
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
253
254
        self.assertRaises(errors.BzrMoveFailedError,
255
                          tree.move, ['a'], 'a')
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
256
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
257
258
    def test_move_after(self):
259
        tree = self.make_branch_and_tree('.')
260
        self.build_tree(['a', 'b/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
261
        tree.add(['a', 'b'])
262
        a_id = tree.path2id('a')
263
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
264
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
265
        root_id = tree.get_root_id()
266
        os.rename('a', 'b/a')
267
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
268
        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.
269
                              tree)
270
        # We don't need after=True as long as source is missing and target
271
        # 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.
272
        self.assertEqual([('a', 'b/a')],
273
            tree.move(['a'], 'b'))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
274
        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.
275
                              tree)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
276
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id)],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
277
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
278
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
279
280
    def test_move_after_with_after(self):
281
        tree = self.make_branch_and_tree('.')
282
        self.build_tree(['a', 'b/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
283
        tree.add(['a', 'b'])
284
        a_id = tree.path2id('a')
285
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
286
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
287
        root_id = tree.get_root_id()
288
        os.rename('a', 'b/a')
289
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
290
        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.
291
                              tree)
292
        # 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.
293
        self.assertEqual([('a', 'b/a')],
294
            tree.move(['a'], 'b', after=True))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
295
        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.
296
                              tree)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
297
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id)],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
298
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
299
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
300
301
    def test_move_after_no_target(self):
302
        tree = self.make_branch_and_tree('.')
303
        self.build_tree(['a', 'b/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
304
        tree.add(['a', 'b'])
305
        a_id = tree.path2id('a')
306
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
307
        tree.commit('initial')
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
308
        root_id = tree.get_root_id()
309
310
        # Passing after when the file hasn't been move raises an exception
311
        self.assertRaises(errors.BzrMoveFailedError,
312
                          tree.move, ['a'], 'b', after=True)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
313
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id)],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
314
                              tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
315
        tree._validate()
2255.2.139 by John Arbash Meinel
test cases for moving after a file has already been moved.
316
317
    def test_move_after_source_and_dest(self):
318
        tree = self.make_branch_and_tree('.')
319
        self.build_tree(['a', 'b/', 'b/a'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
320
        tree.add(['a', 'b'])
321
        a_id = tree.path2id('a')
322
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
323
        tree.commit('initial')
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
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
339
        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.
340
                              tree)
341
        self.assertRaises(errors.RenameFailedFilesExist,
342
                          tree.move, ['a'], 'b', after=False)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
343
        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.
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))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
350
        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.
351
                              tree)
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
352
        self.assertTreeLayout([('', root_id), ('a', a_id), ('b/', b_id)],
2255.2.141 by John Arbash Meinel
Some small changes to move tests.
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/'])
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
362
        tree.add(['a', 'a/b', 'a/c', 'a/c/d', 'e'])
363
        a_id = tree.path2id('a')
364
        b_id = tree.path2id('a/b')
365
        c_id = tree.path2id('a/c')
366
        d_id = tree.path2id('a/c/d')
367
        e_id = tree.path2id('e')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
368
        tree.commit('initial')
2255.2.146 by John Arbash Meinel
Implement move_directory by factoring out move_one
369
        root_id = tree.get_root_id()
370
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.
371
        self.assertEqual([('a', 'e/a')],
372
            tree.move(['a'], 'e'))
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
373
        self.assertTreeLayout([('', root_id), ('e/', e_id), ('e/a/', a_id),
374
                               ('e/a/b', b_id), ('e/a/c/', c_id),
375
                               ('e/a/c/d', d_id)], tree)
376
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('e/', e_id),
377
                               ('a/b', b_id), ('a/c/', c_id),
378
                               ('a/c/d', d_id)], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
379
        tree._validate()
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
380
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
381
    def test_move_directory_into_parent(self):
6039.1.3 by Jelmer Vernooij
Cope with versioned directories in test_move_directory_into_parent.
382
        if not self.workingtree_format.supports_versioned_directories:
383
            raise tests.TestNotApplicable(
384
                "test requires versioned directories")
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
385
        tree = self.make_branch_and_tree('.')
386
        self.build_tree(['c/', 'c/b/', 'c/b/d/'])
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
387
        tree.add(['c', 'c/b', 'c/b/d'])
388
        c_id = tree.path2id('c')
389
        b_id = tree.path2id('c/b')
390
        d_id = tree.path2id('c/b/d')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
391
        tree.commit('initial')
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
392
        root_id = tree.get_root_id()
393
394
        self.assertEqual([('c/b', 'b')],
395
                         tree.move(['c/b'], ''))
396
        self.assertTreeLayout([('', root_id),
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
397
                               ('b/', b_id),
398
                               ('c/', c_id),
399
                               ('b/d/', d_id),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
400
                              ], tree)
401
        tree._validate()
402
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
403
    def test_move_directory_with_children_in_subdir(self):
404
        tree = self.make_branch_and_tree('.')
405
        self.build_tree(['a/', 'a/b', 'a/c/', 'd/'])
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
406
        tree.add(['a', 'a/b', 'a/c', 'd'])
407
        a_id = tree.path2id('a')
408
        b_id = tree.path2id('a/b')
409
        c_id = tree.path2id('a/c')
410
        d_id = tree.path2id('d')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
411
        tree.commit('initial')
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
412
        root_id = tree.get_root_id()
413
414
        tree.rename_one('a/b', 'a/c/b')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
415
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
416
                               ('a/', a_id),
417
                               ('d/', d_id),
418
                               ('a/c/', c_id),
419
                               ('a/c/b', b_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
420
                              ], tree)
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
421
        self.assertEqual([('a', 'd/a')],
422
                         tree.move(['a'], 'd'))
423
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
424
                               ('d/', d_id),
425
                               ('d/a/', a_id),
426
                               ('d/a/c/', c_id),
427
                               ('d/a/c/b', b_id),
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
428
                              ], tree)
429
        tree._validate()
430
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
431
    def test_move_directory_with_deleted_children(self):
432
        tree = self.make_branch_and_tree('.')
433
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'b/'])
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
434
        tree.add(['a', 'b', 'a/b', 'a/c', 'a/d'])
435
        a_id = tree.path2id('a')
436
        ac_id = tree.path2id('a/c')
437
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
438
        tree.commit('initial')
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
439
        root_id = tree.get_root_id()
440
441
        tree.remove(['a/b', 'a/d'])
442
443
        self.assertEqual([('a', 'b/a')],
444
                         tree.move(['a'], 'b'))
445
        self.assertTreeLayout([('', root_id),
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
446
                               ('b/', b_id),
447
                               ('b/a/', a_id),
448
                               ('b/a/c', ac_id),
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
449
                              ], tree)
450
        tree._validate()
451
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
452
    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
453
        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.
454
        self.build_tree(['a/', 'a/c', 'b/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
455
        tree.add(['a', 'b', 'a/c'])
456
        a_id = tree.path2id('a')
457
        b_id = tree.path2id('b')
458
        ac_id = tree.path2id('a/c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
459
        tree.commit('initial')
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
460
        root_id = tree.get_root_id()
461
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
462
        self.build_tree(['a/b', 'a/d'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
463
        tree.add(['a/b', 'a/d'])
464
        ab_id = tree.path2id('a/b')
465
        ad_id = tree.path2id('a/d')
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
466
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
467
        self.assertEqual([('a', 'b/a')], tree.move(['a'], 'b'))
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
468
        self.assertTreeLayout([('', root_id),
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
469
                               ('b/', b_id),
470
                               ('b/a/', a_id),
471
                               ('b/a/b', ab_id),
472
                               ('b/a/c', ac_id),
473
                               ('b/a/d', ad_id),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
474
                              ], tree)
475
        tree._validate()
476
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
477
    def test_move_directory_with_moved_children(self):
478
        tree = self.make_branch_and_tree('.')
479
        self.build_tree(['a/', 'a/b', 'a/c', 'd', 'e/'])
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
480
        tree.add(['a', 'a/b', 'a/c', 'd', 'e'])
481
        a_id = tree.path2id('a')
482
        b_id = tree.path2id('a/b')
483
        c_id = tree.path2id('a/c')
484
        d_id = tree.path2id('d')
485
        e_id = tree.path2id('e')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
486
        tree.commit('initial')
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
487
        root_id = tree.get_root_id()
488
489
        self.assertEqual([('a/b', 'b')],
490
                         tree.move(['a/b'], ''))
491
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
492
                               ('a/', a_id),
493
                               ('b', b_id),
494
                               ('d', d_id),
495
                               ('e/', e_id),
496
                               ('a/c', c_id),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
497
                              ], tree)
498
        self.assertEqual([('d', 'a/d')],
499
                         tree.move(['d'], 'a'))
500
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
501
                               ('a/', a_id),
502
                               ('b', b_id),
503
                               ('e/', e_id),
504
                               ('a/c', c_id),
505
                               ('a/d', d_id),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
506
                              ], tree)
507
        self.assertEqual([('a', 'e/a')],
508
                         tree.move(['a'], 'e'))
509
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
510
                               ('b', b_id),
511
                               ('e/', e_id),
512
                               ('e/a/', a_id),
513
                               ('e/a/c', c_id),
514
                               ('e/a/d', d_id),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
515
                              ], tree)
516
        tree._validate()
517
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
518
    def test_move_directory_with_renamed_child(self):
519
        tree = self.make_branch_and_tree('.')
520
        self.build_tree(['a/', 'a/b', 'a/c', 'd/'])
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
521
        tree.add(['a', 'a/b', 'a/c', 'd'])
522
        a_id = tree.path2id('a')
523
        b_id = tree.path2id('a/b')
524
        c_id = tree.path2id('a/c')
525
        d_id = tree.path2id('d')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
526
        tree.commit('initial')
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
527
        root_id = tree.get_root_id()
528
529
        tree.rename_one('a/b', 'a/d')
530
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
531
                               ('a/', a_id),
532
                               ('d/', d_id),
533
                               ('a/c', c_id),
534
                               ('a/d', b_id),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
535
                              ], tree)
536
        self.assertEqual([('a', 'd/a')],
537
                         tree.move(['a'], 'd'))
538
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
539
                               ('d/', d_id),
540
                               ('d/a/', a_id),
541
                               ('d/a/c', c_id),
542
                               ('d/a/d', b_id),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
543
                              ], tree)
544
        tree._validate()
545
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
546
    def test_move_directory_with_swapped_children(self):
547
        tree = self.make_branch_and_tree('.')
548
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'e/'])
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
549
        tree.add(['a', 'a/b', 'a/c', 'a/d', 'e'])
550
        a_id = tree.path2id('a')
551
        b_id = tree.path2id('a/b')
552
        c_id = tree.path2id('a/c')
553
        d_id = tree.path2id('a/d')
554
        e_id = tree.path2id('e')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
555
        tree.commit('initial')
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
556
        root_id = tree.get_root_id()
557
558
        tree.rename_one('a/b', 'a/bb')
559
        tree.rename_one('a/d', 'a/b')
560
        tree.rename_one('a/bb', 'a/d')
561
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
562
                               ('a/', a_id),
563
                               ('e/', e_id),
564
                               ('a/b', d_id),
565
                               ('a/c', c_id),
566
                               ('a/d', b_id),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
567
                              ], tree)
568
        self.assertEqual([('a', 'e/a')],
569
                         tree.move(['a'], 'e'))
570
        self.assertTreeLayout([('', root_id),
6861.5.2 by Jelmer Vernooij
Fix some more foreign branch tests.
571
                               ('e/', e_id),
572
                               ('e/a/', a_id),
573
                               ('e/a/b', d_id),
574
                               ('e/a/c', c_id),
575
                               ('e/a/d', b_id),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
576
                              ], tree)
577
        tree._validate()
578
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
579
    def test_move_moved(self):
580
        """Moving a moved entry works as expected."""
581
        tree = self.make_branch_and_tree('.')
582
        self.build_tree(['a/', 'a/b', 'c/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
583
        tree.add(['a', 'a/b', 'c'])
584
        a_id = tree.path2id('a')
585
        b_id = tree.path2id('a/b')
586
        c_id = tree.path2id('c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
587
        tree.commit('initial')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
588
        root_id = tree.get_root_id()
589
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.
590
        self.assertEqual([('a/b', 'c/b')],
591
            tree.move(['a/b'], 'c'))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
592
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
593
                               ('c/b', b_id)], tree)
594
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
595
                               ('a/b', b_id)], tree.basis_tree())
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
596
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.
597
        self.assertEqual([('c/b', 'b')],
598
            tree.move(['c/b'], ''))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
599
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('b', b_id),
600
                               ('c/', c_id)], tree)
601
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
602
                               ('a/b', b_id)], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
603
        tree._validate()
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
604
605
    def test_move_to_unversioned_non_ascii_dir(self):
606
        """Check error when moving to unversioned non-ascii directory"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
607
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
608
        tree = self.make_branch_and_tree(".")
609
        self.build_tree(["a", u"\xA7/"])
610
        tree.add(["a"])
611
        e = self.assertRaises(errors.BzrMoveFailedError,
612
            tree.move, ["a"], u"\xA7")
613
        self.assertIsInstance(e.extra, errors.NotVersionedError)
614
        self.assertEqual(e.extra.path, u"\xA7")
615
616
    def test_move_unversioned_non_ascii(self):
617
        """Check error when moving an unversioned non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
618
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
619
        tree = self.make_branch_and_tree(".")
620
        self.build_tree([u"\xA7", "dir/"])
621
        tree.add("dir")
622
        e = self.assertRaises(errors.BzrMoveFailedError,
623
            tree.move, [u"\xA7"], "dir")
624
        self.assertIsInstance(e.extra, errors.NotVersionedError)
625
        self.assertEqual(e.extra.path, u"\xA7")