/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_move.py

Update tests to ensure basis tree is not modified
Small bugfixes for things that would only be triggered if update_minimal
failed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
class TestMove(TestCaseWithWorkingTree):
32
32
 
 
33
    def get_tree_layout(self, tree):
 
34
        """Get the (path, file_id) pairs for the current tree."""
 
35
        tree.lock_read()
 
36
        try:
 
37
            return [(path, ie.file_id) for path, ie
 
38
                    in tree.iter_entries_by_dir()]
 
39
        finally:
 
40
            tree.unlock()
 
41
 
 
42
    def assertTreeLayout(self, expected, tree):
 
43
        """Check that the tree has the correct layout."""
 
44
        actual = self.get_tree_layout(tree)
 
45
        self.assertEqual(expected, actual)
 
46
 
33
47
    def test_move_correct_call_named(self):
34
48
        """tree.move has the deprecated parameter 'to_name'.
35
49
        It has been replaced by 'to_dir' for consistency.
90
104
        tree = self.make_branch_and_tree('.')
91
105
        self.build_tree(['a'])
92
106
        tree.add(['a'])
 
107
        tree.commit('initial', rev_id='rev-1')
93
108
 
94
109
        self.assertRaises(errors.BzrMoveFailedError,
95
110
                          tree.move, ['a'], 'not-a-dir')
98
113
        tree = self.make_branch_and_tree('.')
99
114
        self.build_tree(['a/'])
100
115
        tree.add(['a'])
 
116
        tree.commit('initial', rev_id='rev-1')
101
117
        self.assertRaises(errors.BzrMoveFailedError,
102
118
                          tree.move, ['not-a-file'], 'a')
 
119
        self.assertRaises(errors.BzrMoveFailedError,
 
120
                          tree.move, ['not-a-file'], '')
103
121
 
104
122
    def test_move_target_not_versioned(self):
105
123
        tree = self.make_branch_and_tree('.')
106
124
        self.build_tree(['a/', 'b'])
107
125
        tree.add(['b'])
 
126
        tree.commit('initial', rev_id='rev-1')
108
127
        self.assertRaises(errors.BzrMoveFailedError,
109
128
                          tree.move, ['b'], 'a')
110
129
 
116
135
        tree = self.make_branch_and_tree('.')
117
136
        self.build_tree(['a/', 'b'])
118
137
        tree.add(['a'])
 
138
        tree.commit('initial', rev_id='rev-1')
119
139
        self.assertRaises(errors.BzrMoveFailedError,
120
140
                          tree.move, ['b'], 'a')
121
141
 
122
142
    def test_move_multi_unversioned(self):
123
143
        tree = self.make_branch_and_tree('.')
124
144
        self.build_tree(['a/', 'b', 'c', 'd'])
125
 
        tree.add(['a', 'c', 'd'])
 
145
        tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id'])
 
146
        tree.commit('initial', rev_id='rev-1')
 
147
        root_id = tree.get_root_id()
126
148
        self.assertRaises(errors.BzrMoveFailedError,
127
149
                          tree.move, ['c', 'b', 'd'], 'a')
128
150
        self.assertRaises(errors.BzrMoveFailedError,
129
151
                          tree.move, ['b', 'c', 'd'], 'a')
130
152
        self.assertRaises(errors.BzrMoveFailedError,
131
 
                          tree.move, ['c', 'd', 'b'], 'a')
132
 
 
133
 
    def get_tree_layout(self, tree):
134
 
        """Get the (path, file_id) pairs for the current tree."""
135
 
        tree.lock_read()
136
 
        try:
137
 
            return [(path, ie.file_id) for path, ie
138
 
                    in tree.iter_entries_by_dir()]
139
 
        finally:
140
 
            tree.unlock()
141
 
 
142
 
    def assertTreeLayout(self, expected, tree):
143
 
        """Check that the tree has the correct layout."""
144
 
        actual = self.get_tree_layout(tree)
145
 
        self.assertEqual(expected, actual)
 
153
                          tree.move, ['d', 'c', 'b'], 'a')
 
154
        if osutils.lexists('a/c'):
 
155
            # If 'c' was actually moved, then 'd' should have also been moved
 
156
            self.assertTreeLayout([('', root_id), ('a', 'a-id'),
 
157
                                   ('a/c', 'c-id'),  ('a/d', 'd-id')], tree)
 
158
        else:
 
159
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
160
                                   ('d', 'd-id')], tree)
 
161
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
162
                               ('d', 'd-id')], tree.basis_tree())
146
163
 
147
164
    def test_move_subdir(self):
148
165
        tree = self.make_branch_and_tree('.')
149
166
        self.build_tree(['a', 'b/', 'b/c'])
150
167
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
168
        tree.commit('initial', rev_id='rev-1')
151
169
        root_id = tree.get_root_id()
152
170
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
153
171
                               ('b/c', 'c-id')], tree)
 
172
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
173
                               ('b/c', 'c-id')], tree.basis_tree())
154
174
        a_contents = tree.get_file_text('a-id')
155
175
        tree.move(['a'], 'b')
156
176
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
157
177
                               ('b/c', 'c-id')], tree)
 
178
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
179
                               ('b/c', 'c-id')], tree.basis_tree())
158
180
        self.failIfExists('a')
159
181
        self.assertFileEqual(a_contents, 'b/a')
160
182
 
162
184
        tree = self.make_branch_and_tree('.')
163
185
        self.build_tree(['a', 'b/', 'b/c'])
164
186
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
187
        tree.commit('initial', rev_id='rev-1')
165
188
        root_id = tree.get_root_id()
166
189
        c_contents = tree.get_file_text('c-id')
167
190
        tree.move(['b/c'], '')
168
191
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
169
192
                               ('c', 'c-id')], tree)
 
193
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
194
                               ('b/c', 'c-id')], tree.basis_tree())
170
195
        self.failIfExists('b/c')
171
196
        self.assertFileEqual(c_contents, 'c')
172
197
 
174
199
        tree = self.make_branch_and_tree('.')
175
200
        self.build_tree(['a', 'b/', 'b/a', 'c'])
176
201
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
 
202
        tree.commit('initial', rev_id='rev-1')
177
203
        root_id = tree.get_root_id()
178
204
        # Target already exists
179
205
        self.assertRaises(errors.RenameFailedFilesExist,
187
213
            self.failUnlessExists('b/c')
188
214
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
189
215
                                   ('b/c', 'c-id')], tree)
 
216
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
217
                               ('c', 'c-id')], tree.basis_tree())
190
218
 
191
219
    def test_move_onto_self(self):
192
220
        tree = self.make_branch_and_tree('.')
193
221
        self.build_tree(['b/', 'b/a'])
194
222
        tree.add(['b', 'b/a'], ['b-id', 'a-id'])
 
223
        tree.commit('initial', rev_id='rev-1')
195
224
 
196
225
        self.assertRaises(errors.BzrMoveFailedError,
197
226
                          tree.move, ['b/a'], 'b')
200
229
        tree = self.make_branch_and_tree('.')
201
230
        self.build_tree(['a'])
202
231
        tree.add(['a'], ['a-id'])
 
232
        tree.commit('initial', rev_id='rev-1')
203
233
 
204
234
        self.assertRaises(errors.BzrMoveFailedError,
205
235
                          tree.move, ['a'], 'a')
208
238
        tree = self.make_branch_and_tree('.')
209
239
        self.build_tree(['a', 'b/'])
210
240
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
241
        tree.commit('initial', rev_id='rev-1')
211
242
        root_id = tree.get_root_id()
212
243
        os.rename('a', 'b/a')
213
244
 
223
254
        tree = self.make_branch_and_tree('.')
224
255
        self.build_tree(['a', 'b/'])
225
256
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
257
        tree.commit('initial', rev_id='rev-1')
226
258
        root_id = tree.get_root_id()
227
259
        os.rename('a', 'b/a')
228
260
 
237
269
        tree = self.make_branch_and_tree('.')
238
270
        self.build_tree(['a', 'b/'])
239
271
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
272
        tree.commit('initial', rev_id='rev-1')
240
273
        root_id = tree.get_root_id()
241
274
 
242
275
        # Passing after when the file hasn't been move raises an exception
247
280
        tree = self.make_branch_and_tree('.')
248
281
        self.build_tree(['a', 'b/', 'b/a'])
249
282
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
283
        tree.commit('initial', rev_id='rev-1')
250
284
        root_id = tree.get_root_id()
251
285
 
252
286
        # TODO: jam 20070225 I would usually use 'rb', but assertFileEqual
277
311
        # But it shouldn't actually move anything
278
312
        self.assertFileEqual(a_text, 'a')
279
313
        self.assertFileEqual(ba_text, 'b/a')
280
 
 
281
 
    def dont_test(self):
282
 
        self.run_bzr('mv', 'a', 'b')
283
 
        self.assertMoved('a','b')
284
 
 
285
 
        self.run_bzr('mv', 'b', 'subdir')
286
 
        self.assertMoved('b','subdir/b')
287
 
 
288
 
        self.run_bzr('mv', 'subdir/b', 'a')
289
 
        self.assertMoved('subdir/b','a')
290
 
 
291
 
        self.run_bzr('mv', 'a', 'c', 'subdir')
292
 
        self.assertMoved('a','subdir/a')
293
 
        self.assertMoved('c','subdir/c')
294
 
 
295
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
296
 
        self.assertMoved('subdir/a','subdir/newa')