/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2008-02-29 15:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 3249.
  • Revision ID: bialix@ukr.net-20080229155356-wjc96jdnisg0evah
Allow rename (change case of name) directory on case-insensitive filesystem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
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
 
16
 
 
17
"""Test for 'bzr mv'"""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib import (
 
22
    osutils,
 
23
    workingtree,
 
24
    )
 
25
 
 
26
from bzrlib.tests import (
 
27
    SymlinkFeature,
 
28
    TestCaseWithTransport,
 
29
    )
 
30
 
 
31
 
 
32
class TestMove(TestCaseWithTransport):
 
33
 
 
34
    def assertMoved(self,from_path,to_path):
 
35
        """Assert that to_path is existing and versioned but from_path not. """
 
36
        self.failIfExists(from_path)
 
37
        self.assertNotInWorkingTree(from_path)
 
38
 
 
39
        self.failUnlessExists(to_path)
 
40
        self.assertInWorkingTree(to_path)
 
41
 
 
42
    def test_mv_modes(self):
 
43
        """Test two modes of operation for mv"""
 
44
        tree = self.make_branch_and_tree('.')
 
45
        files = self.build_tree(['a', 'c', 'subdir/'])
 
46
        tree.add(['a', 'c', 'subdir'])
 
47
 
 
48
        self.run_bzr('mv a b')
 
49
        self.assertMoved('a','b')
 
50
 
 
51
        self.run_bzr('mv b subdir')
 
52
        self.assertMoved('b','subdir/b')
 
53
 
 
54
        self.run_bzr('mv subdir/b a')
 
55
        self.assertMoved('subdir/b','a')
 
56
 
 
57
        self.run_bzr('mv a c subdir')
 
58
        self.assertMoved('a','subdir/a')
 
59
        self.assertMoved('c','subdir/c')
 
60
 
 
61
        self.run_bzr('mv subdir/a subdir/newa')
 
62
        self.assertMoved('subdir/a','subdir/newa')
 
63
 
 
64
    def test_mv_unversioned(self):
 
65
        self.build_tree(['unversioned.txt'])
 
66
        self.run_bzr_error(
 
67
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
 
68
             " .*unversioned.txt is not versioned\.$"],
 
69
            'mv unversioned.txt elsewhere')
 
70
 
 
71
    def test_mv_nonexisting(self):
 
72
        self.run_bzr_error(
 
73
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
 
74
             " .*doesnotexist is not versioned\.$"],
 
75
            'mv doesnotexist somewhereelse')
 
76
 
 
77
    def test_mv_unqualified(self):
 
78
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
 
79
        
 
80
    def test_mv_invalid(self):
 
81
        tree = self.make_branch_and_tree('.')
 
82
        self.build_tree(['test.txt', 'sub1/'])
 
83
        tree.add(['test.txt'])
 
84
 
 
85
        self.run_bzr_error(
 
86
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
 
87
            'mv test.txt sub1')
 
88
 
 
89
        self.run_bzr_error(
 
90
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
 
91
             "sub1 is not versioned\.$"],
 
92
            'mv test.txt sub1/hello.txt')
 
93
        
 
94
    def test_mv_dirs(self):
 
95
        tree = self.make_branch_and_tree('.')
 
96
        self.build_tree(['hello.txt', 'sub1/'])
 
97
        tree.add(['hello.txt', 'sub1'])
 
98
 
 
99
        self.run_bzr('mv sub1 sub2')
 
100
        self.assertMoved('sub1','sub2')
 
101
 
 
102
        self.run_bzr('mv hello.txt sub2')
 
103
        self.assertMoved('hello.txt','sub2/hello.txt')
 
104
 
 
105
        self.build_tree(['sub1/'])
 
106
        tree.add(['sub1'])
 
107
        self.run_bzr('mv sub2/hello.txt sub1')
 
108
        self.assertMoved('sub2/hello.txt','sub1/hello.txt')
 
109
 
 
110
        self.run_bzr('mv sub2 sub1')
 
111
        self.assertMoved('sub2','sub1/sub2')
 
112
 
 
113
    def test_mv_relative(self):
 
114
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
 
115
        tree = self.make_branch_and_tree('.')
 
116
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
 
117
 
 
118
        os.chdir('sub1/sub2')
 
119
        self.run_bzr('mv ../hello.txt .')
 
120
        self.failUnlessExists('./hello.txt')
 
121
 
 
122
        os.chdir('..')
 
123
        self.run_bzr('mv sub2/hello.txt .')
 
124
        os.chdir('..')
 
125
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
 
126
 
 
127
    def test_mv_change_case_file(self):
 
128
        # test for bug #77740 (mv unable change filename case on Windows)
 
129
        tree = self.make_branch_and_tree('.')
 
130
        self.build_tree(['test.txt'])
 
131
        tree.add(['test.txt'])
 
132
        self.run_bzr('mv test.txt Test.txt')
 
133
        # we can't use failUnlessExists on case-insensitive filesystem
 
134
        # so try to check shape of the tree
 
135
        shape = sorted(os.listdir(u'.'))
 
136
        self.assertEqual(['.bzr', 'Test.txt'], shape)
 
137
        self.assertInWorkingTree('Test.txt')
 
138
        self.assertNotInWorkingTree('test.txt')
 
139
 
 
140
    def test_mv_change_case_dir(self):
 
141
        tree = self.make_branch_and_tree('.')
 
142
        self.build_tree(['foo/'])
 
143
        tree.add(['foo'])
 
144
        self.run_bzr('mv foo Foo')
 
145
        # we can't use failUnlessExists on case-insensitive filesystem
 
146
        # so try to check shape of the tree
 
147
        shape = sorted(os.listdir(u'.'))
 
148
        self.assertEqual(['.bzr', 'Foo'], shape)
 
149
        self.assertInWorkingTree('Foo')
 
150
        self.assertNotInWorkingTree('foo')
 
151
 
 
152
    def test_mv_change_case_dir_w_files(self):
 
153
        tree = self.make_branch_and_tree('.')
 
154
        self.build_tree(['foo/', 'foo/bar'])
 
155
        tree.add(['foo'])
 
156
        self.run_bzr('mv foo Foo')
 
157
        # we can't use failUnlessExists on case-insensitive filesystem
 
158
        # so try to check shape of the tree
 
159
        shape = sorted(os.listdir(u'.'))
 
160
        self.assertEqual(['.bzr', 'Foo'], shape)
 
161
        self.assertInWorkingTree('Foo')
 
162
        self.assertNotInWorkingTree('foo')
 
163
 
 
164
    def test_mv_file_to_wrong_case_dir(self):
 
165
        tree = self.make_branch_and_tree('.')
 
166
        self.build_tree(['foo/', 'bar'])
 
167
        tree.add(['foo', 'bar'])
 
168
        out, err = self.run_bzr('mv bar Foo', retcode=3)
 
169
        self.assertEquals('', out)
 
170
        self.assertEquals(
 
171
            'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
 
172
            err)
 
173
 
 
174
    def test_mv_smoke_aliases(self):
 
175
        # just test that aliases for mv exist, if their behaviour is changed in
 
176
        # the future, then extend the tests.
 
177
        self.build_tree(['a'])
 
178
        tree = self.make_branch_and_tree('.')
 
179
        tree.add(['a'])
 
180
 
 
181
        self.run_bzr('move a b')
 
182
        self.run_bzr('rename b a')
 
183
 
 
184
    def test_mv_through_symlinks(self):
 
185
        self.requireFeature(SymlinkFeature)
 
186
        tree = self.make_branch_and_tree('.')
 
187
        self.build_tree(['a/', 'a/b'])
 
188
        os.symlink('a', 'c')
 
189
        os.symlink('.', 'd')
 
190
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
 
191
        self.run_bzr('mv c/b b')
 
192
        tree = workingtree.WorkingTree.open('.')
 
193
        self.assertEqual('b-id', tree.path2id('b'))
 
194
 
 
195
    def test_mv_already_moved_file(self):
 
196
        """Test bzr mv original_file to moved_file.
 
197
 
 
198
        Tests if a file which has allready been moved by an external tool,
 
199
        is handled correctly by bzr mv.
 
200
        Setup: a is in the working tree, b does not exist.
 
201
        User does: mv a b; bzr mv a b
 
202
        """
 
203
        self.build_tree(['a'])
 
204
        tree = self.make_branch_and_tree('.')
 
205
        tree.add(['a'])
 
206
 
 
207
        osutils.rename('a', 'b')
 
208
        self.run_bzr('mv a b')
 
209
        self.assertMoved('a','b')
 
210
 
 
211
    def test_mv_already_moved_file_to_versioned_target(self):
 
212
        """Test bzr mv existing_file to versioned_file.
 
213
 
 
214
        Tests if an attempt to move an existing versioned file
 
215
        to another versiond file will fail.
 
216
        Setup: a and b are in the working tree.
 
217
        User does: rm b; mv a b; bzr mv a b
 
218
        """
 
219
        self.build_tree(['a', 'b'])
 
220
        tree = self.make_branch_and_tree('.')
 
221
        tree.add(['a', 'b'])
 
222
 
 
223
        os.remove('b')
 
224
        osutils.rename('a', 'b')
 
225
        self.run_bzr_error(
 
226
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
 
227
            'mv a b')
 
228
        #check that nothing changed
 
229
        self.failIfExists('a')
 
230
        self.failUnlessExists('b')
 
231
 
 
232
    def test_mv_already_moved_file_into_subdir(self):
 
233
        """Test bzr mv original_file to versioned_directory/file.
 
234
 
 
235
        Tests if a file which has already been moved into a versioned
 
236
        directory by an external tool, is handled correctly by bzr mv.
 
237
        Setup: a and sub/ are in the working tree.
 
238
        User does: mv a sub/a; bzr mv a sub/a
 
239
        """
 
240
        self.build_tree(['a', 'sub/'])
 
241
        tree = self.make_branch_and_tree('.')
 
242
        tree.add(['a', 'sub'])
 
243
 
 
244
        osutils.rename('a', 'sub/a')
 
245
        self.run_bzr('mv a sub/a')
 
246
        self.assertMoved('a','sub/a')
 
247
 
 
248
    def test_mv_already_moved_file_into_unversioned_subdir(self):
 
249
        """Test bzr mv original_file to unversioned_directory/file.
 
250
 
 
251
        Tests if an attempt to move an existing versioned file
 
252
        into an unversioned directory will fail.
 
253
        Setup: a is in the working tree, sub/ is not.
 
254
        User does: mv a sub/a; bzr mv a sub/a
 
255
        """
 
256
        self.build_tree(['a', 'sub/'])
 
257
        tree = self.make_branch_and_tree('.')
 
258
        tree.add(['a'])
 
259
 
 
260
        osutils.rename('a', 'sub/a')
 
261
        self.run_bzr_error(
 
262
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
 
263
            'mv a sub/a')
 
264
        self.failIfExists('a')
 
265
        self.failUnlessExists('sub/a')
 
266
 
 
267
    def test_mv_already_moved_files_into_subdir(self):
 
268
        """Test bzr mv original_files to versioned_directory.
 
269
 
 
270
        Tests if files which has already been moved into a versioned
 
271
        directory by an external tool, is handled correctly by bzr mv.
 
272
        Setup: a1, a2, sub are in the working tree.
 
273
        User does: mv a1 sub/.; bzr mv a1 a2 sub
 
274
        """
 
275
        self.build_tree(['a1', 'a2', 'sub/'])
 
276
        tree = self.make_branch_and_tree('.')
 
277
        tree.add(['a1', 'a2', 'sub'])
 
278
 
 
279
        osutils.rename('a1', 'sub/a1')
 
280
        self.run_bzr('mv a1 a2 sub')
 
281
        self.assertMoved('a1','sub/a1')
 
282
        self.assertMoved('a2','sub/a2')
 
283
 
 
284
    def test_mv_already_moved_files_into_unversioned_subdir(self):
 
285
        """Test bzr mv original_file to unversioned_directory.
 
286
 
 
287
        Tests if an attempt to move existing versioned file
 
288
        into an unversioned directory will fail.
 
289
        Setup: a1, a2 are in the working tree, sub is not.
 
290
        User does: mv a1 sub/.; bzr mv a1 a2 sub
 
291
        """
 
292
        self.build_tree(['a1', 'a2', 'sub/'])
 
293
        tree = self.make_branch_and_tree('.')
 
294
        tree.add(['a1', 'a2'])
 
295
 
 
296
        osutils.rename('a1', 'sub/a1')
 
297
        self.run_bzr_error(
 
298
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
 
299
            'mv a1 a2 sub')
 
300
        self.failIfExists('a1')
 
301
        self.failUnlessExists('sub/a1')
 
302
        self.failUnlessExists('a2')
 
303
        self.failIfExists('sub/a2')
 
304
 
 
305
    def test_mv_already_moved_file_forcing_after(self):
 
306
        """Test bzr mv versioned_file to unversioned_file.
 
307
 
 
308
        Tests if an attempt to move an existing versioned file to an existing
 
309
        unversioned file will fail, informing the user to use the --after
 
310
        option to force this.
 
311
        Setup: a is in the working tree, b not versioned.
 
312
        User does: mv a b; touch a; bzr mv a b
 
313
        """
 
314
        self.build_tree(['a', 'b'])
 
315
        tree = self.make_branch_and_tree('.')
 
316
        tree.add(['a'])
 
317
 
 
318
        osutils.rename('a', 'b')
 
319
        self.build_tree(['a']) #touch a
 
320
        self.run_bzr_error(
 
321
            ["^bzr: ERROR: Could not rename a => b because both files exist."
 
322
             " \(Use --after to tell bzr about a rename that has already"
 
323
             " happened\)$"],
 
324
            'mv a b')
 
325
        self.failUnlessExists('a')
 
326
        self.failUnlessExists('b')
 
327
 
 
328
    def test_mv_already_moved_file_using_after(self):
 
329
        """Test bzr mv --after versioned_file to unversioned_file.
 
330
 
 
331
        Tests if an existing versioned file can be forced to move to an
 
332
        existing unversioned file using the --after option. With the result
 
333
        that bazaar considers the unversioned_file to be moved from
 
334
        versioned_file and versioned_file will become unversioned.
 
335
        Setup: a is in the working tree and b exists.
 
336
        User does: mv a b; touch a; bzr mv a b --after
 
337
        Resulting in a => b and a is unknown.
 
338
        """
 
339
        self.build_tree(['a', 'b'])
 
340
        tree = self.make_branch_and_tree('.')
 
341
        tree.add(['a'])
 
342
        osutils.rename('a', 'b')
 
343
        self.build_tree(['a']) #touch a
 
344
 
 
345
        self.run_bzr('mv a b --after')
 
346
        self.failUnlessExists('a')
 
347
        self.assertNotInWorkingTree('a')#a should be unknown now.
 
348
        self.failUnlessExists('b')
 
349
        self.assertInWorkingTree('b')
 
350
 
 
351
    def test_mv_already_moved_files_forcing_after(self):
 
352
        """Test bzr mv versioned_files to directory/unversioned_file.
 
353
 
 
354
        Tests if an attempt to move an existing versioned file to an existing
 
355
        unversioned file in some other directory will fail, informing the user
 
356
        to use the --after option to force this.
 
357
 
 
358
        Setup: a1, a2, sub are versioned and in the working tree,
 
359
               sub/a1, sub/a2 are in working tree.
 
360
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
 
361
        """
 
362
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
 
363
        tree = self.make_branch_and_tree('.')
 
364
        tree.add(['a1', 'a2', 'sub'])
 
365
        osutils.rename('a1', 'sub/a1')
 
366
        osutils.rename('a2', 'sub/a2')
 
367
        self.build_tree(['a1']) #touch a1
 
368
        self.build_tree(['a2']) #touch a2
 
369
 
 
370
        self.run_bzr_error(
 
371
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
 
372
             " exist. \(Use --after to tell bzr about a rename that has already"
 
373
             " happened\)$"],
 
374
            'mv a1 a2 sub')
 
375
        self.failUnlessExists('a1')
 
376
        self.failUnlessExists('a2')
 
377
        self.failUnlessExists('sub/a1')
 
378
        self.failUnlessExists('sub/a2')
 
379
 
 
380
    def test_mv_already_moved_files_using_after(self):
 
381
        """Test bzr mv --after versioned_file to directory/unversioned_file.
 
382
 
 
383
        Tests if an existing versioned file can be forced to move to an
 
384
        existing unversioned file in some other directory using the --after
 
385
        option. With the result that bazaar considers
 
386
        directory/unversioned_file to be moved from versioned_file and
 
387
        versioned_file will become unversioned.
 
388
 
 
389
        Setup: a1, a2, sub are versioned and in the working tree,
 
390
               sub/a1, sub/a2 are in working tree.
 
391
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
 
392
        """
 
393
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
 
394
        tree = self.make_branch_and_tree('.')
 
395
        tree.add(['a1', 'a2', 'sub'])
 
396
        osutils.rename('a1', 'sub/a1')
 
397
        osutils.rename('a2', 'sub/a2')
 
398
        self.build_tree(['a1']) #touch a1
 
399
        self.build_tree(['a2']) #touch a2
 
400
 
 
401
        self.run_bzr('mv a1 a2 sub --after')
 
402
        self.failUnlessExists('a1')
 
403
        self.failUnlessExists('a2')
 
404
        self.failUnlessExists('sub/a1')
 
405
        self.failUnlessExists('sub/a2')
 
406
        self.assertInWorkingTree('sub/a1')
 
407
        self.assertInWorkingTree('sub/a2')