1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
from bzrlib.tests import (
27
from brzlib.tests import (
28
TestCaseWithTransport,
30
from brzlib.tests.features import (
28
31
CaseInsensitiveFilesystemFeature,
30
TestCaseWithTransport,
33
UnicodeFilenameFeature,
36
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):
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 .')
126
self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
127
127
self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
129
129
def test_mv_change_case_file(self):
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)
172
self.assertEqual('', out)
174
174
'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
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
["bzr: 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('.')
229
235
["^bzr: 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
242
"""Test bzr mv original_file to versioned_directory/file.
264
270
self.run_bzr_error(
265
271
["^bzr: 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
277
"""Test bzr mv original_files to versioned_directory.
300
306
self.run_bzr_error(
301
307
["^bzr: 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
315
"""Test bzr mv versioned_file to unversioned_file.
325
331
" \(Use --after to tell bzr 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
338
"""Test bzr mv --after versioned_file to unversioned_file.
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):
375
381
" exist. \(Use --after to tell bzr 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
390
"""Test bzr mv --after versioned_file to directory/unversioned_file.
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')
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):
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 = brzlib.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"])