/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/'])
406
        tree.add(['a', 'a/b', 'a/c', 'd'],
407
                 ['a-id', 'b-id', 'c-id', 'd-id'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
408
        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.
409
        root_id = tree.get_root_id()
410
411
        tree.rename_one('a/b', 'a/c/b')
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
412
        self.assertTreeLayout([('', root_id),
413
                               ('a/', 'a-id'),
414
                               ('d/', 'd-id'),
415
                               ('a/c/', 'c-id'),
416
                               ('a/c/b', 'b-id'),
417
                              ], tree)
2438.1.13 by John Arbash Meinel
Add a test for moving a directory where a child has been moved into a subdir.
418
        self.assertEqual([('a', 'd/a')],
419
                         tree.move(['a'], 'd'))
420
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
421
                               ('d/', 'd-id'),
422
                               ('d/a/', 'a-id'),
423
                               ('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.
424
                               ('d/a/c/b', 'b-id'),
425
                              ], tree)
426
        tree._validate()
427
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
428
    def test_move_directory_with_deleted_children(self):
429
        tree = self.make_branch_and_tree('.')
430
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'b/'])
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
431
        tree.add(['a', 'b', 'a/b', 'a/c', 'a/d'])
432
        a_id = tree.path2id('a')
433
        ac_id = tree.path2id('a/c')
434
        b_id = tree.path2id('b')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
435
        tree.commit('initial')
2438.1.7 by John Arbash Meinel
While in this area, add a test for renaming a directory with removed children.
436
        root_id = tree.get_root_id()
437
438
        tree.remove(['a/b', 'a/d'])
439
440
        self.assertEqual([('a', 'b/a')],
441
                         tree.move(['a'], 'b'))
442
        self.assertTreeLayout([('', root_id),
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
443
                               ('b/', b_id),
444
                               ('b/a/', a_id),
445
                               ('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.
446
                              ], tree)
447
        tree._validate()
448
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
449
    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
450
        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.
451
        self.build_tree(['a/', 'a/c', 'b/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
452
        tree.add(['a', 'b', 'a/c'])
453
        a_id = tree.path2id('a')
454
        b_id = tree.path2id('b')
455
        ac_id = tree.path2id('a/c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
456
        tree.commit('initial')
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
457
        root_id = tree.get_root_id()
458
2438.1.6 by John Arbash Meinel
Simplify the test since all we require is renaming a newly added entry's parent dir.
459
        self.build_tree(['a/b', 'a/d'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
460
        tree.add(['a/b', 'a/d'])
461
        ab_id = tree.path2id('a/b')
462
        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
463
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
464
        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
465
        self.assertTreeLayout([('', root_id),
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
466
                               ('b/', b_id),
467
                               ('b/a/', a_id),
468
                               ('b/a/b', ab_id),
469
                               ('b/a/c', ac_id),
470
                               ('b/a/d', ad_id),
2438.1.3 by John Arbash Meinel
Add 2 new WT.move() tests, one of which exposes bug #105479
471
                              ], tree)
472
        tree._validate()
473
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
474
    def test_move_directory_with_moved_children(self):
475
        tree = self.make_branch_and_tree('.')
476
        self.build_tree(['a/', 'a/b', 'a/c', 'd', 'e/'])
477
        tree.add(['a', 'a/b', 'a/c', 'd', 'e'],
478
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
479
        tree.commit('initial')
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
480
        root_id = tree.get_root_id()
481
482
        self.assertEqual([('a/b', 'b')],
483
                         tree.move(['a/b'], ''))
484
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
485
                               ('a/', 'a-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
486
                               ('b', 'b-id'),
487
                               ('d', 'd-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
488
                               ('e/', 'e-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
489
                               ('a/c', 'c-id'),
490
                              ], tree)
491
        self.assertEqual([('d', 'a/d')],
492
                         tree.move(['d'], 'a'))
493
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
494
                               ('a/', 'a-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
495
                               ('b', 'b-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
496
                               ('e/', 'e-id'),
2438.1.9 by John Arbash Meinel
Add another (failing) test when we move an entry which has a renamed child.
497
                               ('a/c', 'c-id'),
498
                               ('a/d', 'd-id'),
499
                              ], tree)
500
        self.assertEqual([('a', 'e/a')],
501
                         tree.move(['a'], 'e'))
502
        self.assertTreeLayout([('', root_id),
503
                               ('b', 'b-id'),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
504
                               ('e/', 'e-id'),
505
                               ('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.
506
                               ('e/a/c', 'c-id'),
507
                               ('e/a/d', 'd-id'),
508
                              ], tree)
509
        tree._validate()
510
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
511
    def test_move_directory_with_renamed_child(self):
512
        tree = self.make_branch_and_tree('.')
513
        self.build_tree(['a/', 'a/b', 'a/c', 'd/'])
514
        tree.add(['a', 'a/b', 'a/c', 'd'],
515
                 ['a-id', 'b-id', 'c-id', 'd-id'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
516
        tree.commit('initial')
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
517
        root_id = tree.get_root_id()
518
519
        tree.rename_one('a/b', 'a/d')
520
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
521
                               ('a/', 'a-id'),
522
                               ('d/', 'd-id'),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
523
                               ('a/c', 'c-id'),
524
                               ('a/d', 'b-id'),
525
                              ], tree)
526
        self.assertEqual([('a', 'd/a')],
527
                         tree.move(['a'], 'd'))
528
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
529
                               ('d/', 'd-id'),
530
                               ('d/a/', 'a-id'),
2438.1.11 by John Arbash Meinel
Add a test for moving a directory with a renamed child.
531
                               ('d/a/c', 'c-id'),
532
                               ('d/a/d', 'b-id'),
533
                              ], tree)
534
        tree._validate()
535
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
536
    def test_move_directory_with_swapped_children(self):
537
        tree = self.make_branch_and_tree('.')
538
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'e/'])
539
        tree.add(['a', 'a/b', 'a/c', 'a/d', 'e'],
540
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
541
        tree.commit('initial')
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
542
        root_id = tree.get_root_id()
543
544
        tree.rename_one('a/b', 'a/bb')
545
        tree.rename_one('a/d', 'a/b')
546
        tree.rename_one('a/bb', 'a/d')
547
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
548
                               ('a/', 'a-id'),
549
                               ('e/', 'e-id'),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
550
                               ('a/b', 'd-id'),
551
                               ('a/c', 'c-id'),
552
                               ('a/d', 'b-id'),
553
                              ], tree)
554
        self.assertEqual([('a', 'e/a')],
555
                         tree.move(['a'], 'e'))
556
        self.assertTreeLayout([('', root_id),
6110.6.2 by Jelmer Vernooij
In HasLayout, take into consideration Tree.has_versioned_directories.
557
                               ('e/', 'e-id'),
558
                               ('e/a/', 'a-id'),
2438.1.12 by John Arbash Meinel
Add a test with children that have been swapped
559
                               ('e/a/b', 'd-id'),
560
                               ('e/a/c', 'c-id'),
561
                               ('e/a/d', 'b-id'),
562
                              ], tree)
563
        tree._validate()
564
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
565
    def test_move_moved(self):
566
        """Moving a moved entry works as expected."""
567
        tree = self.make_branch_and_tree('.')
568
        self.build_tree(['a/', 'a/b', 'c/'])
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
569
        tree.add(['a', 'a/b', 'c'])
570
        a_id = tree.path2id('a')
571
        b_id = tree.path2id('a/b')
572
        c_id = tree.path2id('c')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
573
        tree.commit('initial')
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
574
        root_id = tree.get_root_id()
575
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.
576
        self.assertEqual([('a/b', 'c/b')],
577
            tree.move(['a/b'], 'c'))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
578
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
579
                               ('c/b', b_id)], tree)
580
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
581
                               ('a/b', b_id)], tree.basis_tree())
2255.7.9 by John Arbash Meinel
Add more tests for WorkingTree.move() and a similar suite
582
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.
583
        self.assertEqual([('c/b', 'b')],
584
            tree.move(['c/b'], ''))
6846.2.1 by Jelmer Vernooij
Skip a few tests that don't apply to brz-git.
585
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('b', b_id),
586
                               ('c/', c_id)], tree)
587
        self.assertTreeLayout([('', root_id), ('a/', a_id), ('c/', c_id),
588
                               ('a/b', b_id)], tree.basis_tree())
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
589
        tree._validate()
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
590
591
    def test_move_to_unversioned_non_ascii_dir(self):
592
        """Check error when moving to unversioned non-ascii directory"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
593
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
594
        tree = self.make_branch_and_tree(".")
595
        self.build_tree(["a", u"\xA7/"])
596
        tree.add(["a"])
597
        e = self.assertRaises(errors.BzrMoveFailedError,
598
            tree.move, ["a"], u"\xA7")
599
        self.assertIsInstance(e.extra, errors.NotVersionedError)
600
        self.assertEqual(e.extra.path, u"\xA7")
601
602
    def test_move_unversioned_non_ascii(self):
603
        """Check error when moving an unversioned non-ascii file"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
604
        self.requireFeature(features.UnicodeFilenameFeature)
5609.8.2 by Martin
Add per_workingtree test for every error case bar one that has unicode problems
605
        tree = self.make_branch_and_tree(".")
606
        self.build_tree([u"\xA7", "dir/"])
607
        tree.add("dir")
608
        e = self.assertRaises(errors.BzrMoveFailedError,
609
            tree.move, [u"\xA7"], "dir")
610
        self.assertIsInstance(e.extra, errors.NotVersionedError)
611
        self.assertEqual(e.extra.path, u"\xA7")