~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006-2010 Canonical Ltd
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
16
17
"""Test for 'bzr mv'"""
18
19
import os
20
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
21
import bzrlib.branch
2091.3.6 by Aaron Bentley
Add symlink test guards
22
from bzrlib import (
23
    osutils,
24
    workingtree,
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
25
    )
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
26
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
27
from bzrlib.tests import (
3246.1.2 by Alexander Belchenko
test_mv_file_to_wrong_case_dir require feature CaseInsensitiveFilesystem
28
    CaseInsensitiveFilesystemFeature,
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
29
    SymlinkFeature,
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
30
    TestCaseWithTransport,
31
    )
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
32
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
33
34
class TestMove(TestCaseWithTransport):
35
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
36
    def assertMoved(self,from_path,to_path):
37
        """Assert that to_path is existing and versioned but from_path not. """
38
        self.failIfExists(from_path)
39
        self.assertNotInWorkingTree(from_path)
40
41
        self.failUnlessExists(to_path)
42
        self.assertInWorkingTree(to_path)
43
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
44
    def test_mv_modes(self):
45
        """Test two modes of operation for mv"""
46
        tree = self.make_branch_and_tree('.')
47
        files = self.build_tree(['a', 'c', 'subdir/'])
48
        tree.add(['a', 'c', 'subdir'])
49
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
50
        self.run_bzr('mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
51
        self.assertMoved('a','b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
52
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
53
        self.run_bzr('mv b subdir')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
54
        self.assertMoved('b','subdir/b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
55
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
56
        self.run_bzr('mv subdir/b a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
57
        self.assertMoved('subdir/b','a')
1846.1.2 by Wouter van Heyst
test mv more rigorously
58
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
59
        self.run_bzr('mv a c subdir')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
60
        self.assertMoved('a','subdir/a')
61
        self.assertMoved('c','subdir/c')
1846.1.2 by Wouter van Heyst
test mv more rigorously
62
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
63
        self.run_bzr('mv subdir/a subdir/newa')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
64
        self.assertMoved('subdir/a','subdir/newa')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
65
66
    def test_mv_unversioned(self):
67
        self.build_tree(['unversioned.txt'])
68
        self.run_bzr_error(
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
69
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
70
             " .*unversioned.txt is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
71
            'mv unversioned.txt elsewhere')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
72
73
    def test_mv_nonexisting(self):
74
        self.run_bzr_error(
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
75
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
76
             " .*doesnotexist is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
77
            'mv doesnotexist somewhereelse')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
78
79
    def test_mv_unqualified(self):
80
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
81
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
82
    def test_mv_invalid(self):
83
        tree = self.make_branch_and_tree('.')
84
        self.build_tree(['test.txt', 'sub1/'])
85
        tree.add(['test.txt'])
86
87
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
88
            ["^bzr: ERROR: Could not move to sub1: sub1 is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
89
            'mv test.txt sub1')
2206.1.7 by Marius Kruger
* errors
90
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
91
        self.run_bzr_error(
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
92
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
93
             "sub1 is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
94
            'mv test.txt sub1/hello.txt')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
95
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
96
    def test_mv_dirs(self):
97
        tree = self.make_branch_and_tree('.')
98
        self.build_tree(['hello.txt', 'sub1/'])
99
        tree.add(['hello.txt', 'sub1'])
100
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
101
        self.run_bzr('mv sub1 sub2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
102
        self.assertMoved('sub1','sub2')
103
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
104
        self.run_bzr('mv hello.txt sub2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
105
        self.assertMoved('hello.txt','sub2/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
106
107
        self.build_tree(['sub1/'])
108
        tree.add(['sub1'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
109
        self.run_bzr('mv sub2/hello.txt sub1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
110
        self.assertMoved('sub2/hello.txt','sub1/hello.txt')
111
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
112
        self.run_bzr('mv sub2 sub1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
113
        self.assertMoved('sub2','sub1/sub2')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
114
1846.1.2 by Wouter van Heyst
test mv more rigorously
115
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
116
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
117
        tree = self.make_branch_and_tree('.')
118
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
119
120
        os.chdir('sub1/sub2')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
121
        self.run_bzr('mv ../hello.txt .')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
122
        self.failUnlessExists('./hello.txt')
123
124
        os.chdir('..')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
125
        self.run_bzr('mv sub2/hello.txt .')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
126
        os.chdir('..')
127
        self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
128
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
129
    def test_mv_change_case_file(self):
2978.8.2 by Alexander Belchenko
teach fancy_rename to handle change case renames in possible case-insensitive filesystem
130
        # test for bug #77740 (mv unable change filename case on Windows)
2978.8.1 by Alexander Belchenko
Rename on Windows is able to change filename case. (#77740)
131
        tree = self.make_branch_and_tree('.')
132
        self.build_tree(['test.txt'])
133
        tree.add(['test.txt'])
134
        self.run_bzr('mv test.txt Test.txt')
2978.8.2 by Alexander Belchenko
teach fancy_rename to handle change case renames in possible case-insensitive filesystem
135
        # we can't use failUnlessExists on case-insensitive filesystem
136
        # so try to check shape of the tree
2978.8.1 by Alexander Belchenko
Rename on Windows is able to change filename case. (#77740)
137
        shape = sorted(os.listdir(u'.'))
138
        self.assertEqual(['.bzr', 'Test.txt'], shape)
139
        self.assertInWorkingTree('Test.txt')
140
        self.assertNotInWorkingTree('test.txt')
141
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
142
    def test_mv_change_case_dir(self):
143
        tree = self.make_branch_and_tree('.')
144
        self.build_tree(['foo/'])
145
        tree.add(['foo'])
146
        self.run_bzr('mv foo Foo')
147
        # we can't use failUnlessExists on case-insensitive filesystem
148
        # so try to check shape of the tree
149
        shape = sorted(os.listdir(u'.'))
150
        self.assertEqual(['.bzr', 'Foo'], shape)
151
        self.assertInWorkingTree('Foo')
152
        self.assertNotInWorkingTree('foo')
153
154
    def test_mv_change_case_dir_w_files(self):
155
        tree = self.make_branch_and_tree('.')
156
        self.build_tree(['foo/', 'foo/bar'])
157
        tree.add(['foo'])
158
        self.run_bzr('mv foo Foo')
159
        # we can't use failUnlessExists on case-insensitive filesystem
160
        # so try to check shape of the tree
161
        shape = sorted(os.listdir(u'.'))
162
        self.assertEqual(['.bzr', 'Foo'], shape)
163
        self.assertInWorkingTree('Foo')
164
        self.assertNotInWorkingTree('foo')
165
166
    def test_mv_file_to_wrong_case_dir(self):
3246.1.2 by Alexander Belchenko
test_mv_file_to_wrong_case_dir require feature CaseInsensitiveFilesystem
167
        self.requireFeature(CaseInsensitiveFilesystemFeature)
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
168
        tree = self.make_branch_and_tree('.')
169
        self.build_tree(['foo/', 'bar'])
170
        tree.add(['foo', 'bar'])
171
        out, err = self.run_bzr('mv bar Foo', retcode=3)
172
        self.assertEquals('', out)
173
        self.assertEquals(
174
            'bzr: ERROR: Could not move to Foo: Foo is not versioned.\n',
175
            err)
176
1846.1.2 by Wouter van Heyst
test mv more rigorously
177
    def test_mv_smoke_aliases(self):
178
        # just test that aliases for mv exist, if their behaviour is changed in
179
        # the future, then extend the tests.
180
        self.build_tree(['a'])
181
        tree = self.make_branch_and_tree('.')
182
        tree.add(['a'])
183
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
184
        self.run_bzr('move a b')
185
        self.run_bzr('rename b a')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
186
187
    def test_mv_through_symlinks(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
188
        self.requireFeature(SymlinkFeature)
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
189
        tree = self.make_branch_and_tree('.')
190
        self.build_tree(['a/', 'a/b'])
191
        os.symlink('a', 'c')
192
        os.symlink('.', 'd')
193
        tree.add(['a', 'a/b', 'c'], ['a-id', 'b-id', 'c-id'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
194
        self.run_bzr('mv c/b b')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
195
        tree = workingtree.WorkingTree.open('.')
196
        self.assertEqual('b-id', tree.path2id('b'))
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
197
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
198
    def test_mv_already_moved_file(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
199
        """Test bzr mv original_file to moved_file.
200
201
        Tests if a file which has allready been moved by an external tool,
202
        is handled correctly by bzr mv.
203
        Setup: a is in the working tree, b does not exist.
204
        User does: mv a b; bzr mv a b
205
        """
206
        self.build_tree(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
207
        tree = self.make_branch_and_tree('.')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
208
        tree.add(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
209
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
210
        osutils.rename('a', 'b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
211
        self.run_bzr('mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
212
        self.assertMoved('a','b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
213
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
214
    def test_mv_already_moved_file_to_versioned_target(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
215
        """Test bzr mv existing_file to versioned_file.
216
217
        Tests if an attempt to move an existing versioned file
218
        to another versiond file will fail.
219
        Setup: a and b are in the working tree.
220
        User does: rm b; mv a b; bzr mv a b
221
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
222
        self.build_tree(['a', 'b'])
223
        tree = self.make_branch_and_tree('.')
224
        tree.add(['a', 'b'])
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
225
226
        os.remove('b')
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
227
        osutils.rename('a', 'b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
228
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
229
            ["^bzr: ERROR: Could not move a => b. b is already versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
230
            'mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
231
        #check that nothing changed
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
232
        self.failIfExists('a')
233
        self.failUnlessExists('b')
234
235
    def test_mv_already_moved_file_into_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
236
        """Test bzr mv original_file to versioned_directory/file.
237
238
        Tests if a file which has already been moved into a versioned
239
        directory by an external tool, is handled correctly by bzr mv.
240
        Setup: a and sub/ are in the working tree.
241
        User does: mv a sub/a; bzr mv a sub/a
242
        """
243
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
244
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
245
        tree.add(['a', 'sub'])
246
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
247
        osutils.rename('a', 'sub/a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
248
        self.run_bzr('mv a sub/a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
249
        self.assertMoved('a','sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
250
251
    def test_mv_already_moved_file_into_unversioned_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
252
        """Test bzr mv original_file to unversioned_directory/file.
253
254
        Tests if an attempt to move an existing versioned file
255
        into an unversioned directory will fail.
256
        Setup: a is in the working tree, sub/ is not.
257
        User does: mv a sub/a; bzr mv a sub/a
258
        """
259
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
260
        tree = self.make_branch_and_tree('.')
261
        tree.add(['a'])
262
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
263
        osutils.rename('a', 'sub/a')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
264
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
265
            ["^bzr: ERROR: Could not move a => a: sub is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
266
            'mv a sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
267
        self.failIfExists('a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
268
        self.failUnlessExists('sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
269
270
    def test_mv_already_moved_files_into_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
271
        """Test bzr mv original_files to versioned_directory.
272
273
        Tests if files which has already been moved into a versioned
274
        directory by an external tool, is handled correctly by bzr mv.
275
        Setup: a1, a2, sub are in the working tree.
276
        User does: mv a1 sub/.; bzr mv a1 a2 sub
277
        """
278
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
279
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
280
        tree.add(['a1', 'a2', 'sub'])
281
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
282
        osutils.rename('a1', 'sub/a1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
283
        self.run_bzr('mv a1 a2 sub')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
284
        self.assertMoved('a1','sub/a1')
285
        self.assertMoved('a2','sub/a2')
286
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
287
    def test_mv_already_moved_files_into_unversioned_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
288
        """Test bzr mv original_file to unversioned_directory.
289
290
        Tests if an attempt to move existing versioned file
291
        into an unversioned directory will fail.
292
        Setup: a1, a2 are in the working tree, sub is not.
293
        User does: mv a1 sub/.; bzr mv a1 a2 sub
294
        """
295
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
296
        tree = self.make_branch_and_tree('.')
297
        tree.add(['a1', 'a2'])
298
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
299
        osutils.rename('a1', 'sub/a1')
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
300
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
301
            ["^bzr: ERROR: Could not move to sub. sub is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
302
            'mv a1 a2 sub')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
303
        self.failIfExists('a1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
304
        self.failUnlessExists('sub/a1')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
305
        self.failUnlessExists('a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
306
        self.failIfExists('sub/a2')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
307
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
308
    def test_mv_already_moved_file_forcing_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
309
        """Test bzr mv versioned_file to unversioned_file.
310
311
        Tests if an attempt to move an existing versioned file to an existing
312
        unversioned file will fail, informing the user to use the --after
313
        option to force this.
314
        Setup: a is in the working tree, b not versioned.
315
        User does: mv a b; touch a; bzr mv a b
316
        """
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
317
        self.build_tree(['a', 'b'])
318
        tree = self.make_branch_and_tree('.')
319
        tree.add(['a'])
320
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
321
        osutils.rename('a', 'b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
322
        self.build_tree(['a']) #touch a
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
323
        self.run_bzr_error(
2220.1.12 by Marius Kruger
* Fix errors.py import order
324
            ["^bzr: ERROR: Could not rename a => b because both files exist."
2967.3.2 by Daniel Watkins
Modified tests to reflect modified error messages.
325
             " \(Use --after to tell bzr about a rename that has already"
326
             " happened\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
327
            'mv a b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
328
        self.failUnlessExists('a')
329
        self.failUnlessExists('b')
330
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
331
    def test_mv_already_moved_file_using_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
332
        """Test bzr mv --after versioned_file to unversioned_file.
333
334
        Tests if an existing versioned file can be forced to move to an
335
        existing unversioned file using the --after option. With the result
336
        that bazaar considers the unversioned_file to be moved from
337
        versioned_file and versioned_file will become unversioned.
338
        Setup: a is in the working tree and b exists.
339
        User does: mv a b; touch a; bzr mv a b --after
340
        Resulting in a => b and a is unknown.
341
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
342
        self.build_tree(['a', 'b'])
343
        tree = self.make_branch_and_tree('.')
344
        tree.add(['a'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
345
        osutils.rename('a', 'b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
346
        self.build_tree(['a']) #touch a
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
347
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
348
        self.run_bzr('mv a b --after')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
349
        self.failUnlessExists('a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
350
        self.assertNotInWorkingTree('a')#a should be unknown now.
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
351
        self.failUnlessExists('b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
352
        self.assertInWorkingTree('b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
353
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
354
    def test_mv_already_moved_files_forcing_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
355
        """Test bzr mv versioned_files to directory/unversioned_file.
356
357
        Tests if an attempt to move an existing versioned file to an existing
358
        unversioned file in some other directory will fail, informing the user
359
        to use the --after option to force this.
360
361
        Setup: a1, a2, sub are versioned and in the working tree,
362
               sub/a1, sub/a2 are in working tree.
363
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
364
        """
365
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
366
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
367
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
368
        osutils.rename('a1', 'sub/a1')
369
        osutils.rename('a2', 'sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
370
        self.build_tree(['a1']) #touch a1
371
        self.build_tree(['a2']) #touch a2
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
372
373
        self.run_bzr_error(
2967.3.2 by Daniel Watkins
Modified tests to reflect modified error messages.
374
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
375
             " exist. \(Use --after to tell bzr about a rename that has already"
376
             " happened\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
377
            'mv a1 a2 sub')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
378
        self.failUnlessExists('a1')
379
        self.failUnlessExists('a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
380
        self.failUnlessExists('sub/a1')
381
        self.failUnlessExists('sub/a2')
382
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
383
    def test_mv_already_moved_files_using_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
384
        """Test bzr mv --after versioned_file to directory/unversioned_file.
385
386
        Tests if an existing versioned file can be forced to move to an
387
        existing unversioned file in some other directory using the --after
388
        option. With the result that bazaar considers
389
        directory/unversioned_file to be moved from versioned_file and
390
        versioned_file will become unversioned.
391
392
        Setup: a1, a2, sub are versioned and in the working tree,
393
               sub/a1, sub/a2 are in working tree.
394
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
395
        """
396
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
397
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
398
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
399
        osutils.rename('a1', 'sub/a1')
400
        osutils.rename('a2', 'sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
401
        self.build_tree(['a1']) #touch a1
402
        self.build_tree(['a2']) #touch a2
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
403
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
404
        self.run_bzr('mv a1 a2 sub --after')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
405
        self.failUnlessExists('a1')
406
        self.failUnlessExists('a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
407
        self.failUnlessExists('sub/a1')
408
        self.failUnlessExists('sub/a2')
409
        self.assertInWorkingTree('sub/a1')
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
410
        self.assertInWorkingTree('sub/a2')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
411
412
    def test_mv_already_moved_directory(self):
413
        """Use `bzr mv a b` to mark a directory as renamed.
414
415
        https://bugs.launchpad.net/bzr/+bug/107967/
416
        """
417
        self.build_tree(['a/', 'c/'])
418
        tree = self.make_branch_and_tree('.')
419
        tree.add(['a', 'c'])
420
        osutils.rename('a', 'b')
421
        osutils.rename('c', 'd')
422
        # mv a b should work just like it does for already renamed files
423
        self.run_bzr('mv a b')
424
        self.failIfExists('a')
425
        self.assertNotInWorkingTree('a')
426
        self.failUnlessExists('b')
427
        self.assertInWorkingTree('b')
428
        # and --after should work, too (technically it's ignored)
429
        self.run_bzr('mv --after c d')
430
        self.failIfExists('c')
431
        self.assertNotInWorkingTree('c')
432
        self.failUnlessExists('d')
433
        self.assertInWorkingTree('d')
3193.8.35 by Aaron Bentley
Implement mv --auto.
434
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
435
    def make_abcd_tree(self):
3193.8.35 by Aaron Bentley
Implement mv --auto.
436
        tree = self.make_branch_and_tree('tree')
437
        self.build_tree(['tree/a', 'tree/c'])
438
        tree.add(['a', 'c'])
439
        tree.commit('record old names')
440
        osutils.rename('tree/a', 'tree/b')
441
        osutils.rename('tree/c', 'tree/d')
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
442
        return tree
443
444
    def test_mv_auto(self):
445
        self.make_abcd_tree()
3193.8.35 by Aaron Bentley
Implement mv --auto.
446
        out, err = self.run_bzr('mv --auto', working_dir='tree')
447
        self.assertEqual(out, '')
448
        self.assertEqual(err, 'a => b\nc => d\n')
449
        tree = workingtree.WorkingTree.open('tree')
450
        self.assertIsNot(None, tree.path2id('b'))
451
        self.assertIsNot(None, tree.path2id('d'))
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
452
453
    def test_mv_auto_one_path(self):
454
        self.make_abcd_tree()
455
        out, err = self.run_bzr('mv --auto tree')
456
        self.assertEqual(out, '')
457
        self.assertEqual(err, 'a => b\nc => d\n')
458
        tree = workingtree.WorkingTree.open('tree')
459
        self.assertIsNot(None, tree.path2id('b'))
460
        self.assertIsNot(None, tree.path2id('d'))
461
462
    def test_mv_auto_two_paths(self):
463
        self.make_abcd_tree()
464
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
465
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
466
                         ' --auto.\n', err)
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
467
468
    def test_mv_auto_dry_run(self):
469
        self.make_abcd_tree()
470
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
471
        self.assertEqual(out, '')
472
        self.assertEqual(err, 'a => b\nc => d\n')
473
        tree = workingtree.WorkingTree.open('tree')
474
        self.assertIsNot(None, tree.path2id('a'))
475
        self.assertIsNot(None, tree.path2id('c'))
476
477
    def test_mv_no_auto_dry_run(self):
478
        self.make_abcd_tree()
479
        out, err = self.run_bzr('mv c d --dry-run',
480
                                working_dir='tree', retcode=3)
481
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
482
483
    def test_mv_auto_after(self):
484
        self.make_abcd_tree()
485
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
486
                                retcode=3)
487
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
488
                         ' --auto.\n', err)
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
489
4795.3.2 by Andrew Bennetts
Add test, and NEWS entry.
490
    def test_mv_quiet(self):
491
        tree = self.make_branch_and_tree('.')
492
        self.build_tree(['aaa'])
493
        tree.add(['aaa'])
494
        out, err = self.run_bzr('mv --quiet aaa bbb')
495
        self.assertEqual(out, '')
496
        self.assertEqual(err, '')
497
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
498
    def test_mv_readonly_lightweight_checkout(self):
499
        branch = self.make_branch('foo')
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
500
        branch = bzrlib.branch.Branch.open(self.get_readonly_url('foo'))
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
501
        tree = branch.create_checkout('tree', lightweight=True)
502
        self.build_tree(['tree/path'])
503
        tree.add('path')
504
        # If this fails, the tree is trying to acquire a branch lock, which it
505
        # shouldn't.
506
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])