~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_mv.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-28 20:13:31 UTC
  • mfrom: (3658 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3688.
  • Revision ID: john@arbash-meinel.com-20080828201331-dqffxf54l2heokll
Merge bzr.dev 3658

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Test for 'bzr mv'"""
18
18
 
19
19
import os
20
20
 
21
 
import bzrlib.branch
22
21
from bzrlib import (
23
22
    osutils,
24
23
    workingtree,
25
24
    )
26
25
 
27
26
from bzrlib.tests import (
28
 
    TestCaseWithTransport,
29
 
    )
30
 
from bzrlib.tests.features import (
31
27
    CaseInsensitiveFilesystemFeature,
32
28
    SymlinkFeature,
33
 
    UnicodeFilenameFeature,
 
29
    TestCaseWithTransport,
34
30
    )
35
31
 
36
32
 
38
34
 
39
35
    def assertMoved(self,from_path,to_path):
40
36
        """Assert that to_path is existing and versioned but from_path not. """
41
 
        self.assertPathDoesNotExist(from_path)
 
37
        self.failIfExists(from_path)
42
38
        self.assertNotInWorkingTree(from_path)
43
39
 
44
 
        self.assertPathExists(to_path)
 
40
        self.failUnlessExists(to_path)
45
41
        self.assertInWorkingTree(to_path)
46
42
 
47
43
    def test_mv_modes(self):
81
77
 
82
78
    def test_mv_unqualified(self):
83
79
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
84
 
 
 
80
        
85
81
    def test_mv_invalid(self):
86
82
        tree = self.make_branch_and_tree('.')
87
83
        self.build_tree(['test.txt', 'sub1/'])
95
91
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
96
92
             "sub1 is not versioned\.$"],
97
93
            'mv test.txt sub1/hello.txt')
98
 
 
 
94
        
99
95
    def test_mv_dirs(self):
100
96
        tree = self.make_branch_and_tree('.')
101
97
        self.build_tree(['hello.txt', 'sub1/'])
122
118
 
123
119
        os.chdir('sub1/sub2')
124
120
        self.run_bzr('mv ../hello.txt .')
125
 
        self.assertPathExists('./hello.txt')
 
121
        self.failUnlessExists('./hello.txt')
126
122
 
127
123
        os.chdir('..')
128
124
        self.run_bzr('mv sub2/hello.txt .')
232
228
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
233
229
            'mv a b')
234
230
        #check that nothing changed
235
 
        self.assertPathDoesNotExist('a')
236
 
        self.assertPathExists('b')
 
231
        self.failIfExists('a')
 
232
        self.failUnlessExists('b')
237
233
 
238
234
    def test_mv_already_moved_file_into_subdir(self):
239
235
        """Test bzr mv original_file to versioned_directory/file.
267
263
        self.run_bzr_error(
268
264
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
269
265
            'mv a sub/a')
270
 
        self.assertPathDoesNotExist('a')
271
 
        self.assertPathExists('sub/a')
 
266
        self.failIfExists('a')
 
267
        self.failUnlessExists('sub/a')
272
268
 
273
269
    def test_mv_already_moved_files_into_subdir(self):
274
270
        """Test bzr mv original_files to versioned_directory.
303
299
        self.run_bzr_error(
304
300
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
305
301
            'mv a1 a2 sub')
306
 
        self.assertPathDoesNotExist('a1')
307
 
        self.assertPathExists('sub/a1')
308
 
        self.assertPathExists('a2')
309
 
        self.assertPathDoesNotExist('sub/a2')
 
302
        self.failIfExists('a1')
 
303
        self.failUnlessExists('sub/a1')
 
304
        self.failUnlessExists('a2')
 
305
        self.failIfExists('sub/a2')
310
306
 
311
307
    def test_mv_already_moved_file_forcing_after(self):
312
308
        """Test bzr mv versioned_file to unversioned_file.
328
324
             " \(Use --after to tell bzr about a rename that has already"
329
325
             " happened\)$"],
330
326
            'mv a b')
331
 
        self.assertPathExists('a')
332
 
        self.assertPathExists('b')
 
327
        self.failUnlessExists('a')
 
328
        self.failUnlessExists('b')
333
329
 
334
330
    def test_mv_already_moved_file_using_after(self):
335
331
        """Test bzr mv --after versioned_file to unversioned_file.
349
345
        self.build_tree(['a']) #touch a
350
346
 
351
347
        self.run_bzr('mv a b --after')
352
 
        self.assertPathExists('a')
 
348
        self.failUnlessExists('a')
353
349
        self.assertNotInWorkingTree('a')#a should be unknown now.
354
 
        self.assertPathExists('b')
 
350
        self.failUnlessExists('b')
355
351
        self.assertInWorkingTree('b')
356
352
 
357
353
    def test_mv_already_moved_files_forcing_after(self):
378
374
             " exist. \(Use --after to tell bzr about a rename that has already"
379
375
             " happened\)$"],
380
376
            'mv a1 a2 sub')
381
 
        self.assertPathExists('a1')
382
 
        self.assertPathExists('a2')
383
 
        self.assertPathExists('sub/a1')
384
 
        self.assertPathExists('sub/a2')
 
377
        self.failUnlessExists('a1')
 
378
        self.failUnlessExists('a2')
 
379
        self.failUnlessExists('sub/a1')
 
380
        self.failUnlessExists('sub/a2')
385
381
 
386
382
    def test_mv_already_moved_files_using_after(self):
387
383
        """Test bzr mv --after versioned_file to directory/unversioned_file.
405
401
        self.build_tree(['a2']) #touch a2
406
402
 
407
403
        self.run_bzr('mv a1 a2 sub --after')
408
 
        self.assertPathExists('a1')
409
 
        self.assertPathExists('a2')
410
 
        self.assertPathExists('sub/a1')
411
 
        self.assertPathExists('sub/a2')
 
404
        self.failUnlessExists('a1')
 
405
        self.failUnlessExists('a2')
 
406
        self.failUnlessExists('sub/a1')
 
407
        self.failUnlessExists('sub/a2')
412
408
        self.assertInWorkingTree('sub/a1')
413
409
        self.assertInWorkingTree('sub/a2')
414
410
 
424
420
        osutils.rename('c', 'd')
425
421
        # mv a b should work just like it does for already renamed files
426
422
        self.run_bzr('mv a b')
427
 
        self.assertPathDoesNotExist('a')
 
423
        self.failIfExists('a')
428
424
        self.assertNotInWorkingTree('a')
429
 
        self.assertPathExists('b')
 
425
        self.failUnlessExists('b')
430
426
        self.assertInWorkingTree('b')
431
427
        # and --after should work, too (technically it's ignored)
432
428
        self.run_bzr('mv --after c d')
433
 
        self.assertPathDoesNotExist('c')
 
429
        self.failIfExists('c')
434
430
        self.assertNotInWorkingTree('c')
435
 
        self.assertPathExists('d')
 
431
        self.failUnlessExists('d')
436
432
        self.assertInWorkingTree('d')
437
 
 
438
 
    def make_abcd_tree(self):
439
 
        tree = self.make_branch_and_tree('tree')
440
 
        self.build_tree(['tree/a', 'tree/c'])
441
 
        tree.add(['a', 'c'])
442
 
        tree.commit('record old names')
443
 
        osutils.rename('tree/a', 'tree/b')
444
 
        osutils.rename('tree/c', 'tree/d')
445
 
        return tree
446
 
 
447
 
    def test_mv_auto(self):
448
 
        self.make_abcd_tree()
449
 
        out, err = self.run_bzr('mv --auto', working_dir='tree')
450
 
        self.assertEqual(out, '')
451
 
        self.assertEqual(err, 'a => b\nc => d\n')
452
 
        tree = workingtree.WorkingTree.open('tree')
453
 
        self.assertIsNot(None, tree.path2id('b'))
454
 
        self.assertIsNot(None, tree.path2id('d'))
455
 
 
456
 
    def test_mv_auto_one_path(self):
457
 
        self.make_abcd_tree()
458
 
        out, err = self.run_bzr('mv --auto tree')
459
 
        self.assertEqual(out, '')
460
 
        self.assertEqual(err, 'a => b\nc => d\n')
461
 
        tree = workingtree.WorkingTree.open('tree')
462
 
        self.assertIsNot(None, tree.path2id('b'))
463
 
        self.assertIsNot(None, tree.path2id('d'))
464
 
 
465
 
    def test_mv_auto_two_paths(self):
466
 
        self.make_abcd_tree()
467
 
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
468
 
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
469
 
                         ' --auto.\n', err)
470
 
 
471
 
    def test_mv_auto_dry_run(self):
472
 
        self.make_abcd_tree()
473
 
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
474
 
        self.assertEqual(out, '')
475
 
        self.assertEqual(err, 'a => b\nc => d\n')
476
 
        tree = workingtree.WorkingTree.open('tree')
477
 
        self.assertIsNot(None, tree.path2id('a'))
478
 
        self.assertIsNot(None, tree.path2id('c'))
479
 
 
480
 
    def test_mv_no_auto_dry_run(self):
481
 
        self.make_abcd_tree()
482
 
        out, err = self.run_bzr('mv c d --dry-run',
483
 
                                working_dir='tree', retcode=3)
484
 
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
485
 
 
486
 
    def test_mv_auto_after(self):
487
 
        self.make_abcd_tree()
488
 
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
489
 
                                retcode=3)
490
 
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
491
 
                         ' --auto.\n', err)
492
 
 
493
 
    def test_mv_quiet(self):
494
 
        tree = self.make_branch_and_tree('.')
495
 
        self.build_tree(['aaa'])
496
 
        tree.add(['aaa'])
497
 
        out, err = self.run_bzr('mv --quiet aaa bbb')
498
 
        self.assertEqual(out, '')
499
 
        self.assertEqual(err, '')
500
 
 
501
 
    def test_mv_readonly_lightweight_checkout(self):
502
 
        branch = self.make_branch('foo')
503
 
        branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
504
 
        tree = branch.create_checkout('tree', lightweight=True)
505
 
        self.build_tree(['tree/path'])
506
 
        tree.add('path')
507
 
        # If this fails, the tree is trying to acquire a branch lock, which it
508
 
        # shouldn't.
509
 
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])
510
 
 
511
 
    def test_mv_unversioned_non_ascii(self):
512
 
        """Clear error on mv of an unversioned non-ascii file, see lp:707954"""
513
 
        self.requireFeature(UnicodeFilenameFeature)
514
 
        tree = self.make_branch_and_tree(".")
515
 
        self.build_tree([u"\xA7"])
516
 
        out, err = self.run_bzr_error(["Could not rename", "not versioned"],
517
 
            ["mv", u"\xA7", "b"])