24
24
import bzrlib.osutils as osutils
25
from bzrlib.tests import TestCaseInTempDir, TestSkipped
25
from bzrlib.tests import TestCaseWithTransport, TestSkipped
26
26
from bzrlib.trace import mutter, note
27
27
import bzrlib.urlutils as urlutils
30
class TestNonAscii(TestCaseInTempDir):
30
class TestNonAscii(TestCaseWithTransport):
31
31
"""Test that bzr handles files/committers/etc which are non-ascii."""
72
72
' filesystem encoding "%s")')
73
73
% (thing, terminal_enc, fs_enc))
75
wt = self.make_branch_and_tree('.')
76
76
open('a', 'wb').write('foo\n')
78
bzr('commit', '-m', 'adding a')
80
80
open('b', 'wb').write('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')
82
bzr('commit', '-m', self.info['message'])
82
wt.commit(self.info['message'])
84
84
open(fname, 'wb').write('unicode filename\n')
86
bzr('commit', '-m', u'And a unicode file\n')
86
wt.commit(u'And a unicode file\n')
88
89
def test_status(self):
89
90
bzr = self.run_bzr_decode
184
185
self.failIfExists('a')
185
186
self.failUnlessExists(fname2)
187
bzr('commit', '-m', 'renamed to non-ascii')
188
# After 'mv' we need to re-open the working tree
189
self.wt = self.wt.bzrdir.open_workingtree()
190
self.wt.commit('renamed to non-ascii')
189
bzr('mkdir', dirname)
190
194
txt = bzr('mv', fname1, fname2, dirname)
191
195
self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
192
196
u'%s => %s/%s' % (fname2, dirname, fname2)]
212
216
dirname1 = self.info['directory']
213
217
dirname2 = self.info['directory'] + '2'
214
bzr('branch', '.', dirname1)
215
bzr('branch', dirname1, dirname2)
218
url1 = urlutils.local_path_to_url(dirname1)
219
url2 = urlutils.local_path_to_url(dirname2)
220
out_bzrdir = self.wt.bzrdir.sprout(url1)
221
out_bzrdir.sprout(url2)
217
223
os.chdir(dirname1)
218
224
open('a', 'ab').write('more text\n')
219
bzr('commit', '-m', 'mod a')
225
self.wt.commit('mod a')
221
227
pwd = osutils.getcwd()
228
234
os.chdir('../' + dirname1)
229
235
open('a', 'ab').write('and yet more\n')
230
bzr('commit', '-m', 'modifying a by ' + self.info['committer'])
236
self.wt.commit(u'modifying a by ' + self.info['committer'])
232
238
os.chdir('../' + dirname2)
233
239
# We should be able to pull, even if our encoding is bad
246
252
bzr('push', dirname)
248
254
open('a', 'ab').write('adding more text\n')
249
bzr('commit', '-m', 'added some stuff')
255
self.wt.commit('added some stuff')
251
257
# TODO: check the output text is properly encoded
254
260
f = open('a', 'ab')
255
f.write('and a bit more: ')
256
f.write(dirname.encode('utf-8'))
262
f.write('and a bit more: ')
263
f.write(dirname.encode('utf-8'))
260
bzr('commit', '-m', u'Added some ' + dirname)
268
self.wt.commit('Added some ' + dirname)
261
269
bzr('push', '--verbose', encoding='ascii')
263
271
bzr('push', '--verbose', dirname + '2')
306
314
# Create a directory structure
307
315
fname = self.info['filename']
308
316
dirname = self.info['directory']
310
bzr('mkdir', 'base/' + dirname)
318
os.mkdir('base/' + dirname)
320
self.wt.add('base/'+dirname)
311
321
path = '/'.join(['base', dirname, fname])
312
bzr('mv', fname, path)
313
bzr('commit', '-m', 'moving things around')
322
self.wt.rename_one(fname, path)
323
self.wt.commit('moving things around')
315
325
txt = bzr('file-path', path)
385
395
bzr = self.run_bzr_decode
387
397
dirname = self.info['directory']
398
url = urlutils.local_path_to_url(dirname)
390
bzr('branch', u'.', dirname)
401
self.wt.bzrdir.sprout(url)
392
403
os.chdir(dirname)
421
432
self.assertEqual(u' 3 added %s\n' % (fname,), txt)
423
434
fname2 = self.info['filename'] + '2'
424
bzr('mv', fname, fname2)
425
bzr('commit', '-m', u'Renamed %s => %s' % (fname, fname2))
435
self.wt.rename_one(fname, fname2)
436
self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
427
438
txt = bzr('touching-revisions', fname2)
428
439
expected_txt = (u' 3 added %s\n'
464
475
fname2 = self.info['filename'] + '2.txt'
465
476
open(fname2, 'wb').write('ignored\n')
467
txt = bzr('unknowns')
468
self.assertEqual(u'"%s"\n' % (fname2,), txt)
478
def check_unknowns(expected):
479
self.assertEqual(expected, list(self.wt.unknowns()))
481
check_unknowns([fname2])
470
483
bzr('ignore', './' + fname2)
471
txt = bzr('unknowns')
472
self.assertEqual(u'', txt)
484
# After 'ignore' you must re-open the working tree
485
self.wt = self.wt.bzrdir.open_workingtree()
474
488
fname3 = self.info['filename'] + '3.txt'
475
489
open(fname3, 'wb').write('unknown 3\n')
476
txt = bzr('unknowns')
477
self.assertEqual(u'"%s"\n' % (fname3,), txt)
490
check_unknowns([fname3])
479
492
# Ignore should not care what the encoding is
480
493
# (right now it doesn't print anything)
481
494
bzr('ignore', fname3, encoding='ascii')
482
txt = bzr('unknowns')
483
self.assertEqual('', txt)
495
self.wt = self.wt.bzrdir.open_workingtree()
485
498
# Now try a wildcard match
486
499
fname4 = self.info['filename'] + '4.txt'
487
500
open(fname4, 'wb').write('unknown 4\n')
488
501
bzr('ignore', '*.txt')
489
txt = bzr('unknowns')
490
self.assertEqual('', txt)
502
self.wt = self.wt.bzrdir.open_workingtree()
505
# and a different wildcard that matches everything
492
506
os.remove('.bzrignore')
493
507
bzr('ignore', self.info['filename'] + '*')
494
txt = bzr('unknowns')
495
self.assertEqual('', txt)
508
self.wt = self.wt.bzrdir.open_workingtree()
497
511
def test_missing(self):
498
512
bzr = self.run_bzr_decode