14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test for 'brz mv'"""
17
"""Test for 'bzr mv'"""
27
from breezy.tests import (
27
from bzrlib.tests import (
28
28
TestCaseWithTransport,
30
from breezy.tests.features import (
30
from bzrlib.tests.features import (
31
31
CaseInsensitiveFilesystemFeature,
33
33
UnicodeFilenameFeature,
37
37
class TestMove(TestCaseWithTransport):
39
def assertMoved(self, from_path, to_path):
39
def assertMoved(self,from_path,to_path):
40
40
"""Assert that to_path is existing and versioned but from_path not. """
41
41
self.assertPathDoesNotExist(from_path)
42
42
self.assertNotInWorkingTree(from_path)
51
51
tree.add(['a', 'c', 'subdir'])
53
53
self.run_bzr('mv a b')
54
self.assertMoved('a', 'b')
54
self.assertMoved('a','b')
56
56
self.run_bzr('mv b subdir')
57
self.assertMoved('b', 'subdir/b')
57
self.assertMoved('b','subdir/b')
59
59
self.run_bzr('mv subdir/b a')
60
self.assertMoved('subdir/b', 'a')
60
self.assertMoved('subdir/b','a')
62
62
self.run_bzr('mv a c subdir')
63
self.assertMoved('a', 'subdir/a')
64
self.assertMoved('c', 'subdir/c')
63
self.assertMoved('a','subdir/a')
64
self.assertMoved('c','subdir/c')
66
66
self.run_bzr('mv subdir/a subdir/newa')
67
self.assertMoved('subdir/a', 'subdir/newa')
67
self.assertMoved('subdir/a','subdir/newa')
69
69
def test_mv_unversioned(self):
70
70
self.build_tree(['unversioned.txt'])
71
71
self.run_bzr_error(
72
["^brz: ERROR: Could not rename unversioned.txt => elsewhere."
73
" .*unversioned.txt is not versioned\\.$"],
72
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
73
" .*unversioned.txt is not versioned\.$"],
74
74
'mv unversioned.txt elsewhere')
76
76
def test_mv_nonexisting(self):
77
77
self.run_bzr_error(
78
["^brz: ERROR: Could not rename doesnotexist => somewhereelse."
79
" .*doesnotexist is not versioned\\.$"],
78
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
79
" .*doesnotexist is not versioned\.$"],
80
80
'mv doesnotexist somewhereelse')
82
82
def test_mv_unqualified(self):
83
self.run_bzr_error(['^brz: ERROR: missing file argument$'], 'mv')
83
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
85
85
def test_mv_invalid(self):
86
86
tree = self.make_branch_and_tree('.')
88
88
tree.add(['test.txt'])
90
90
self.run_bzr_error(
91
["^brz: ERROR: Could not move to sub1: sub1 is not versioned\\.$"],
91
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
92
92
'mv test.txt sub1')
94
94
self.run_bzr_error(
95
["^brz: ERROR: Could not move test.txt => .*hello.txt: "
96
"sub1 is not versioned\\.$"],
95
["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
96
"sub1 is not versioned\.$"],
97
97
'mv test.txt sub1/hello.txt')
99
99
def test_mv_dirs(self):
102
102
tree.add(['hello.txt', 'sub1'])
104
104
self.run_bzr('mv sub1 sub2')
105
self.assertMoved('sub1', 'sub2')
105
self.assertMoved('sub1','sub2')
107
107
self.run_bzr('mv hello.txt sub2')
108
self.assertMoved('hello.txt', 'sub2/hello.txt')
108
self.assertMoved('hello.txt','sub2/hello.txt')
110
110
self.build_tree(['sub1/'])
111
111
tree.add(['sub1'])
112
112
self.run_bzr('mv sub2/hello.txt sub1')
113
self.assertMoved('sub2/hello.txt', 'sub1/hello.txt')
113
self.assertMoved('sub2/hello.txt','sub1/hello.txt')
115
115
self.run_bzr('mv sub2 sub1')
116
self.assertMoved('sub2', 'sub1/sub2')
116
self.assertMoved('sub2','sub1/sub2')
118
118
def test_mv_relative(self):
119
119
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
124
124
self.assertPathExists('sub1/sub2/hello.txt')
126
126
self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
127
self.assertMoved('sub1/sub2/hello.txt', 'sub1/hello.txt')
127
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
129
129
def test_mv_change_case_file(self):
130
130
# test for bug #77740 (mv unable change filename case on Windows)
169
169
self.build_tree(['foo/', 'bar'])
170
170
tree.add(['foo', 'bar'])
171
171
out, err = self.run_bzr('mv bar Foo', retcode=3)
172
self.assertEqual('', out)
174
'brz: ERROR: Could not move to Foo: Foo is not versioned.\n',
172
self.assertEquals('', out)
174
'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
177
177
def test_mv_smoke_aliases(self):
187
187
def test_mv_no_root(self):
188
188
tree = self.make_branch_and_tree('.')
189
189
self.run_bzr_error(
190
["brz: ERROR: can not move root of branch"],
190
["bzr: ERROR: can not move root of branch"],
193
193
def test_mv_through_symlinks(self):
196
196
self.build_tree(['a/', 'a/b'])
197
197
os.symlink('a', 'c')
198
198
os.symlink('.', 'd')
199
tree.add(['a', 'a/b', 'c'], [b'a-id', b'b-id', b'c-id'])
199
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
200
200
self.run_bzr('mv c/b b')
201
201
tree = workingtree.WorkingTree.open('.')
202
202
self.assertEqual('b-id', tree.path2id('b'))
204
204
def test_mv_already_moved_file(self):
205
"""Test brz mv original_file to moved_file.
205
"""Test bzr mv original_file to moved_file.
207
207
Tests if a file which has allready been moved by an external tool,
208
is handled correctly by brz mv.
208
is handled correctly by bzr mv.
209
209
Setup: a is in the working tree, b does not exist.
210
User does: mv a b; brz mv a b
210
User does: mv a b; bzr mv a b
212
212
self.build_tree(['a'])
213
213
tree = self.make_branch_and_tree('.')
216
216
osutils.rename('a', 'b')
217
217
self.run_bzr('mv a b')
218
self.assertMoved('a', 'b')
218
self.assertMoved('a','b')
220
220
def test_mv_already_moved_file_to_versioned_target(self):
221
"""Test brz mv existing_file to versioned_file.
221
"""Test bzr mv existing_file to versioned_file.
223
223
Tests if an attempt to move an existing versioned file
224
224
to another versiond file will fail.
225
225
Setup: a and b are in the working tree.
226
User does: rm b; mv a b; brz mv a b
226
User does: rm b; mv a b; bzr mv a b
228
228
self.build_tree(['a', 'b'])
229
229
tree = self.make_branch_and_tree('.')
233
233
osutils.rename('a', 'b')
234
234
self.run_bzr_error(
235
["^brz: ERROR: Could not move a => b. b is already versioned\\.$"],
235
["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
237
237
#check that nothing changed
238
238
self.assertPathDoesNotExist('a')
239
239
self.assertPathExists('b')
241
241
def test_mv_already_moved_file_into_subdir(self):
242
"""Test brz mv original_file to versioned_directory/file.
242
"""Test bzr mv original_file to versioned_directory/file.
244
244
Tests if a file which has already been moved into a versioned
245
directory by an external tool, is handled correctly by brz mv.
245
directory by an external tool, is handled correctly by bzr mv.
246
246
Setup: a and sub/ are in the working tree.
247
User does: mv a sub/a; brz mv a sub/a
247
User does: mv a sub/a; bzr mv a sub/a
249
249
self.build_tree(['a', 'sub/'])
250
250
tree = self.make_branch_and_tree('.')
253
253
osutils.rename('a', 'sub/a')
254
254
self.run_bzr('mv a sub/a')
255
self.assertMoved('a', 'sub/a')
255
self.assertMoved('a','sub/a')
257
257
def test_mv_already_moved_file_into_unversioned_subdir(self):
258
"""Test brz mv original_file to unversioned_directory/file.
258
"""Test bzr mv original_file to unversioned_directory/file.
260
260
Tests if an attempt to move an existing versioned file
261
261
into an unversioned directory will fail.
262
262
Setup: a is in the working tree, sub/ is not.
263
User does: mv a sub/a; brz mv a sub/a
263
User does: mv a sub/a; bzr mv a sub/a
265
265
self.build_tree(['a', 'sub/'])
266
266
tree = self.make_branch_and_tree('.')
269
269
osutils.rename('a', 'sub/a')
270
270
self.run_bzr_error(
271
["^brz: ERROR: Could not move a => a: sub is not versioned\\.$"],
271
["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
273
273
self.assertPathDoesNotExist('a')
274
274
self.assertPathExists('sub/a')
276
276
def test_mv_already_moved_files_into_subdir(self):
277
"""Test brz mv original_files to versioned_directory.
277
"""Test bzr mv original_files to versioned_directory.
279
279
Tests if files which has already been moved into a versioned
280
directory by an external tool, is handled correctly by brz mv.
280
directory by an external tool, is handled correctly by bzr mv.
281
281
Setup: a1, a2, sub are in the working tree.
282
User does: mv a1 sub/.; brz mv a1 a2 sub
282
User does: mv a1 sub/.; bzr mv a1 a2 sub
284
284
self.build_tree(['a1', 'a2', 'sub/'])
285
285
tree = self.make_branch_and_tree('.')
288
288
osutils.rename('a1', 'sub/a1')
289
289
self.run_bzr('mv a1 a2 sub')
290
self.assertMoved('a1', 'sub/a1')
291
self.assertMoved('a2', 'sub/a2')
290
self.assertMoved('a1','sub/a1')
291
self.assertMoved('a2','sub/a2')
293
293
def test_mv_already_moved_files_into_unversioned_subdir(self):
294
"""Test brz mv original_file to unversioned_directory.
294
"""Test bzr mv original_file to unversioned_directory.
296
296
Tests if an attempt to move existing versioned file
297
297
into an unversioned directory will fail.
298
298
Setup: a1, a2 are in the working tree, sub is not.
299
User does: mv a1 sub/.; brz mv a1 a2 sub
299
User does: mv a1 sub/.; bzr mv a1 a2 sub
301
301
self.build_tree(['a1', 'a2', 'sub/'])
302
302
tree = self.make_branch_and_tree('.')
305
305
osutils.rename('a1', 'sub/a1')
306
306
self.run_bzr_error(
307
["^brz: ERROR: Could not move to sub. sub is not versioned\\.$"],
307
["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
309
309
self.assertPathDoesNotExist('a1')
310
310
self.assertPathExists('sub/a1')
312
312
self.assertPathDoesNotExist('sub/a2')
314
314
def test_mv_already_moved_file_forcing_after(self):
315
"""Test brz mv versioned_file to unversioned_file.
315
"""Test bzr mv versioned_file to unversioned_file.
317
317
Tests if an attempt to move an existing versioned file to an existing
318
318
unversioned file will fail, informing the user to use the --after
319
319
option to force this.
320
320
Setup: a is in the working tree, b not versioned.
321
User does: mv a b; touch a; brz mv a b
321
User does: mv a b; touch a; bzr mv a b
323
323
self.build_tree(['a', 'b'])
324
324
tree = self.make_branch_and_tree('.')
327
327
osutils.rename('a', 'b')
328
328
self.build_tree(['a']) #touch a
329
329
self.run_bzr_error(
330
["^brz: ERROR: Could not rename a => b because both files exist."
331
" \\(Use --after to tell brz about a rename that has already"
330
["^bzr: ERROR: Could not rename a => b because both files exist."
331
" \(Use --after to tell bzr about a rename that has already"
334
334
self.assertPathExists('a')
335
335
self.assertPathExists('b')
337
337
def test_mv_already_moved_file_using_after(self):
338
"""Test brz mv --after versioned_file to unversioned_file.
338
"""Test bzr mv --after versioned_file to unversioned_file.
340
340
Tests if an existing versioned file can be forced to move to an
341
341
existing unversioned file using the --after option. With the result
342
342
that bazaar considers the unversioned_file to be moved from
343
343
versioned_file and versioned_file will become unversioned.
344
344
Setup: a is in the working tree and b exists.
345
User does: mv a b; touch a; brz mv a b --after
345
User does: mv a b; touch a; bzr mv a b --after
346
346
Resulting in a => b and a is unknown.
348
348
self.build_tree(['a', 'b'])
358
358
self.assertInWorkingTree('b')
360
360
def test_mv_already_moved_files_forcing_after(self):
361
"""Test brz mv versioned_files to directory/unversioned_file.
361
"""Test bzr mv versioned_files to directory/unversioned_file.
363
363
Tests if an attempt to move an existing versioned file to an existing
364
364
unversioned file in some other directory will fail, informing the user
367
367
Setup: a1, a2, sub are versioned and in the working tree,
368
368
sub/a1, sub/a2 are in working tree.
369
User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub
369
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
371
371
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
372
372
tree = self.make_branch_and_tree('.')
377
377
self.build_tree(['a2']) #touch a2
379
379
self.run_bzr_error(
380
["^brz: ERROR: Could not rename a1 => sub/a1 because both files"
381
" exist. \\(Use --after to tell brz about a rename that has already"
380
["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
381
" exist. \(Use --after to tell bzr about a rename that has already"
384
384
self.assertPathExists('a1')
385
385
self.assertPathExists('a2')
387
387
self.assertPathExists('sub/a2')
389
389
def test_mv_already_moved_files_using_after(self):
390
"""Test brz mv --after versioned_file to directory/unversioned_file.
390
"""Test bzr mv --after versioned_file to directory/unversioned_file.
392
392
Tests if an existing versioned file can be forced to move to an
393
393
existing unversioned file in some other directory using the --after
398
398
Setup: a1, a2, sub are versioned and in the working tree,
399
399
sub/a1, sub/a2 are in working tree.
400
User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub --after
400
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
402
402
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
403
403
tree = self.make_branch_and_tree('.')
453
453
self.assertEqual(out, '')
454
454
self.assertEqual(err, 'a => b\nc => d\n')
455
455
tree = workingtree.WorkingTree.open('tree')
456
self.assertTrue(tree.is_versioned('b'))
457
self.assertTrue(tree.is_versioned('d'))
456
self.assertIsNot(None, tree.path2id('b'))
457
self.assertIsNot(None, tree.path2id('d'))
459
459
def test_mv_auto_one_path(self):
460
460
self.make_abcd_tree()
462
462
self.assertEqual(out, '')
463
463
self.assertEqual(err, 'a => b\nc => d\n')
464
464
tree = workingtree.WorkingTree.open('tree')
465
self.assertTrue(tree.is_versioned('b'))
466
self.assertTrue(tree.is_versioned('d'))
465
self.assertIsNot(None, tree.path2id('b'))
466
self.assertIsNot(None, tree.path2id('d'))
468
468
def test_mv_auto_two_paths(self):
469
469
self.make_abcd_tree()
470
470
out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
471
self.assertEqual('brz: ERROR: Only one path may be specified to'
471
self.assertEqual('bzr: ERROR: Only one path may be specified to'
472
472
' --auto.\n', err)
474
474
def test_mv_auto_dry_run(self):
477
477
self.assertEqual(out, '')
478
478
self.assertEqual(err, 'a => b\nc => d\n')
479
479
tree = workingtree.WorkingTree.open('tree')
480
self.assertTrue(tree.is_versioned('a'))
481
self.assertTrue(tree.is_versioned('c'))
480
self.assertIsNot(None, tree.path2id('a'))
481
self.assertIsNot(None, tree.path2id('c'))
483
483
def test_mv_no_auto_dry_run(self):
484
484
self.make_abcd_tree()
485
485
out, err = self.run_bzr('mv c d --dry-run',
486
486
working_dir='tree', retcode=3)
487
self.assertEqual('brz: ERROR: --dry-run requires --auto.\n', err)
487
self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
489
489
def test_mv_auto_after(self):
490
490
self.make_abcd_tree()
491
491
out, err = self.run_bzr('mv --auto --after', working_dir='tree',
493
self.assertEqual('brz: ERROR: --after cannot be specified with'
493
self.assertEqual('bzr: ERROR: --after cannot be specified with'
494
494
' --auto.\n', err)
496
496
def test_mv_quiet(self):
504
504
def test_mv_readonly_lightweight_checkout(self):
505
505
branch = self.make_branch('foo')
506
branch = breezy.branch.Branch.open(self.get_readonly_url('foo'))
506
branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
507
507
tree = branch.create_checkout('tree', lightweight=True)
508
508
self.build_tree(['tree/path'])