26
26
from bzrlib.tests import (
27
CaseInsensitiveFilesystemFeature,
27
29
TestCaseWithTransport,
32
33
class TestMove(TestCaseWithTransport):
34
def assertInWorkingTree(self,path):
35
tree = workingtree.WorkingTree.open('.')
36
self.assertIsNot(tree.path2id(path), None,
37
path+' not in working tree.')
39
def assertNotInWorkingTree(self,path):
40
tree = workingtree.WorkingTree.open('.')
41
self.assertIs(tree.path2id(path), None, path+' in working tree.')
43
35
def assertMoved(self,from_path,to_path):
44
36
"""Assert that to_path is existing and versioned but from_path not. """
45
37
self.failIfExists(from_path)
54
46
files = self.build_tree(['a', 'c', 'subdir/'])
55
47
tree.add(['a', 'c', 'subdir'])
57
self.run_bzr('mv', 'a', 'b')
49
self.run_bzr('mv a b')
58
50
self.assertMoved('a','b')
60
self.run_bzr('mv', 'b', 'subdir')
52
self.run_bzr('mv b subdir')
61
53
self.assertMoved('b','subdir/b')
63
self.run_bzr('mv', 'subdir/b', 'a')
55
self.run_bzr('mv subdir/b a')
64
56
self.assertMoved('subdir/b','a')
66
self.run_bzr('mv', 'a', 'c', 'subdir')
58
self.run_bzr('mv a c subdir')
67
59
self.assertMoved('a','subdir/a')
68
60
self.assertMoved('c','subdir/c')
70
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
62
self.run_bzr('mv subdir/a subdir/newa')
71
63
self.assertMoved('subdir/a','subdir/newa')
73
65
def test_mv_unversioned(self):
74
66
self.build_tree(['unversioned.txt'])
75
67
self.run_bzr_error(
76
68
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
77
" .*unversioned.txt is not versioned$"],
78
'mv', 'unversioned.txt', 'elsewhere')
69
" .*unversioned.txt is not versioned\.$"],
70
'mv unversioned.txt elsewhere')
80
72
def test_mv_nonexisting(self):
81
73
self.run_bzr_error(
82
74
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
83
" .*doesnotexist is not versioned$"],
84
'mv', 'doesnotexist', 'somewhereelse')
75
" .*doesnotexist is not versioned\.$"],
76
'mv doesnotexist somewhereelse')
86
78
def test_mv_unqualified(self):
87
79
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
92
84
tree.add(['test.txt'])
94
86
self.run_bzr_error(
95
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
96
'mv', 'test.txt', 'sub1')
87
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
98
90
self.run_bzr_error(
99
91
["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
100
"sub1 is not versioned$"],
101
'mv', 'test.txt', 'sub1/hello.txt')
92
"sub1 is not versioned\.$"],
93
'mv test.txt sub1/hello.txt')
103
95
def test_mv_dirs(self):
104
96
tree = self.make_branch_and_tree('.')
105
97
self.build_tree(['hello.txt', 'sub1/'])
106
98
tree.add(['hello.txt', 'sub1'])
108
self.run_bzr('mv', 'sub1', 'sub2')
100
self.run_bzr('mv sub1 sub2')
109
101
self.assertMoved('sub1','sub2')
111
self.run_bzr('mv', 'hello.txt', 'sub2')
103
self.run_bzr('mv hello.txt sub2')
112
104
self.assertMoved('hello.txt','sub2/hello.txt')
114
tree.read_working_inventory()
116
106
self.build_tree(['sub1/'])
117
107
tree.add(['sub1'])
118
self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
108
self.run_bzr('mv sub2/hello.txt sub1')
119
109
self.assertMoved('sub2/hello.txt','sub1/hello.txt')
121
self.run_bzr('mv', 'sub2', 'sub1')
111
self.run_bzr('mv sub2 sub1')
122
112
self.assertMoved('sub2','sub1/sub2')
124
114
def test_mv_relative(self):
127
117
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
129
119
os.chdir('sub1/sub2')
130
self.run_bzr('mv', '../hello.txt', '.')
120
self.run_bzr('mv ../hello.txt .')
131
121
self.failUnlessExists('./hello.txt')
132
tree.read_working_inventory()
135
self.run_bzr('mv', 'sub2/hello.txt', '.')
124
self.run_bzr('mv sub2/hello.txt .')
137
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',
139
176
def test_mv_smoke_aliases(self):
140
177
# just test that aliases for mv exist, if their behaviour is changed in
141
178
# the future, then extend the tests.
143
180
tree = self.make_branch_and_tree('.')
146
self.run_bzr('move', 'a', 'b')
147
self.run_bzr('rename', 'b', 'a')
183
self.run_bzr('move a b')
184
self.run_bzr('rename b a')
149
186
def test_mv_through_symlinks(self):
150
if not osutils.has_symlinks():
151
raise TestSkipped('Symlinks are not supported on this platform')
187
self.requireFeature(SymlinkFeature)
152
188
tree = self.make_branch_and_tree('.')
153
189
self.build_tree(['a/', 'a/b'])
154
190
os.symlink('a', 'c')
155
191
os.symlink('.', 'd')
156
192
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
157
self.run_bzr('mv', 'c/b', 'b')
193
self.run_bzr('mv c/b b')
158
194
tree = workingtree.WorkingTree.open('.')
159
195
self.assertEqual('b-id', tree.path2id('b'))
242
278
tree = self.make_branch_and_tree('.')
243
279
tree.add(['a1', 'a2', 'sub'])
245
os.rename('a1', 'sub/a1')
246
self.run_bzr('mv', 'a1', 'a2', 'sub')
281
osutils.rename('a1', 'sub/a1')
282
self.run_bzr('mv a1 a2 sub')
247
283
self.assertMoved('a1','sub/a1')
248
284
self.assertMoved('a2','sub/a2')
259
295
tree = self.make_branch_and_tree('.')
260
296
tree.add(['a1', 'a2'])
262
os.rename('a1', 'sub/a1')
298
osutils.rename('a1', 'sub/a1')
263
299
self.run_bzr_error(
264
["^bzr: ERROR: Could not move to sub. sub is not versioned$"],
265
'mv', 'a1', 'a2', 'sub')
300
["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
266
302
self.failIfExists('a1')
267
303
self.failUnlessExists('sub/a1')
268
304
self.failUnlessExists('a2')
304
341
self.build_tree(['a', 'b'])
305
342
tree = self.make_branch_and_tree('.')
344
osutils.rename('a', 'b')
308
345
self.build_tree(['a']) #touch a
310
self.run_bzr('mv', 'a', 'b', '--after')
347
self.run_bzr('mv a b --after')
311
348
self.failUnlessExists('a')
312
349
self.assertNotInWorkingTree('a')#a should be unknown now.
313
350
self.failUnlessExists('b')
327
364
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
328
365
tree = self.make_branch_and_tree('.')
329
366
tree.add(['a1', 'a2', 'sub'])
330
os.rename('a1', 'sub/a1')
331
os.rename('a2', 'sub/a2')
367
osutils.rename('a1', 'sub/a1')
368
osutils.rename('a2', 'sub/a2')
332
369
self.build_tree(['a1']) #touch a1
333
370
self.build_tree(['a2']) #touch a2
335
372
self.run_bzr_error(
336
["^bzr: ERROR: Could not rename a1 => sub/a1 because both files exist."
337
" \(Use --after to update the Bazaar id\)$"],
338
'mv', 'a1', 'a2', 'sub')
373
["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
374
" exist. \(Use --after to tell bzr about a rename that has already"
339
377
self.failUnlessExists('a1')
340
378
self.failUnlessExists('a2')
341
379
self.failUnlessExists('sub/a1')
357
395
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
358
396
tree = self.make_branch_and_tree('.')
359
397
tree.add(['a1', 'a2', 'sub'])
360
os.rename('a1', 'sub/a1')
361
os.rename('a2', 'sub/a2')
398
osutils.rename('a1', 'sub/a1')
399
osutils.rename('a2', 'sub/a2')
362
400
self.build_tree(['a1']) #touch a1
363
401
self.build_tree(['a2']) #touch a2
365
self.run_bzr('mv', 'a1', 'a2', 'sub', '--after')
403
self.run_bzr('mv a1 a2 sub --after')
366
404
self.failUnlessExists('a1')
367
405
self.failUnlessExists('a2')
368
406
self.failUnlessExists('sub/a1')
369
407
self.failUnlessExists('sub/a2')
370
408
self.assertInWorkingTree('sub/a1')
371
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')