~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-04-23 02:29:35 UTC
  • mfrom: (2441 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070423022935-9hhongamvk6bfdso
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        tree.commit('initial commit')
55
55
        self.assertEqual([('a1', 'sub1/a1')],
56
56
            tree.move(['a1'], to_dir='sub1', after=False))
 
57
        tree._validate()
57
58
 
58
59
    def test_move_correct_call_unnamed(self):
59
60
        """tree.move has the deprecated parameter 'to_name'.
66
67
        tree.commit('initial commit')
67
68
        self.assertEqual([('a1', 'sub1/a1')],
68
69
            tree.move(['a1'], 'sub1', after=False))
 
70
        tree._validate()
69
71
 
70
72
    def test_move_deprecated_wrong_call(self):
71
73
        """tree.move has the deprecated parameter 'to_name'.
79
81
        self.assertRaises(TypeError, tree.move, ['a1'],
80
82
                          to_this_parameter_does_not_exist='sub1',
81
83
                          after=False)
 
84
        tree._validate()
82
85
 
83
86
    def test_move_deprecated_call(self):
84
87
        """tree.move has the deprecated parameter 'to_name'.
100
103
            # since it was deprecated before the class was introduced.
101
104
            if not isinstance(self.workingtree_format, WorkingTreeFormat4):
102
105
                raise
 
106
        tree._validate()
103
107
 
104
108
    def test_move_target_not_dir(self):
105
109
        tree = self.make_branch_and_tree('.')
109
113
 
110
114
        self.assertRaises(errors.BzrMoveFailedError,
111
115
                          tree.move, ['a'], 'not-a-dir')
 
116
        tree._validate()
112
117
 
113
118
    def test_move_non_existent(self):
114
119
        tree = self.make_branch_and_tree('.')
119
124
                          tree.move, ['not-a-file'], 'a')
120
125
        self.assertRaises(errors.BzrMoveFailedError,
121
126
                          tree.move, ['not-a-file'], '')
 
127
        tree._validate()
122
128
 
123
129
    def test_move_target_not_versioned(self):
124
130
        tree = self.make_branch_and_tree('.')
127
133
        tree.commit('initial', rev_id='rev-1')
128
134
        self.assertRaises(errors.BzrMoveFailedError,
129
135
                          tree.move, ['b'], 'a')
 
136
        tree._validate()
130
137
 
131
138
    def test_move_unversioned(self):
132
139
        tree = self.make_branch_and_tree('.')
135
142
        tree.commit('initial', rev_id='rev-1')
136
143
        self.assertRaises(errors.BzrMoveFailedError,
137
144
                          tree.move, ['b'], 'a')
 
145
        tree._validate()
138
146
 
139
147
    def test_move_multi_unversioned(self):
140
148
        tree = self.make_branch_and_tree('.')
157
165
                                   ('d', 'd-id')], tree)
158
166
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
159
167
                               ('d', 'd-id')], tree.basis_tree())
 
168
        tree._validate()
160
169
 
161
170
    def test_move_subdir(self):
162
171
        tree = self.make_branch_and_tree('.')
177
186
                               ('b/c', 'c-id')], tree.basis_tree())
178
187
        self.failIfExists('a')
179
188
        self.assertFileEqual(a_contents, 'b/a')
 
189
        tree._validate()
180
190
 
181
191
    def test_move_parent_dir(self):
182
192
        tree = self.make_branch_and_tree('.')
193
203
                               ('b/c', 'c-id')], tree.basis_tree())
194
204
        self.failIfExists('b/c')
195
205
        self.assertFileEqual(c_contents, 'c')
 
206
        tree._validate()
196
207
 
197
208
    def test_move_fail_consistent(self):
198
209
        tree = self.make_branch_and_tree('.')
214
225
                                   ('b/c', 'c-id')], tree)
215
226
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
216
227
                               ('c', 'c-id')], tree.basis_tree())
 
228
        tree._validate()
217
229
 
218
230
    def test_move_onto_self(self):
219
231
        tree = self.make_branch_and_tree('.')
223
235
 
224
236
        self.assertRaises(errors.BzrMoveFailedError,
225
237
                          tree.move, ['b/a'], 'b')
 
238
        tree._validate()
226
239
 
227
240
    def test_move_onto_self_root(self):
228
241
        tree = self.make_branch_and_tree('.')
232
245
 
233
246
        self.assertRaises(errors.BzrMoveFailedError,
234
247
                          tree.move, ['a'], 'a')
 
248
        tree._validate()
235
249
 
236
250
    def test_move_after(self):
237
251
        tree = self.make_branch_and_tree('.')
251
265
                              tree)
252
266
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
253
267
                              tree.basis_tree())
 
268
        tree._validate()
254
269
 
255
270
    def test_move_after_with_after(self):
256
271
        tree = self.make_branch_and_tree('.')
269
284
                              tree)
270
285
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
271
286
                              tree.basis_tree())
 
287
        tree._validate()
272
288
 
273
289
    def test_move_after_no_target(self):
274
290
        tree = self.make_branch_and_tree('.')
282
298
                          tree.move, ['a'], 'b', after=True)
283
299
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
284
300
                              tree.basis_tree())
 
301
        tree._validate()
285
302
 
286
303
    def test_move_after_source_and_dest(self):
287
304
        tree = self.make_branch_and_tree('.')
321
338
        # But it shouldn't actually move anything
322
339
        self.assertFileEqual(a_text, 'a')
323
340
        self.assertFileEqual(ba_text, 'b/a')
 
341
        tree._validate()
324
342
 
325
343
    def test_move_directory(self):
326
344
        tree = self.make_branch_and_tree('.')
338
356
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('e', 'e-id'),
339
357
                               ('a/b', 'b-id'), ('a/c', 'c-id'),
340
358
                               ('a/c/d', 'd-id')], tree.basis_tree())
 
359
        tree._validate()
 
360
 
 
361
    def test_move_directory_into_parent(self):
 
362
        tree = self.make_branch_and_tree('.')
 
363
        self.build_tree(['c/', 'c/b/', 'c/b/d/'])
 
364
        tree.add(['c', 'c/b', 'c/b/d'],
 
365
                 ['c-id', 'b-id', 'd-id'])
 
366
        tree.commit('initial', rev_id='rev-1')
 
367
        root_id = tree.get_root_id()
 
368
 
 
369
        self.assertEqual([('c/b', 'b')],
 
370
                         tree.move(['c/b'], ''))
 
371
        self.assertTreeLayout([('', root_id),
 
372
                               ('b', 'b-id'),
 
373
                               ('c', 'c-id'),
 
374
                               ('b/d', 'd-id'),
 
375
                              ], tree)
 
376
        tree._validate()
 
377
 
 
378
    def test_move_directory_with_children_in_subdir(self):
 
379
        tree = self.make_branch_and_tree('.')
 
380
        self.build_tree(['a/', 'a/b', 'a/c/', 'd/'])
 
381
        tree.add(['a', 'a/b', 'a/c', 'd'],
 
382
                 ['a-id', 'b-id', 'c-id', 'd-id'])
 
383
        tree.commit('initial', rev_id='rev-1')
 
384
        root_id = tree.get_root_id()
 
385
 
 
386
 
 
387
        tree.rename_one('a/b', 'a/c/b')
 
388
        self.assertTreeLayout([('', root_id),
 
389
                               ('a', 'a-id'),
 
390
                               ('d', 'd-id'),
 
391
                               ('a/c', 'c-id'),
 
392
                               ('a/c/b', 'b-id'),
 
393
                              ], tree)
 
394
        self.assertEqual([('a', 'd/a')],
 
395
                         tree.move(['a'], 'd'))
 
396
        self.assertTreeLayout([('', root_id),
 
397
                               ('d', 'd-id'),
 
398
                               ('d/a', 'a-id'),
 
399
                               ('d/a/c', 'c-id'),
 
400
                               ('d/a/c/b', 'b-id'),
 
401
                              ], tree)
 
402
        tree._validate()
 
403
 
 
404
    def test_move_directory_with_deleted_children(self):
 
405
        tree = self.make_branch_and_tree('.')
 
406
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'b/'])
 
407
        tree.add(['a', 'b', 'a/b', 'a/c', 'a/d'],
 
408
                 ['a-id', 'b-id', 'ab-id', 'ac-id', 'ad-id'])
 
409
        tree.commit('initial', rev_id='rev-1')
 
410
        root_id = tree.get_root_id()
 
411
 
 
412
        tree.remove(['a/b', 'a/d'])
 
413
 
 
414
        self.assertEqual([('a', 'b/a')],
 
415
                         tree.move(['a'], 'b'))
 
416
        self.assertTreeLayout([('', root_id),
 
417
                               ('b', 'b-id'),
 
418
                               ('b/a', 'a-id'),
 
419
                               ('b/a/c', 'ac-id'),
 
420
                              ], tree)
 
421
        tree._validate()
 
422
 
 
423
    def test_move_directory_with_new_children(self):
 
424
        tree = self.make_branch_and_tree('.')
 
425
        self.build_tree(['a/', 'a/c', 'b/'])
 
426
        tree.add(['a', 'b', 'a/c'], ['a-id', 'b-id', 'ac-id'])
 
427
        tree.commit('initial', rev_id='rev-1')
 
428
        root_id = tree.get_root_id()
 
429
 
 
430
        self.build_tree(['a/b', 'a/d'])
 
431
        tree.add(['a/b', 'a/d'], ['ab-id', 'ad-id'])
 
432
 
 
433
        self.assertEqual([('a', 'b/a')],
 
434
                         tree.move(['a'], 'b'))
 
435
        self.assertTreeLayout([('', root_id),
 
436
                               ('b', 'b-id'),
 
437
                               ('b/a', 'a-id'),
 
438
                               ('b/a/b', 'ab-id'),
 
439
                               ('b/a/c', 'ac-id'),
 
440
                               ('b/a/d', 'ad-id'),
 
441
                              ], tree)
 
442
        tree._validate()
 
443
 
 
444
    def test_move_directory_with_moved_children(self):
 
445
        tree = self.make_branch_and_tree('.')
 
446
        self.build_tree(['a/', 'a/b', 'a/c', 'd', 'e/'])
 
447
        tree.add(['a', 'a/b', 'a/c', 'd', 'e'],
 
448
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
 
449
        tree.commit('initial', rev_id='rev-1')
 
450
        root_id = tree.get_root_id()
 
451
 
 
452
        self.assertEqual([('a/b', 'b')],
 
453
                         tree.move(['a/b'], ''))
 
454
        self.assertTreeLayout([('', root_id),
 
455
                               ('a', 'a-id'),
 
456
                               ('b', 'b-id'),
 
457
                               ('d', 'd-id'),
 
458
                               ('e', 'e-id'),
 
459
                               ('a/c', 'c-id'),
 
460
                              ], tree)
 
461
        self.assertEqual([('d', 'a/d')],
 
462
                         tree.move(['d'], 'a'))
 
463
        self.assertTreeLayout([('', root_id),
 
464
                               ('a', 'a-id'),
 
465
                               ('b', 'b-id'),
 
466
                               ('e', 'e-id'),
 
467
                               ('a/c', 'c-id'),
 
468
                               ('a/d', 'd-id'),
 
469
                              ], tree)
 
470
        self.assertEqual([('a', 'e/a')],
 
471
                         tree.move(['a'], 'e'))
 
472
        self.assertTreeLayout([('', root_id),
 
473
                               ('b', 'b-id'),
 
474
                               ('e', 'e-id'),
 
475
                               ('e/a', 'a-id'),
 
476
                               ('e/a/c', 'c-id'),
 
477
                               ('e/a/d', 'd-id'),
 
478
                              ], tree)
 
479
        tree._validate()
 
480
 
 
481
    def test_move_directory_with_renamed_child(self):
 
482
        tree = self.make_branch_and_tree('.')
 
483
        self.build_tree(['a/', 'a/b', 'a/c', 'd/'])
 
484
        tree.add(['a', 'a/b', 'a/c', 'd'],
 
485
                 ['a-id', 'b-id', 'c-id', 'd-id'])
 
486
        tree.commit('initial', rev_id='rev-1')
 
487
        root_id = tree.get_root_id()
 
488
 
 
489
        tree.rename_one('a/b', 'a/d')
 
490
        self.assertTreeLayout([('', root_id),
 
491
                               ('a', 'a-id'),
 
492
                               ('d', 'd-id'),
 
493
                               ('a/c', 'c-id'),
 
494
                               ('a/d', 'b-id'),
 
495
                              ], tree)
 
496
        self.assertEqual([('a', 'd/a')],
 
497
                         tree.move(['a'], 'd'))
 
498
        self.assertTreeLayout([('', root_id),
 
499
                               ('d', 'd-id'),
 
500
                               ('d/a', 'a-id'),
 
501
                               ('d/a/c', 'c-id'),
 
502
                               ('d/a/d', 'b-id'),
 
503
                              ], tree)
 
504
        tree._validate()
 
505
 
 
506
    def test_move_directory_with_swapped_children(self):
 
507
        tree = self.make_branch_and_tree('.')
 
508
        self.build_tree(['a/', 'a/b', 'a/c', 'a/d', 'e/'])
 
509
        tree.add(['a', 'a/b', 'a/c', 'a/d', 'e'],
 
510
                 ['a-id', 'b-id', 'c-id', 'd-id', 'e-id'])
 
511
        tree.commit('initial', rev_id='rev-1')
 
512
        root_id = tree.get_root_id()
 
513
 
 
514
        tree.rename_one('a/b', 'a/bb')
 
515
        tree.rename_one('a/d', 'a/b')
 
516
        tree.rename_one('a/bb', 'a/d')
 
517
        self.assertTreeLayout([('', root_id),
 
518
                               ('a', 'a-id'),
 
519
                               ('e', 'e-id'),
 
520
                               ('a/b', 'd-id'),
 
521
                               ('a/c', 'c-id'),
 
522
                               ('a/d', 'b-id'),
 
523
                              ], tree)
 
524
        self.assertEqual([('a', 'e/a')],
 
525
                         tree.move(['a'], 'e'))
 
526
        self.assertTreeLayout([('', root_id),
 
527
                               ('e', 'e-id'),
 
528
                               ('e/a', 'a-id'),
 
529
                               ('e/a/b', 'd-id'),
 
530
                               ('e/a/c', 'c-id'),
 
531
                               ('e/a/d', 'b-id'),
 
532
                              ], tree)
 
533
        tree._validate()
341
534
 
342
535
    def test_move_moved(self):
343
536
        """Moving a moved entry works as expected."""
360
553
                               ('c', 'c-id')], tree)
361
554
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
362
555
                               ('a/b', 'b-id')], tree.basis_tree())
 
556
        tree._validate()