46
45
class BranchStatus(TestCaseWithTransport):
49
super(BranchStatus, self).setUp()
50
# As TestCase.setUp clears all hooks, we install this default
51
# post_status hook handler for the test.
52
status.hooks.install_named_hook('post_status',
53
status._show_shelve_summary,
56
def assertStatus(self, expected_lines, working_tree, specific_files=None,
47
def assertStatus(self, expected_lines, working_tree,
57
48
revision=None, short=False, pending=True, verbose=False):
58
49
"""Run status in working_tree and look for output.
60
51
:param expected_lines: The lines to look for.
61
52
:param working_tree: The tree to run status in.
63
output_string = self.status_string(working_tree, specific_files, revision, short,
54
output_string = self.status_string(working_tree, revision, short,
65
56
self.assertEqual(expected_lines, output_string.splitlines(True))
67
def status_string(self, wt, specific_files=None, revision=None,
68
short=False, pending=True, verbose=False):
58
def status_string(self, wt, revision=None, short=False, pending=True,
69
60
# use a real file rather than StringIO because it doesn't handle
70
61
# Unicode very well.
71
62
tof = codecs.getwriter('utf-8')(TemporaryFile())
72
show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
revision=revision, short=short, show_pending=pending,
63
show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
show_pending=pending, verbose=verbose)
76
66
return tof.read().decode('utf-8')
212
202
wt = self.make_branch_and_tree('.')
215
self.build_tree(['directory/','directory/hello.c',
216
'bye.c','test.c','dir2/',
205
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
218
206
wt.add('directory')
220
208
wt.commit('testing')
224
210
self.assertStatus([
278
261
self.assertEquals(tof.readlines(), ['+N test.c\n'])
281
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
283
self.assertEquals(tof.readlines(),
288
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
291
self.assertEquals(tof.readlines(),
294
263
def test_specific_files_conflicts(self):
295
264
tree = self.make_branch_and_tree('.')
296
265
self.build_tree(['dir2/'])
327
296
wt.commit('Create five empty files.')
328
with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
329
with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
297
open('FILE_B', 'w').write('Modification to file FILE_B.')
298
open('FILE_C', 'w').write('Modification to file FILE_C.')
330
299
unlink('FILE_E') # FILE_E will be versioned but missing
331
with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
332
301
wt.add('FILE_Q') # FILE_Q will be added but not committed
333
302
open('UNVERSIONED_BUT_EXISTING', 'w')
479
448
'X NONEXISTENT\n',
482
450
out, err = self.run_bzr('status --short NONEXISTENT '
483
451
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
484
452
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
485
actual = out.splitlines(True)
487
self.assertEqual(expected, actual)
453
self.assertEqual(expected, out.splitlines(True))
488
454
self.assertContainsRe(err,
489
455
r'.*ERROR: Path\(s\) do not exist: '
506
472
self.assertEqual("working tree is out of date, run 'bzr update'\n",
509
def test_status_on_ignored(self):
510
"""Tests branch status on an unversioned file which is considered ignored.
512
See https://bugs.launchpad.net/bzr/+bug/40103
514
tree = self.make_branch_and_tree('.')
516
self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
517
result = self.run_bzr('status')[0]
518
self.assertContainsRe(result, "unknown:\n test1.c\n")
519
short_result = self.run_bzr('status --short')[0]
520
self.assertContainsRe(short_result, "\? test1.c\n")
522
result = self.run_bzr('status test1.c')[0]
523
self.assertContainsRe(result, "unknown:\n test1.c\n")
524
short_result = self.run_bzr('status --short test1.c')[0]
525
self.assertContainsRe(short_result, "\? test1.c\n")
527
result = self.run_bzr('status test1.c~')[0]
528
self.assertContainsRe(result, "ignored:\n test1.c~\n")
529
short_result = self.run_bzr('status --short test1.c~')[0]
530
self.assertContainsRe(short_result, "I test1.c~\n")
532
result = self.run_bzr('status test1.c~ test2.c~')[0]
533
self.assertContainsRe(result, "ignored:\n test1.c~\n test2.c~\n")
534
short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
535
self.assertContainsRe(short_result, "I test1.c~\nI test2.c~\n")
537
result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
538
self.assertContainsRe(result, "unknown:\n test1.c\nignored:\n test1.c~\n test2.c~\n")
539
short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
540
self.assertContainsRe(short_result, "\? test1.c\nI test1.c~\nI test2.c~\n")
542
475
def test_status_write_lock(self):
543
476
"""Test that status works without fetching history and
544
477
having a write lock.
554
487
out, err = self.run_bzr('status branch1 -rbranch:branch2')
555
488
self.assertEqual('', out)
557
def test_status_with_shelves(self):
558
"""Ensure that _show_shelve_summary handler works.
560
wt = self.make_branch_and_tree('.')
561
self.build_tree(['hello.c'])
563
self.run_bzr(['shelve', '--all', '-m', 'foo'])
564
self.build_tree(['bye.c'])
569
'1 shelf exists. See "bzr shelve --list" for details.\n',
572
self.run_bzr(['shelve', '--all', '-m', 'bar'])
573
self.build_tree(['eggs.c', 'spam.c'])
580
'2 shelves exist. See "bzr shelve --list" for details.\n',
588
specific_files=['spam.c'])
591
491
class CheckoutStatus(BranchStatus):
598
498
def make_branch_and_tree(self, relpath):
599
499
source = self.make_branch(pathjoin('..', relpath))
600
500
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
601
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
602
target_branch=source)
501
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
603
502
return checkout.create_workingtree()
646
545
self.assertContainsRe(result, "[+]N hello.txt\n")
648
547
self.build_tree(['world.txt'])
649
result = self.run_bzr("status -S -r 0")[0]
548
result = self.run_bzr("status --short -r 0")[0]
650
549
self.assertContainsRe(result, "[+]N hello.txt\n" \
651
550
"[?] world.txt\n")
652
result2 = self.run_bzr("status -S -r 0..")[0]
551
result2 = self.run_bzr("status --short -r 0..")[0]
653
552
self.assertEquals(result2, result)
655
554
def test_status_versioned(self):
696
595
result2 = self.run_bzr("status -SV -r 0..")[0]
697
596
self.assertEquals(result2, result)
699
def assertStatusContains(self, pattern, short=False):
598
def assertStatusContains(self, pattern):
700
599
"""Run status, and assert it contains the given pattern"""
702
result = self.run_bzr("status --short")[0]
704
result = self.run_bzr("status")[0]
600
result = self.run_bzr("status --short")[0]
705
601
self.assertContainsRe(result, pattern)
707
def test_kind_change_plain(self):
708
tree = self.make_branch_and_tree('.')
709
self.build_tree(['file'])
711
tree.commit('added file')
713
self.build_tree(['file/'])
714
self.assertStatusContains('kind changed:\n file \(file => directory\)')
715
tree.rename_one('file', 'directory')
716
self.assertStatusContains('renamed:\n file/ => directory/\n' \
717
'modified:\n directory/\n')
719
self.assertStatusContains('removed:\n file\n')
721
603
def test_kind_change_short(self):
722
604
tree = self.make_branch_and_tree('.')
723
605
self.build_tree(['file'])
725
607
tree.commit('added file')
727
609
self.build_tree(['file/'])
728
self.assertStatusContains('K file => file/',
610
self.assertStatusContains('K file => file/')
730
611
tree.rename_one('file', 'directory')
731
self.assertStatusContains('RK file => directory/',
612
self.assertStatusContains('RK file => directory/')
733
613
rmdir('directory')
734
self.assertStatusContains('RD file => directory',
614
self.assertStatusContains('RD file => directory')
737
616
def test_status_illegal_revision_specifiers(self):
738
617
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
772
651
class TestStatusEncodings(TestCaseWithTransport):
654
TestCaseWithTransport.setUp(self)
655
self.user_encoding = osutils._cached_user_encoding
656
self.stdout = sys.stdout
659
osutils._cached_user_encoding = self.user_encoding
660
sys.stdout = self.stdout
661
TestCaseWithTransport.tearDown(self)
774
663
def make_uncommitted_tree(self):
775
664
"""Build a branch with uncommitted unicode named changes in the cwd."""
776
665
working_tree = self.make_branch_and_tree(u'.')
784
673
return working_tree
786
675
def test_stdout_ascii(self):
787
self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
676
sys.stdout = StringIO()
677
osutils._cached_user_encoding = 'ascii'
788
678
working_tree = self.make_uncommitted_tree()
789
679
stdout, stderr = self.run_bzr("status")
796
686
def test_stdout_latin1(self):
797
self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
687
sys.stdout = StringIO()
688
osutils._cached_user_encoding = 'latin-1'
798
689
working_tree = self.make_uncommitted_tree()
799
690
stdout, stderr = self.run_bzr('status')