~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: 2007-08-09 15:19:06 UTC
  • mfrom: (2681.1.7 send-bundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070809151906-hdn9oyslf2qib2op
Allow omitting -o for bundle, add --format

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., 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
 
24
24
    )
25
25
 
26
26
from bzrlib.tests import (
27
 
    CaseInsensitiveFilesystemFeature,
28
 
    SymlinkFeature,
29
27
    TestCaseWithTransport,
 
28
    TestSkipped,
30
29
    )
31
30
 
32
31
 
66
65
        self.build_tree(['unversioned.txt'])
67
66
        self.run_bzr_error(
68
67
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
69
 
             " .*unversioned.txt is not versioned\.$"],
 
68
             " .*unversioned.txt is not versioned$"],
70
69
            'mv unversioned.txt elsewhere')
71
70
 
72
71
    def test_mv_nonexisting(self):
73
72
        self.run_bzr_error(
74
73
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
75
 
             " .*doesnotexist is not versioned\.$"],
 
74
             " .*doesnotexist is not versioned$"],
76
75
            'mv doesnotexist somewhereelse')
77
76
 
78
77
    def test_mv_unqualified(self):
79
78
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
80
 
 
 
79
        
81
80
    def test_mv_invalid(self):
82
81
        tree = self.make_branch_and_tree('.')
83
82
        self.build_tree(['test.txt', 'sub1/'])
84
83
        tree.add(['test.txt'])
85
84
 
86
85
        self.run_bzr_error(
87
 
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
 
86
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
88
87
            'mv test.txt sub1')
89
88
 
90
89
        self.run_bzr_error(
91
90
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
92
 
             "sub1 is not versioned\.$"],
 
91
             "sub1 is not versioned$"],
93
92
            'mv test.txt sub1/hello.txt')
94
 
 
 
93
        
95
94
    def test_mv_dirs(self):
96
95
        tree = self.make_branch_and_tree('.')
97
96
        self.build_tree(['hello.txt', 'sub1/'])
125
124
        os.chdir('..')
126
125
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
127
126
 
128
 
    def test_mv_change_case_file(self):
129
 
        # test for bug #77740 (mv unable change filename case on Windows)
130
 
        tree = self.make_branch_and_tree('.')
131
 
        self.build_tree(['test.txt'])
132
 
        tree.add(['test.txt'])
133
 
        self.run_bzr('mv test.txt Test.txt')
134
 
        # we can't use failUnlessExists on case-insensitive filesystem
135
 
        # so try to check shape of the tree
136
 
        shape = sorted(os.listdir(u'.'))
137
 
        self.assertEqual(['.bzr', 'Test.txt'], shape)
138
 
        self.assertInWorkingTree('Test.txt')
139
 
        self.assertNotInWorkingTree('test.txt')
140
 
 
141
 
    def test_mv_change_case_dir(self):
142
 
        tree = self.make_branch_and_tree('.')
143
 
        self.build_tree(['foo/'])
144
 
        tree.add(['foo'])
145
 
        self.run_bzr('mv foo Foo')
146
 
        # we can't use failUnlessExists on case-insensitive filesystem
147
 
        # so try to check shape of the tree
148
 
        shape = sorted(os.listdir(u'.'))
149
 
        self.assertEqual(['.bzr', 'Foo'], shape)
150
 
        self.assertInWorkingTree('Foo')
151
 
        self.assertNotInWorkingTree('foo')
152
 
 
153
 
    def test_mv_change_case_dir_w_files(self):
154
 
        tree = self.make_branch_and_tree('.')
155
 
        self.build_tree(['foo/', 'foo/bar'])
156
 
        tree.add(['foo'])
157
 
        self.run_bzr('mv foo Foo')
158
 
        # we can't use failUnlessExists on case-insensitive filesystem
159
 
        # so try to check shape of the tree
160
 
        shape = sorted(os.listdir(u'.'))
161
 
        self.assertEqual(['.bzr', 'Foo'], shape)
162
 
        self.assertInWorkingTree('Foo')
163
 
        self.assertNotInWorkingTree('foo')
164
 
 
165
 
    def test_mv_file_to_wrong_case_dir(self):
166
 
        self.requireFeature(CaseInsensitiveFilesystemFeature)
167
 
        tree = self.make_branch_and_tree('.')
168
 
        self.build_tree(['foo/', 'bar'])
169
 
        tree.add(['foo', 'bar'])
170
 
        out, err = self.run_bzr('mv bar Foo', retcode=3)
171
 
        self.assertEquals('', out)
172
 
        self.assertEquals(
173
 
            'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
174
 
            err)
175
 
 
176
127
    def test_mv_smoke_aliases(self):
177
128
        # just test that aliases for mv exist, if their behaviour is changed in
178
129
        # the future, then extend the tests.
184
135
        self.run_bzr('rename b a')
185
136
 
186
137
    def test_mv_through_symlinks(self):
187
 
        self.requireFeature(SymlinkFeature)
 
138
        if not osutils.has_symlinks():
 
139
            raise TestSkipped('Symlinks are not supported on this platform')
188
140
        tree = self.make_branch_and_tree('.')
189
141
        self.build_tree(['a/', 'a/b'])
190
142
        os.symlink('a', 'c')
225
177
        os.remove('b')
226
178
        osutils.rename('a', 'b')
227
179
        self.run_bzr_error(
228
 
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
 
180
            ["^bzr: ERROR: Could not move a => b. b is already versioned$"],
229
181
            'mv a b')
230
182
        #check that nothing changed
231
183
        self.failIfExists('a')
261
213
 
262
214
        osutils.rename('a', 'sub/a')
263
215
        self.run_bzr_error(
264
 
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
 
216
            ["^bzr: ERROR: Could not move a => a: sub is not versioned$"],
265
217
            'mv a sub/a')
266
218
        self.failIfExists('a')
267
219
        self.failUnlessExists('sub/a')
297
249
 
298
250
        osutils.rename('a1', 'sub/a1')
299
251
        self.run_bzr_error(
300
 
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
 
252
            ["^bzr: ERROR: Could not move to sub. sub is not versioned$"],
301
253
            'mv a1 a2 sub')
302
254
        self.failIfExists('a1')
303
255
        self.failUnlessExists('sub/a1')
321
273
        self.build_tree(['a']) #touch a
322
274
        self.run_bzr_error(
323
275
            ["^bzr: ERROR: Could not rename a => b because both files exist."
324
 
             " \(Use --after to tell bzr about a rename that has already"
325
 
             " happened\)$"],
 
276
             " \(Use --after to update the Bazaar id\)$"],
326
277
            'mv a b')
327
278
        self.failUnlessExists('a')
328
279
        self.failUnlessExists('b')
370
321
        self.build_tree(['a2']) #touch a2
371
322
 
372
323
        self.run_bzr_error(
373
 
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
374
 
             " exist. \(Use --after to tell bzr about a rename that has already"
375
 
             " happened\)$"],
 
324
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files exist."
 
325
             " \(Use --after to update the Bazaar id\)$"],
376
326
            'mv a1 a2 sub')
377
327
        self.failUnlessExists('a1')
378
328
        self.failUnlessExists('a2')
407
357
        self.failUnlessExists('sub/a2')
408
358
        self.assertInWorkingTree('sub/a1')
409
359
        self.assertInWorkingTree('sub/a2')
410
 
 
411
 
    def test_mv_already_moved_directory(self):
412
 
        """Use `bzr mv a b` to mark a directory as renamed.
413
 
 
414
 
        https://bugs.launchpad.net/bzr/+bug/107967/
415
 
        """
416
 
        self.build_tree(['a/', 'c/'])
417
 
        tree = self.make_branch_and_tree('.')
418
 
        tree.add(['a', 'c'])
419
 
        osutils.rename('a', 'b')
420
 
        osutils.rename('c', 'd')
421
 
        # mv a b should work just like it does for already renamed files
422
 
        self.run_bzr('mv a b')
423
 
        self.failIfExists('a')
424
 
        self.assertNotInWorkingTree('a')
425
 
        self.failUnlessExists('b')
426
 
        self.assertInWorkingTree('b')
427
 
        # and --after should work, too (technically it's ignored)
428
 
        self.run_bzr('mv --after c d')
429
 
        self.failIfExists('c')
430
 
        self.assertNotInWorkingTree('c')
431
 
        self.failUnlessExists('d')
432
 
        self.assertInWorkingTree('d')
433
 
 
434
 
    def make_abcd_tree(self):
435
 
        tree = self.make_branch_and_tree('tree')
436
 
        self.build_tree(['tree/a', 'tree/c'])
437
 
        tree.add(['a', 'c'])
438
 
        tree.commit('record old names')
439
 
        osutils.rename('tree/a', 'tree/b')
440
 
        osutils.rename('tree/c', 'tree/d')
441
 
        return tree
442
 
 
443
 
    def test_mv_auto(self):
444
 
        self.make_abcd_tree()
445
 
        out, err = self.run_bzr('mv --auto', working_dir='tree')
446
 
        self.assertEqual(out, '')
447
 
        self.assertEqual(err, 'a => b\nc => d\n')
448
 
        tree = workingtree.WorkingTree.open('tree')
449
 
        self.assertIsNot(None, tree.path2id('b'))
450
 
        self.assertIsNot(None, tree.path2id('d'))
451
 
 
452
 
    def test_mv_auto_one_path(self):
453
 
        self.make_abcd_tree()
454
 
        out, err = self.run_bzr('mv --auto tree')
455
 
        self.assertEqual(out, '')
456
 
        self.assertEqual(err, 'a => b\nc => d\n')
457
 
        tree = workingtree.WorkingTree.open('tree')
458
 
        self.assertIsNot(None, tree.path2id('b'))
459
 
        self.assertIsNot(None, tree.path2id('d'))
460
 
 
461
 
    def test_mv_auto_two_paths(self):
462
 
        self.make_abcd_tree()
463
 
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
464
 
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
465
 
                         ' --auto.\n', err)
466
 
 
467
 
    def test_mv_auto_dry_run(self):
468
 
        self.make_abcd_tree()
469
 
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
470
 
        self.assertEqual(out, '')
471
 
        self.assertEqual(err, 'a => b\nc => d\n')
472
 
        tree = workingtree.WorkingTree.open('tree')
473
 
        self.assertIsNot(None, tree.path2id('a'))
474
 
        self.assertIsNot(None, tree.path2id('c'))
475
 
 
476
 
    def test_mv_no_auto_dry_run(self):
477
 
        self.make_abcd_tree()
478
 
        out, err = self.run_bzr('mv c d --dry-run',
479
 
                                working_dir='tree', retcode=3)
480
 
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
481
 
 
482
 
    def test_mv_auto_after(self):
483
 
        self.make_abcd_tree()
484
 
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
485
 
                                retcode=3)
486
 
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
487
 
                         ' --auto.\n', err)