~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
                          tree.move, ['d', 'c', 'b'], 'a')
127
127
        if osutils.lexists('a/c'):
128
128
            # If 'c' was actually moved, then 'd' should have also been moved
129
 
            self.assertTreeLayout([('', root_id), ('a', 'a-id'),
 
129
            self.assertTreeLayout([('', root_id), ('a/', 'a-id'),
130
130
                                   ('a/c', 'c-id'),  ('a/d', 'd-id')], tree)
131
131
        else:
132
 
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
132
            self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c', 'c-id'),
133
133
                                   ('d', 'd-id')], tree)
134
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
134
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c', 'c-id'),
135
135
                               ('d', 'd-id')], tree.basis_tree())
136
136
        tree._validate()
137
137
 
145
145
        tree.remove(['a/b'], keep_files=False)
146
146
        self.assertEqual([('b', 'a/b')], tree.move(['b'], 'a'))
147
147
        self.assertTreeLayout([('', root_id),
148
 
                               ('a', 'a-id'),
 
148
                               ('a/', 'a-id'),
149
149
                               ('a/b', 'b-id'),
150
150
                              ], tree)
151
151
        tree._validate()
156
156
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
157
157
        tree.commit('initial', rev_id='rev-1')
158
158
        root_id = tree.get_root_id()
159
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
159
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
160
160
                               ('b/c', 'c-id')], tree)
161
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
161
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
162
162
                               ('b/c', 'c-id')], tree.basis_tree())
163
163
        a_contents = tree.get_file_text('a-id')
164
164
        self.assertEqual([('a', 'b/a')],
165
165
            tree.move(['a'], 'b'))
166
 
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id'),
 
166
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id'),
167
167
                               ('b/c', 'c-id')], tree)
168
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
168
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
169
169
                               ('b/c', 'c-id')], tree.basis_tree())
170
170
        self.assertPathDoesNotExist('a')
171
171
        self.assertFileEqual(a_contents, 'b/a')
180
180
        c_contents = tree.get_file_text('c-id')
181
181
        self.assertEqual([('b/c', 'c')],
182
182
            tree.move(['b/c'], ''))
183
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
183
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
184
184
                               ('c', 'c-id')], tree)
185
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
185
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
186
186
                               ('b/c', 'c-id')], tree.basis_tree())
187
187
        self.assertPathDoesNotExist('b/c')
188
188
        self.assertFileEqual(c_contents, 'c')
200
200
        # 'c' may or may not have been moved, but either way the tree should
201
201
        # maintain a consistent state.
202
202
        if osutils.lexists('c'):
203
 
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
203
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
204
204
                                   ('c', 'c-id')], tree)
205
205
        else:
206
206
            self.assertPathExists('b/c')
207
 
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
207
            self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
208
208
                                   ('b/c', 'c-id')], tree)
209
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
 
209
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id'),
210
210
                               ('c', 'c-id')], tree.basis_tree())
211
211
        tree._validate()
212
212
 
238
238
        root_id = tree.get_root_id()
239
239
        os.rename('a', 'b/a')
240
240
 
241
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
241
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
242
242
                              tree)
243
243
        # We don't need after=True as long as source is missing and target
244
244
        # exists.
245
245
        self.assertEqual([('a', 'b/a')],
246
246
            tree.move(['a'], 'b'))
247
 
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
 
247
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
248
248
                              tree)
249
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
249
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
250
250
                              tree.basis_tree())
251
251
        tree._validate()
252
252
 
258
258
        root_id = tree.get_root_id()
259
259
        os.rename('a', 'b/a')
260
260
 
261
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
261
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
262
262
                              tree)
263
263
        # Passing after=True should work as well
264
264
        self.assertEqual([('a', 'b/a')],
265
265
            tree.move(['a'], 'b', after=True))
266
 
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
 
266
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
267
267
                              tree)
268
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
268
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
269
269
                              tree.basis_tree())
270
270
        tree._validate()
271
271
 
279
279
        # Passing after when the file hasn't been move raises an exception
280
280
        self.assertRaises(errors.BzrMoveFailedError,
281
281
                          tree.move, ['a'], 'b', after=True)
282
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
282
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
283
283
                              tree.basis_tree())
284
284
        tree._validate()
285
285
 
303
303
        finally:
304
304
            ba_file.close()
305
305
 
306
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
306
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
307
307
                              tree)
308
308
        self.assertRaises(errors.RenameFailedFilesExist,
309
309
                          tree.move, ['a'], 'b', after=False)
310
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
310
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
311
311
                              tree)
312
312
        self.assertFileEqual(a_text, 'a')
313
313
        self.assertFileEqual(ba_text, 'b/a')
314
314
        # But you can pass after=True
315
315
        self.assertEqual([('a', 'b/a')],
316
316
            tree.move(['a'], 'b', after=True))
317
 
        self.assertTreeLayout([('', root_id), ('b', 'b-id'), ('b/a', 'a-id')],
 
317
        self.assertTreeLayout([('', root_id), ('b/', 'b-id'), ('b/a', 'a-id')],
318
318
                              tree)
319
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id')],
 
319
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b/', 'b-id')],
320
320
                              tree.basis_tree())
321
321
        # But it shouldn't actually move anything
322
322
        self.assertFileEqual(a_text, 'a')
333
333
 
334
334
        self.assertEqual([('a', 'e/a')],
335
335
            tree.move(['a'], 'e'))
336
 
        self.assertTreeLayout([('', root_id), ('e', 'e-id'), ('e/a', 'a-id'),
337
 
                               ('e/a/b', 'b-id'), ('e/a/c', 'c-id'),
 
336
        self.assertTreeLayout([('', root_id), ('e/', 'e-id'), ('e/a/', 'a-id'),
 
337
                               ('e/a/b', 'b-id'), ('e/a/c/', 'c-id'),
338
338
                               ('e/a/c/d', 'd-id')], tree)
339
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('e', 'e-id'),
340
 
                               ('a/b', 'b-id'), ('a/c', 'c-id'),
 
339
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('e/', 'e-id'),
 
340
                               ('a/b', 'b-id'), ('a/c/', 'c-id'),
341
341
                               ('a/c/d', 'd-id')], tree.basis_tree())
342
342
        tree._validate()
343
343
 
355
355
        self.assertEqual([('c/b', 'b')],
356
356
                         tree.move(['c/b'], ''))
357
357
        self.assertTreeLayout([('', root_id),
358
 
                               ('b', 'b-id'),
359
 
                               ('c', 'c-id'),
360
 
                               ('b/d', 'd-id'),
 
358
                               ('b/', 'b-id'),
 
359
                               ('c/', 'c-id'),
 
360
                               ('b/d/', 'd-id'),
361
361
                              ], tree)
362
362
        tree._validate()
363
363
 
370
370
        root_id = tree.get_root_id()
371
371
 
372
372
        tree.rename_one('a/b', 'a/c/b')
373
 
        if self.workingtree_format.supports_versioned_directories:
374
 
            self.assertTreeLayout([('', root_id),
375
 
                                   ('a', 'a-id'),
376
 
                                   ('d', 'd-id'),
377
 
                                   ('a/c', 'c-id'),
378
 
                                   ('a/c/b', 'b-id'),
379
 
                                  ], tree)
380
 
        else:
381
 
            self.assertTreeLayout([('', root_id),
382
 
                                   ('a', 'a-id'),
383
 
                                   ('a/c', 'c-id'),
384
 
                                   ('a/c/b', 'b-id'),
385
 
                                  ], tree)
 
373
        self.assertTreeLayout([('', root_id),
 
374
                               ('a/', 'a-id'),
 
375
                               ('d/', 'd-id'),
 
376
                               ('a/c/', 'c-id'),
 
377
                               ('a/c/b', 'b-id'),
 
378
                              ], tree)
386
379
        self.assertEqual([('a', 'd/a')],
387
380
                         tree.move(['a'], 'd'))
388
381
        self.assertTreeLayout([('', root_id),
389
 
                               ('d', 'd-id'),
390
 
                               ('d/a', 'a-id'),
391
 
                               ('d/a/c', 'c-id'),
 
382
                               ('d/', 'd-id'),
 
383
                               ('d/a/', 'a-id'),
 
384
                               ('d/a/c/', 'c-id'),
392
385
                               ('d/a/c/b', 'b-id'),
393
386
                              ], tree)
394
387
        tree._validate()
406
399
        self.assertEqual([('a', 'b/a')],
407
400
                         tree.move(['a'], 'b'))
408
401
        self.assertTreeLayout([('', root_id),
409
 
                               ('b', 'b-id'),
410
 
                               ('b/a', 'a-id'),
 
402
                               ('b/', 'b-id'),
 
403
                               ('b/a/', 'a-id'),
411
404
                               ('b/a/c', 'ac-id'),
412
405
                              ], tree)
413
406
        tree._validate()
425
418
        self.assertEqual([('a', 'b/a')],
426
419
                         tree.move(['a'], 'b'))
427
420
        self.assertTreeLayout([('', root_id),
428
 
                               ('b', 'b-id'),
429
 
                               ('b/a', 'a-id'),
 
421
                               ('b/', 'b-id'),
 
422
                               ('b/a/', 'a-id'),
430
423
                               ('b/a/b', 'ab-id'),
431
424
                               ('b/a/c', 'ac-id'),
432
425
                               ('b/a/d', 'ad-id'),
444
437
        self.assertEqual([('a/b', 'b')],
445
438
                         tree.move(['a/b'], ''))
446
439
        self.assertTreeLayout([('', root_id),
447
 
                               ('a', 'a-id'),
 
440
                               ('a/', 'a-id'),
448
441
                               ('b', 'b-id'),
449
442
                               ('d', 'd-id'),
450
 
                               ('e', 'e-id'),
 
443
                               ('e/', 'e-id'),
451
444
                               ('a/c', 'c-id'),
452
445
                              ], tree)
453
446
        self.assertEqual([('d', 'a/d')],
454
447
                         tree.move(['d'], 'a'))
455
448
        self.assertTreeLayout([('', root_id),
456
 
                               ('a', 'a-id'),
 
449
                               ('a/', 'a-id'),
457
450
                               ('b', 'b-id'),
458
 
                               ('e', 'e-id'),
 
451
                               ('e/', 'e-id'),
459
452
                               ('a/c', 'c-id'),
460
453
                               ('a/d', 'd-id'),
461
454
                              ], tree)
463
456
                         tree.move(['a'], 'e'))
464
457
        self.assertTreeLayout([('', root_id),
465
458
                               ('b', 'b-id'),
466
 
                               ('e', 'e-id'),
467
 
                               ('e/a', 'a-id'),
 
459
                               ('e/', 'e-id'),
 
460
                               ('e/a/', 'a-id'),
468
461
                               ('e/a/c', 'c-id'),
469
462
                               ('e/a/d', 'd-id'),
470
463
                              ], tree)
480
473
 
481
474
        tree.rename_one('a/b', 'a/d')
482
475
        self.assertTreeLayout([('', root_id),
483
 
                               ('a', 'a-id'),
484
 
                               ('d', 'd-id'),
 
476
                               ('a/', 'a-id'),
 
477
                               ('d/', 'd-id'),
485
478
                               ('a/c', 'c-id'),
486
479
                               ('a/d', 'b-id'),
487
480
                              ], tree)
488
481
        self.assertEqual([('a', 'd/a')],
489
482
                         tree.move(['a'], 'd'))
490
483
        self.assertTreeLayout([('', root_id),
491
 
                               ('d', 'd-id'),
492
 
                               ('d/a', 'a-id'),
 
484
                               ('d/', 'd-id'),
 
485
                               ('d/a/', 'a-id'),
493
486
                               ('d/a/c', 'c-id'),
494
487
                               ('d/a/d', 'b-id'),
495
488
                              ], tree)
507
500
        tree.rename_one('a/d', 'a/b')
508
501
        tree.rename_one('a/bb', 'a/d')
509
502
        self.assertTreeLayout([('', root_id),
510
 
                               ('a', 'a-id'),
511
 
                               ('e', 'e-id'),
 
503
                               ('a/', 'a-id'),
 
504
                               ('e/', 'e-id'),
512
505
                               ('a/b', 'd-id'),
513
506
                               ('a/c', 'c-id'),
514
507
                               ('a/d', 'b-id'),
516
509
        self.assertEqual([('a', 'e/a')],
517
510
                         tree.move(['a'], 'e'))
518
511
        self.assertTreeLayout([('', root_id),
519
 
                               ('e', 'e-id'),
520
 
                               ('e/a', 'a-id'),
 
512
                               ('e/', 'e-id'),
 
513
                               ('e/a/', 'a-id'),
521
514
                               ('e/a/b', 'd-id'),
522
515
                               ('e/a/c', 'c-id'),
523
516
                               ('e/a/d', 'b-id'),
534
527
 
535
528
        self.assertEqual([('a/b', 'c/b')],
536
529
            tree.move(['a/b'], 'c'))
537
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
530
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
538
531
                               ('c/b', 'b-id')], tree)
539
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
532
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
540
533
                               ('a/b', 'b-id')], tree.basis_tree())
541
534
 
542
535
        self.assertEqual([('c/b', 'b')],
543
536
            tree.move(['c/b'], ''))
544
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
545
 
                               ('c', 'c-id')], tree)
546
 
        self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
 
537
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('b', 'b-id'),
 
538
                               ('c/', 'c-id')], tree)
 
539
        self.assertTreeLayout([('', root_id), ('a/', 'a-id'), ('c/', 'c-id'),
547
540
                               ('a/b', 'b-id')], tree.basis_tree())
548
541
        tree._validate()
549
542