424
420
osutils.rename('c', 'd')
425
421
# mv a b should work just like it does for already renamed files
426
422
self.run_bzr('mv a b')
427
self.assertPathDoesNotExist('a')
423
self.failIfExists('a')
428
424
self.assertNotInWorkingTree('a')
429
self.assertPathExists('b')
425
self.failUnlessExists('b')
430
426
self.assertInWorkingTree('b')
431
427
# and --after should work, too (technically it's ignored)
432
428
self.run_bzr('mv --after c d')
433
self.assertPathDoesNotExist('c')
429
self.failIfExists('c')
434
430
self.assertNotInWorkingTree('c')
435
self.assertPathExists('d')
431
self.failUnlessExists('d')
436
432
self.assertInWorkingTree('d')
438
def make_abcd_tree(self):
439
tree = self.make_branch_and_tree('tree')
440
self.build_tree(['tree/a', 'tree/c'])
442
tree.commit('record old names')
443
osutils.rename('tree/a', 'tree/b')
444
osutils.rename('tree/c', 'tree/d')
447
def test_mv_auto(self):
448
self.make_abcd_tree()
449
out, err = self.run_bzr('mv --auto', working_dir='tree')
450
self.assertEqual(out, '')
451
self.assertEqual(err, 'a => b\nc => d\n')
452
tree = workingtree.WorkingTree.open('tree')
453
self.assertIsNot(None, tree.path2id('b'))
454
self.assertIsNot(None, tree.path2id('d'))
456
def test_mv_auto_one_path(self):
457
self.make_abcd_tree()
458
out, err = self.run_bzr('mv --auto tree')
459
self.assertEqual(out, '')
460
self.assertEqual(err, 'a => b\nc => d\n')
461
tree = workingtree.WorkingTree.open('tree')
462
self.assertIsNot(None, tree.path2id('b'))
463
self.assertIsNot(None, tree.path2id('d'))
465
def test_mv_auto_two_paths(self):
466
self.make_abcd_tree()
467
out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
468
self.assertEqual('bzr: ERROR: Only one path may be specified to'
471
def test_mv_auto_dry_run(self):
472
self.make_abcd_tree()
473
out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
474
self.assertEqual(out, '')
475
self.assertEqual(err, 'a => b\nc => d\n')
476
tree = workingtree.WorkingTree.open('tree')
477
self.assertIsNot(None, tree.path2id('a'))
478
self.assertIsNot(None, tree.path2id('c'))
480
def test_mv_no_auto_dry_run(self):
481
self.make_abcd_tree()
482
out, err = self.run_bzr('mv c d --dry-run',
483
working_dir='tree', retcode=3)
484
self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
486
def test_mv_auto_after(self):
487
self.make_abcd_tree()
488
out, err = self.run_bzr('mv --auto --after', working_dir='tree',
490
self.assertEqual('bzr: ERROR: --after cannot be specified with'
493
def test_mv_quiet(self):
494
tree = self.make_branch_and_tree('.')
495
self.build_tree(['aaa'])
497
out, err = self.run_bzr('mv --quiet aaa bbb')
498
self.assertEqual(out, '')
499
self.assertEqual(err, '')
501
def test_mv_readonly_lightweight_checkout(self):
502
branch = self.make_branch('foo')
503
branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
504
tree = branch.create_checkout('tree', lightweight=True)
505
self.build_tree(['tree/path'])
507
# If this fails, the tree is trying to acquire a branch lock, which it
509
self.run_bzr(['mv', 'tree/path', 'tree/path2'])
511
def test_mv_unversioned_non_ascii(self):
512
"""Clear error on mv of an unversioned non-ascii file, see lp:707954"""
513
self.requireFeature(UnicodeFilenameFeature)
514
tree = self.make_branch_and_tree(".")
515
self.build_tree([u"\xA7"])
516
out, err = self.run_bzr_error(["Could not rename", "not versioned"],
517
["mv", u"\xA7", "b"])