127
130
self.assertEqual('unicode filename\n', txt)
129
132
def test_cat_revision(self):
130
bzr = self.run_bzr_decode
132
133
committer = self.info['committer']
133
txt = bzr('cat-revision -r 1')
134
txt = self.run_bzr_decode('cat-revision -r 1')
134
135
self.failUnless(committer in txt,
135
136
'failed to find %r in %r' % (committer, txt))
137
138
msg = self.info['message']
138
txt = bzr('cat-revision -r 2')
139
txt = self.run_bzr_decode('cat-revision -r 2')
139
140
self.failUnless(msg in txt, 'failed to find %r in %r' % (msg, txt))
141
142
def test_mkdir(self):
142
bzr = self.run_bzr_decode
144
txt = bzr(['mkdir', self.info['directory']])
143
txt = self.run_bzr_decode(['mkdir', self.info['directory']])
145
144
self.assertEqual(u'added %s\n' % self.info['directory'], txt)
147
146
# The text should be garbled, but the command should succeed
148
txt = bzr(['mkdir', self.info['directory'] + '2'], encoding='ascii')
147
txt = self.run_bzr_decode(['mkdir', self.info['directory'] + '2'],
149
149
expected = u'added %s2\n' % (self.info['directory'],)
150
150
expected = expected.encode('ascii', 'replace')
151
151
self.assertEqual(expected, txt)
153
153
def test_relpath(self):
154
bzr = self.run_bzr_decode
156
txt = bzr(['relpath', self.info['filename']])
154
txt = self.run_bzr_decode(['relpath', self.info['filename']])
157
155
self.assertEqual(self.info['filename'] + '\n', txt)
159
bzr(['relpath', self.info['filename']], encoding='ascii', fail=True)
157
self.run_bzr_decode(['relpath', self.info['filename']],
158
encoding='ascii', fail=True)
161
160
def test_inventory(self):
162
bzr = self.run_bzr_decode
164
txt = bzr('inventory')
161
txt = self.run_bzr_decode('inventory')
165
162
self.assertEqual(['a', 'b', self.info['filename']],
166
163
txt.splitlines())
168
165
# inventory should fail if unable to encode
169
bzr('inventory', encoding='ascii', fail=True)
166
self.run_bzr_decode('inventory', encoding='ascii', fail=True)
171
168
# We don't really care about the ids themselves,
172
169
# but the command shouldn't fail
173
txt = bzr('inventory --show-ids')
170
txt = self.run_bzr_decode('inventory --show-ids')
175
172
def test_revno(self):
176
173
# There isn't a lot to test here, since revno should always
178
bzr = self.run_bzr_decode
180
self.assertEqual('3\n', bzr('revno'))
181
self.assertEqual('3\n', bzr('revno', encoding='ascii'))
175
self.assertEqual('3\n', self.run_bzr_decode('revno'))
176
self.assertEqual('3\n', self.run_bzr_decode('revno', encoding='ascii'))
183
178
def test_revision_info(self):
184
bzr = self.run_bzr_decode
186
bzr('revision-info -r 1')
179
self.run_bzr_decode('revision-info -r 1')
188
181
# TODO: jam 20060105 If we support revisions with non-ascii characters,
189
182
# this should be strict and fail.
190
bzr('revision-info -r 1', encoding='ascii')
183
self.run_bzr_decode('revision-info -r 1', encoding='ascii')
192
185
def test_mv(self):
193
bzr = self.run_bzr_decode
195
186
fname1 = self.info['filename']
196
187
fname2 = self.info['filename'] + '2'
197
188
dirname = self.info['directory']
199
190
# fname1 already exists
200
bzr(['mv', 'a', fname1], fail=True)
191
self.run_bzr_decode(['mv', 'a', fname1], fail=True)
202
txt = bzr(['mv', 'a', fname2])
193
txt = self.run_bzr_decode(['mv', 'a', fname2])
203
194
self.assertEqual(u'a => %s\n' % fname2, txt)
204
195
self.failIfExists('a')
205
196
self.failUnlessExists(fname2)
239
228
out_bzrdir = self.wt.bzrdir.sprout(url1)
240
229
out_bzrdir.sprout(url2)
243
open('a', 'ab').write('more text\n')
231
self.build_tree_contents(
232
[(osutils.pathjoin(dirname1, "a"), 'different text\n')])
244
233
self.wt.commit('mod a')
246
pwd = osutils.getcwd()
248
os.chdir(u'../' + dirname2)
235
txt = self.run_bzr_decode('pull', working_dir=dirname2)
237
expected = osutils.pathjoin(osutils.getcwd(), dirname1)
251
238
self.assertEqual(u'Using saved location: %s/\n'
252
'No revisions to pull.\n' % (pwd,), txt)
239
'No revisions to pull.\n' % (expected,), txt)
254
os.chdir('../' + dirname1)
255
open('a', 'ab').write('and yet more\n')
241
self.build_tree_contents(
242
[(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')])
256
243
self.wt.commit(u'modifying a by ' + self.info['committer'])
258
os.chdir('../' + dirname2)
259
245
# We should be able to pull, even if our encoding is bad
260
bzr('pull --verbose', encoding='ascii')
246
self.run_bzr_decode('pull --verbose', encoding='ascii',
247
working_dir=dirname2)
262
249
def test_push(self):
263
250
# TODO: Test push to an SFTP location
264
251
# Make sure we can pull from paths that can't be encoded
265
bzr = self.run_bzr_decode
267
252
# TODO: jam 20060427 For drastically improving performance, we probably
268
253
# could create a local repository, so it wouldn't have to copy
269
254
# the files around as much.
271
256
dirname = self.info['directory']
272
bzr(['push', dirname])
257
self.run_bzr_decode(['push', dirname])
274
open('a', 'ab').write('adding more text\n')
259
self.build_tree_contents([('a', 'adding more text\n')])
275
260
self.wt.commit('added some stuff')
277
262
# TODO: check the output text is properly encoded
263
self.run_bzr_decode('push')
282
f.write('and a bit more: ')
283
f.write(dirname.encode('utf-8'))
265
self.build_tree_contents(
266
[('a', 'and a bit more: \n%s\n' % (dirname.encode('utf-8'),))])
288
268
self.wt.commit('Added some ' + dirname)
289
bzr('push --verbose', encoding='ascii')
291
bzr(['push', '--verbose', dirname + '2'])
293
bzr(['push', '--verbose', dirname + '3'], encoding='ascii')
295
bzr(['push', '--verbose', '--create-prefix',
296
dirname + '4/' + dirname + '5'])
297
bzr(['push', '--verbose', '--create-prefix',
298
dirname + '6/' + dirname + '7'], encoding='ascii')
269
self.run_bzr_decode('push --verbose', encoding='ascii')
271
self.run_bzr_decode(['push', '--verbose', dirname + '2'])
273
self.run_bzr_decode(['push', '--verbose', dirname + '3'],
276
self.run_bzr_decode(['push', '--verbose', '--create-prefix',
277
dirname + '4/' + dirname + '5'])
278
self.run_bzr_decode(['push', '--verbose', '--create-prefix',
279
dirname + '6/' + dirname + '7'], encoding='ascii')
300
281
def test_renames(self):
301
bzr = self.run_bzr_decode
303
282
fname = self.info['filename'] + '2'
304
bzr(['mv', 'a', fname])
283
self.wt.rename_one('a', fname)
284
txt = self.run_bzr_decode('renames')
306
285
self.assertEqual(u'a => %s\n' % fname, txt)
308
bzr('renames', fail=True, encoding='ascii')
287
self.run_bzr_decode('renames', fail=True, encoding='ascii')
310
289
def test_remove(self):
311
bzr = self.run_bzr_decode
313
290
fname = self.info['filename']
314
txt = bzr(['remove', fname], encoding='ascii')
291
txt = self.run_bzr_decode(['remove', fname], encoding='ascii')
316
293
def test_remove_verbose(self):
317
bzr = self.run_bzr_decode
319
294
fname = self.info['filename']
320
txt = bzr(['remove', '--verbose', fname], encoding='ascii')
295
txt = self.run_bzr_decode(['remove', '--verbose', fname],
322
298
def test_file_id(self):
323
bzr = self.run_bzr_decode
325
299
fname = self.info['filename']
326
txt = bzr(['file-id', fname])
300
txt = self.run_bzr_decode(['file-id', fname])
328
302
# TODO: jam 20060106 We don't support non-ascii file ids yet,
329
303
# so there is nothing which would fail in ascii encoding
330
304
# This *should* be retcode=3
331
txt = bzr(['file-id', fname], encoding='ascii')
305
txt = self.run_bzr_decode(['file-id', fname], encoding='ascii')
333
307
def test_file_path(self):
334
bzr = self.run_bzr_decode
336
308
# Create a directory structure
337
309
fname = self.info['filename']
338
310
dirname = self.info['directory']
340
os.mkdir('base/' + dirname)
311
self.build_tree_contents([
313
(osutils.pathjoin('base', '%s/' % (dirname,)), )])
341
314
self.wt.add('base')
342
315
self.wt.add('base/'+dirname)
343
path = '/'.join(['base', dirname, fname])
316
path = osutils.pathjoin('base', dirname, fname)
344
317
self.wt.rename_one(fname, path)
345
318
self.wt.commit('moving things around')
347
txt = bzr(['file-path', path])
320
txt = self.run_bzr_decode(['file-path', path])
349
322
# TODO: jam 20060106 We don't support non-ascii file ids yet,
350
323
# so there is nothing which would fail in ascii encoding
351
324
# This *should* be retcode=3
352
txt = bzr(['file-path', path], encoding='ascii')
325
txt = self.run_bzr_decode(['file-path', path], encoding='ascii')
354
327
def test_revision_history(self):
355
bzr = self.run_bzr_decode
357
328
# TODO: jam 20060106 We don't support non-ascii revision ids yet,
358
329
# so there is nothing which would fail in ascii encoding
359
txt = bzr('revision-history')
330
txt = self.run_bzr_decode('revision-history')
361
332
def test_ancestry(self):
362
bzr = self.run_bzr_decode
364
333
# TODO: jam 20060106 We don't support non-ascii revision ids yet,
365
334
# so there is nothing which would fail in ascii encoding
366
txt = bzr('ancestry')
335
txt = self.run_bzr_decode('ancestry')
368
337
def test_diff(self):
369
338
# TODO: jam 20060106 diff is a difficult one to test, because it
370
339
# shouldn't encode the file contents, but it needs some sort
371
340
# of encoding for the paths, etc which are displayed.
372
open(self.info['filename'], 'ab').write('newline\n')
341
self.build_tree_contents([(self.info['filename'], 'newline\n')])
373
342
txt = self.run_bzr('diff', retcode=1)[0]
375
344
def test_deleted(self):
376
bzr = self.run_bzr_decode
378
345
fname = self.info['filename']
380
347
self.wt.remove(fname)
349
txt = self.run_bzr_decode('deleted')
383
350
self.assertEqual(fname+'\n', txt)
385
txt = bzr('deleted --show-ids')
352
txt = self.run_bzr_decode('deleted --show-ids')
386
353
self.failUnless(txt.startswith(fname))
388
355
# Deleted should fail if cannot decode
389
356
# Because it is giving the exact paths
390
357
# which might be used by a front end
391
bzr('deleted', encoding='ascii', fail=True)
358
self.run_bzr_decode('deleted', encoding='ascii', fail=True)
393
360
def test_modified(self):
394
bzr = self.run_bzr_decode
396
361
fname = self.info['filename']
397
open(fname, 'ab').write('modified\n')
362
self.build_tree_contents([(fname, 'modified\n')])
399
txt = bzr('modified')
364
txt = self.run_bzr_decode('modified')
400
365
self.assertEqual(fname+'\n', txt)
402
bzr('modified', encoding='ascii', fail=True)
367
self.run_bzr_decode('modified', encoding='ascii', fail=True)
404
369
def test_added(self):
405
bzr = self.run_bzr_decode
407
370
fname = self.info['filename'] + '2'
408
open(fname, 'wb').write('added\n')
371
self.build_tree_contents([(fname, 'added\n')])
409
372
self.wt.add(fname)
374
txt = self.run_bzr_decode('added')
412
375
self.assertEqual(fname+'\n', txt)
414
bzr('added', encoding='ascii', fail=True)
377
self.run_bzr_decode('added', encoding='ascii', fail=True)
416
379
def test_root(self):
417
bzr = self.run_bzr_decode
419
380
dirname = self.info['directory']
420
381
url = urlutils.local_path_to_url(dirname)
382
self.run_bzr_decode('root')
423
384
self.wt.bzrdir.sprout(url)
386
txt = self.run_bzr_decode('root', working_dir=dirname)
428
387
self.failUnless(txt.endswith(dirname+'\n'))
430
txt = bzr('root', encoding='ascii', fail=True)
389
txt = self.run_bzr_decode('root', encoding='ascii', fail=True,
432
392
def test_log(self):
433
bzr = self.run_bzr_decode
435
393
fname = self.info['filename']
395
txt = self.run_bzr_decode('log')
438
396
self.assertNotEqual(-1, txt.find(self.info['committer']))
439
397
self.assertNotEqual(-1, txt.find(self.info['message']))
441
txt = bzr('log --verbose')
399
txt = self.run_bzr_decode('log --verbose')
442
400
self.assertNotEqual(-1, txt.find(fname))
444
402
# Make sure log doesn't fail even if we can't write out
445
txt = bzr('log --verbose', encoding='ascii')
403
txt = self.run_bzr_decode('log --verbose', encoding='ascii')
446
404
self.assertEqual(-1, txt.find(fname))
447
405
self.assertNotEqual(-1, txt.find(fname.encode('ascii', 'replace')))
449
407
def test_touching_revisions(self):
450
bzr = self.run_bzr_decode
452
408
fname = self.info['filename']
453
txt = bzr(['touching-revisions', fname])
409
txt = self.run_bzr_decode(['touching-revisions', fname])
454
410
self.assertEqual(u' 3 added %s\n' % (fname,), txt)
456
412
fname2 = self.info['filename'] + '2'
457
413
self.wt.rename_one(fname, fname2)
458
414
self.wt.commit(u'Renamed %s => %s' % (fname, fname2))
460
txt = bzr(['touching-revisions', fname2])
416
txt = self.run_bzr_decode(['touching-revisions', fname2])
461
417
expected_txt = (u' 3 added %s\n'
462
418
u' 4 renamed %s => %s\n'
463
419
% (fname, fname, fname2))
464
420
self.assertEqual(expected_txt, txt)
466
bzr(['touching-revisions', fname2], encoding='ascii', fail=True)
422
self.run_bzr_decode(['touching-revisions', fname2], encoding='ascii',
468
425
def test_ls(self):
469
bzr = self.run_bzr_decode
426
txt = self.run_bzr_decode('ls')
472
427
self.assertEqual(sorted(['a', 'b', self.info['filename']]),
473
428
sorted(txt.splitlines()))
474
txt = bzr('ls --null')
429
txt = self.run_bzr_decode('ls --null')
475
430
self.assertEqual(sorted(['', 'a', 'b', self.info['filename']]),
476
431
sorted(txt.split('\0')))
478
txt = bzr('ls', encoding='ascii', fail=True)
479
txt = bzr('ls --null', encoding='ascii', fail=True)
433
txt = self.run_bzr_decode('ls', encoding='ascii', fail=True)
434
txt = self.run_bzr_decode('ls --null', encoding='ascii', fail=True)
481
436
def test_unknowns(self):
482
bzr = self.run_bzr_decode
484
437
fname = self.info['filename'] + '2'
485
open(fname, 'wb').write('unknown\n')
438
self.build_tree_contents([(fname, 'unknown\n')])
487
440
# TODO: jam 20060112 bzr unknowns is the only one which
488
441
# quotes paths do we really want it to?
489
txt = bzr('unknowns')
442
txt = self.run_bzr_decode('unknowns')
490
443
self.assertEqual(u'"%s"\n' % (fname,), txt)
492
bzr('unknowns', encoding='ascii', fail=True)
445
self.run_bzr_decode('unknowns', encoding='ascii', fail=True)
494
447
def test_ignore(self):
495
bzr = self.run_bzr_decode
497
448
fname2 = self.info['filename'] + '2.txt'
498
open(fname2, 'wb').write('ignored\n')
449
self.build_tree_contents([(fname2, 'ignored\n')])
500
451
def check_unknowns(expected):
501
452
self.assertEqual(expected, list(self.wt.unknowns()))
503
454
check_unknowns([fname2])
505
bzr(['ignore', './' + fname2])
506
# After 'ignore' you must re-open the working tree
507
self.wt = self.wt.bzrdir.open_workingtree()
456
self.run_bzr_decode(['ignore', './' + fname2])
508
457
check_unknowns([])
510
459
fname3 = self.info['filename'] + '3.txt'
511
open(fname3, 'wb').write('unknown 3\n')
460
self.build_tree_contents([(fname3, 'unknown 3\n')])
512
461
check_unknowns([fname3])
514
463
# Ignore should not care what the encoding is
515
464
# (right now it doesn't print anything)
516
bzr(['ignore', fname3], encoding='ascii')
517
self.wt = self.wt.bzrdir.open_workingtree()
465
self.run_bzr_decode(['ignore', fname3], encoding='ascii')
518
466
check_unknowns([])
520
468
# Now try a wildcard match
521
469
fname4 = self.info['filename'] + '4.txt'
522
open(fname4, 'wb').write('unknown 4\n')
524
self.wt = self.wt.bzrdir.open_workingtree()
470
self.build_tree_contents([(fname4, 'unknown 4\n')])
471
self.run_bzr_decode('ignore *.txt')
525
472
check_unknowns([])
527
474
# and a different wildcard that matches everything
528
475
os.remove('.bzrignore')
529
bzr(['ignore', self.info['filename'] + '*'])
530
self.wt = self.wt.bzrdir.open_workingtree()
476
self.run_bzr_decode(['ignore', self.info['filename'] + '*'])
531
477
check_unknowns([])
533
479
def test_missing(self):
534
bzr = self.run_bzr_decode
536
480
# create empty tree as reference for missing
537
self.run_bzr('init empty-tree')
481
self.make_branch_and_tree('empty-tree')
539
483
msg = self.info['message']
541
txt = bzr('missing empty-tree', retcode=1)
485
txt = self.run_bzr_decode('missing empty-tree')
542
486
self.assertNotEqual(-1, txt.find(self.info['committer']))
543
487
self.assertNotEqual(-1, txt.find(msg))
545
489
# Make sure missing doesn't fail even if we can't write out
546
txt = bzr('missing empty-tree', encoding='ascii', retcode=1)
490
txt = self.run_bzr_decode('missing empty-tree', encoding='ascii')
547
491
self.assertEqual(-1, txt.find(msg))
548
492
self.assertNotEqual(-1, txt.find(msg.encode('ascii', 'replace')))