23
from bzrlib import ignores, osutils, urlutils
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
import bzrlib.urlutils as urlutils
30
class TestNonAscii(TestCaseInTempDir):
29
class TestNonAscii(TestCaseWithTransport):
31
30
"""Test that bzr handles files/committers/etc which are non-ascii."""
34
33
super(TestNonAscii, self).setUp()
35
self._orig_email = os.environ.get('BZREMAIL', None)
34
self._orig_email = os.environ.get('BZR_EMAIL', None)
36
35
self._orig_encoding = bzrlib.user_encoding
38
37
bzrlib.user_encoding = self.encoding
39
38
email = self.info['committer'] + ' <joe@foo.com>'
40
os.environ['BZREMAIL'] = email.encode(bzrlib.user_encoding)
39
os.environ['BZR_EMAIL'] = email.encode(bzrlib.user_encoding)
43
42
def tearDown(self):
44
43
if self._orig_email is not None:
45
os.environ['BZREMAIL'] = self._orig_email
44
os.environ['BZR_EMAIL'] = self._orig_email
47
if os.environ.get('BZREMAIL', None) is not None:
48
del os.environ['BZREMAIL']
46
if os.environ.get('BZR_EMAIL', None) is not None:
47
del os.environ['BZR_EMAIL']
49
48
bzrlib.user_encoding = self._orig_encoding
50
49
super(TestNonAscii, self).tearDown()
72
71
' filesystem encoding "%s")')
73
72
% (thing, terminal_enc, fs_enc))
74
wt = self.make_branch_and_tree('.')
76
75
open('a', 'wb').write('foo\n')
78
bzr('commit', '-m', 'adding a')
80
79
open('b', 'wb').write('non-ascii \xFF\xFF\xFC\xFB\x00 in b\n')
82
bzr('commit', '-m', self.info['message'])
81
wt.commit(self.info['message'])
84
83
open(fname, 'wb').write('unicode filename\n')
86
bzr('commit', '-m', u'And a unicode file\n')
85
wt.commit(u'And a unicode file\n')
88
88
def test_status(self):
89
89
bzr = self.run_bzr_decode
184
184
self.failIfExists('a')
185
185
self.failUnlessExists(fname2)
187
bzr('commit', '-m', 'renamed to non-ascii')
187
# After 'mv' we need to re-open the working tree
188
self.wt = self.wt.bzrdir.open_workingtree()
189
self.wt.commit('renamed to non-ascii')
189
bzr('mkdir', dirname)
190
193
txt = bzr('mv', fname1, fname2, dirname)
191
194
self.assertEqual([u'%s => %s/%s' % (fname1, dirname, fname1),
192
195
u'%s => %s/%s' % (fname2, dirname, fname2)]
212
215
dirname1 = self.info['directory']
213
216
dirname2 = self.info['directory'] + '2'
214
bzr('branch', '.', dirname1)
215
bzr('branch', dirname1, dirname2)
217
url1 = urlutils.local_path_to_url(dirname1)
218
url2 = urlutils.local_path_to_url(dirname2)
219
out_bzrdir = self.wt.bzrdir.sprout(url1)
220
out_bzrdir.sprout(url2)
217
222
os.chdir(dirname1)
218
223
open('a', 'ab').write('more text\n')
219
bzr('commit', '-m', 'mod a')
224
self.wt.commit('mod a')
221
226
pwd = osutils.getcwd()
228
233
os.chdir('../' + dirname1)
229
234
open('a', 'ab').write('and yet more\n')
230
bzr('commit', '-m', 'modifying a by ' + self.info['committer'])
235
self.wt.commit(u'modifying a by ' + self.info['committer'])
232
237
os.chdir('../' + dirname2)
233
238
# We should be able to pull, even if our encoding is bad
246
251
bzr('push', dirname)
248
253
open('a', 'ab').write('adding more text\n')
249
bzr('commit', '-m', 'added some stuff')
254
self.wt.commit('added some stuff')
251
256
# TODO: check the output text is properly encoded
254
259
f = open('a', 'ab')
255
f.write('and a bit more: ')
256
f.write(dirname.encode('utf-8'))
261
f.write('and a bit more: ')
262
f.write(dirname.encode('utf-8'))
260
bzr('commit', '-m', u'Added some ' + dirname)
267
self.wt.commit('Added some ' + dirname)
261
268
bzr('push', '--verbose', encoding='ascii')
263
270
bzr('push', '--verbose', dirname + '2')
306
313
# Create a directory structure
307
314
fname = self.info['filename']
308
315
dirname = self.info['directory']
310
bzr('mkdir', 'base/' + dirname)
317
os.mkdir('base/' + dirname)
319
self.wt.add('base/'+dirname)
311
320
path = '/'.join(['base', dirname, fname])
312
bzr('mv', fname, path)
313
bzr('commit', '-m', 'moving things around')
321
self.wt.rename_one(fname, path)
322
self.wt.commit('moving things around')
315
324
txt = bzr('file-path', path)
421
431
self.assertEqual(u' 3 added %s\n' % (fname,), txt)
423
433
fname2 = self.info['filename'] + '2'
424
bzr('mv', fname, fname2)
425
bzr('commit', '-m', u'Renamed %s => %s' % (fname, fname2))
434
self.wt.rename_one(fname, fname2)
435
self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
427
437
txt = bzr('touching-revisions', fname2)
428
438
expected_txt = (u' 3 added %s\n'
436
446
bzr = self.run_bzr_decode
439
self.assertEqual(['a', 'b', self.info['filename']],
449
self.assertEqual(sorted(['a', 'b', self.info['filename']]),
450
sorted(txt.splitlines()))
441
451
txt = bzr('ls', '--null')
442
self.assertEqual(['a', 'b', self.info['filename'], ''],
452
self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
453
sorted(txt.split('\0')))
445
455
txt = bzr('ls', encoding='ascii', retcode=3)
446
456
txt = bzr('ls', '--null', encoding='ascii', retcode=3)
461
471
def test_ignore(self):
462
472
bzr = self.run_bzr_decode
474
ignores._set_user_ignores(['./.bazaar'])
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()
511
def test_missing(self):
512
bzr = self.run_bzr_decode
514
# create empty tree as reference for missing
515
self.run_bzr('init', 'empty-tree')
517
msg = self.info['message']
519
txt = bzr('missing', 'empty-tree', retcode=1)
520
self.assertNotEqual(-1, txt.find(self.info['committer']))
521
self.assertNotEqual(-1, txt.find(msg))
523
# Make sure missing doesn't fail even if we can't write out
524
txt = bzr('missing', 'empty-tree', encoding='ascii', retcode=1)
525
self.assertEqual(-1, txt.find(msg))
526
self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))