~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 11:43:10 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909114310-glw7tv76i5gnx9pt
put rules back in Makefile supporting plain-style docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test for 'bzr mv'"""
18
18
 
19
19
import os
20
20
 
 
21
import bzrlib.branch
21
22
from bzrlib import (
22
23
    osutils,
23
24
    workingtree,
24
25
    )
25
26
 
26
27
from bzrlib.tests import (
 
28
    CaseInsensitiveFilesystemFeature,
 
29
    SymlinkFeature,
27
30
    TestCaseWithTransport,
28
 
    TestSkipped,
29
31
    )
30
32
 
31
33
 
76
78
 
77
79
    def test_mv_unqualified(self):
78
80
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
79
 
        
 
81
 
80
82
    def test_mv_invalid(self):
81
83
        tree = self.make_branch_and_tree('.')
82
84
        self.build_tree(['test.txt', 'sub1/'])
90
92
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
91
93
             "sub1 is not versioned\.$"],
92
94
            'mv test.txt sub1/hello.txt')
93
 
        
 
95
 
94
96
    def test_mv_dirs(self):
95
97
        tree = self.make_branch_and_tree('.')
96
98
        self.build_tree(['hello.txt', 'sub1/'])
124
126
        os.chdir('..')
125
127
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
126
128
 
 
129
    def test_mv_change_case_file(self):
 
130
        # test for bug #77740 (mv unable change filename case on Windows)
 
131
        tree = self.make_branch_and_tree('.')
 
132
        self.build_tree(['test.txt'])
 
133
        tree.add(['test.txt'])
 
134
        self.run_bzr('mv test.txt Test.txt')
 
135
        # we can't use failUnlessExists on case-insensitive filesystem
 
136
        # so try to check shape of the tree
 
137
        shape = sorted(os.listdir(u'.'))
 
138
        self.assertEqual(['.bzr', 'Test.txt'], shape)
 
139
        self.assertInWorkingTree('Test.txt')
 
140
        self.assertNotInWorkingTree('test.txt')
 
141
 
 
142
    def test_mv_change_case_dir(self):
 
143
        tree = self.make_branch_and_tree('.')
 
144
        self.build_tree(['foo/'])
 
145
        tree.add(['foo'])
 
146
        self.run_bzr('mv foo Foo')
 
147
        # we can't use failUnlessExists on case-insensitive filesystem
 
148
        # so try to check shape of the tree
 
149
        shape = sorted(os.listdir(u'.'))
 
150
        self.assertEqual(['.bzr', 'Foo'], shape)
 
151
        self.assertInWorkingTree('Foo')
 
152
        self.assertNotInWorkingTree('foo')
 
153
 
 
154
    def test_mv_change_case_dir_w_files(self):
 
155
        tree = self.make_branch_and_tree('.')
 
156
        self.build_tree(['foo/', 'foo/bar'])
 
157
        tree.add(['foo'])
 
158
        self.run_bzr('mv foo Foo')
 
159
        # we can't use failUnlessExists on case-insensitive filesystem
 
160
        # so try to check shape of the tree
 
161
        shape = sorted(os.listdir(u'.'))
 
162
        self.assertEqual(['.bzr', 'Foo'], shape)
 
163
        self.assertInWorkingTree('Foo')
 
164
        self.assertNotInWorkingTree('foo')
 
165
 
 
166
    def test_mv_file_to_wrong_case_dir(self):
 
167
        self.requireFeature(CaseInsensitiveFilesystemFeature)
 
168
        tree = self.make_branch_and_tree('.')
 
169
        self.build_tree(['foo/', 'bar'])
 
170
        tree.add(['foo', 'bar'])
 
171
        out, err = self.run_bzr('mv bar Foo', retcode=3)
 
172
        self.assertEquals('', out)
 
173
        self.assertEquals(
 
174
            'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
 
175
            err)
 
176
 
127
177
    def test_mv_smoke_aliases(self):
128
178
        # just test that aliases for mv exist, if their behaviour is changed in
129
179
        # the future, then extend the tests.
135
185
        self.run_bzr('rename b a')
136
186
 
137
187
    def test_mv_through_symlinks(self):
138
 
        if not osutils.has_symlinks():
139
 
            raise TestSkipped('Symlinks are not supported on this platform')
 
188
        self.requireFeature(SymlinkFeature)
140
189
        tree = self.make_branch_and_tree('.')
141
190
        self.build_tree(['a/', 'a/b'])
142
191
        os.symlink('a', 'c')
273
322
        self.build_tree(['a']) #touch a
274
323
        self.run_bzr_error(
275
324
            ["^bzr: ERROR: Could not rename a => b because both files exist."
276
 
             " \(Use --after to update the Bazaar id\)$"],
 
325
             " \(Use --after to tell bzr about a rename that has already"
 
326
             " happened\)$"],
277
327
            'mv a b')
278
328
        self.failUnlessExists('a')
279
329
        self.failUnlessExists('b')
321
371
        self.build_tree(['a2']) #touch a2
322
372
 
323
373
        self.run_bzr_error(
324
 
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files exist."
325
 
             " \(Use --after to update the Bazaar id\)$"],
 
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"
 
376
             " happened\)$"],
326
377
            'mv a1 a2 sub')
327
378
        self.failUnlessExists('a1')
328
379
        self.failUnlessExists('a2')
357
408
        self.failUnlessExists('sub/a2')
358
409
        self.assertInWorkingTree('sub/a1')
359
410
        self.assertInWorkingTree('sub/a2')
 
411
 
 
412
    def test_mv_already_moved_directory(self):
 
413
        """Use `bzr mv a b` to mark a directory as renamed.
 
414
 
 
415
        https://bugs.launchpad.net/bzr/+bug/107967/
 
416
        """
 
417
        self.build_tree(['a/', 'c/'])
 
418
        tree = self.make_branch_and_tree('.')
 
419
        tree.add(['a', 'c'])
 
420
        osutils.rename('a', 'b')
 
421
        osutils.rename('c', 'd')
 
422
        # mv a b should work just like it does for already renamed files
 
423
        self.run_bzr('mv a b')
 
424
        self.failIfExists('a')
 
425
        self.assertNotInWorkingTree('a')
 
426
        self.failUnlessExists('b')
 
427
        self.assertInWorkingTree('b')
 
428
        # and --after should work, too (technically it's ignored)
 
429
        self.run_bzr('mv --after c d')
 
430
        self.failIfExists('c')
 
431
        self.assertNotInWorkingTree('c')
 
432
        self.failUnlessExists('d')
 
433
        self.assertInWorkingTree('d')
 
434
 
 
435
    def make_abcd_tree(self):
 
436
        tree = self.make_branch_and_tree('tree')
 
437
        self.build_tree(['tree/a', 'tree/c'])
 
438
        tree.add(['a', 'c'])
 
439
        tree.commit('record old names')
 
440
        osutils.rename('tree/a', 'tree/b')
 
441
        osutils.rename('tree/c', 'tree/d')
 
442
        return tree
 
443
 
 
444
    def test_mv_auto(self):
 
445
        self.make_abcd_tree()
 
446
        out, err = self.run_bzr('mv --auto', working_dir='tree')
 
447
        self.assertEqual(out, '')
 
448
        self.assertEqual(err, 'a => b\nc => d\n')
 
449
        tree = workingtree.WorkingTree.open('tree')
 
450
        self.assertIsNot(None, tree.path2id('b'))
 
451
        self.assertIsNot(None, tree.path2id('d'))
 
452
 
 
453
    def test_mv_auto_one_path(self):
 
454
        self.make_abcd_tree()
 
455
        out, err = self.run_bzr('mv --auto tree')
 
456
        self.assertEqual(out, '')
 
457
        self.assertEqual(err, 'a => b\nc => d\n')
 
458
        tree = workingtree.WorkingTree.open('tree')
 
459
        self.assertIsNot(None, tree.path2id('b'))
 
460
        self.assertIsNot(None, tree.path2id('d'))
 
461
 
 
462
    def test_mv_auto_two_paths(self):
 
463
        self.make_abcd_tree()
 
464
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
 
465
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
 
466
                         ' --auto.\n', err)
 
467
 
 
468
    def test_mv_auto_dry_run(self):
 
469
        self.make_abcd_tree()
 
470
        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')
 
473
        tree = workingtree.WorkingTree.open('tree')
 
474
        self.assertIsNot(None, tree.path2id('a'))
 
475
        self.assertIsNot(None, tree.path2id('c'))
 
476
 
 
477
    def test_mv_no_auto_dry_run(self):
 
478
        self.make_abcd_tree()
 
479
        out, err = self.run_bzr('mv c d --dry-run',
 
480
                                working_dir='tree', retcode=3)
 
481
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
 
482
 
 
483
    def test_mv_auto_after(self):
 
484
        self.make_abcd_tree()
 
485
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
 
486
                                retcode=3)
 
487
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
 
488
                         ' --auto.\n', err)
 
489
 
 
490
    def test_mv_readonly_lightweight_checkout(self):
 
491
        branch = self.make_branch('foo')
 
492
        branch = bzrlib.branch.Branch.open('readonly+' + branch.base)
 
493
        tree = branch.create_checkout('tree', lightweight=True)
 
494
        self.build_tree(['tree/path'])
 
495
        tree.add('path')
 
496
        # If this fails, the tree is trying to acquire a branch lock, which it
 
497
        # shouldn't.
 
498
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])