47
45
files = self.build_tree(['a', 'c', 'subdir/'])
48
46
tree.add(['a', 'c', 'subdir'])
50
self.run_bzr('mv a b')
48
self.run_bzr('mv', 'a', 'b')
51
49
self.assertMoved('a','b')
53
self.run_bzr('mv b subdir')
51
self.run_bzr('mv', 'b', 'subdir')
54
52
self.assertMoved('b','subdir/b')
56
self.run_bzr('mv subdir/b a')
54
self.run_bzr('mv', 'subdir/b', 'a')
57
55
self.assertMoved('subdir/b','a')
59
self.run_bzr('mv a c subdir')
57
self.run_bzr('mv', 'a', 'c', 'subdir')
60
58
self.assertMoved('a','subdir/a')
61
59
self.assertMoved('c','subdir/c')
63
self.run_bzr('mv subdir/a subdir/newa')
61
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
64
62
self.assertMoved('subdir/a','subdir/newa')
66
64
def test_mv_unversioned(self):
67
65
self.build_tree(['unversioned.txt'])
68
66
self.run_bzr_error(
69
67
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
70
" .*unversioned.txt is not versioned\.$"],
71
'mv unversioned.txt elsewhere')
68
" .*unversioned.txt is not versioned$"],
69
'mv', 'unversioned.txt', 'elsewhere')
73
71
def test_mv_nonexisting(self):
74
72
self.run_bzr_error(
75
73
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
76
" .*doesnotexist is not versioned\.$"],
77
'mv doesnotexist somewhereelse')
74
" .*doesnotexist is not versioned$"],
75
'mv', 'doesnotexist', 'somewhereelse')
79
77
def test_mv_unqualified(self):
80
78
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
82
80
def test_mv_invalid(self):
83
81
tree = self.make_branch_and_tree('.')
84
82
self.build_tree(['test.txt', 'sub1/'])
85
83
tree.add(['test.txt'])
87
85
self.run_bzr_error(
88
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
86
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
87
'mv', 'test.txt', 'sub1')
91
89
self.run_bzr_error(
92
90
["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
93
"sub1 is not versioned\.$"],
94
'mv test.txt sub1/hello.txt')
91
"sub1 is not versioned$"],
92
'mv', 'test.txt', 'sub1/hello.txt')
96
94
def test_mv_dirs(self):
97
95
tree = self.make_branch_and_tree('.')
98
96
self.build_tree(['hello.txt', 'sub1/'])
99
97
tree.add(['hello.txt', 'sub1'])
101
self.run_bzr('mv sub1 sub2')
99
self.run_bzr('mv', 'sub1', 'sub2')
102
100
self.assertMoved('sub1','sub2')
104
self.run_bzr('mv hello.txt sub2')
102
self.run_bzr('mv', 'hello.txt', 'sub2')
105
103
self.assertMoved('hello.txt','sub2/hello.txt')
107
105
self.build_tree(['sub1/'])
108
106
tree.add(['sub1'])
109
self.run_bzr('mv sub2/hello.txt sub1')
107
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
110
108
self.assertMoved('sub2/hello.txt','sub1/hello.txt')
112
self.run_bzr('mv sub2 sub1')
110
self.run_bzr('mv', 'sub2', 'sub1')
113
111
self.assertMoved('sub2','sub1/sub2')
115
113
def test_mv_relative(self):
118
116
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
120
118
os.chdir('sub1/sub2')
121
self.run_bzr('mv ../hello.txt .')
119
self.run_bzr('mv', '../hello.txt', '.')
122
120
self.failUnlessExists('./hello.txt')
125
self.run_bzr('mv sub2/hello.txt .')
123
self.run_bzr('mv', 'sub2/hello.txt', '.')
127
125
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
129
def test_mv_change_case_file(self):
130
# test for bug #77740 (mv unable change filename case on Windows)
131
tree = self.make_branch_and_tree('.')
132
self.build_tree(['test.txt'])
133
tree.add(['test.txt'])
134
self.run_bzr('mv test.txt Test.txt')
135
# we can't use failUnlessExists on case-insensitive filesystem
136
# so try to check shape of the tree
137
shape = sorted(os.listdir(u'.'))
138
self.assertEqual(['.bzr', 'Test.txt'], shape)
139
self.assertInWorkingTree('Test.txt')
140
self.assertNotInWorkingTree('test.txt')
142
def test_mv_change_case_dir(self):
143
tree = self.make_branch_and_tree('.')
144
self.build_tree(['foo/'])
146
self.run_bzr('mv foo Foo')
147
# we can't use failUnlessExists on case-insensitive filesystem
148
# so try to check shape of the tree
149
shape = sorted(os.listdir(u'.'))
150
self.assertEqual(['.bzr', 'Foo'], shape)
151
self.assertInWorkingTree('Foo')
152
self.assertNotInWorkingTree('foo')
154
def test_mv_change_case_dir_w_files(self):
155
tree = self.make_branch_and_tree('.')
156
self.build_tree(['foo/', 'foo/bar'])
158
self.run_bzr('mv foo Foo')
159
# we can't use failUnlessExists on case-insensitive filesystem
160
# so try to check shape of the tree
161
shape = sorted(os.listdir(u'.'))
162
self.assertEqual(['.bzr', 'Foo'], shape)
163
self.assertInWorkingTree('Foo')
164
self.assertNotInWorkingTree('foo')
166
def test_mv_file_to_wrong_case_dir(self):
167
self.requireFeature(CaseInsensitiveFilesystemFeature)
168
tree = self.make_branch_and_tree('.')
169
self.build_tree(['foo/', 'bar'])
170
tree.add(['foo', 'bar'])
171
out, err = self.run_bzr('mv bar Foo', retcode=3)
172
self.assertEquals('', out)
174
'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
177
127
def test_mv_smoke_aliases(self):
178
128
# just test that aliases for mv exist, if their behaviour is changed in
179
129
# the future, then extend the tests.
181
131
tree = self.make_branch_and_tree('.')
184
self.run_bzr('move a b')
185
self.run_bzr('rename b a')
134
self.run_bzr('move', 'a', 'b')
135
self.run_bzr('rename', 'b', 'a')
187
137
def test_mv_through_symlinks(self):
188
self.requireFeature(SymlinkFeature)
138
if not osutils.has_symlinks():
139
raise TestSkipped('Symlinks are not supported on this platform')
189
140
tree = self.make_branch_and_tree('.')
190
141
self.build_tree(['a/', 'a/b'])
191
142
os.symlink('a', 'c')
192
143
os.symlink('.', 'd')
193
144
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
194
self.run_bzr('mv c/b b')
145
self.run_bzr('mv', 'c/b', 'b')
195
146
tree = workingtree.WorkingTree.open('.')
196
147
self.assertEqual('b-id', tree.path2id('b'))
401
350
self.build_tree(['a1']) #touch a1
402
351
self.build_tree(['a2']) #touch a2
404
self.run_bzr('mv a1 a2 sub --after')
353
self.run_bzr('mv', 'a1', 'a2', 'sub', '--after')
405
354
self.failUnlessExists('a1')
406
355
self.failUnlessExists('a2')
407
356
self.failUnlessExists('sub/a1')
408
357
self.failUnlessExists('sub/a2')
409
358
self.assertInWorkingTree('sub/a1')
410
359
self.assertInWorkingTree('sub/a2')
412
def test_mv_already_moved_directory(self):
413
"""Use `bzr mv a b` to mark a directory as renamed.
415
https://bugs.launchpad.net/bzr/+bug/107967/
417
self.build_tree(['a/', 'c/'])
418
tree = self.make_branch_and_tree('.')
420
osutils.rename('a', 'b')
421
osutils.rename('c', 'd')
422
# mv a b should work just like it does for already renamed files
423
self.run_bzr('mv a b')
424
self.failIfExists('a')
425
self.assertNotInWorkingTree('a')
426
self.failUnlessExists('b')
427
self.assertInWorkingTree('b')
428
# and --after should work, too (technically it's ignored)
429
self.run_bzr('mv --after c d')
430
self.failIfExists('c')
431
self.assertNotInWorkingTree('c')
432
self.failUnlessExists('d')
433
self.assertInWorkingTree('d')
435
def make_abcd_tree(self):
436
tree = self.make_branch_and_tree('tree')
437
self.build_tree(['tree/a', 'tree/c'])
439
tree.commit('record old names')
440
osutils.rename('tree/a', 'tree/b')
441
osutils.rename('tree/c', 'tree/d')
444
def test_mv_auto(self):
445
self.make_abcd_tree()
446
out, err = self.run_bzr('mv --auto', working_dir='tree')
447
self.assertEqual(out, '')
448
self.assertEqual(err, 'a => b\nc => d\n')
449
tree = workingtree.WorkingTree.open('tree')
450
self.assertIsNot(None, tree.path2id('b'))
451
self.assertIsNot(None, tree.path2id('d'))
453
def test_mv_auto_one_path(self):
454
self.make_abcd_tree()
455
out, err = self.run_bzr('mv --auto tree')
456
self.assertEqual(out, '')
457
self.assertEqual(err, 'a => b\nc => d\n')
458
tree = workingtree.WorkingTree.open('tree')
459
self.assertIsNot(None, tree.path2id('b'))
460
self.assertIsNot(None, tree.path2id('d'))
462
def test_mv_auto_two_paths(self):
463
self.make_abcd_tree()
464
out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
465
self.assertEqual('bzr: ERROR: Only one path may be specified to'
468
def test_mv_auto_dry_run(self):
469
self.make_abcd_tree()
470
out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
471
self.assertEqual(out, '')
472
self.assertEqual(err, 'a => b\nc => d\n')
473
tree = workingtree.WorkingTree.open('tree')
474
self.assertIsNot(None, tree.path2id('a'))
475
self.assertIsNot(None, tree.path2id('c'))
477
def test_mv_no_auto_dry_run(self):
478
self.make_abcd_tree()
479
out, err = self.run_bzr('mv c d --dry-run',
480
working_dir='tree', retcode=3)
481
self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
483
def test_mv_auto_after(self):
484
self.make_abcd_tree()
485
out, err = self.run_bzr('mv --auto --after', working_dir='tree',
487
self.assertEqual('bzr: ERROR: --after cannot be specified with'
490
def test_mv_quiet(self):
491
tree = self.make_branch_and_tree('.')
492
self.build_tree(['aaa'])
494
out, err = self.run_bzr('mv --quiet aaa bbb')
495
self.assertEqual(out, '')
496
self.assertEqual(err, '')
498
def test_mv_readonly_lightweight_checkout(self):
499
branch = self.make_branch('foo')
500
branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
501
tree = branch.create_checkout('tree', lightweight=True)
502
self.build_tree(['tree/path'])
504
# If this fails, the tree is trying to acquire a branch lock, which it
506
self.run_bzr(['mv', 'tree/path', 'tree/path2'])