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 'bzr mv'"""
17
"""Test for 'brz mv'"""
27
from bzrlib.tests import (
27
from breezy.tests import (
28
TestCaseWithTransport,
30
from breezy.tests.features import (
28
31
CaseInsensitiveFilesystemFeature,
30
TestCaseWithTransport,
33
UnicodeFilenameFeature,
34
37
class TestMove(TestCaseWithTransport):
36
def assertMoved(self,from_path,to_path):
39
def assertMoved(self, from_path, to_path):
37
40
"""Assert that to_path is existing and versioned but from_path not. """
38
self.failIfExists(from_path)
41
self.assertPathDoesNotExist(from_path)
39
42
self.assertNotInWorkingTree(from_path)
41
self.failUnlessExists(to_path)
44
self.assertPathExists(to_path)
42
45
self.assertInWorkingTree(to_path)
44
47
def test_mv_modes(self):
48
51
tree.add(['a', 'c', 'subdir'])
50
53
self.run_bzr('mv a b')
51
self.assertMoved('a','b')
54
self.assertMoved('a', 'b')
53
56
self.run_bzr('mv b subdir')
54
self.assertMoved('b','subdir/b')
57
self.assertMoved('b', 'subdir/b')
56
59
self.run_bzr('mv subdir/b a')
57
self.assertMoved('subdir/b','a')
60
self.assertMoved('subdir/b', 'a')
59
62
self.run_bzr('mv a c subdir')
60
self.assertMoved('a','subdir/a')
61
self.assertMoved('c','subdir/c')
63
self.assertMoved('a', 'subdir/a')
64
self.assertMoved('c', 'subdir/c')
63
66
self.run_bzr('mv subdir/a subdir/newa')
64
self.assertMoved('subdir/a','subdir/newa')
67
self.assertMoved('subdir/a', 'subdir/newa')
66
69
def test_mv_unversioned(self):
67
70
self.build_tree(['unversioned.txt'])
68
71
self.run_bzr_error(
69
["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
70
" .*unversioned.txt is not versioned\.$"],
72
[b"^brz: ERROR: Could not rename unversioned.txt => elsewhere."
73
b" .*unversioned.txt is not versioned\\.$"],
71
74
'mv unversioned.txt elsewhere')
73
76
def test_mv_nonexisting(self):
74
77
self.run_bzr_error(
75
["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
76
" .*doesnotexist is not versioned\.$"],
78
[b"^brz: ERROR: Could not rename doesnotexist => somewhereelse."
79
b" .*doesnotexist is not versioned\\.$"],
77
80
'mv doesnotexist somewhereelse')
79
82
def test_mv_unqualified(self):
80
self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
83
self.run_bzr_error([b'^brz: ERROR: missing file argument$'], 'mv')
82
85
def test_mv_invalid(self):
83
86
tree = self.make_branch_and_tree('.')
99
102
tree.add(['hello.txt', 'sub1'])
101
104
self.run_bzr('mv sub1 sub2')
102
self.assertMoved('sub1','sub2')
105
self.assertMoved('sub1', 'sub2')
104
107
self.run_bzr('mv hello.txt sub2')
105
self.assertMoved('hello.txt','sub2/hello.txt')
108
self.assertMoved('hello.txt', 'sub2/hello.txt')
107
110
self.build_tree(['sub1/'])
108
111
tree.add(['sub1'])
109
112
self.run_bzr('mv sub2/hello.txt sub1')
110
self.assertMoved('sub2/hello.txt','sub1/hello.txt')
113
self.assertMoved('sub2/hello.txt', 'sub1/hello.txt')
112
115
self.run_bzr('mv sub2 sub1')
113
self.assertMoved('sub2','sub1/sub2')
116
self.assertMoved('sub2', 'sub1/sub2')
115
118
def test_mv_relative(self):
116
119
self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
117
120
tree = self.make_branch_and_tree('.')
118
121
tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
120
os.chdir('sub1/sub2')
121
self.run_bzr('mv ../hello.txt .')
122
self.failUnlessExists('./hello.txt')
123
self.run_bzr('mv ../hello.txt .', working_dir='sub1/sub2')
124
self.assertPathExists('sub1/sub2/hello.txt')
125
self.run_bzr('mv sub2/hello.txt .')
127
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
126
self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
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)
184
184
self.run_bzr('move a b')
185
185
self.run_bzr('rename b a')
187
def test_mv_no_root(self):
188
tree = self.make_branch_and_tree('.')
190
[b"brz: ERROR: can not move root of branch"],
187
193
def test_mv_through_symlinks(self):
188
194
self.requireFeature(SymlinkFeature)
189
195
tree = self.make_branch_and_tree('.')
190
196
self.build_tree(['a/', 'a/b'])
191
197
os.symlink('a', 'c')
192
198
os.symlink('.', 'd')
193
tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
199
tree.add(['a', 'a/b', 'c'], [b'a-id', b'b-id', b'c-id'])
194
200
self.run_bzr('mv c/b b')
195
201
tree = workingtree.WorkingTree.open('.')
196
self.assertEqual('b-id', tree.path2id('b'))
202
self.assertEqual(b'b-id', tree.path2id('b'))
198
204
def test_mv_already_moved_file(self):
199
"""Test bzr mv original_file to moved_file.
205
"""Test brz mv original_file to moved_file.
201
207
Tests if a file which has allready been moved by an external tool,
202
is handled correctly by bzr mv.
208
is handled correctly by brz mv.
203
209
Setup: a is in the working tree, b does not exist.
204
User does: mv a b; bzr mv a b
210
User does: mv a b; brz mv a b
206
212
self.build_tree(['a'])
207
213
tree = self.make_branch_and_tree('.')
227
233
osutils.rename('a', 'b')
228
234
self.run_bzr_error(
229
["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
235
[b"^brz: ERROR: Could not move a => b. b is already versioned\\.$"],
231
237
#check that nothing changed
232
self.failIfExists('a')
233
self.failUnlessExists('b')
238
self.assertPathDoesNotExist('a')
239
self.assertPathExists('b')
235
241
def test_mv_already_moved_file_into_subdir(self):
236
"""Test bzr mv original_file to versioned_directory/file.
242
"""Test brz mv original_file to versioned_directory/file.
238
244
Tests if a file which has already been moved into a versioned
239
directory by an external tool, is handled correctly by bzr mv.
245
directory by an external tool, is handled correctly by brz mv.
240
246
Setup: a and sub/ are in the working tree.
241
User does: mv a sub/a; bzr mv a sub/a
247
User does: mv a sub/a; brz mv a sub/a
243
249
self.build_tree(['a', 'sub/'])
244
250
tree = self.make_branch_and_tree('.')
247
253
osutils.rename('a', 'sub/a')
248
254
self.run_bzr('mv a sub/a')
249
self.assertMoved('a','sub/a')
255
self.assertMoved('a', 'sub/a')
251
257
def test_mv_already_moved_file_into_unversioned_subdir(self):
252
"""Test bzr mv original_file to unversioned_directory/file.
258
"""Test brz mv original_file to unversioned_directory/file.
254
260
Tests if an attempt to move an existing versioned file
255
261
into an unversioned directory will fail.
256
262
Setup: a is in the working tree, sub/ is not.
257
User does: mv a sub/a; bzr mv a sub/a
263
User does: mv a sub/a; brz mv a sub/a
259
265
self.build_tree(['a', 'sub/'])
260
266
tree = self.make_branch_and_tree('.')
263
269
osutils.rename('a', 'sub/a')
264
270
self.run_bzr_error(
265
["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
271
[b"^brz: ERROR: Could not move a => a: sub is not versioned\\.$"],
267
self.failIfExists('a')
268
self.failUnlessExists('sub/a')
273
self.assertPathDoesNotExist('a')
274
self.assertPathExists('sub/a')
270
276
def test_mv_already_moved_files_into_subdir(self):
271
"""Test bzr mv original_files to versioned_directory.
277
"""Test brz mv original_files to versioned_directory.
273
279
Tests if files which has already been moved into a versioned
274
directory by an external tool, is handled correctly by bzr mv.
280
directory by an external tool, is handled correctly by brz mv.
275
281
Setup: a1, a2, sub are in the working tree.
276
User does: mv a1 sub/.; bzr mv a1 a2 sub
282
User does: mv a1 sub/.; brz mv a1 a2 sub
278
284
self.build_tree(['a1', 'a2', 'sub/'])
279
285
tree = self.make_branch_and_tree('.')
282
288
osutils.rename('a1', 'sub/a1')
283
289
self.run_bzr('mv a1 a2 sub')
284
self.assertMoved('a1','sub/a1')
285
self.assertMoved('a2','sub/a2')
290
self.assertMoved('a1', 'sub/a1')
291
self.assertMoved('a2', 'sub/a2')
287
293
def test_mv_already_moved_files_into_unversioned_subdir(self):
288
"""Test bzr mv original_file to unversioned_directory.
294
"""Test brz mv original_file to unversioned_directory.
290
296
Tests if an attempt to move existing versioned file
291
297
into an unversioned directory will fail.
292
298
Setup: a1, a2 are in the working tree, sub is not.
293
User does: mv a1 sub/.; bzr mv a1 a2 sub
299
User does: mv a1 sub/.; brz mv a1 a2 sub
295
301
self.build_tree(['a1', 'a2', 'sub/'])
296
302
tree = self.make_branch_and_tree('.')
299
305
osutils.rename('a1', 'sub/a1')
300
306
self.run_bzr_error(
301
["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
307
[b"^brz: ERROR: Could not move to sub. sub is not versioned\\.$"],
303
self.failIfExists('a1')
304
self.failUnlessExists('sub/a1')
305
self.failUnlessExists('a2')
306
self.failIfExists('sub/a2')
309
self.assertPathDoesNotExist('a1')
310
self.assertPathExists('sub/a1')
311
self.assertPathExists('a2')
312
self.assertPathDoesNotExist('sub/a2')
308
314
def test_mv_already_moved_file_forcing_after(self):
309
"""Test bzr mv versioned_file to unversioned_file.
315
"""Test brz mv versioned_file to unversioned_file.
311
317
Tests if an attempt to move an existing versioned file to an existing
312
318
unversioned file will fail, informing the user to use the --after
313
319
option to force this.
314
320
Setup: a is in the working tree, b not versioned.
315
User does: mv a b; touch a; bzr mv a b
321
User does: mv a b; touch a; brz mv a b
317
323
self.build_tree(['a', 'b'])
318
324
tree = self.make_branch_and_tree('.')
321
327
osutils.rename('a', 'b')
322
328
self.build_tree(['a']) #touch a
323
329
self.run_bzr_error(
324
["^bzr: ERROR: Could not rename a => b because both files exist."
325
" \(Use --after to tell bzr about a rename that has already"
330
[b"^brz: ERROR: Could not rename a => b because both files exist."
331
b" \\(Use --after to tell brz about a rename that has already"
328
self.failUnlessExists('a')
329
self.failUnlessExists('b')
334
self.assertPathExists('a')
335
self.assertPathExists('b')
331
337
def test_mv_already_moved_file_using_after(self):
332
"""Test bzr mv --after versioned_file to unversioned_file.
338
"""Test brz mv --after versioned_file to unversioned_file.
334
340
Tests if an existing versioned file can be forced to move to an
335
341
existing unversioned file using the --after option. With the result
336
342
that bazaar considers the unversioned_file to be moved from
337
343
versioned_file and versioned_file will become unversioned.
338
344
Setup: a is in the working tree and b exists.
339
User does: mv a b; touch a; bzr mv a b --after
345
User does: mv a b; touch a; brz mv a b --after
340
346
Resulting in a => b and a is unknown.
342
348
self.build_tree(['a', 'b'])
371
377
self.build_tree(['a2']) #touch a2
373
379
self.run_bzr_error(
374
["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
375
" exist. \(Use --after to tell bzr about a rename that has already"
380
[b"^brz: ERROR: Could not rename a1 => sub/a1 because both files"
381
b" exist. \\(Use --after to tell brz about a rename that has already"
378
self.failUnlessExists('a1')
379
self.failUnlessExists('a2')
380
self.failUnlessExists('sub/a1')
381
self.failUnlessExists('sub/a2')
384
self.assertPathExists('a1')
385
self.assertPathExists('a2')
386
self.assertPathExists('sub/a1')
387
self.assertPathExists('sub/a2')
383
389
def test_mv_already_moved_files_using_after(self):
384
"""Test bzr mv --after versioned_file to directory/unversioned_file.
390
"""Test brz mv --after versioned_file to directory/unversioned_file.
386
392
Tests if an existing versioned file can be forced to move to an
387
393
existing unversioned file in some other directory using the --after
402
408
self.build_tree(['a2']) #touch a2
404
410
self.run_bzr('mv a1 a2 sub --after')
405
self.failUnlessExists('a1')
406
self.failUnlessExists('a2')
407
self.failUnlessExists('sub/a1')
408
self.failUnlessExists('sub/a2')
411
self.assertPathExists('a1')
412
self.assertPathExists('a2')
413
self.assertPathExists('sub/a1')
414
self.assertPathExists('sub/a2')
409
415
self.assertInWorkingTree('sub/a1')
410
416
self.assertInWorkingTree('sub/a2')
412
418
def test_mv_already_moved_directory(self):
413
"""Use `bzr mv a b` to mark a directory as renamed.
419
"""Use `brz mv a b` to mark a directory as renamed.
415
421
https://bugs.launchpad.net/bzr/+bug/107967/
444
450
def test_mv_auto(self):
445
451
self.make_abcd_tree()
446
452
out, err = self.run_bzr('mv --auto', working_dir='tree')
447
self.assertEqual(out, '')
448
self.assertEqual(err, 'a => b\nc => d\n')
453
self.assertEqual(out, b'')
454
self.assertEqual(err, b'a => b\nc => d\n')
449
455
tree = workingtree.WorkingTree.open('tree')
450
self.assertIsNot(None, tree.path2id('b'))
451
self.assertIsNot(None, tree.path2id('d'))
456
self.assertTrue(tree.is_versioned('b'))
457
self.assertTrue(tree.is_versioned('d'))
453
459
def test_mv_auto_one_path(self):
454
460
self.make_abcd_tree()
455
461
out, err = self.run_bzr('mv --auto tree')
456
self.assertEqual(out, '')
457
self.assertEqual(err, 'a => b\nc => d\n')
462
self.assertEqual(out, b'')
463
self.assertEqual(err, b'a => b\nc => d\n')
458
464
tree = workingtree.WorkingTree.open('tree')
459
self.assertIsNot(None, tree.path2id('b'))
460
self.assertIsNot(None, tree.path2id('d'))
465
self.assertTrue(tree.is_versioned('b'))
466
self.assertTrue(tree.is_versioned('d'))
462
468
def test_mv_auto_two_paths(self):
463
469
self.make_abcd_tree()
464
470
out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
465
self.assertEqual('bzr: ERROR: Only one path may be specified to'
471
self.assertEqual(b'brz: ERROR: Only one path may be specified to'
468
474
def test_mv_auto_dry_run(self):
469
475
self.make_abcd_tree()
470
476
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')
477
self.assertEqual(out, b'')
478
self.assertEqual(err, b'a => b\nc => d\n')
473
479
tree = workingtree.WorkingTree.open('tree')
474
self.assertIsNot(None, tree.path2id('a'))
475
self.assertIsNot(None, tree.path2id('c'))
480
self.assertTrue(tree.is_versioned('a'))
481
self.assertTrue(tree.is_versioned('c'))
477
483
def test_mv_no_auto_dry_run(self):
478
484
self.make_abcd_tree()
479
485
out, err = self.run_bzr('mv c d --dry-run',
480
486
working_dir='tree', retcode=3)
481
self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
487
self.assertEqual(b'brz: ERROR: --dry-run requires --auto.\n', err)
483
489
def test_mv_auto_after(self):
484
490
self.make_abcd_tree()
485
491
out, err = self.run_bzr('mv --auto --after', working_dir='tree',
487
self.assertEqual('bzr: ERROR: --after cannot be specified with'
493
self.assertEqual(b'brz: ERROR: --after cannot be specified with'
490
496
def test_mv_quiet(self):
491
497
tree = self.make_branch_and_tree('.')
492
498
self.build_tree(['aaa'])
493
499
tree.add(['aaa'])
494
500
out, err = self.run_bzr('mv --quiet aaa bbb')
495
self.assertEqual(out, '')
496
self.assertEqual(err, '')
501
self.assertEqual(out, b'')
502
self.assertEqual(err, b'')
498
504
def test_mv_readonly_lightweight_checkout(self):
499
505
branch = self.make_branch('foo')
500
branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
506
branch = breezy.branch.Branch.open(self.get_readonly_url('foo'))
501
507
tree = branch.create_checkout('tree', lightweight=True)
502
508
self.build_tree(['tree/path'])
504
510
# If this fails, the tree is trying to acquire a branch lock, which it
506
512
self.run_bzr(['mv', 'tree/path', 'tree/path2'])
514
def test_mv_unversioned_non_ascii(self):
515
"""Clear error on mv of an unversioned non-ascii file, see lp:707954"""
516
self.requireFeature(UnicodeFilenameFeature)
517
tree = self.make_branch_and_tree(".")
518
self.build_tree([u"\xA7"])
519
out, err = self.run_bzr_error([b"Could not rename", b"not versioned"],
520
["mv", u"\xA7", "b"])
522
def test_mv_removed_non_ascii(self):
523
"""Clear error on mv of a removed non-ascii file, see lp:898541"""
524
self.requireFeature(UnicodeFilenameFeature)
525
tree = self.make_branch_and_tree(".")
526
self.build_tree([u"\xA7"])
528
tree.commit(u"Adding \xA7")
530
out, err = self.run_bzr_error([b"Could not rename", b"not exist"],
531
["mv", u"\xA7", "b"])