~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jonathan Lange
  • Date: 2012-10-22 15:51:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6571.
  • Revision ID: jml@canonical.com-20121022155131-vmkbs89a8kpdsxju
Document the behaviour

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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
25
25
    )
26
26
 
27
27
from bzrlib.tests import (
 
28
    TestCaseWithTransport,
 
29
    )
 
30
from bzrlib.tests.features import (
28
31
    CaseInsensitiveFilesystemFeature,
29
32
    SymlinkFeature,
30
 
    TestCaseWithTransport,
 
33
    UnicodeFilenameFeature,
31
34
    )
32
35
 
33
36
 
35
38
 
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)
40
43
 
41
 
        self.failUnlessExists(to_path)
 
44
        self.assertPathExists(to_path)
42
45
        self.assertInWorkingTree(to_path)
43
46
 
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'])
119
122
 
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')
123
125
 
124
 
        os.chdir('..')
125
 
        self.run_bzr('mv sub2/hello.txt .')
126
 
        os.chdir('..')
 
126
        self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
127
127
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
128
128
 
129
129
    def test_mv_change_case_file(self):
184
184
        self.run_bzr('move a b')
185
185
        self.run_bzr('rename b a')
186
186
 
 
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
 
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\.$"],
230
236
            'mv a b')
231
237
        #check that nothing changed
232
 
        self.failIfExists('a')
233
 
        self.failUnlessExists('b')
 
238
        self.assertPathDoesNotExist('a')
 
239
        self.assertPathExists('b')
234
240
 
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\.$"],
266
272
            'mv a sub/a')
267
 
        self.failIfExists('a')
268
 
        self.failUnlessExists('sub/a')
 
273
        self.assertPathDoesNotExist('a')
 
274
        self.assertPathExists('sub/a')
269
275
 
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\.$"],
302
308
            'mv a1 a2 sub')
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')
307
313
 
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"
326
332
             " happened\)$"],
327
333
            'mv a b')
328
 
        self.failUnlessExists('a')
329
 
        self.failUnlessExists('b')
 
334
        self.assertPathExists('a')
 
335
        self.assertPathExists('b')
330
336
 
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
347
353
 
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')
353
359
 
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"
376
382
             " happened\)$"],
377
383
            'mv a1 a2 sub')
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')
382
388
 
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
403
409
 
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')
411
417
 
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')
434
440
 
435
441
    def make_abcd_tree(self):
504
510
        # If this fails, the tree is trying to acquire a branch lock, which it
505
511
        # shouldn't.
506
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"])