/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: John Arbash Meinel
  • Date: 2007-11-16 23:53:17 UTC
  • mto: This revision was merged to the branch mainline in revision 3027.
  • Revision ID: john@arbash-meinel.com-20071116235317-uymqhilped1rloqy
Implement LRUCache.get() which acts like dict.get()
so that we can return a default if the key isn't present.

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_smoke_aliases(self):
 
128
        # just test that aliases for mv exist, if their behaviour is changed in
 
129
        # the future, then extend the tests.
 
130
        self.build_tree(['a'])
 
131
        tree = self.make_branch_and_tree('.')
 
132
        tree.add(['a'])
 
133
 
 
134
        self.run_bzr('move a b')
 
135
        self.run_bzr('rename b a')
 
136
 
 
137
    def test_mv_through_symlinks(self):
 
138
        self.requireFeature(SymlinkFeature)
 
139
        tree = self.make_branch_and_tree('.')
 
140
        self.build_tree(['a/', 'a/b'])
 
141
        os.symlink('a', 'c')
 
142
        os.symlink('.', 'd')
 
143
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
 
144
        self.run_bzr('mv c/b b')
 
145
        tree = workingtree.WorkingTree.open('.')
 
146
        self.assertEqual('b-id', tree.path2id('b'))
 
147
 
 
148
    def test_mv_already_moved_file(self):
 
149
        """Test bzr mv original_file to moved_file.
 
150
 
 
151
        Tests if a file which has allready been moved by an external tool,
 
152
        is handled correctly by bzr mv.
 
153
        Setup: a is in the working tree, b does not exist.
 
154
        User does: mv a b; bzr mv a b
 
155
        """
 
156
        self.build_tree(['a'])
 
157
        tree = self.make_branch_and_tree('.')
 
158
        tree.add(['a'])
 
159
 
 
160
        osutils.rename('a', 'b')
 
161
        self.run_bzr('mv a b')
 
162
        self.assertMoved('a','b')
 
163
 
 
164
    def test_mv_already_moved_file_to_versioned_target(self):
 
165
        """Test bzr mv existing_file to versioned_file.
 
166
 
 
167
        Tests if an attempt to move an existing versioned file
 
168
        to another versiond file will fail.
 
169
        Setup: a and b are in the working tree.
 
170
        User does: rm b; mv a b; bzr mv a b
 
171
        """
 
172
        self.build_tree(['a', 'b'])
 
173
        tree = self.make_branch_and_tree('.')
 
174
        tree.add(['a', 'b'])
 
175
 
 
176
        os.remove('b')
 
177
        osutils.rename('a', 'b')
 
178
        self.run_bzr_error(
 
179
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
 
180
            'mv a b')
 
181
        #check that nothing changed
 
182
        self.failIfExists('a')
 
183
        self.failUnlessExists('b')
 
184
 
 
185
    def test_mv_already_moved_file_into_subdir(self):
 
186
        """Test bzr mv original_file to versioned_directory/file.
 
187
 
 
188
        Tests if a file which has already been moved into a versioned
 
189
        directory by an external tool, is handled correctly by bzr mv.
 
190
        Setup: a and sub/ are in the working tree.
 
191
        User does: mv a sub/a; bzr mv a sub/a
 
192
        """
 
193
        self.build_tree(['a', 'sub/'])
 
194
        tree = self.make_branch_and_tree('.')
 
195
        tree.add(['a', 'sub'])
 
196
 
 
197
        osutils.rename('a', 'sub/a')
 
198
        self.run_bzr('mv a sub/a')
 
199
        self.assertMoved('a','sub/a')
 
200
 
 
201
    def test_mv_already_moved_file_into_unversioned_subdir(self):
 
202
        """Test bzr mv original_file to unversioned_directory/file.
 
203
 
 
204
        Tests if an attempt to move an existing versioned file
 
205
        into an unversioned directory will fail.
 
206
        Setup: a is in the working tree, sub/ is not.
 
207
        User does: mv a sub/a; bzr mv a sub/a
 
208
        """
 
209
        self.build_tree(['a', 'sub/'])
 
210
        tree = self.make_branch_and_tree('.')
 
211
        tree.add(['a'])
 
212
 
 
213
        osutils.rename('a', 'sub/a')
 
214
        self.run_bzr_error(
 
215
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
 
216
            'mv a sub/a')
 
217
        self.failIfExists('a')
 
218
        self.failUnlessExists('sub/a')
 
219
 
 
220
    def test_mv_already_moved_files_into_subdir(self):
 
221
        """Test bzr mv original_files to versioned_directory.
 
222
 
 
223
        Tests if files which has already been moved into a versioned
 
224
        directory by an external tool, is handled correctly by bzr mv.
 
225
        Setup: a1, a2, sub are in the working tree.
 
226
        User does: mv a1 sub/.; bzr mv a1 a2 sub
 
227
        """
 
228
        self.build_tree(['a1', 'a2', 'sub/'])
 
229
        tree = self.make_branch_and_tree('.')
 
230
        tree.add(['a1', 'a2', 'sub'])
 
231
 
 
232
        osutils.rename('a1', 'sub/a1')
 
233
        self.run_bzr('mv a1 a2 sub')
 
234
        self.assertMoved('a1','sub/a1')
 
235
        self.assertMoved('a2','sub/a2')
 
236
 
 
237
    def test_mv_already_moved_files_into_unversioned_subdir(self):
 
238
        """Test bzr mv original_file to unversioned_directory.
 
239
 
 
240
        Tests if an attempt to move existing versioned file
 
241
        into an unversioned directory will fail.
 
242
        Setup: a1, a2 are in the working tree, sub is not.
 
243
        User does: mv a1 sub/.; bzr mv a1 a2 sub
 
244
        """
 
245
        self.build_tree(['a1', 'a2', 'sub/'])
 
246
        tree = self.make_branch_and_tree('.')
 
247
        tree.add(['a1', 'a2'])
 
248
 
 
249
        osutils.rename('a1', 'sub/a1')
 
250
        self.run_bzr_error(
 
251
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
 
252
            'mv a1 a2 sub')
 
253
        self.failIfExists('a1')
 
254
        self.failUnlessExists('sub/a1')
 
255
        self.failUnlessExists('a2')
 
256
        self.failIfExists('sub/a2')
 
257
 
 
258
    def test_mv_already_moved_file_forcing_after(self):
 
259
        """Test bzr mv versioned_file to unversioned_file.
 
260
 
 
261
        Tests if an attempt to move an existing versioned file to an existing
 
262
        unversioned file will fail, informing the user to use the --after
 
263
        option to force this.
 
264
        Setup: a is in the working tree, b not versioned.
 
265
        User does: mv a b; touch a; bzr mv a b
 
266
        """
 
267
        self.build_tree(['a', 'b'])
 
268
        tree = self.make_branch_and_tree('.')
 
269
        tree.add(['a'])
 
270
 
 
271
        osutils.rename('a', 'b')
 
272
        self.build_tree(['a']) #touch a
 
273
        self.run_bzr_error(
 
274
            ["^bzr: ERROR: Could not rename a => b because both files exist."
 
275
             " \(Use --after to tell bzr about a rename that has already"
 
276
             " happened\)$"],
 
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"
 
325
             " exist. \(Use --after to tell bzr about a rename that has already"
 
326
             " happened\)$"],
 
327
            'mv a1 a2 sub')
 
328
        self.failUnlessExists('a1')
 
329
        self.failUnlessExists('a2')
 
330
        self.failUnlessExists('sub/a1')
 
331
        self.failUnlessExists('sub/a2')
 
332
 
 
333
    def test_mv_already_moved_files_using_after(self):
 
334
        """Test bzr mv --after versioned_file to directory/unversioned_file.
 
335
 
 
336
        Tests if an existing versioned file can be forced to move to an
 
337
        existing unversioned file in some other directory using the --after
 
338
        option. With the result that bazaar considers
 
339
        directory/unversioned_file to be moved from versioned_file and
 
340
        versioned_file will become unversioned.
 
341
 
 
342
        Setup: a1, a2, sub are versioned and in the working tree,
 
343
               sub/a1, sub/a2 are in working tree.
 
344
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
 
345
        """
 
346
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
 
347
        tree = self.make_branch_and_tree('.')
 
348
        tree.add(['a1', 'a2', 'sub'])
 
349
        osutils.rename('a1', 'sub/a1')
 
350
        osutils.rename('a2', 'sub/a2')
 
351
        self.build_tree(['a1']) #touch a1
 
352
        self.build_tree(['a2']) #touch a2
 
353
 
 
354
        self.run_bzr('mv a1 a2 sub --after')
 
355
        self.failUnlessExists('a1')
 
356
        self.failUnlessExists('a2')
 
357
        self.failUnlessExists('sub/a1')
 
358
        self.failUnlessExists('sub/a2')
 
359
        self.assertInWorkingTree('sub/a1')
 
360
        self.assertInWorkingTree('sub/a2')