~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-03 22:30:56 UTC
  • mfrom: (3644.2.13 index_builder_cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20080903223056-b108iytb38xkznci
(jam) Streamline BTreeBuilder.add_node et al to make btree creation
        faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 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/'])
120
116
        tree = self.make_branch_and_tree('.')
121
117
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
122
118
 
123
 
        self.run_bzr('mv ../hello.txt .', working_dir='sub1/sub2')
124
 
        self.assertPathExists('sub1/sub2/hello.txt')
 
119
        os.chdir('sub1/sub2')
 
120
        self.run_bzr('mv ../hello.txt .')
 
121
        self.failUnlessExists('./hello.txt')
125
122
 
126
 
        self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
 
123
        os.chdir('..')
 
124
        self.run_bzr('mv sub2/hello.txt .')
 
125
        os.chdir('..')
127
126
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
128
127
 
129
128
    def test_mv_change_case_file(self):
169
168
        self.build_tree(['foo/', 'bar'])
170
169
        tree.add(['foo', 'bar'])
171
170
        out, err = self.run_bzr('mv bar Foo', retcode=3)
172
 
        self.assertEqual('', out)
173
 
        self.assertEqual(
 
171
        self.assertEquals('', out)
 
172
        self.assertEquals(
174
173
            'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
175
174
            err)
176
175
 
184
183
        self.run_bzr('move a b')
185
184
        self.run_bzr('rename b a')
186
185
 
187
 
    def test_mv_no_root(self):
188
 
        tree = self.make_branch_and_tree('.')
189
 
        self.run_bzr_error(
190
 
            ["bzr: ERROR: can not move root of branch"],
191
 
            'mv . a')
192
 
 
193
186
    def test_mv_through_symlinks(self):
194
187
        self.requireFeature(SymlinkFeature)
195
188
        tree = self.make_branch_and_tree('.')
235
228
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
236
229
            'mv a b')
237
230
        #check that nothing changed
238
 
        self.assertPathDoesNotExist('a')
239
 
        self.assertPathExists('b')
 
231
        self.failIfExists('a')
 
232
        self.failUnlessExists('b')
240
233
 
241
234
    def test_mv_already_moved_file_into_subdir(self):
242
235
        """Test bzr mv original_file to versioned_directory/file.
270
263
        self.run_bzr_error(
271
264
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
272
265
            'mv a sub/a')
273
 
        self.assertPathDoesNotExist('a')
274
 
        self.assertPathExists('sub/a')
 
266
        self.failIfExists('a')
 
267
        self.failUnlessExists('sub/a')
275
268
 
276
269
    def test_mv_already_moved_files_into_subdir(self):
277
270
        """Test bzr mv original_files to versioned_directory.
306
299
        self.run_bzr_error(
307
300
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
308
301
            'mv a1 a2 sub')
309
 
        self.assertPathDoesNotExist('a1')
310
 
        self.assertPathExists('sub/a1')
311
 
        self.assertPathExists('a2')
312
 
        self.assertPathDoesNotExist('sub/a2')
 
302
        self.failIfExists('a1')
 
303
        self.failUnlessExists('sub/a1')
 
304
        self.failUnlessExists('a2')
 
305
        self.failIfExists('sub/a2')
313
306
 
314
307
    def test_mv_already_moved_file_forcing_after(self):
315
308
        """Test bzr mv versioned_file to unversioned_file.
331
324
             " \(Use --after to tell bzr about a rename that has already"
332
325
             " happened\)$"],
333
326
            'mv a b')
334
 
        self.assertPathExists('a')
335
 
        self.assertPathExists('b')
 
327
        self.failUnlessExists('a')
 
328
        self.failUnlessExists('b')
336
329
 
337
330
    def test_mv_already_moved_file_using_after(self):
338
331
        """Test bzr mv --after versioned_file to unversioned_file.
352
345
        self.build_tree(['a']) #touch a
353
346
 
354
347
        self.run_bzr('mv a b --after')
355
 
        self.assertPathExists('a')
 
348
        self.failUnlessExists('a')
356
349
        self.assertNotInWorkingTree('a')#a should be unknown now.
357
 
        self.assertPathExists('b')
 
350
        self.failUnlessExists('b')
358
351
        self.assertInWorkingTree('b')
359
352
 
360
353
    def test_mv_already_moved_files_forcing_after(self):
381
374
             " exist. \(Use --after to tell bzr about a rename that has already"
382
375
             " happened\)$"],
383
376
            'mv a1 a2 sub')
384
 
        self.assertPathExists('a1')
385
 
        self.assertPathExists('a2')
386
 
        self.assertPathExists('sub/a1')
387
 
        self.assertPathExists('sub/a2')
 
377
        self.failUnlessExists('a1')
 
378
        self.failUnlessExists('a2')
 
379
        self.failUnlessExists('sub/a1')
 
380
        self.failUnlessExists('sub/a2')
388
381
 
389
382
    def test_mv_already_moved_files_using_after(self):
390
383
        """Test bzr mv --after versioned_file to directory/unversioned_file.
408
401
        self.build_tree(['a2']) #touch a2
409
402
 
410
403
        self.run_bzr('mv a1 a2 sub --after')
411
 
        self.assertPathExists('a1')
412
 
        self.assertPathExists('a2')
413
 
        self.assertPathExists('sub/a1')
414
 
        self.assertPathExists('sub/a2')
 
404
        self.failUnlessExists('a1')
 
405
        self.failUnlessExists('a2')
 
406
        self.failUnlessExists('sub/a1')
 
407
        self.failUnlessExists('sub/a2')
415
408
        self.assertInWorkingTree('sub/a1')
416
409
        self.assertInWorkingTree('sub/a2')
417
410
 
427
420
        osutils.rename('c', 'd')
428
421
        # mv a b should work just like it does for already renamed files
429
422
        self.run_bzr('mv a b')
430
 
        self.assertPathDoesNotExist('a')
 
423
        self.failIfExists('a')
431
424
        self.assertNotInWorkingTree('a')
432
 
        self.assertPathExists('b')
 
425
        self.failUnlessExists('b')
433
426
        self.assertInWorkingTree('b')
434
427
        # and --after should work, too (technically it's ignored)
435
428
        self.run_bzr('mv --after c d')
436
 
        self.assertPathDoesNotExist('c')
 
429
        self.failIfExists('c')
437
430
        self.assertNotInWorkingTree('c')
438
 
        self.assertPathExists('d')
 
431
        self.failUnlessExists('d')
439
432
        self.assertInWorkingTree('d')
440
 
 
441
 
    def make_abcd_tree(self):
442
 
        tree = self.make_branch_and_tree('tree')
443
 
        self.build_tree(['tree/a', 'tree/c'])
444
 
        tree.add(['a', 'c'])
445
 
        tree.commit('record old names')
446
 
        osutils.rename('tree/a', 'tree/b')
447
 
        osutils.rename('tree/c', 'tree/d')
448
 
        return tree
449
 
 
450
 
    def test_mv_auto(self):
451
 
        self.make_abcd_tree()
452
 
        out, err = self.run_bzr('mv --auto', working_dir='tree')
453
 
        self.assertEqual(out, '')
454
 
        self.assertEqual(err, 'a => b\nc => d\n')
455
 
        tree = workingtree.WorkingTree.open('tree')
456
 
        self.assertIsNot(None, tree.path2id('b'))
457
 
        self.assertIsNot(None, tree.path2id('d'))
458
 
 
459
 
    def test_mv_auto_one_path(self):
460
 
        self.make_abcd_tree()
461
 
        out, err = self.run_bzr('mv --auto tree')
462
 
        self.assertEqual(out, '')
463
 
        self.assertEqual(err, 'a => b\nc => d\n')
464
 
        tree = workingtree.WorkingTree.open('tree')
465
 
        self.assertIsNot(None, tree.path2id('b'))
466
 
        self.assertIsNot(None, tree.path2id('d'))
467
 
 
468
 
    def test_mv_auto_two_paths(self):
469
 
        self.make_abcd_tree()
470
 
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
471
 
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
472
 
                         ' --auto.\n', err)
473
 
 
474
 
    def test_mv_auto_dry_run(self):
475
 
        self.make_abcd_tree()
476
 
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
477
 
        self.assertEqual(out, '')
478
 
        self.assertEqual(err, 'a => b\nc => d\n')
479
 
        tree = workingtree.WorkingTree.open('tree')
480
 
        self.assertIsNot(None, tree.path2id('a'))
481
 
        self.assertIsNot(None, tree.path2id('c'))
482
 
 
483
 
    def test_mv_no_auto_dry_run(self):
484
 
        self.make_abcd_tree()
485
 
        out, err = self.run_bzr('mv c d --dry-run',
486
 
                                working_dir='tree', retcode=3)
487
 
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
488
 
 
489
 
    def test_mv_auto_after(self):
490
 
        self.make_abcd_tree()
491
 
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
492
 
                                retcode=3)
493
 
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
494
 
                         ' --auto.\n', err)
495
 
 
496
 
    def test_mv_quiet(self):
497
 
        tree = self.make_branch_and_tree('.')
498
 
        self.build_tree(['aaa'])
499
 
        tree.add(['aaa'])
500
 
        out, err = self.run_bzr('mv --quiet aaa bbb')
501
 
        self.assertEqual(out, '')
502
 
        self.assertEqual(err, '')
503
 
 
504
 
    def test_mv_readonly_lightweight_checkout(self):
505
 
        branch = self.make_branch('foo')
506
 
        branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
507
 
        tree = branch.create_checkout('tree', lightweight=True)
508
 
        self.build_tree(['tree/path'])
509
 
        tree.add('path')
510
 
        # If this fails, the tree is trying to acquire a branch lock, which it
511
 
        # shouldn't.
512
 
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])
513
 
 
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"])
521
 
 
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"])
527
 
        tree.add([u"\xA7"])
528
 
        tree.commit(u"Adding \xA7")
529
 
        os.remove(u"\xA7")
530
 
        out, err = self.run_bzr_error(["Could not rename", "not exist"],
531
 
            ["mv", u"\xA7", "b"])