~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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., 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
    TestCaseWithTransport,
 
29
    )
 
30
from bzrlib.tests.features import (
27
31
    CaseInsensitiveFilesystemFeature,
28
32
    SymlinkFeature,
29
 
    TestCaseWithTransport,
 
33
    UnicodeFilenameFeature,
30
34
    )
31
35
 
32
36
 
34
38
 
35
39
    def assertMoved(self,from_path,to_path):
36
40
        """Assert that to_path is existing and versioned but from_path not. """
37
 
        self.failIfExists(from_path)
 
41
        self.assertPathDoesNotExist(from_path)
38
42
        self.assertNotInWorkingTree(from_path)
39
43
 
40
 
        self.failUnlessExists(to_path)
 
44
        self.assertPathExists(to_path)
41
45
        self.assertInWorkingTree(to_path)
42
46
 
43
47
    def test_mv_modes(self):
77
81
 
78
82
    def test_mv_unqualified(self):
79
83
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
80
 
        
 
84
 
81
85
    def test_mv_invalid(self):
82
86
        tree = self.make_branch_and_tree('.')
83
87
        self.build_tree(['test.txt', 'sub1/'])
91
95
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
92
96
             "sub1 is not versioned\.$"],
93
97
            'mv test.txt sub1/hello.txt')
94
 
        
 
98
 
95
99
    def test_mv_dirs(self):
96
100
        tree = self.make_branch_and_tree('.')
97
101
        self.build_tree(['hello.txt', 'sub1/'])
118
122
 
119
123
        os.chdir('sub1/sub2')
120
124
        self.run_bzr('mv ../hello.txt .')
121
 
        self.failUnlessExists('./hello.txt')
 
125
        self.assertPathExists('./hello.txt')
122
126
 
123
127
        os.chdir('..')
124
128
        self.run_bzr('mv sub2/hello.txt .')
228
232
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
229
233
            'mv a b')
230
234
        #check that nothing changed
231
 
        self.failIfExists('a')
232
 
        self.failUnlessExists('b')
 
235
        self.assertPathDoesNotExist('a')
 
236
        self.assertPathExists('b')
233
237
 
234
238
    def test_mv_already_moved_file_into_subdir(self):
235
239
        """Test bzr mv original_file to versioned_directory/file.
263
267
        self.run_bzr_error(
264
268
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
265
269
            'mv a sub/a')
266
 
        self.failIfExists('a')
267
 
        self.failUnlessExists('sub/a')
 
270
        self.assertPathDoesNotExist('a')
 
271
        self.assertPathExists('sub/a')
268
272
 
269
273
    def test_mv_already_moved_files_into_subdir(self):
270
274
        """Test bzr mv original_files to versioned_directory.
299
303
        self.run_bzr_error(
300
304
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
301
305
            'mv a1 a2 sub')
302
 
        self.failIfExists('a1')
303
 
        self.failUnlessExists('sub/a1')
304
 
        self.failUnlessExists('a2')
305
 
        self.failIfExists('sub/a2')
 
306
        self.assertPathDoesNotExist('a1')
 
307
        self.assertPathExists('sub/a1')
 
308
        self.assertPathExists('a2')
 
309
        self.assertPathDoesNotExist('sub/a2')
306
310
 
307
311
    def test_mv_already_moved_file_forcing_after(self):
308
312
        """Test bzr mv versioned_file to unversioned_file.
324
328
             " \(Use --after to tell bzr about a rename that has already"
325
329
             " happened\)$"],
326
330
            'mv a b')
327
 
        self.failUnlessExists('a')
328
 
        self.failUnlessExists('b')
 
331
        self.assertPathExists('a')
 
332
        self.assertPathExists('b')
329
333
 
330
334
    def test_mv_already_moved_file_using_after(self):
331
335
        """Test bzr mv --after versioned_file to unversioned_file.
345
349
        self.build_tree(['a']) #touch a
346
350
 
347
351
        self.run_bzr('mv a b --after')
348
 
        self.failUnlessExists('a')
 
352
        self.assertPathExists('a')
349
353
        self.assertNotInWorkingTree('a')#a should be unknown now.
350
 
        self.failUnlessExists('b')
 
354
        self.assertPathExists('b')
351
355
        self.assertInWorkingTree('b')
352
356
 
353
357
    def test_mv_already_moved_files_forcing_after(self):
374
378
             " exist. \(Use --after to tell bzr about a rename that has already"
375
379
             " happened\)$"],
376
380
            'mv a1 a2 sub')
377
 
        self.failUnlessExists('a1')
378
 
        self.failUnlessExists('a2')
379
 
        self.failUnlessExists('sub/a1')
380
 
        self.failUnlessExists('sub/a2')
 
381
        self.assertPathExists('a1')
 
382
        self.assertPathExists('a2')
 
383
        self.assertPathExists('sub/a1')
 
384
        self.assertPathExists('sub/a2')
381
385
 
382
386
    def test_mv_already_moved_files_using_after(self):
383
387
        """Test bzr mv --after versioned_file to directory/unversioned_file.
401
405
        self.build_tree(['a2']) #touch a2
402
406
 
403
407
        self.run_bzr('mv a1 a2 sub --after')
404
 
        self.failUnlessExists('a1')
405
 
        self.failUnlessExists('a2')
406
 
        self.failUnlessExists('sub/a1')
407
 
        self.failUnlessExists('sub/a2')
 
408
        self.assertPathExists('a1')
 
409
        self.assertPathExists('a2')
 
410
        self.assertPathExists('sub/a1')
 
411
        self.assertPathExists('sub/a2')
408
412
        self.assertInWorkingTree('sub/a1')
409
413
        self.assertInWorkingTree('sub/a2')
410
414
 
420
424
        osutils.rename('c', 'd')
421
425
        # mv a b should work just like it does for already renamed files
422
426
        self.run_bzr('mv a b')
423
 
        self.failIfExists('a')
 
427
        self.assertPathDoesNotExist('a')
424
428
        self.assertNotInWorkingTree('a')
425
 
        self.failUnlessExists('b')
 
429
        self.assertPathExists('b')
426
430
        self.assertInWorkingTree('b')
427
431
        # and --after should work, too (technically it's ignored)
428
432
        self.run_bzr('mv --after c d')
429
 
        self.failIfExists('c')
 
433
        self.assertPathDoesNotExist('c')
430
434
        self.assertNotInWorkingTree('c')
431
 
        self.failUnlessExists('d')
 
435
        self.assertPathExists('d')
432
436
        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"])