/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
17
"""Test for 'brz mv'"""
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
18
19
import os
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
import breezy.branch
22
from breezy import (
2091.3.6 by Aaron Bentley
Add symlink test guards
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.tests import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
28
    TestCaseWithTransport,
7211.7.1 by Jelmer Vernooij
Add test reproducing bug.
29
    script,
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
30
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
31
from breezy.tests.features import (
3246.1.2 by Alexander Belchenko
test_mv_file_to_wrong_case_dir require feature CaseInsensitiveFilesystem
32
    CaseInsensitiveFilesystemFeature,
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
33
    SymlinkFeature,
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
34
    UnicodeFilenameFeature,
2158.2.1 by v.ladeuil+lp at free
Windows tests cleanup.
35
    )
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
36
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
37
38
class TestMove(TestCaseWithTransport):
39
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
40
    def assertMoved(self, from_path, to_path):
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
41
        """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
42
        self.assertPathDoesNotExist(from_path)
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
43
        self.assertNotInWorkingTree(from_path)
44
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
45
        self.assertPathExists(to_path)
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
46
        self.assertInWorkingTree(to_path)
47
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
48
    def test_mv_modes(self):
49
        """Test two modes of operation for mv"""
50
        tree = self.make_branch_and_tree('.')
51
        files = self.build_tree(['a', 'c', 'subdir/'])
52
        tree.add(['a', 'c', 'subdir'])
53
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
54
        self.run_bzr('mv a b')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
55
        self.assertMoved('a', 'b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
56
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
57
        self.run_bzr('mv b subdir')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
58
        self.assertMoved('b', 'subdir/b')
1846.1.2 by Wouter van Heyst
test mv more rigorously
59
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
60
        self.run_bzr('mv subdir/b a')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
61
        self.assertMoved('subdir/b', 'a')
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 a c subdir')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
64
        self.assertMoved('a', 'subdir/a')
65
        self.assertMoved('c', 'subdir/c')
1846.1.2 by Wouter van Heyst
test mv more rigorously
66
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
67
        self.run_bzr('mv subdir/a subdir/newa')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
68
        self.assertMoved('subdir/a', 'subdir/newa')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
69
70
    def test_mv_unversioned(self):
71
        self.build_tree(['unversioned.txt'])
72
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
73
            ["^brz: ERROR: Could not rename unversioned.txt => elsewhere."
74
             " .*unversioned.txt is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
75
            'mv unversioned.txt elsewhere')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
76
77
    def test_mv_nonexisting(self):
78
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
79
            ["^brz: ERROR: Could not rename doesnotexist => somewhereelse."
80
             " .*doesnotexist is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
81
            'mv doesnotexist somewhereelse')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
82
83
    def test_mv_unqualified(self):
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
84
        self.run_bzr_error(['^brz: ERROR: missing file argument$'], 'mv')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
85
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
86
    def test_mv_invalid(self):
87
        tree = self.make_branch_and_tree('.')
88
        self.build_tree(['test.txt', 'sub1/'])
89
        tree.add(['test.txt'])
90
91
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
92
            ["^brz: ERROR: Could not move to sub1: sub1 is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
93
            'mv test.txt sub1')
2206.1.7 by Marius Kruger
* errors
94
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
95
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
96
            ["^brz: ERROR: Could not move test.txt => .*hello.txt: "
97
             "sub1 is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
            'mv test.txt sub1/hello.txt')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
99
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
100
    def test_mv_dirs(self):
101
        tree = self.make_branch_and_tree('.')
102
        self.build_tree(['hello.txt', 'sub1/'])
103
        tree.add(['hello.txt', 'sub1'])
104
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
105
        self.run_bzr('mv sub1 sub2')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
106
        self.assertMoved('sub1', 'sub2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
107
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
108
        self.run_bzr('mv hello.txt sub2')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
109
        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.
110
111
        self.build_tree(['sub1/'])
112
        tree.add(['sub1'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
113
        self.run_bzr('mv sub2/hello.txt sub1')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
114
        self.assertMoved('sub2/hello.txt', 'sub1/hello.txt')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
115
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
116
        self.run_bzr('mv sub2 sub1')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
117
        self.assertMoved('sub2', 'sub1/sub2')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
118
1846.1.2 by Wouter van Heyst
test mv more rigorously
119
    def test_mv_relative(self):
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
120
        self.build_tree(['sub1/', 'sub1/sub2/', 'sub1/hello.txt'])
121
        tree = self.make_branch_and_tree('.')
122
        tree.add(['sub1', 'sub1/sub2', 'sub1/hello.txt'])
123
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.
124
        self.run_bzr('mv ../hello.txt .', working_dir='sub1/sub2')
125
        self.assertPathExists('sub1/sub2/hello.txt')
1846.1.1 by Wouter van Heyst
Don't fail on 'bzr mv', extract move tests from OldTests.
126
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.
127
        self.run_bzr('mv sub2/hello.txt .', working_dir='sub1')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
128
        self.assertMoved('sub1/sub2/hello.txt', 'sub1/hello.txt')
1846.1.2 by Wouter van Heyst
test mv more rigorously
129
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
130
    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
131
        # 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)
132
        tree = self.make_branch_and_tree('.')
133
        self.build_tree(['test.txt'])
134
        tree.add(['test.txt'])
135
        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
136
        # we can't use failUnlessExists on case-insensitive filesystem
137
        # so try to check shape of the tree
2978.8.1 by Alexander Belchenko
Rename on Windows is able to change filename case. (#77740)
138
        shape = sorted(os.listdir(u'.'))
139
        self.assertEqual(['.bzr', 'Test.txt'], shape)
140
        self.assertInWorkingTree('Test.txt')
141
        self.assertNotInWorkingTree('test.txt')
142
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
143
    def test_mv_change_case_dir(self):
144
        tree = self.make_branch_and_tree('.')
145
        self.build_tree(['foo/'])
146
        tree.add(['foo'])
147
        self.run_bzr('mv foo Foo')
148
        # we can't use failUnlessExists on case-insensitive filesystem
149
        # so try to check shape of the tree
150
        shape = sorted(os.listdir(u'.'))
151
        self.assertEqual(['.bzr', 'Foo'], shape)
152
        self.assertInWorkingTree('Foo')
153
        self.assertNotInWorkingTree('foo')
154
155
    def test_mv_change_case_dir_w_files(self):
156
        tree = self.make_branch_and_tree('.')
157
        self.build_tree(['foo/', 'foo/bar'])
158
        tree.add(['foo'])
159
        self.run_bzr('mv foo Foo')
160
        # we can't use failUnlessExists on case-insensitive filesystem
161
        # so try to check shape of the tree
162
        shape = sorted(os.listdir(u'.'))
163
        self.assertEqual(['.bzr', 'Foo'], shape)
164
        self.assertInWorkingTree('Foo')
165
        self.assertNotInWorkingTree('foo')
166
167
    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
168
        self.requireFeature(CaseInsensitiveFilesystemFeature)
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
169
        tree = self.make_branch_and_tree('.')
170
        self.build_tree(['foo/', 'bar'])
171
        tree.add(['foo', 'bar'])
172
        out, err = self.run_bzr('mv bar Foo', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
173
        self.assertEqual('', out)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
174
        self.assertEqual(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
175
            'brz: ERROR: Could not move to Foo: Foo is not versioned.\n',
3246.1.1 by Alexander Belchenko
Allow rename (change case of name) directory on case-insensitive filesystem.
176
            err)
177
1846.1.2 by Wouter van Heyst
test mv more rigorously
178
    def test_mv_smoke_aliases(self):
179
        # just test that aliases for mv exist, if their behaviour is changed in
180
        # the future, then extend the tests.
181
        self.build_tree(['a'])
182
        tree = self.make_branch_and_tree('.')
183
        tree.add(['a'])
184
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
185
        self.run_bzr('move a b')
186
        self.run_bzr('rename b a')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
187
6220.3.4 by Jonathan Riddell
add test
188
    def test_mv_no_root(self):
189
        tree = self.make_branch_and_tree('.')
190
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
191
            ["brz: ERROR: can not move root of branch"],
6220.3.4 by Jonathan Riddell
add test
192
            'mv . a')
193
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
194
    def test_mv_through_symlinks(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
195
        self.requireFeature(SymlinkFeature)
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
196
        tree = self.make_branch_and_tree('.')
197
        self.build_tree(['a/', 'a/b'])
198
        os.symlink('a', 'c')
199
        os.symlink('.', 'd')
6855.4.1 by Jelmer Vernooij
Yet more bees.
200
        tree.add(['a', 'a/b', 'c'], [b'a-id', b'b-id', b'c-id'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
201
        self.run_bzr('mv c/b b')
2091.3.2 by Aaron Bentley
Traverse non-terminal symlinks for mv et al
202
        tree = workingtree.WorkingTree.open('.')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
203
        self.assertEqual(b'b-id', tree.path2id('b'))
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
204
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
205
    def test_mv_already_moved_file(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
206
        """Test brz mv original_file to moved_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
207
208
        Tests if a file which has allready been moved by an external tool,
6622.1.29 by Jelmer Vernooij
Fix some more tests.
209
        is handled correctly by brz mv.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
210
        Setup: a is in the working tree, b does not exist.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
211
        User does: mv a b; brz mv a b
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
212
        """
213
        self.build_tree(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
214
        tree = self.make_branch_and_tree('.')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
215
        tree.add(['a'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
216
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
217
        osutils.rename('a', 'b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
218
        self.run_bzr('mv a b')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
219
        self.assertMoved('a', 'b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
220
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
221
    def test_mv_already_moved_file_to_versioned_target(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
222
        """Test brz mv existing_file to versioned_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
223
224
        Tests if an attempt to move an existing versioned file
225
        to another versiond file will fail.
226
        Setup: a and b are in the working tree.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
227
        User does: rm b; mv a b; brz mv a b
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
228
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
229
        self.build_tree(['a', 'b'])
230
        tree = self.make_branch_and_tree('.')
231
        tree.add(['a', 'b'])
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
232
233
        os.remove('b')
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
234
        osutils.rename('a', 'b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
235
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
236
            ["^brz: ERROR: Could not move a => b. b is already versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
237
            'mv a b')
7143.15.2 by Jelmer Vernooij
Run autopep8.
238
        # check that nothing changed
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
239
        self.assertPathDoesNotExist('a')
240
        self.assertPathExists('b')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
241
242
    def test_mv_already_moved_file_into_subdir(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
243
        """Test brz mv original_file to versioned_directory/file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
244
245
        Tests if a file which has already been moved into a versioned
6622.1.29 by Jelmer Vernooij
Fix some more tests.
246
        directory by an external tool, is handled correctly by brz mv.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
247
        Setup: a and sub/ are in the working tree.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
248
        User does: mv a sub/a; brz mv a sub/a
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
249
        """
250
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
251
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
252
        tree.add(['a', 'sub'])
253
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
254
        osutils.rename('a', 'sub/a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
255
        self.run_bzr('mv a sub/a')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
256
        self.assertMoved('a', 'sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
257
258
    def test_mv_already_moved_file_into_unversioned_subdir(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
259
        """Test brz mv original_file to unversioned_directory/file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
260
261
        Tests if an attempt to move an existing versioned file
262
        into an unversioned directory will fail.
263
        Setup: a is in the working tree, sub/ is not.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
264
        User does: mv a sub/a; brz mv a sub/a
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
265
        """
266
        self.build_tree(['a', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
267
        tree = self.make_branch_and_tree('.')
268
        tree.add(['a'])
269
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
270
        osutils.rename('a', 'sub/a')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
271
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
272
            ["^brz: ERROR: Could not move a => a: sub is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
273
            'mv a sub/a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
274
        self.assertPathDoesNotExist('a')
275
        self.assertPathExists('sub/a')
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
276
277
    def test_mv_already_moved_files_into_subdir(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
278
        """Test brz mv original_files to versioned_directory.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
279
280
        Tests if files which has already been moved into a versioned
6622.1.29 by Jelmer Vernooij
Fix some more tests.
281
        directory by an external tool, is handled correctly by brz mv.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
282
        Setup: a1, a2, sub are in the working tree.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
283
        User does: mv a1 sub/.; brz mv a1 a2 sub
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
284
        """
285
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
286
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
287
        tree.add(['a1', 'a2', 'sub'])
288
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
289
        osutils.rename('a1', 'sub/a1')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
290
        self.run_bzr('mv a1 a2 sub')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
291
        self.assertMoved('a1', 'sub/a1')
292
        self.assertMoved('a2', 'sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
293
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
294
    def test_mv_already_moved_files_into_unversioned_subdir(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
295
        """Test brz mv original_file to unversioned_directory.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
296
297
        Tests if an attempt to move existing versioned file
298
        into an unversioned directory will fail.
299
        Setup: a1, a2 are in the working tree, sub is not.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
300
        User does: mv a1 sub/.; brz mv a1 a2 sub
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
301
        """
302
        self.build_tree(['a1', 'a2', 'sub/'])
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
303
        tree = self.make_branch_and_tree('.')
304
        tree.add(['a1', 'a2'])
305
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
306
        osutils.rename('a1', 'sub/a1')
2206.1.8 by Marius Kruger
Converted move/rename error messages to show source => target.
307
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
308
            ["^brz: ERROR: Could not move to sub. sub is not versioned\\.$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
309
            'mv a1 a2 sub')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
310
        self.assertPathDoesNotExist('a1')
311
        self.assertPathExists('sub/a1')
312
        self.assertPathExists('a2')
313
        self.assertPathDoesNotExist('sub/a2')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
314
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
315
    def test_mv_already_moved_file_forcing_after(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
316
        """Test brz mv versioned_file to unversioned_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
317
318
        Tests if an attempt to move an existing versioned file to an existing
319
        unversioned file will fail, informing the user to use the --after
320
        option to force this.
321
        Setup: a is in the working tree, b not versioned.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
322
        User does: mv a b; touch a; brz mv a b
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
323
        """
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
324
        self.build_tree(['a', 'b'])
325
        tree = self.make_branch_and_tree('.')
326
        tree.add(['a'])
327
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
328
        osutils.rename('a', 'b')
7143.15.2 by Jelmer Vernooij
Run autopep8.
329
        self.build_tree(['a'])  # touch a
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
330
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
331
            ["^brz: ERROR: Could not rename a => b because both files exist."
332
             " \\(Use --after to tell brz about a rename that has already"
333
             " happened\\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
334
            'mv a b')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
335
        self.assertPathExists('a')
336
        self.assertPathExists('b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
337
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
338
    def test_mv_already_moved_file_using_after(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
339
        """Test brz mv --after versioned_file to unversioned_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
340
341
        Tests if an existing versioned file can be forced to move to an
342
        existing unversioned file using the --after option. With the result
343
        that bazaar considers the unversioned_file to be moved from
344
        versioned_file and versioned_file will become unversioned.
345
        Setup: a is in the working tree and b exists.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
346
        User does: mv a b; touch a; brz mv a b --after
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
347
        Resulting in a => b and a is unknown.
348
        """
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
349
        self.build_tree(['a', 'b'])
350
        tree = self.make_branch_and_tree('.')
351
        tree.add(['a'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
352
        osutils.rename('a', 'b')
7143.15.2 by Jelmer Vernooij
Run autopep8.
353
        self.build_tree(['a'])  # touch a
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
354
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
355
        self.run_bzr('mv a b --after')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
356
        self.assertPathExists('a')
7143.15.2 by Jelmer Vernooij
Run autopep8.
357
        self.assertNotInWorkingTree('a')  # a should be unknown now.
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
358
        self.assertPathExists('b')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
359
        self.assertInWorkingTree('b')
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
360
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
361
    def test_mv_already_moved_files_forcing_after(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
362
        """Test brz mv versioned_files to directory/unversioned_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
363
364
        Tests if an attempt to move an existing versioned file to an existing
365
        unversioned file in some other directory will fail, informing the user
366
        to use the --after option to force this.
367
368
        Setup: a1, a2, sub are versioned and in the working tree,
369
               sub/a1, sub/a2 are in working tree.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
370
        User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
371
        """
372
        self.build_tree(['a1', 'a2', 'sub/', 'sub/a1', 'sub/a2'])
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
373
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
374
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
375
        osutils.rename('a1', 'sub/a1')
376
        osutils.rename('a2', 'sub/a2')
7143.15.2 by Jelmer Vernooij
Run autopep8.
377
        self.build_tree(['a1'])  # touch a1
378
        self.build_tree(['a2'])  # touch a2
2123.3.4 by Steffen Eichenberg
a few new blackbox test for mv
379
380
        self.run_bzr_error(
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
381
            ["^brz: ERROR: Could not rename a1 => sub/a1 because both files"
382
             " exist. \\(Use --after to tell brz about a rename that has already"
383
             " happened\\)$"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
384
            'mv a1 a2 sub')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
385
        self.assertPathExists('a1')
386
        self.assertPathExists('a2')
387
        self.assertPathExists('sub/a1')
388
        self.assertPathExists('sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
389
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
390
    def test_mv_already_moved_files_using_after(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
391
        """Test brz mv --after versioned_file to directory/unversioned_file.
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
392
393
        Tests if an existing versioned file can be forced to move to an
394
        existing unversioned file in some other directory using the --after
395
        option. With the result that bazaar considers
396
        directory/unversioned_file to be moved from versioned_file and
397
        versioned_file will become unversioned.
398
399
        Setup: a1, a2, sub are versioned and in the working tree,
400
               sub/a1, sub/a2 are in working tree.
6622.1.29 by Jelmer Vernooij
Fix some more tests.
401
        User does: mv a* sub; touch a1; touch a2; brz mv a1 a2 sub --after
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
402
        """
403
        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
404
        tree = self.make_branch_and_tree('.')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
405
        tree.add(['a1', 'a2', 'sub'])
2309.2.3 by Alexander Belchenko
blackbox.test_mv: using safe osutils.rename instead of os.rename
406
        osutils.rename('a1', 'sub/a1')
407
        osutils.rename('a2', 'sub/a2')
7143.15.2 by Jelmer Vernooij
Run autopep8.
408
        self.build_tree(['a1'])  # touch a1
409
        self.build_tree(['a2'])  # touch a2
2123.3.7 by Steffen Eichenberg
split tests so that each new method contains one test only
410
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
411
        self.run_bzr('mv a1 a2 sub --after')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
412
        self.assertPathExists('a1')
413
        self.assertPathExists('a2')
414
        self.assertPathExists('sub/a1')
415
        self.assertPathExists('sub/a2')
2220.1.5 by Marius Kruger
* bzrlib/tests/blackbox/test_mv.py
416
        self.assertInWorkingTree('sub/a1')
2220.1.14 by Aaron Bentley
Cleanup formatting and error handling
417
        self.assertInWorkingTree('sub/a2')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
418
419
    def test_mv_already_moved_directory(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
420
        """Use `brz mv a b` to mark a directory as renamed.
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
421
422
        https://bugs.launchpad.net/bzr/+bug/107967/
423
        """
424
        self.build_tree(['a/', 'c/'])
425
        tree = self.make_branch_and_tree('.')
426
        tree.add(['a', 'c'])
427
        osutils.rename('a', 'b')
428
        osutils.rename('c', 'd')
429
        # mv a b should work just like it does for already renamed files
430
        self.run_bzr('mv a b')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
431
        self.assertPathDoesNotExist('a')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
432
        self.assertNotInWorkingTree('a')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
433
        self.assertPathExists('b')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
434
        self.assertInWorkingTree('b')
435
        # and --after should work, too (technically it's ignored)
436
        self.run_bzr('mv --after c d')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
437
        self.assertPathDoesNotExist('c')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
438
        self.assertNotInWorkingTree('c')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
439
        self.assertPathExists('d')
3201.2.1 by Lukáš Lalinský
Make 'mv a b' work for already renamed directories, like it does for files
440
        self.assertInWorkingTree('d')
3193.8.35 by Aaron Bentley
Implement mv --auto.
441
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
442
    def make_abcd_tree(self):
3193.8.35 by Aaron Bentley
Implement mv --auto.
443
        tree = self.make_branch_and_tree('tree')
444
        self.build_tree(['tree/a', 'tree/c'])
445
        tree.add(['a', 'c'])
446
        tree.commit('record old names')
447
        osutils.rename('tree/a', 'tree/b')
448
        osutils.rename('tree/c', 'tree/d')
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
449
        return tree
450
451
    def test_mv_auto(self):
452
        self.make_abcd_tree()
3193.8.35 by Aaron Bentley
Implement mv --auto.
453
        out, err = self.run_bzr('mv --auto', working_dir='tree')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
454
        self.assertEqual(out, '')
455
        self.assertEqual(err, 'a => b\nc => d\n')
3193.8.35 by Aaron Bentley
Implement mv --auto.
456
        tree = workingtree.WorkingTree.open('tree')
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
457
        self.assertTrue(tree.is_versioned('b'))
458
        self.assertTrue(tree.is_versioned('d'))
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
459
460
    def test_mv_auto_one_path(self):
461
        self.make_abcd_tree()
462
        out, err = self.run_bzr('mv --auto tree')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
463
        self.assertEqual(out, '')
464
        self.assertEqual(err, 'a => b\nc => d\n')
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
465
        tree = workingtree.WorkingTree.open('tree')
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
466
        self.assertTrue(tree.is_versioned('b'))
467
        self.assertTrue(tree.is_versioned('d'))
3193.8.36 by Aaron Bentley
Get remaining behaviour under test.
468
469
    def test_mv_auto_two_paths(self):
470
        self.make_abcd_tree()
471
        out, err = self.run_bzr('mv --auto tree tree2', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
472
        self.assertEqual('brz: ERROR: Only one path may be specified to'
473
                         ' --auto.\n', err)
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
474
475
    def test_mv_auto_dry_run(self):
476
        self.make_abcd_tree()
477
        out, err = self.run_bzr('mv --auto --dry-run', working_dir='tree')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
478
        self.assertEqual(out, '')
479
        self.assertEqual(err, 'a => b\nc => d\n')
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
480
        tree = workingtree.WorkingTree.open('tree')
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
481
        self.assertTrue(tree.is_versioned('a'))
482
        self.assertTrue(tree.is_versioned('c'))
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
483
484
    def test_mv_no_auto_dry_run(self):
485
        self.make_abcd_tree()
486
        out, err = self.run_bzr('mv c d --dry-run',
487
                                working_dir='tree', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
488
        self.assertEqual('brz: ERROR: --dry-run requires --auto.\n', err)
3193.8.37 by Aaron Bentley
Finish up conversion to mv --auto.
489
490
    def test_mv_auto_after(self):
491
        self.make_abcd_tree()
492
        out, err = self.run_bzr('mv --auto --after', working_dir='tree',
493
                                retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
494
        self.assertEqual('brz: ERROR: --after cannot be specified with'
495
                         ' --auto.\n', err)
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
496
4795.3.2 by Andrew Bennetts
Add test, and NEWS entry.
497
    def test_mv_quiet(self):
498
        tree = self.make_branch_and_tree('.')
499
        self.build_tree(['aaa'])
500
        tree.add(['aaa'])
501
        out, err = self.run_bzr('mv --quiet aaa bbb')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
502
        self.assertEqual(out, '')
503
        self.assertEqual(err, '')
4795.3.2 by Andrew Bennetts
Add test, and NEWS entry.
504
4539.2.1 by Robert Collins
Change cmd_mv not to take out branch locks. (Robert Collins, bug 216541)
505
    def test_mv_readonly_lightweight_checkout(self):
506
        branch = self.make_branch('foo')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
507
        branch = breezy.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)
508
        tree = branch.create_checkout('tree', lightweight=True)
509
        self.build_tree(['tree/path'])
510
        tree.add('path')
511
        # If this fails, the tree is trying to acquire a branch lock, which it
512
        # shouldn't.
513
        self.run_bzr(['mv', 'tree/path', 'tree/path2'])
5609.8.1 by Martin
Blackbox test reproducing problem encounted in bug 707954
514
515
    def test_mv_unversioned_non_ascii(self):
516
        """Clear error on mv of an unversioned non-ascii file, see lp:707954"""
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
517
        self.requireFeature(UnicodeFilenameFeature)
5609.8.1 by Martin
Blackbox test reproducing problem encounted in bug 707954
518
        tree = self.make_branch_and_tree(".")
519
        self.build_tree([u"\xA7"])
7045.4.8 by Jelmer Vernooij
Fix another 128 tests on python 3.
520
        out, err = self.run_bzr_error(["Could not rename", "not versioned"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
521
                                      ["mv", u"\xA7", "b"])
6346.1.1 by Martin Packman
Add blackbox test for mv on a removed non-ascii file
522
523
    def test_mv_removed_non_ascii(self):
524
        """Clear error on mv of a removed non-ascii file, see lp:898541"""
525
        self.requireFeature(UnicodeFilenameFeature)
526
        tree = self.make_branch_and_tree(".")
527
        self.build_tree([u"\xA7"])
528
        tree.add([u"\xA7"])
529
        tree.commit(u"Adding \xA7")
530
        os.remove(u"\xA7")
7045.4.8 by Jelmer Vernooij
Fix another 128 tests on python 3.
531
        out, err = self.run_bzr_error(["Could not rename", "not exist"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
532
                                      ["mv", u"\xA7", "b"])
7211.7.1 by Jelmer Vernooij
Add test reproducing bug.
533
534
    def test_dupe_move(self):
535
        self.script_runner = script.ScriptRunner()
536
        self.script_runner.run_script(self, '''
537
        $ brz init brz-bug
538
        Created a standalone tree (format: 2a)
539
        $ cd brz-bug
540
        $ mkdir dir
541
        $ brz add
542
        adding dir
543
        $ echo text >> dir/test.txt
544
        $ brz add
545
        adding dir/test.txt
546
        $ brz ci -m "Add files"
547
        2>Committing to: .../brz-bug/
548
        2>added dir
549
        2>added dir/test.txt
550
        2>Committed revision 1.
551
        $ mv dir dir2
552
        $ mv dir2/test.txt dir2/test2.txt
553
        $ brz st
554
        removed:
555
          dir/
556
          dir/test.txt
557
        unknown:
558
          dir2/
559
        $ brz mv dir dir2
560
        dir => dir2
561
        $ brz st
562
        removed:
563
          dir/test.txt
564
        renamed:
565
          dir/ => dir2/
566
        unknown:
567
          dir2/test2.txt
568
        $ brz mv dir/test.txt dir2/test2.txt
7211.7.2 by Jelmer Vernooij
Fix move when file was in different location, rather than removed.
569
        dir/test.txt => dir2/test2.txt
7211.7.1 by Jelmer Vernooij
Add test reproducing bug.
570
        ''')