~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2005-09-30 05:56:05 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930055605-a2c534529b392a7d
- fix upgrade for transport changes

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
 
    TestCaseWithTransport,
28
 
    TestSkipped,
29
 
    )
30
 
 
31
 
 
32
 
class TestMove(TestCaseWithTransport):
33
 
 
34
 
    def assertInWorkingTree(self,path):
35
 
        tree = workingtree.WorkingTree.open('.')
36
 
        self.assertIsNot(tree.path2id(path), None,
37
 
            path+' not in working tree.')
38
 
 
39
 
    def assertNotInWorkingTree(self,path):
40
 
        tree = workingtree.WorkingTree.open('.')
41
 
        self.assertIs(tree.path2id(path), None, path+' in working tree.')
42
 
 
43
 
    def assertMoved(self,from_path,to_path):
44
 
        """Assert that to_path is existing and versioned but from_path not. """
45
 
        self.failIfExists(from_path)
46
 
        self.assertNotInWorkingTree(from_path)
47
 
 
48
 
        self.failUnlessExists(to_path)
49
 
        self.assertInWorkingTree(to_path)
50
 
 
51
 
    def test_mv_modes(self):
52
 
        """Test two modes of operation for mv"""
53
 
        tree = self.make_branch_and_tree('.')
54
 
        files = self.build_tree(['a', 'c', 'subdir/'])
55
 
        tree.add(['a', 'c', 'subdir'])
56
 
 
57
 
        self.run_bzr('mv', 'a', 'b')
58
 
        self.assertMoved('a','b')
59
 
 
60
 
        self.run_bzr('mv', 'b', 'subdir')
61
 
        self.assertMoved('b','subdir/b')
62
 
 
63
 
        self.run_bzr('mv', 'subdir/b', 'a')
64
 
        self.assertMoved('subdir/b','a')
65
 
 
66
 
        self.run_bzr('mv', 'a', 'c', 'subdir')
67
 
        self.assertMoved('a','subdir/a')
68
 
        self.assertMoved('c','subdir/c')
69
 
 
70
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
71
 
        self.assertMoved('subdir/a','subdir/newa')
72
 
 
73
 
    def test_mv_unversioned(self):
74
 
        self.build_tree(['unversioned.txt'])
75
 
        self.run_bzr_error(
76
 
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
77
 
             " .*unversioned.txt is not versioned$"],
78
 
            'mv', 'unversioned.txt', 'elsewhere')
79
 
 
80
 
    def test_mv_nonexisting(self):
81
 
        self.run_bzr_error(
82
 
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
83
 
             " .*doesnotexist is not versioned$"],
84
 
            'mv', 'doesnotexist', 'somewhereelse')
85
 
 
86
 
    def test_mv_unqualified(self):
87
 
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
88
 
        
89
 
    def test_mv_invalid(self):
90
 
        tree = self.make_branch_and_tree('.')
91
 
        self.build_tree(['test.txt', 'sub1/'])
92
 
        tree.add(['test.txt'])
93
 
 
94
 
        self.run_bzr_error(
95
 
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
96
 
            'mv', 'test.txt', 'sub1')
97
 
 
98
 
        self.run_bzr_error(
99
 
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
100
 
             "sub1 is not versioned$"],
101
 
            'mv', 'test.txt', 'sub1/hello.txt')
102
 
        
103
 
    def test_mv_dirs(self):
104
 
        tree = self.make_branch_and_tree('.')
105
 
        self.build_tree(['hello.txt', 'sub1/'])
106
 
        tree.add(['hello.txt', 'sub1'])
107
 
 
108
 
        self.run_bzr('mv', 'sub1', 'sub2')
109
 
        self.assertMoved('sub1','sub2')
110
 
 
111
 
        self.run_bzr('mv', 'hello.txt', 'sub2')
112
 
        self.assertMoved('hello.txt','sub2/hello.txt')
113
 
 
114
 
        tree.read_working_inventory()
115
 
 
116
 
        self.build_tree(['sub1/'])
117
 
        tree.add(['sub1'])
118
 
        self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
119
 
        self.assertMoved('sub2/hello.txt','sub1/hello.txt')
120
 
 
121
 
        self.run_bzr('mv', 'sub2', 'sub1')
122
 
        self.assertMoved('sub2','sub1/sub2')
123
 
 
124
 
    def test_mv_relative(self):
125
 
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
126
 
        tree = self.make_branch_and_tree('.')
127
 
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
128
 
 
129
 
        os.chdir('sub1/sub2')
130
 
        self.run_bzr('mv', '../hello.txt', '.')
131
 
        self.failUnlessExists('./hello.txt')
132
 
        tree.read_working_inventory()
133
 
 
134
 
        os.chdir('..')
135
 
        self.run_bzr('mv', 'sub2/hello.txt', '.')
136
 
        os.chdir('..')
137
 
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
138
 
 
139
 
    def test_mv_smoke_aliases(self):
140
 
        # just test that aliases for mv exist, if their behaviour is changed in
141
 
        # the future, then extend the tests.
142
 
        self.build_tree(['a'])
143
 
        tree = self.make_branch_and_tree('.')
144
 
        tree.add(['a'])
145
 
 
146
 
        self.run_bzr('move', 'a', 'b')
147
 
        self.run_bzr('rename', 'b', 'a')
148
 
 
149
 
    def test_mv_through_symlinks(self):
150
 
        if not osutils.has_symlinks():
151
 
            raise TestSkipped('Symlinks are not supported on this platform')
152
 
        tree = self.make_branch_and_tree('.')
153
 
        self.build_tree(['a/', 'a/b'])
154
 
        os.symlink('a', 'c')
155
 
        os.symlink('.', 'd')
156
 
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
157
 
        self.run_bzr('mv', 'c/b', 'b')
158
 
        tree = workingtree.WorkingTree.open('.')
159
 
        self.assertEqual('b-id', tree.path2id('b'))
160
 
 
161
 
    def test_mv_already_moved_file(self):
162
 
        """Test bzr mv original_file to moved_file.
163
 
 
164
 
        Tests if a file which has allready been moved by an external tool,
165
 
        is handled correctly by bzr mv.
166
 
        Setup: a is in the working tree, b does not exist.
167
 
        User does: mv a b; bzr mv a b
168
 
        """
169
 
        self.build_tree(['a'])
170
 
        tree = self.make_branch_and_tree('.')
171
 
        tree.add(['a'])
172
 
 
173
 
        os.rename('a', 'b')
174
 
        self.run_bzr('mv', 'a', 'b')
175
 
        self.assertMoved('a','b')
176
 
 
177
 
    def test_mv_already_moved_file_to_versioned_target(self):
178
 
        """Test bzr mv existing_file to versioned_file.
179
 
 
180
 
        Tests if an attempt to move an existing versioned file
181
 
        to another versiond file will fail.
182
 
        Setup: a and b are in the working tree.
183
 
        User does: rm b; mv a b; bzr mv a b
184
 
        """
185
 
        self.build_tree(['a', 'b'])
186
 
        tree = self.make_branch_and_tree('.')
187
 
        tree.add(['a', 'b'])
188
 
 
189
 
        os.remove('b')
190
 
        os.rename('a', 'b')
191
 
        self.run_bzr_error(
192
 
            ["^bzr: ERROR: Could not move a => b. b is already versioned$"],
193
 
            'mv', 'a', 'b')
194
 
        #check that nothing changed
195
 
        self.failIfExists('a')
196
 
        self.failUnlessExists('b')
197
 
 
198
 
    def test_mv_already_moved_file_into_subdir(self):
199
 
        """Test bzr mv original_file to versioned_directory/file.
200
 
 
201
 
        Tests if a file which has already been moved into a versioned
202
 
        directory by an external tool, is handled correctly by bzr mv.
203
 
        Setup: a and sub/ are in the working tree.
204
 
        User does: mv a sub/a; bzr mv a sub/a
205
 
        """
206
 
        self.build_tree(['a', 'sub/'])
207
 
        tree = self.make_branch_and_tree('.')
208
 
        tree.add(['a', 'sub'])
209
 
 
210
 
        os.rename('a', 'sub/a')
211
 
        self.run_bzr('mv', 'a', 'sub/a')
212
 
        self.assertMoved('a','sub/a')
213
 
 
214
 
    def test_mv_already_moved_file_into_unversioned_subdir(self):
215
 
        """Test bzr mv original_file to unversioned_directory/file.
216
 
 
217
 
        Tests if an attempt to move an existing versioned file
218
 
        into an unversioned directory will fail.
219
 
        Setup: a is in the working tree, sub/ is not.
220
 
        User does: mv a sub/a; bzr mv a sub/a
221
 
        """
222
 
        self.build_tree(['a', 'sub/'])
223
 
        tree = self.make_branch_and_tree('.')
224
 
        tree.add(['a'])
225
 
 
226
 
        os.rename('a', 'sub/a')
227
 
        self.run_bzr_error(
228
 
            ["^bzr: ERROR: Could not move a => a: sub is not versioned$"],
229
 
            'mv', 'a', 'sub/a')
230
 
        self.failIfExists('a')
231
 
        self.failUnlessExists('sub/a')
232
 
 
233
 
    def test_mv_already_moved_files_into_subdir(self):
234
 
        """Test bzr mv original_files to versioned_directory.
235
 
 
236
 
        Tests if files which has already been moved into a versioned
237
 
        directory by an external tool, is handled correctly by bzr mv.
238
 
        Setup: a1, a2, sub are in the working tree.
239
 
        User does: mv a1 sub/.; bzr mv a1 a2 sub
240
 
        """
241
 
        self.build_tree(['a1', 'a2', 'sub/'])
242
 
        tree = self.make_branch_and_tree('.')
243
 
        tree.add(['a1', 'a2', 'sub'])
244
 
 
245
 
        os.rename('a1', 'sub/a1')
246
 
        self.run_bzr('mv', 'a1', 'a2', 'sub')
247
 
        self.assertMoved('a1','sub/a1')
248
 
        self.assertMoved('a2','sub/a2')
249
 
 
250
 
    def test_mv_already_moved_files_into_unversioned_subdir(self):
251
 
        """Test bzr mv original_file to unversioned_directory.
252
 
 
253
 
        Tests if an attempt to move existing versioned file
254
 
        into an unversioned directory will fail.
255
 
        Setup: a1, a2 are in the working tree, sub is not.
256
 
        User does: mv a1 sub/.; bzr mv a1 a2 sub
257
 
        """
258
 
        self.build_tree(['a1', 'a2', 'sub/'])
259
 
        tree = self.make_branch_and_tree('.')
260
 
        tree.add(['a1', 'a2'])
261
 
 
262
 
        os.rename('a1', 'sub/a1')
263
 
        self.run_bzr_error(
264
 
            ["^bzr: ERROR: Could not move to sub. sub is not versioned$"],
265
 
            'mv', 'a1', 'a2', 'sub')
266
 
        self.failIfExists('a1')
267
 
        self.failUnlessExists('sub/a1')
268
 
        self.failUnlessExists('a2')
269
 
        self.failIfExists('sub/a2')
270
 
 
271
 
    def test_mv_already_moved_file_forcing_after(self):
272
 
        """Test bzr mv versioned_file to unversioned_file.
273
 
 
274
 
        Tests if an attempt to move an existing versioned file to an existing
275
 
        unversioned file will fail, informing the user to use the --after
276
 
        option to force this.
277
 
        Setup: a is in the working tree, b not versioned.
278
 
        User does: mv a b; touch a; bzr mv a b
279
 
        """
280
 
        self.build_tree(['a', 'b'])
281
 
        tree = self.make_branch_and_tree('.')
282
 
        tree.add(['a'])
283
 
 
284
 
        os.rename('a', 'b')
285
 
        self.build_tree(['a']) #touch a
286
 
        self.run_bzr_error(
287
 
            ["^bzr: ERROR: Could not rename a => b because both files exist."
288
 
             " \(Use --after to update the Bazaar id\)$"],
289
 
            'mv', 'a', 'b')
290
 
        self.failUnlessExists('a')
291
 
        self.failUnlessExists('b')
292
 
 
293
 
    def test_mv_already_moved_file_using_after(self):
294
 
        """Test bzr mv --after versioned_file to unversioned_file.
295
 
 
296
 
        Tests if an existing versioned file can be forced to move to an
297
 
        existing unversioned file using the --after option. With the result
298
 
        that bazaar considers the unversioned_file to be moved from
299
 
        versioned_file and versioned_file will become unversioned.
300
 
        Setup: a is in the working tree and b exists.
301
 
        User does: mv a b; touch a; bzr mv a b --after
302
 
        Resulting in a => b and a is unknown.
303
 
        """
304
 
        self.build_tree(['a', 'b'])
305
 
        tree = self.make_branch_and_tree('.')
306
 
        tree.add(['a'])
307
 
        os.rename('a', 'b')
308
 
        self.build_tree(['a']) #touch a
309
 
 
310
 
        self.run_bzr('mv', 'a', 'b', '--after')
311
 
        self.failUnlessExists('a')
312
 
        self.assertNotInWorkingTree('a')#a should be unknown now.
313
 
        self.failUnlessExists('b')
314
 
        self.assertInWorkingTree('b')
315
 
 
316
 
    def test_mv_already_moved_files_forcing_after(self):
317
 
        """Test bzr mv versioned_files to directory/unversioned_file.
318
 
 
319
 
        Tests if an attempt to move an existing versioned file to an existing
320
 
        unversioned file in some other directory will fail, informing the user
321
 
        to use the --after option to force this.
322
 
 
323
 
        Setup: a1, a2, sub are versioned and in the working tree,
324
 
               sub/a1, sub/a2 are in working tree.
325
 
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
326
 
        """
327
 
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
328
 
        tree = self.make_branch_and_tree('.')
329
 
        tree.add(['a1', 'a2', 'sub'])
330
 
        os.rename('a1', 'sub/a1')
331
 
        os.rename('a2', 'sub/a2')
332
 
        self.build_tree(['a1']) #touch a1
333
 
        self.build_tree(['a2']) #touch a2
334
 
 
335
 
        self.run_bzr_error(
336
 
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files exist."
337
 
             " \(Use --after to update the Bazaar id\)$"],
338
 
            'mv', 'a1', 'a2', 'sub')
339
 
        self.failUnlessExists('a1')
340
 
        self.failUnlessExists('a2')
341
 
        self.failUnlessExists('sub/a1')
342
 
        self.failUnlessExists('sub/a2')
343
 
 
344
 
    def test_mv_already_moved_files_using_after(self):
345
 
        """Test bzr mv --after versioned_file to directory/unversioned_file.
346
 
 
347
 
        Tests if an existing versioned file can be forced to move to an
348
 
        existing unversioned file in some other directory using the --after
349
 
        option. With the result that bazaar considers
350
 
        directory/unversioned_file to be moved from versioned_file and
351
 
        versioned_file will become unversioned.
352
 
 
353
 
        Setup: a1, a2, sub are versioned and in the working tree,
354
 
               sub/a1, sub/a2 are in working tree.
355
 
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
356
 
        """
357
 
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
358
 
        tree = self.make_branch_and_tree('.')
359
 
        tree.add(['a1', 'a2', 'sub'])
360
 
        os.rename('a1', 'sub/a1')
361
 
        os.rename('a2', 'sub/a2')
362
 
        self.build_tree(['a1']) #touch a1
363
 
        self.build_tree(['a2']) #touch a2
364
 
 
365
 
        self.run_bzr('mv', 'a1', 'a2', 'sub', '--after')
366
 
        self.failUnlessExists('a1')
367
 
        self.failUnlessExists('a2')
368
 
        self.failUnlessExists('sub/a1')
369
 
        self.failUnlessExists('sub/a2')
370
 
        self.assertInWorkingTree('sub/a1')
371
 
        self.assertInWorkingTree('sub/a2')