65
66
self.build_tree(['unversioned.txt'])
66
67
self.run_bzr_error(
67
68
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
68
" .*unversioned.txt is not versioned$"],
69
" .*unversioned.txt is not versioned\.$"],
69
70
'mv unversioned.txt elsewhere')
71
72
def test_mv_nonexisting(self):
72
73
self.run_bzr_error(
73
74
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
74
" .*doesnotexist is not versioned$"],
75
" .*doesnotexist is not versioned\.$"],
75
76
'mv doesnotexist somewhereelse')
77
78
def test_mv_unqualified(self):
78
79
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
80
81
def test_mv_invalid(self):
81
82
tree = self.make_branch_and_tree('.')
82
83
self.build_tree(['test.txt', 'sub1/'])
83
84
tree.add(['test.txt'])
85
86
self.run_bzr_error(
86
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
87
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
87
88
'mv test.txt sub1')
89
90
self.run_bzr_error(
90
91
["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
91
"sub1 is not versioned$"],
92
"sub1 is not versioned\.$"],
92
93
'mv test.txt sub1/hello.txt')
94
95
def test_mv_dirs(self):
95
96
tree = self.make_branch_and_tree('.')
96
97
self.build_tree(['hello.txt', 'sub1/'])
125
126
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
128
def test_mv_change_case_file(self):
129
# test for bug #77740 (mv unable change filename case on Windows)
130
tree = self.make_branch_and_tree('.')
131
self.build_tree(['test.txt'])
132
tree.add(['test.txt'])
133
self.run_bzr('mv test.txt Test.txt')
134
# we can't use failUnlessExists on case-insensitive filesystem
135
# so try to check shape of the tree
136
shape = sorted(os.listdir(u'.'))
137
self.assertEqual(['.bzr', 'Test.txt'], shape)
138
self.assertInWorkingTree('Test.txt')
139
self.assertNotInWorkingTree('test.txt')
141
def test_mv_change_case_dir(self):
142
tree = self.make_branch_and_tree('.')
143
self.build_tree(['foo/'])
145
self.run_bzr('mv foo Foo')
146
# we can't use failUnlessExists on case-insensitive filesystem
147
# so try to check shape of the tree
148
shape = sorted(os.listdir(u'.'))
149
self.assertEqual(['.bzr', 'Foo'], shape)
150
self.assertInWorkingTree('Foo')
151
self.assertNotInWorkingTree('foo')
153
def test_mv_change_case_dir_w_files(self):
154
tree = self.make_branch_and_tree('.')
155
self.build_tree(['foo/', 'foo/bar'])
157
self.run_bzr('mv foo Foo')
158
# we can't use failUnlessExists on case-insensitive filesystem
159
# so try to check shape of the tree
160
shape = sorted(os.listdir(u'.'))
161
self.assertEqual(['.bzr', 'Foo'], shape)
162
self.assertInWorkingTree('Foo')
163
self.assertNotInWorkingTree('foo')
165
def test_mv_file_to_wrong_case_dir(self):
166
self.requireFeature(CaseInsensitiveFilesystemFeature)
167
tree = self.make_branch_and_tree('.')
168
self.build_tree(['foo/', 'bar'])
169
tree.add(['foo', 'bar'])
170
out, err = self.run_bzr('mv bar Foo', retcode=3)
171
self.assertEquals('', out)
173
'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
127
176
def test_mv_smoke_aliases(self):
128
177
# just test that aliases for mv exist, if their behaviour is changed in
129
178
# the future, then extend the tests.
357
407
self.failUnlessExists('sub/a2')
358
408
self.assertInWorkingTree('sub/a1')
359
409
self.assertInWorkingTree('sub/a2')
411
def test_mv_already_moved_directory(self):
412
"""Use `bzr mv a b` to mark a directory as renamed.
414
https://bugs.launchpad.net/bzr/+bug/107967/
416
self.build_tree(['a/', 'c/'])
417
tree = self.make_branch_and_tree('.')
419
osutils.rename('a', 'b')
420
osutils.rename('c', 'd')
421
# mv a b should work just like it does for already renamed files
422
self.run_bzr('mv a b')
423
self.failIfExists('a')
424
self.assertNotInWorkingTree('a')
425
self.failUnlessExists('b')
426
self.assertInWorkingTree('b')
427
# and --after should work, too (technically it's ignored)
428
self.run_bzr('mv --after c d')
429
self.failIfExists('c')
430
self.assertNotInWorkingTree('c')
431
self.failUnlessExists('d')
432
self.assertInWorkingTree('d')
434
def make_abcd_tree(self):
435
tree = self.make_branch_and_tree('tree')
436
self.build_tree(['tree/a', 'tree/c'])
438
tree.commit('record old names')
439
osutils.rename('tree/a', 'tree/b')
440
osutils.rename('tree/c', 'tree/d')
443
def test_mv_auto(self):
444
self.make_abcd_tree()
445
out, err = self.run_bzr('mv --auto', working_dir='tree')
446
self.assertEqual(out, '')
447
self.assertEqual(err, 'a => b\nc => d\n')
448
tree = workingtree.WorkingTree.open('tree')
449
self.assertIsNot(None, tree.path2id('b'))
450
self.assertIsNot(None, tree.path2id('d'))
452
def test_mv_auto_one_path(self):
453
self.make_abcd_tree()
454
out, err = self.run_bzr('mv --auto tree')
455
self.assertEqual(out, '')
456
self.assertEqual(err, 'a => b\nc => d\n')
457
tree = workingtree.WorkingTree.open('tree')
458
self.assertIsNot(None, tree.path2id('b'))
459
self.assertIsNot(None, tree.path2id('d'))
461
def test_mv_auto_two_paths(self):
462
self.make_abcd_tree()
463
out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
464
self.assertEqual('bzr: ERROR: Only one path may be specified to'
467
def test_mv_auto_dry_run(self):
468
self.make_abcd_tree()
469
out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
470
self.assertEqual(out, '')
471
self.assertEqual(err, 'a => b\nc => d\n')
472
tree = workingtree.WorkingTree.open('tree')
473
self.assertIsNot(None, tree.path2id('a'))
474
self.assertIsNot(None, tree.path2id('c'))
476
def test_mv_no_auto_dry_run(self):
477
self.make_abcd_tree()
478
out, err = self.run_bzr('mv c d --dry-run',
479
working_dir='tree', retcode=3)
480
self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
482
def test_mv_auto_after(self):
483
self.make_abcd_tree()
484
out, err = self.run_bzr('mv --auto --after', working_dir='tree',
486
self.assertEqual('bzr: ERROR: --after cannot be specified with'