~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-02 08:23:44 UTC
  • mfrom: (3140.1.9 find-branches)
  • Revision ID: pqm@pqm.ubuntu.com-20080102082344-qret383z2bdk1ud4
Optimize find_branches for standalone repositories (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    )
25
25
 
26
26
from bzrlib.tests import (
 
27
    SymlinkFeature,
27
28
    TestCaseWithTransport,
28
 
    TestSkipped,
29
29
    )
30
30
 
31
31
 
45
45
        files = self.build_tree(['a', 'c', 'subdir/'])
46
46
        tree.add(['a', 'c', 'subdir'])
47
47
 
48
 
        self.run_bzr('mv', 'a', 'b')
 
48
        self.run_bzr('mv a b')
49
49
        self.assertMoved('a','b')
50
50
 
51
 
        self.run_bzr('mv', 'b', 'subdir')
 
51
        self.run_bzr('mv b subdir')
52
52
        self.assertMoved('b','subdir/b')
53
53
 
54
 
        self.run_bzr('mv', 'subdir/b', 'a')
 
54
        self.run_bzr('mv subdir/b a')
55
55
        self.assertMoved('subdir/b','a')
56
56
 
57
 
        self.run_bzr('mv', 'a', 'c', 'subdir')
 
57
        self.run_bzr('mv a c subdir')
58
58
        self.assertMoved('a','subdir/a')
59
59
        self.assertMoved('c','subdir/c')
60
60
 
61
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
61
        self.run_bzr('mv subdir/a subdir/newa')
62
62
        self.assertMoved('subdir/a','subdir/newa')
63
63
 
64
64
    def test_mv_unversioned(self):
65
65
        self.build_tree(['unversioned.txt'])
66
66
        self.run_bzr_error(
67
67
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
68
 
             " .*unversioned.txt is not versioned$"],
69
 
            'mv', 'unversioned.txt', 'elsewhere')
 
68
             " .*unversioned.txt is not versioned\.$"],
 
69
            'mv unversioned.txt elsewhere')
70
70
 
71
71
    def test_mv_nonexisting(self):
72
72
        self.run_bzr_error(
73
73
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
74
 
             " .*doesnotexist is not versioned$"],
75
 
            'mv', 'doesnotexist', 'somewhereelse')
 
74
             " .*doesnotexist is not versioned\.$"],
 
75
            'mv doesnotexist somewhereelse')
76
76
 
77
77
    def test_mv_unqualified(self):
78
78
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
83
83
        tree.add(['test.txt'])
84
84
 
85
85
        self.run_bzr_error(
86
 
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned$"],
87
 
            'mv', 'test.txt', 'sub1')
 
86
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
 
87
            'mv test.txt sub1')
88
88
 
89
89
        self.run_bzr_error(
90
90
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
91
 
             "sub1 is not versioned$"],
92
 
            'mv', 'test.txt', 'sub1/hello.txt')
 
91
             "sub1 is not versioned\.$"],
 
92
            'mv test.txt sub1/hello.txt')
93
93
        
94
94
    def test_mv_dirs(self):
95
95
        tree = self.make_branch_and_tree('.')
96
96
        self.build_tree(['hello.txt', 'sub1/'])
97
97
        tree.add(['hello.txt', 'sub1'])
98
98
 
99
 
        self.run_bzr('mv', 'sub1', 'sub2')
 
99
        self.run_bzr('mv sub1 sub2')
100
100
        self.assertMoved('sub1','sub2')
101
101
 
102
 
        self.run_bzr('mv', 'hello.txt', 'sub2')
 
102
        self.run_bzr('mv hello.txt sub2')
103
103
        self.assertMoved('hello.txt','sub2/hello.txt')
104
104
 
105
105
        self.build_tree(['sub1/'])
106
106
        tree.add(['sub1'])
107
 
        self.run_bzr('mv', 'sub2/hello.txt', 'sub1')
 
107
        self.run_bzr('mv sub2/hello.txt sub1')
108
108
        self.assertMoved('sub2/hello.txt','sub1/hello.txt')
109
109
 
110
 
        self.run_bzr('mv', 'sub2', 'sub1')
 
110
        self.run_bzr('mv sub2 sub1')
111
111
        self.assertMoved('sub2','sub1/sub2')
112
112
 
113
113
    def test_mv_relative(self):
116
116
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
117
117
 
118
118
        os.chdir('sub1/sub2')
119
 
        self.run_bzr('mv', '../hello.txt', '.')
 
119
        self.run_bzr('mv ../hello.txt .')
120
120
        self.failUnlessExists('./hello.txt')
121
121
 
122
122
        os.chdir('..')
123
 
        self.run_bzr('mv', 'sub2/hello.txt', '.')
 
123
        self.run_bzr('mv sub2/hello.txt .')
124
124
        os.chdir('..')
125
125
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
126
126
 
 
127
    def test_mv_change_case(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
 
127
140
    def test_mv_smoke_aliases(self):
128
141
        # just test that aliases for mv exist, if their behaviour is changed in
129
142
        # the future, then extend the tests.
131
144
        tree = self.make_branch_and_tree('.')
132
145
        tree.add(['a'])
133
146
 
134
 
        self.run_bzr('move', 'a', 'b')
135
 
        self.run_bzr('rename', 'b', 'a')
 
147
        self.run_bzr('move a b')
 
148
        self.run_bzr('rename b a')
136
149
 
137
150
    def test_mv_through_symlinks(self):
138
 
        if not osutils.has_symlinks():
139
 
            raise TestSkipped('Symlinks are not supported on this platform')
 
151
        self.requireFeature(SymlinkFeature)
140
152
        tree = self.make_branch_and_tree('.')
141
153
        self.build_tree(['a/', 'a/b'])
142
154
        os.symlink('a', 'c')
143
155
        os.symlink('.', 'd')
144
156
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
145
 
        self.run_bzr('mv', 'c/b', 'b')
 
157
        self.run_bzr('mv c/b b')
146
158
        tree = workingtree.WorkingTree.open('.')
147
159
        self.assertEqual('b-id', tree.path2id('b'))
148
160
 
159
171
        tree.add(['a'])
160
172
 
161
173
        osutils.rename('a', 'b')
162
 
        self.run_bzr('mv', 'a', 'b')
 
174
        self.run_bzr('mv a b')
163
175
        self.assertMoved('a','b')
164
176
 
165
177
    def test_mv_already_moved_file_to_versioned_target(self):
177
189
        os.remove('b')
178
190
        osutils.rename('a', 'b')
179
191
        self.run_bzr_error(
180
 
            ["^bzr: ERROR: Could not move a => b. b is already versioned$"],
181
 
            'mv', 'a', 'b')
 
192
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
 
193
            'mv a b')
182
194
        #check that nothing changed
183
195
        self.failIfExists('a')
184
196
        self.failUnlessExists('b')
196
208
        tree.add(['a', 'sub'])
197
209
 
198
210
        osutils.rename('a', 'sub/a')
199
 
        self.run_bzr('mv', 'a', 'sub/a')
 
211
        self.run_bzr('mv a sub/a')
200
212
        self.assertMoved('a','sub/a')
201
213
 
202
214
    def test_mv_already_moved_file_into_unversioned_subdir(self):
213
225
 
214
226
        osutils.rename('a', 'sub/a')
215
227
        self.run_bzr_error(
216
 
            ["^bzr: ERROR: Could not move a => a: sub is not versioned$"],
217
 
            'mv', 'a', 'sub/a')
 
228
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
 
229
            'mv a sub/a')
218
230
        self.failIfExists('a')
219
231
        self.failUnlessExists('sub/a')
220
232
 
231
243
        tree.add(['a1', 'a2', 'sub'])
232
244
 
233
245
        osutils.rename('a1', 'sub/a1')
234
 
        self.run_bzr('mv', 'a1', 'a2', 'sub')
 
246
        self.run_bzr('mv a1 a2 sub')
235
247
        self.assertMoved('a1','sub/a1')
236
248
        self.assertMoved('a2','sub/a2')
237
249
 
249
261
 
250
262
        osutils.rename('a1', 'sub/a1')
251
263
        self.run_bzr_error(
252
 
            ["^bzr: ERROR: Could not move to sub. sub is not versioned$"],
253
 
            'mv', 'a1', 'a2', 'sub')
 
264
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
 
265
            'mv a1 a2 sub')
254
266
        self.failIfExists('a1')
255
267
        self.failUnlessExists('sub/a1')
256
268
        self.failUnlessExists('a2')
273
285
        self.build_tree(['a']) #touch a
274
286
        self.run_bzr_error(
275
287
            ["^bzr: ERROR: Could not rename a => b because both files exist."
276
 
             " \(Use --after to update the Bazaar id\)$"],
277
 
            'mv', 'a', 'b')
 
288
             " \(Use --after to tell bzr about a rename that has already"
 
289
             " happened\)$"],
 
290
            'mv a b')
278
291
        self.failUnlessExists('a')
279
292
        self.failUnlessExists('b')
280
293
 
295
308
        osutils.rename('a', 'b')
296
309
        self.build_tree(['a']) #touch a
297
310
 
298
 
        self.run_bzr('mv', 'a', 'b', '--after')
 
311
        self.run_bzr('mv a b --after')
299
312
        self.failUnlessExists('a')
300
313
        self.assertNotInWorkingTree('a')#a should be unknown now.
301
314
        self.failUnlessExists('b')
321
334
        self.build_tree(['a2']) #touch a2
322
335
 
323
336
        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')
 
337
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
 
338
             " exist. \(Use --after to tell bzr about a rename that has already"
 
339
             " happened\)$"],
 
340
            'mv a1 a2 sub')
327
341
        self.failUnlessExists('a1')
328
342
        self.failUnlessExists('a2')
329
343
        self.failUnlessExists('sub/a1')
350
364
        self.build_tree(['a1']) #touch a1
351
365
        self.build_tree(['a2']) #touch a2
352
366
 
353
 
        self.run_bzr('mv', 'a1', 'a2', 'sub', '--after')
 
367
        self.run_bzr('mv a1 a2 sub --after')
354
368
        self.failUnlessExists('a1')
355
369
        self.failUnlessExists('a2')
356
370
        self.failUnlessExists('sub/a1')