~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 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 (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
28
    TestCaseWithTransport,
29
    )
30
from bzrlib.tests.features import (
3246.1.2 by Alexander Belchenko
test_mv_file_to_wrong_case_dir require feature CaseInsensitiveFilesystem
31
    CaseInsensitiveFilesystemFeature,
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
32
    SymlinkFeature,
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
33
    UnicodeFilenameFeature,
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
34
    )
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
35
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
36
37
class TestMove(TestCaseWithTransport):
38
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
39
    def assertMoved(self,from_path,to_path):
40
        """Assert that to_path is existing and versioned but from_path not. """
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
41
        self.assertPathDoesNotExist(from_path)
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
42
        self.assertNotInWorkingTree(from_path)
43
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
44
        self.assertPathExists(to_path)
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
45
        self.assertInWorkingTree(to_path)
46
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
47
    def test_mv_modes(self):
48
        """Test two modes of operation for mv"""
49
        tree = self.make_branch_and_tree('.')
50
        files = self.build_tree(['a', 'c', 'subdir/'])
51
        tree.add(['a', 'c', 'subdir'])
52
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
53
        self.run_bzr('mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
54
        self.assertMoved('a','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 b subdir')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
57
        self.assertMoved('b','subdir/b')
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 subdir/b a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
60
        self.assertMoved('subdir/b','a')
1846.1.2 by Wouter van Heyst
test mv more rigorously
61
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
62
        self.run_bzr('mv a c subdir')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
63
        self.assertMoved('a','subdir/a')
64
        self.assertMoved('c','subdir/c')
1846.1.2 by Wouter van Heyst
test mv more rigorously
65
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
66
        self.run_bzr('mv subdir/a subdir/newa')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
67
        self.assertMoved('subdir/a','subdir/newa')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
68
69
    def test_mv_unversioned(self):
70
        self.build_tree(['unversioned.txt'])
71
        self.run_bzr_error(
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
72
            ["^bzr: ERROR: Could not rename unversioned.txt => elsewhere."
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
73
             " .*unversioned.txt is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
74
            'mv unversioned.txt elsewhere')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
75
76
    def test_mv_nonexisting(self):
77
        self.run_bzr_error(
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
78
            ["^bzr: ERROR: Could not rename doesnotexist => somewhereelse."
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
79
             " .*doesnotexist is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
80
            'mv doesnotexist somewhereelse')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
81
82
    def test_mv_unqualified(self):
83
        self.run_bzr_error(['^bzr: ERROR: missing file argument$'], 'mv')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
84
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
85
    def test_mv_invalid(self):
86
        tree = self.make_branch_and_tree('.')
87
        self.build_tree(['test.txt', 'sub1/'])
88
        tree.add(['test.txt'])
89
90
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
91
            ["^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.
92
            'mv test.txt sub1')
2206.1.7 by Marius Kruger
* errors
93
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
94
        self.run_bzr_error(
2206.1.9 by Marius Kruger
* Change move/rename errors yet again
95
            ["^bzr: ERROR: Could not move test.txt => .*hello.txt: "
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
96
             "sub1 is not versioned\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
97
            'mv test.txt sub1/hello.txt')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
98
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
99
    def test_mv_dirs(self):
100
        tree = self.make_branch_and_tree('.')
101
        self.build_tree(['hello.txt', 'sub1/'])
102
        tree.add(['hello.txt', 'sub1'])
103
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
104
        self.run_bzr('mv sub1 sub2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
105
        self.assertMoved('sub1','sub2')
106
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
107
        self.run_bzr('mv hello.txt sub2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
108
        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.
109
110
        self.build_tree(['sub1/'])
111
        tree.add(['sub1'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
112
        self.run_bzr('mv sub2/hello.txt sub1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
113
        self.assertMoved('sub2/hello.txt','sub1/hello.txt')
114
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
115
        self.run_bzr('mv sub2 sub1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
116
        self.assertMoved('sub2','sub1/sub2')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
117
1846.1.2 by Wouter van Heyst
test mv more rigorously
118
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
119
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
120
        tree = self.make_branch_and_tree('.')
121
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
122
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
123
        self.run_bzr('mv ../hello.txt .', working_dir='sub1/sub2')
124
        self.assertPathExists('sub1/sub2/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
125
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
126
        self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
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)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
172
        self.assertEqual('', out)
173
        self.assertEqual(
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
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
6220.3.4 by Jonathan Riddell
add test
187
    def test_mv_no_root(self):
188
        tree = self.make_branch_and_tree('.')
189
        self.run_bzr_error(
190
            ["bzr: ERROR: can not move root of branch"],
191
            'mv . a')
192
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
193
    def test_mv_through_symlinks(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
194
        self.requireFeature(SymlinkFeature)
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
195
        tree = self.make_branch_and_tree('.')
196
        self.build_tree(['a/', 'a/b'])
197
        os.symlink('a', 'c')
198
        os.symlink('.', 'd')
199
        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.
200
        self.run_bzr('mv c/b b')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
201
        tree = workingtree.WorkingTree.open('.')
202
        self.assertEqual('b-id', tree.path2id('b'))
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
203
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
204
    def test_mv_already_moved_file(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
205
        """Test bzr mv original_file to moved_file.
206
207
        Tests if a file which has allready been moved by an external tool,
208
        is handled correctly by bzr mv.
209
        Setup: a is in the working tree, b does not exist.
210
        User does: mv a b; bzr mv a b
211
        """
212
        self.build_tree(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
213
        tree = self.make_branch_and_tree('.')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
214
        tree.add(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
215
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
216
        osutils.rename('a', 'b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
217
        self.run_bzr('mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
218
        self.assertMoved('a','b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
219
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
220
    def test_mv_already_moved_file_to_versioned_target(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
221
        """Test bzr mv existing_file to versioned_file.
222
223
        Tests if an attempt to move an existing versioned file
224
        to another versiond file will fail.
225
        Setup: a and b are in the working tree.
226
        User does: rm b; mv a b; bzr mv a b
227
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
228
        self.build_tree(['a', 'b'])
229
        tree = self.make_branch_and_tree('.')
230
        tree.add(['a', 'b'])
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
231
232
        os.remove('b')
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
233
        osutils.rename('a', 'b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
234
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
235
            ["^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.
236
            'mv a b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
237
        #check that nothing changed
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
238
        self.assertPathDoesNotExist('a')
239
        self.assertPathExists('b')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
240
241
    def test_mv_already_moved_file_into_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
242
        """Test bzr mv original_file to versioned_directory/file.
243
244
        Tests if a file which has already been moved into a versioned
245
        directory by an external tool, is handled correctly by bzr mv.
246
        Setup: a and sub/ are in the working tree.
247
        User does: mv a sub/a; bzr mv a sub/a
248
        """
249
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
250
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
251
        tree.add(['a', 'sub'])
252
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
253
        osutils.rename('a', 'sub/a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
254
        self.run_bzr('mv a sub/a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
255
        self.assertMoved('a','sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
256
257
    def test_mv_already_moved_file_into_unversioned_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
258
        """Test bzr mv original_file to unversioned_directory/file.
259
260
        Tests if an attempt to move an existing versioned file
261
        into an unversioned directory will fail.
262
        Setup: a is in the working tree, sub/ is not.
263
        User does: mv a sub/a; bzr mv a sub/a
264
        """
265
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
266
        tree = self.make_branch_and_tree('.')
267
        tree.add(['a'])
268
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
269
        osutils.rename('a', 'sub/a')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
270
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
271
            ["^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.
272
            'mv a sub/a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
273
        self.assertPathDoesNotExist('a')
274
        self.assertPathExists('sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
275
276
    def test_mv_already_moved_files_into_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
277
        """Test bzr mv original_files to versioned_directory.
278
279
        Tests if files which has already been moved into a versioned
280
        directory by an external tool, is handled correctly by bzr mv.
281
        Setup: a1, a2, sub are in the working tree.
282
        User does: mv a1 sub/.; bzr mv a1 a2 sub
283
        """
284
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
285
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
286
        tree.add(['a1', 'a2', 'sub'])
287
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
288
        osutils.rename('a1', 'sub/a1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
289
        self.run_bzr('mv a1 a2 sub')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
290
        self.assertMoved('a1','sub/a1')
291
        self.assertMoved('a2','sub/a2')
292
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
293
    def test_mv_already_moved_files_into_unversioned_subdir(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
294
        """Test bzr mv original_file to unversioned_directory.
295
296
        Tests if an attempt to move existing versioned file
297
        into an unversioned directory will fail.
298
        Setup: a1, a2 are in the working tree, sub is not.
299
        User does: mv a1 sub/.; bzr mv a1 a2 sub
300
        """
301
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
302
        tree = self.make_branch_and_tree('.')
303
        tree.add(['a1', 'a2'])
304
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
305
        osutils.rename('a1', 'sub/a1')
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
306
        self.run_bzr_error(
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
307
            ["^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.
308
            'mv a1 a2 sub')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
309
        self.assertPathDoesNotExist('a1')
310
        self.assertPathExists('sub/a1')
311
        self.assertPathExists('a2')
312
        self.assertPathDoesNotExist('sub/a2')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
313
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
314
    def test_mv_already_moved_file_forcing_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
315
        """Test bzr mv versioned_file to unversioned_file.
316
317
        Tests if an attempt to move an existing versioned file to an existing
318
        unversioned file will fail, informing the user to use the --after
319
        option to force this.
320
        Setup: a is in the working tree, b not versioned.
321
        User does: mv a b; touch a; bzr mv a b
322
        """
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
323
        self.build_tree(['a', 'b'])
324
        tree = self.make_branch_and_tree('.')
325
        tree.add(['a'])
326
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
327
        osutils.rename('a', 'b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
328
        self.build_tree(['a']) #touch a
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
329
        self.run_bzr_error(
2220.1.12 by Marius Kruger
* Fix errors.py import order
330
            ["^bzr: ERROR: Could not rename a => b because both files exist."
2967.3.2 by Daniel Watkins
Modified tests to reflect modified error messages.
331
             " \(Use --after to tell bzr about a rename that has already"
332
             " happened\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
333
            'mv a b')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
334
        self.assertPathExists('a')
335
        self.assertPathExists('b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
336
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
337
    def test_mv_already_moved_file_using_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
338
        """Test bzr mv --after versioned_file to unversioned_file.
339
340
        Tests if an existing versioned file can be forced to move to an
341
        existing unversioned file using the --after option. With the result
342
        that bazaar considers the unversioned_file to be moved from
343
        versioned_file and versioned_file will become unversioned.
344
        Setup: a is in the working tree and b exists.
345
        User does: mv a b; touch a; bzr mv a b --after
346
        Resulting in a => b and a is unknown.
347
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
348
        self.build_tree(['a', 'b'])
349
        tree = self.make_branch_and_tree('.')
350
        tree.add(['a'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
351
        osutils.rename('a', 'b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
352
        self.build_tree(['a']) #touch a
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
353
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
354
        self.run_bzr('mv a b --after')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
355
        self.assertPathExists('a')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
356
        self.assertNotInWorkingTree('a')#a should be unknown now.
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
357
        self.assertPathExists('b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
358
        self.assertInWorkingTree('b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
359
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
360
    def test_mv_already_moved_files_forcing_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
361
        """Test bzr mv versioned_files to directory/unversioned_file.
362
363
        Tests if an attempt to move an existing versioned file to an existing
364
        unversioned file in some other directory will fail, informing the user
365
        to use the --after option to force this.
366
367
        Setup: a1, a2, sub are versioned and in the working tree,
368
               sub/a1, sub/a2 are in working tree.
369
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub
370
        """
371
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
372
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
373
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
374
        osutils.rename('a1', 'sub/a1')
375
        osutils.rename('a2', 'sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
376
        self.build_tree(['a1']) #touch a1
377
        self.build_tree(['a2']) #touch a2
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
378
379
        self.run_bzr_error(
2967.3.2 by Daniel Watkins
Modified tests to reflect modified error messages.
380
            ["^bzr: ERROR: Could not rename a1 => sub/a1 because both files"
381
             " exist. \(Use --after to tell bzr about a rename that has already"
382
             " happened\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
383
            'mv a1 a2 sub')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
384
        self.assertPathExists('a1')
385
        self.assertPathExists('a2')
386
        self.assertPathExists('sub/a1')
387
        self.assertPathExists('sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
388
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
389
    def test_mv_already_moved_files_using_after(self):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
390
        """Test bzr mv --after versioned_file to directory/unversioned_file.
391
392
        Tests if an existing versioned file can be forced to move to an
393
        existing unversioned file in some other directory using the --after
394
        option. With the result that bazaar considers
395
        directory/unversioned_file to be moved from versioned_file and
396
        versioned_file will become unversioned.
397
398
        Setup: a1, a2, sub are versioned and in the working tree,
399
               sub/a1, sub/a2 are in working tree.
400
        User does: mv a* sub; touch a1; touch a2; bzr mv a1 a2 sub --after
401
        """
402
        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
403
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
404
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
405
        osutils.rename('a1', 'sub/a1')
406
        osutils.rename('a2', 'sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
407
        self.build_tree(['a1']) #touch a1
408
        self.build_tree(['a2']) #touch a2
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
409
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
410
        self.run_bzr('mv a1 a2 sub --after')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
411
        self.assertPathExists('a1')
412
        self.assertPathExists('a2')
413
        self.assertPathExists('sub/a1')
414
        self.assertPathExists('sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
415
        self.assertInWorkingTree('sub/a1')
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
416
        self.assertInWorkingTree('sub/a2')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
417
418
    def test_mv_already_moved_directory(self):
419
        """Use `bzr mv a b` to mark a directory as renamed.
420
421
        https://bugs.launchpad.net/bzr/+bug/107967/
422
        """
423
        self.build_tree(['a/', 'c/'])
424
        tree = self.make_branch_and_tree('.')
425
        tree.add(['a', 'c'])
426
        osutils.rename('a', 'b')
427
        osutils.rename('c', 'd')
428
        # mv a b should work just like it does for already renamed files
429
        self.run_bzr('mv a b')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
430
        self.assertPathDoesNotExist('a')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
431
        self.assertNotInWorkingTree('a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
432
        self.assertPathExists('b')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
433
        self.assertInWorkingTree('b')
434
        # and --after should work, too (technically it's ignored)
435
        self.run_bzr('mv --after c d')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
436
        self.assertPathDoesNotExist('c')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
437
        self.assertNotInWorkingTree('c')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
438
        self.assertPathExists('d')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
439
        self.assertInWorkingTree('d')
3193.8.35 by Aaron Bentley
Implement mv --auto.
440
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
441
    def make_abcd_tree(self):
3193.8.35 by Aaron Bentley
Implement mv --auto.
442
        tree = self.make_branch_and_tree('tree')
443
        self.build_tree(['tree/a', 'tree/c'])
444
        tree.add(['a', 'c'])
445
        tree.commit('record old names')
446
        osutils.rename('tree/a', 'tree/b')
447
        osutils.rename('tree/c', 'tree/d')
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
448
        return tree
449
450
    def test_mv_auto(self):
451
        self.make_abcd_tree()
3193.8.35 by Aaron Bentley
Implement mv --auto.
452
        out, err = self.run_bzr('mv --auto', working_dir='tree')
453
        self.assertEqual(out, '')
454
        self.assertEqual(err, 'a => b\nc => d\n')
455
        tree = workingtree.WorkingTree.open('tree')
456
        self.assertIsNot(None, tree.path2id('b'))
457
        self.assertIsNot(None, tree.path2id('d'))
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
458
459
    def test_mv_auto_one_path(self):
460
        self.make_abcd_tree()
461
        out, err = self.run_bzr('mv --auto tree')
462
        self.assertEqual(out, '')
463
        self.assertEqual(err, 'a => b\nc => d\n')
464
        tree = workingtree.WorkingTree.open('tree')
465
        self.assertIsNot(None, tree.path2id('b'))
466
        self.assertIsNot(None, tree.path2id('d'))
467
468
    def test_mv_auto_two_paths(self):
469
        self.make_abcd_tree()
470
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
471
        self.assertEqual('bzr: ERROR: Only one path may be specified to'
472
                         ' --auto.\n', err)
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
473
474
    def test_mv_auto_dry_run(self):
475
        self.make_abcd_tree()
476
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
477
        self.assertEqual(out, '')
478
        self.assertEqual(err, 'a => b\nc => d\n')
479
        tree = workingtree.WorkingTree.open('tree')
480
        self.assertIsNot(None, tree.path2id('a'))
481
        self.assertIsNot(None, tree.path2id('c'))
482
483
    def test_mv_no_auto_dry_run(self):
484
        self.make_abcd_tree()
485
        out, err = self.run_bzr('mv c d --dry-run',
486
                                working_dir='tree', retcode=3)
487
        self.assertEqual('bzr: ERROR: --dry-run requires --auto.\n', err)
488
489
    def test_mv_auto_after(self):
490
        self.make_abcd_tree()
491
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
492
                                retcode=3)
493
        self.assertEqual('bzr: ERROR: --after cannot be specified with'
494
                         ' --auto.\n', err)
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
495
4795.3.2 by Andrew Bennetts
Add test, and NEWS entry.
496
    def test_mv_quiet(self):
497
        tree = self.make_branch_and_tree('.')
498
        self.build_tree(['aaa'])
499
        tree.add(['aaa'])
500
        out, err = self.run_bzr('mv --quiet aaa bbb')
501
        self.assertEqual(out, '')
502
        self.assertEqual(err, '')
503
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
504
    def test_mv_readonly_lightweight_checkout(self):
505
        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.
506
        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)
507
        tree = branch.create_checkout('tree', lightweight=True)
508
        self.build_tree(['tree/path'])
509
        tree.add('path')
510
        # If this fails, the tree is trying to acquire a branch lock, which it
511
        # shouldn't.
512
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])
5609.8.1 by Martin
Blackbox test reproducing problem encounted in bug 707954
513
514
    def test_mv_unversioned_non_ascii(self):
515
        """Clear error on mv of an unversioned non-ascii file, see lp:707954"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
516
        self.requireFeature(UnicodeFilenameFeature)
5609.8.1 by Martin
Blackbox test reproducing problem encounted in bug 707954
517
        tree = self.make_branch_and_tree(".")
518
        self.build_tree([u"\xA7"])
519
        out, err = self.run_bzr_error(["Could not rename", "not versioned"],
520
            ["mv", u"\xA7", "b"])
6346.1.1 by Martin Packman
Add blackbox test for mv on a removed non-ascii file
521
522
    def test_mv_removed_non_ascii(self):
523
        """Clear error on mv of a removed non-ascii file, see lp:898541"""
524
        self.requireFeature(UnicodeFilenameFeature)
525
        tree = self.make_branch_and_tree(".")
526
        self.build_tree([u"\xA7"])
527
        tree.add([u"\xA7"])
528
        tree.commit(u"Adding \xA7")
529
        os.remove(u"\xA7")
530
        out, err = self.run_bzr_error(["Could not rename", "not exist"],
531
            ["mv", u"\xA7", "b"])