44
45
class BranchStatus(TestCaseWithTransport):
46
47
def assertStatus(self, expected_lines, working_tree,
47
revision=None, short=False, pending=True):
48
revision=None, short=False, pending=True, verbose=False):
48
49
"""Run status in working_tree and look for output.
50
51
:param expected_lines: The lines to look for.
51
52
:param working_tree: The tree to run status in.
53
54
output_string = self.status_string(working_tree, revision, short,
55
56
self.assertEqual(expected_lines, output_string.splitlines(True))
57
def status_string(self, wt, revision=None, short=False, pending=True):
58
def status_string(self, wt, revision=None, short=False, pending=True,
58
60
# use a real file rather than StringIO because it doesn't handle
59
61
# Unicode very well.
60
62
tof = codecs.getwriter('utf-8')(TemporaryFile())
61
63
show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
show_pending=pending, verbose=verbose)
64
66
return tof.read().decode('utf-8')
274
284
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
287
def _prepare_nonexistent(self):
288
wt = self.make_branch_and_tree('.')
289
self.assertStatus([], wt)
290
self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
296
wt.commit('Create five empty files.')
297
open('FILE_B', 'w').write('Modification to file FILE_B.')
298
open('FILE_C', 'w').write('Modification to file FILE_C.')
299
unlink('FILE_E') # FILE_E will be versioned but missing
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
301
wt.add('FILE_Q') # FILE_Q will be added but not committed
302
open('UNVERSIONED_BUT_EXISTING', 'w')
277
305
def test_status_nonexistent_file(self):
278
306
# files that don't exist in either the basis tree or working tree
279
307
# should give an error
280
wt = self.make_branch_and_tree('.')
281
out, err = self.run_bzr('status does-not-exist', retcode=3)
282
self.assertContainsRe(err, r'do not exist.*does-not-exist')
308
wt = self._prepare_nonexistent()
318
' UNVERSIONED_BUT_EXISTING\n',
326
'? UNVERSIONED_BUT_EXISTING\n',
330
# Okay, everything's looking good with the existent files.
331
# Let's see what happens when we throw in non-existent files.
333
# bzr st [--short] NONEXISTENT '
338
out, err = self.run_bzr('status NONEXISTENT', retcode=3)
339
self.assertEqual(expected, out.splitlines(True))
340
self.assertContainsRe(err,
341
r'.*ERROR: Path\(s\) do not exist: '
346
out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
347
self.assertContainsRe(err,
348
r'.*ERROR: Path\(s\) do not exist: '
351
def test_status_nonexistent_file_with_others(self):
352
# bzr st [--short] NONEXISTENT ...others..
353
wt = self._prepare_nonexistent()
363
out, err = self.run_bzr('status NONEXISTENT '
364
'FILE_A FILE_B FILE_C FILE_D FILE_E',
366
self.assertEqual(expected, out.splitlines(True))
367
self.assertContainsRe(err,
368
r'.*ERROR: Path\(s\) do not exist: '
376
out, err = self.run_bzr('status --short NONEXISTENT '
377
'FILE_A FILE_B FILE_C FILE_D FILE_E',
379
self.assertEqual(expected, out.splitlines(True))
380
self.assertContainsRe(err,
381
r'.*ERROR: Path\(s\) do not exist: '
384
def test_status_multiple_nonexistent_files(self):
385
# bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
386
wt = self._prepare_nonexistent()
394
' ANOTHER_NONEXISTENT\n',
397
out, err = self.run_bzr('status NONEXISTENT '
398
'FILE_A FILE_B ANOTHER_NONEXISTENT '
399
'FILE_C FILE_D FILE_E', retcode=3)
400
self.assertEqual(expected, out.splitlines(True))
401
self.assertContainsRe(err,
402
r'.*ERROR: Path\(s\) do not exist: '
403
'ANOTHER_NONEXISTENT NONEXISTENT.*')
408
'X ANOTHER_NONEXISTENT\n',
411
out, err = self.run_bzr('status --short NONEXISTENT '
412
'FILE_A FILE_B ANOTHER_NONEXISTENT '
413
'FILE_C FILE_D FILE_E', retcode=3)
414
self.assertEqual(expected, out.splitlines(True))
415
self.assertContainsRe(err,
416
r'.*ERROR: Path\(s\) do not exist: '
417
'ANOTHER_NONEXISTENT NONEXISTENT.*')
419
def test_status_nonexistent_file_with_unversioned(self):
420
# bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
421
wt = self._prepare_nonexistent()
431
' UNVERSIONED_BUT_EXISTING\n',
435
out, err = self.run_bzr('status NONEXISTENT '
436
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
437
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
438
self.assertEqual(expected, out.splitlines(True))
439
self.assertContainsRe(err,
440
r'.*ERROR: Path\(s\) do not exist: '
444
'? UNVERSIONED_BUT_EXISTING\n',
450
out, err = self.run_bzr('status --short NONEXISTENT '
451
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
self.assertEqual(expected, out.splitlines(True))
454
self.assertContainsRe(err,
455
r'.*ERROR: Path\(s\) do not exist: '
284
458
def test_status_out_of_date(self):
285
459
"""Simulate status of out-of-date tree after remote push"""
454
643
tree.merge_from_branch(alt.branch)
455
644
output = self.make_utf8_encoded_stringio()
456
645
show_tree_status(tree, to_file=output)
457
self.assertContainsRe(output.getvalue(), 'pending merges:')
646
self.assertContainsRe(output.getvalue(), 'pending merge')
458
647
out, err = self.run_bzr('status tree/a')
459
self.assertNotContainsRe(out, 'pending merges:')
648
self.assertNotContainsRe(out, 'pending merge')
462
651
class TestStatusEncodings(TestCaseWithTransport):
465
654
TestCaseWithTransport.setUp(self)
466
self.user_encoding = bzrlib.user_encoding
655
self.user_encoding = osutils._cached_user_encoding
467
656
self.stdout = sys.stdout
469
658
def tearDown(self):
470
bzrlib.user_encoding = self.user_encoding
659
osutils._cached_user_encoding = self.user_encoding
471
660
sys.stdout = self.stdout
472
661
TestCaseWithTransport.tearDown(self)