~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

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