/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: Marius Kruger
  • Date: 2007-01-19 19:42:19 UTC
  • mto: This revision was merged to the branch mainline in revision 2241.
  • Revision ID: amanic@gmail.com-20070119194219-mlzsauq30x2az9sq
Remove assertNone

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