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