1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
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.
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.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Tests variations of case-insensitive and case-preserving file-systems."""
26
from bzrlib.tests import KnownFailure
27
from bzrlib.osutils import canonical_relpath, pathjoin
28
from bzrlib.tests.script import run_script
29
from bzrlib.tests.features import (
30
CaseInsCasePresFilenameFeature,
35
class TestCICPBase(tests.TestCaseWithTransport):
36
"""Base class for tests on a case-insensitive, case-preserving filesystem.
39
_test_needs_features = [CaseInsCasePresFilenameFeature]
41
def _make_mixed_case_tree(self):
42
"""Make a working tree with mixed-case filenames."""
43
wt = self.make_branch_and_tree('.')
44
# create a file on disk with the mixed-case parent and base name
45
self.build_tree(['CamelCaseParent/', 'lowercaseparent/'])
46
self.build_tree_contents([('CamelCaseParent/CamelCase', 'camel case'),
47
('lowercaseparent/lowercase', 'lower case'),
48
('lowercaseparent/mixedCase', 'mixedCasecase'),
53
class TestAdd(TestCICPBase):
55
def test_add_simple(self):
56
"""Test add always uses the case of the filename reported by the os."""
57
wt = self.make_branch_and_tree('.')
58
# create a file on disk with the mixed-case name
59
self.build_tree(['CamelCase'])
65
def test_add_subdir(self):
66
"""test_add_simple but with subdirectories tested too."""
67
wt = self.make_branch_and_tree('.')
68
# create a file on disk with the mixed-case parent and base name
69
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
71
$ bzr add camelcaseparent/camelcase
72
adding CamelCaseParent
73
adding CamelCaseParent/CamelCase
76
def test_add_implied(self):
77
"""test add with no args sees the correct names."""
78
wt = self.make_branch_and_tree('.')
79
# create a file on disk with the mixed-case parent and base name
80
self.build_tree(['CamelCaseParent/', 'CamelCaseParent/CamelCase'])
83
adding CamelCaseParent
84
adding CamelCaseParent/CamelCase
87
def test_re_add(self):
88
"""Test than when a file has 'unintentionally' changed case, we can't
89
add a new entry using the new case."""
90
wt = self.make_branch_and_tree('.')
91
# create a file on disk with the mixed-case name
92
self.build_tree(['MixedCase'])
97
# 'accidently' rename the file on disk
98
osutils.rename('MixedCase', 'mixedcase')
103
def test_re_add_dir(self):
104
# like re-add, but tests when the operation is on a directory.
105
"""Test than when a file has 'unintentionally' changed case, we can't
106
add a new entry using the new case."""
107
wt = self.make_branch_and_tree('.')
108
# create a file on disk with the mixed-case name
109
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
111
$ bzr add MixedCaseParent
112
adding MixedCaseParent
113
adding MixedCaseParent/MixedCase
115
# 'accidently' rename the directory on disk
116
osutils.rename('MixedCaseParent', 'mixedcaseparent')
118
$ bzr add mixedcaseparent
121
def test_add_not_found(self):
122
"""Test add when the input file doesn't exist."""
123
wt = self.make_branch_and_tree('.')
124
# create a file on disk with the mixed-case name
125
self.build_tree(['MixedCaseParent/', 'MixedCaseParent/MixedCase'])
126
expected_fname = pathjoin(wt.basedir, "MixedCaseParent", "notfound")
128
$ bzr add mixedcaseparent/notfound
129
2>bzr: ERROR: No such file: %s
130
""" % (repr(expected_fname),))
133
class TestMove(TestCICPBase):
135
def test_mv_newname(self):
136
wt = self._make_mixed_case_tree()
140
$ bzr mv camelcaseparent/camelcase camelcaseparent/NewCamelCase
141
CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
144
def test_mv_newname_after(self):
145
wt = self._make_mixed_case_tree()
146
# In this case we can specify the incorrect case for the destination,
147
# as we use --after, so the file-system is sniffed.
151
$ mv CamelCaseParent/CamelCase CamelCaseParent/NewCamelCase
152
$ bzr mv --after camelcaseparent/camelcase camelcaseparent/newcamelcase
153
CamelCaseParent/CamelCase => CamelCaseParent/NewCamelCase
156
def test_mv_newname_exists(self):
157
# test a mv, but when the target already exists with a name that
158
# differs only by case.
159
wt = self._make_mixed_case_tree()
161
self.run_bzr('ci -m message')
163
$ bzr mv camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
164
2>bzr: ERROR: Could not move CamelCase => lowercase: \
165
lowercaseparent/lowercase is already versioned.
168
def test_mv_newname_exists_after(self):
169
# test a 'mv --after', but when the target already exists with a name
170
# that differs only by case. Note that this is somewhat unlikely
171
# but still reasonable.
172
wt = self._make_mixed_case_tree()
174
self.run_bzr('ci -m message')
175
# Remove the source and create a destination file on disk with a different case.
176
# bzr should report that the filename is already versioned.
177
os.unlink('CamelCaseParent/CamelCase')
178
osutils.rename('lowercaseparent/lowercase', 'lowercaseparent/LOWERCASE')
180
$ bzr mv --after camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
181
2>bzr: ERROR: Could not move CamelCase => lowercase: \
182
lowercaseparent/lowercase is already versioned.
185
def test_mv_newname_root(self):
186
wt = self._make_mixed_case_tree()
188
self.run_bzr('ci -m message')
190
$ bzr mv camelcaseparent NewCamelCaseParent
191
CamelCaseParent => NewCamelCaseParent
194
def test_mv_newname_root_after(self):
195
wt = self._make_mixed_case_tree()
197
self.run_bzr('ci -m message')
198
# In this case we can specify the incorrect case for the destination,
199
# as we use --after, so the file-system is sniffed.
201
$ mv CamelCaseParent NewCamelCaseParent
202
$ bzr mv --after camelcaseparent NewCamelCaseParent
203
CamelCaseParent => NewCamelCaseParent
206
def test_mv_newcase(self):
207
wt = self._make_mixed_case_tree()
209
self.run_bzr('ci -m message')
211
# perform a mv to the new case - we expect bzr to accept the new
212
# name, as specified, and rename the file on the file-system too.
214
$ bzr mv camelcaseparent/camelcase camelcaseparent/camelCase
215
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
217
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
218
'CamelCaseParent/camelCase')
220
def test_mv_newcase_after(self):
221
wt = self._make_mixed_case_tree()
223
self.run_bzr('ci -m message')
225
# perform a mv to the new case - we must ensure the file-system has the
227
osutils.rename('CamelCaseParent/CamelCase', 'CamelCaseParent/camelCase')
229
$ bzr mv --after camelcaseparent/camelcase camelcaseparent/camelCase
230
CamelCaseParent/CamelCase => CamelCaseParent/camelCase
232
# bzr should not have renamed the file to a different case
233
self.failUnlessEqual(canonical_relpath(wt.basedir, 'camelcaseparent/camelcase'),
234
'CamelCaseParent/camelCase')
236
def test_mv_multiple(self):
237
wt = self._make_mixed_case_tree()
239
self.run_bzr('ci -m message')
241
$ bzr mv LOWercaseparent/LOWercase LOWercaseparent/MIXEDCase camelcaseparent
242
lowercaseparent/lowercase => CamelCaseParent/lowercase
243
lowercaseparent/mixedCase => CamelCaseParent/mixedCase
247
class TestMisc(TestCICPBase):
249
def test_status(self):
250
wt = self._make_mixed_case_tree()
253
$ bzr status camelcaseparent/camelcase LOWERCASEPARENT/LOWERCASE
256
CamelCaseParent/CamelCase
258
lowercaseparent/lowercase
262
wt = self._make_mixed_case_tree()
265
got = self.run_bzr('ci -m message camelcaseparent LOWERCASEPARENT')[1]
266
for expected in ['CamelCaseParent', 'lowercaseparent',
267
'CamelCaseParent/CamelCase', 'lowercaseparent/lowercase']:
268
self.assertContainsRe(got, 'added ' + expected + '\n')
271
wt = self._make_mixed_case_tree()
273
self.run_bzr('ci -m message')
275
got = self.run_bzr('rm camelcaseparent LOWERCASEPARENT')[1]
276
for expected in ['lowercaseparent/lowercase', 'CamelCaseParent/CamelCase']:
277
self.assertContainsRe(got, 'deleted ' + expected + '\n')
280
# The following commands need tests and/or cicp lovin':
281
# update, remove, file_id, file_path, diff, log, touching_revisions, ls,
282
# ignore, cat, revert, resolve.