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
["^brz: ERROR: Could not rename unversioned.txt => elsewhere."
73
" .*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
["^brz: ERROR: Could not rename doesnotexist => somewhereelse."
79
" .*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(['^brz: ERROR: missing file argument$'], 'mv')
82
85
def test_mv_invalid(self):
83
86
tree = self.make_branch_and_tree('.')
85
88
tree.add(['test.txt'])
87
90
self.run_bzr_error(
88
["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
91
["^brz: ERROR: Could not move to sub1: sub1 is not versioned\\.$"],
89
92
'mv test.txt sub1')
91
94
self.run_bzr_error(
92
["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
93
"sub1 is not versioned\.$"],
95
["^brz: ERROR: Could not move test.txt => .*hello.txt: "
96
"sub1 is not versioned\\.$"],
94
97
'mv test.txt sub1/hello.txt')
96
99
def test_mv_dirs(self):
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)
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.assertEquals('', out)
174
'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
172
self.assertEqual('', out)
174
'brz: ERROR: Could not move to Foo: Foo is not versioned.\n',
177
177
def test_mv_smoke_aliases(self):
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
["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('.')
210
216
osutils.rename('a', 'b')
211
217
self.run_bzr('mv a b')
212
self.assertMoved('a','b')
218
self.assertMoved('a', 'b')
214
220
def test_mv_already_moved_file_to_versioned_target(self):
215
"""Test bzr mv existing_file to versioned_file.
221
"""Test brz mv existing_file to versioned_file.
217
223
Tests if an attempt to move an existing versioned file
218
224
to another versiond file will fail.
219
225
Setup: a and b are in the working tree.
220
User does: rm b; mv a b; bzr mv a b
226
User does: rm b; mv a b; brz mv a b
222
228
self.build_tree(['a', 'b'])
223
229
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
["^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
["^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
["^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
["^brz: ERROR: Could not rename a => b because both files exist."
331
" \\(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'])
346
352
self.build_tree(['a']) #touch a
348
354
self.run_bzr('mv a b --after')
349
self.failUnlessExists('a')
355
self.assertPathExists('a')
350
356
self.assertNotInWorkingTree('a')#a should be unknown now.
351
self.failUnlessExists('b')
357
self.assertPathExists('b')
352
358
self.assertInWorkingTree('b')
354
360
def test_mv_already_moved_files_forcing_after(self):
355
"""Test bzr mv versioned_files to directory/unversioned_file.
361
"""Test brz mv versioned_files to directory/unversioned_file.
357
363
Tests if an attempt to move an existing versioned file to an existing
358
364
unversioned file in some other directory will fail, informing the user
361
367
Setup: a1, a2, sub are versioned and in the working tree,
362
368
sub/a1, sub/a2 are in working tree.
363
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
369
User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub
365
371
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
366
372
tree = self.make_branch_and_tree('.')
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
["^brz: ERROR: Could not rename a1 => sub/a1 because both files"
381
" 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
392
398
Setup: a1, a2, sub are versioned and in the working tree,
393
399
sub/a1, sub/a2 are in working tree.
394
User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
400
User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub --after
396
402
self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
397
403
tree = self.make_branch_and_tree('.')
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/
421
427
osutils.rename('c', 'd')
422
428
# mv a b should work just like it does for already renamed files
423
429
self.run_bzr('mv a b')
424
self.failIfExists('a')
430
self.assertPathDoesNotExist('a')
425
431
self.assertNotInWorkingTree('a')
426
self.failUnlessExists('b')
432
self.assertPathExists('b')
427
433
self.assertInWorkingTree('b')
428
434
# and --after should work, too (technically it's ignored)
429
435
self.run_bzr('mv --after c d')
430
self.failIfExists('c')
436
self.assertPathDoesNotExist('c')
431
437
self.assertNotInWorkingTree('c')
432
self.failUnlessExists('d')
438
self.assertPathExists('d')
433
439
self.assertInWorkingTree('d')
435
441
def make_abcd_tree(self):
447
453
self.assertEqual(out, '')
448
454
self.assertEqual(err, '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()
456
462
self.assertEqual(out, '')
457
463
self.assertEqual(err, '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('brz: ERROR: Only one path may be specified to'
466
472
' --auto.\n', err)
468
474
def test_mv_auto_dry_run(self):
471
477
self.assertEqual(out, '')
472
478
self.assertEqual(err, '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('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('brz: ERROR: --after cannot be specified with'
488
494
' --auto.\n', err)
490
496
def test_mv_quiet(self):
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(["Could not rename", "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(["Could not rename", "not exist"],
531
["mv", u"\xA7", "b"])