1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests of status command.
19
19
Most of these depend on the particular formatting used.
20
As such they really are blackbox tests even though some of the
20
As such they really are blackbox tests even though some of the
21
21
tests are not using self.capture. If we add tests for the programmatic
22
22
interface later, they will be non blackbox tests.
45
45
class BranchStatus(TestCaseWithTransport):
47
47
def assertStatus(self, expected_lines, working_tree,
48
48
revision=None, short=False, pending=True, verbose=False):
49
49
"""Run status in working_tree and look for output.
51
51
:param expected_lines: The lines to look for.
52
52
:param working_tree: The tree to run status in.
54
54
output_string = self.status_string(working_tree, revision, short,
56
56
self.assertEqual(expected_lines, output_string.splitlines(True))
58
58
def status_string(self, wt, revision=None, short=False, pending=True,
60
60
# use a real file rather than StringIO because it doesn't handle
226
226
self.assertRaises(errors.PathsDoNotExist,
227
227
show_tree_status,
228
wt, specific_files=['bye.c','test.c','absent.c'],
228
wt, specific_files=['bye.c','test.c','absent.c'],
232
232
show_tree_status(wt, specific_files=['directory'], to_file=tof)
296
296
wt.commit('Create five empty files.')
297
297
open('FILE_B', 'w').write('Modification to file FILE_B.')
298
298
open('FILE_C', 'w').write('Modification to file FILE_C.')
299
unlink('FILE_E') # FILE_E will be versioned but missing
299
unlink('FILE_E') # FILE_E will be versioned but missing
300
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
301
301
wt.add('FILE_Q') # FILE_Q will be added but not committed
302
302
open('UNVERSIONED_BUT_EXISTING', 'w')
347
347
self.assertContainsRe(err,
348
348
r'.*ERROR: Path\(s\) do not exist: '
351
351
def test_status_nonexistent_file_with_others(self):
352
352
# bzr st [--short] NONEXISTENT ...others..
353
353
wt = self._prepare_nonexistent()
380
380
self.assertContainsRe(err,
381
381
r'.*ERROR: Path\(s\) do not exist: '
384
384
def test_status_multiple_nonexistent_files(self):
385
385
# bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
386
386
wt = self._prepare_nonexistent()
415
415
self.assertContainsRe(err,
416
416
r'.*ERROR: Path\(s\) do not exist: '
417
417
'ANOTHER_NONEXISTENT NONEXISTENT.*')
419
419
def test_status_nonexistent_file_with_unversioned(self):
420
420
# bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
421
421
wt = self._prepare_nonexistent()
472
472
self.assertEqual("working tree is out of date, run 'bzr update'\n",
475
def test_status_on_ignored(self):
476
"""Tests branch status on an unversioned file which is considered ignored.
478
See https://bugs.launchpad.net/bzr/+bug/40103
480
tree = self.make_branch_and_tree('.')
482
self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
483
result = self.run_bzr('status')[0]
484
self.assertContainsRe(result, "unknown:\n test1.c\n")
485
short_result = self.run_bzr('status --short')[0]
486
self.assertContainsRe(short_result, "\? test1.c\n")
488
result = self.run_bzr('status test1.c')[0]
489
self.assertContainsRe(result, "unknown:\n test1.c\n")
490
short_result = self.run_bzr('status --short test1.c')[0]
491
self.assertContainsRe(short_result, "\? test1.c\n")
493
result = self.run_bzr('status test1.c~')[0]
494
self.assertContainsRe(result, "ignored:\n test1.c~\n")
495
short_result = self.run_bzr('status --short test1.c~')[0]
496
self.assertContainsRe(short_result, "I test1.c~\n")
498
result = self.run_bzr('status test1.c~ test2.c~')[0]
499
self.assertContainsRe(result, "ignored:\n test1.c~\n test2.c~\n")
500
short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
501
self.assertContainsRe(short_result, "I test1.c~\nI test2.c~\n")
503
result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
504
self.assertContainsRe(result, "unknown:\n test1.c\nignored:\n test1.c~\n test2.c~\n")
505
short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
506
self.assertContainsRe(short_result, "\? test1.c\nI test1.c~\nI test2.c~\n")
508
475
def test_status_write_lock(self):
509
476
"""Test that status works without fetching history and
510
477
having a write lock.
527
494
super(CheckoutStatus, self).setUp()
531
498
def make_branch_and_tree(self, relpath):
532
499
source = self.make_branch(pathjoin('..', relpath))
533
500
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
534
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
535
target_branch=source)
501
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
536
502
return checkout.create_workingtree()
629
595
result2 = self.run_bzr("status -SV -r 0..")[0]
630
596
self.assertEquals(result2, result)
632
def assertStatusContains(self, pattern, short=False):
598
def assertStatusContains(self, pattern):
633
599
"""Run status, and assert it contains the given pattern"""
635
result = self.run_bzr("status --short")[0]
637
result = self.run_bzr("status")[0]
600
result = self.run_bzr("status --short")[0]
638
601
self.assertContainsRe(result, pattern)
640
def test_kind_change_plain(self):
641
tree = self.make_branch_and_tree('.')
642
self.build_tree(['file'])
644
tree.commit('added file')
646
self.build_tree(['file/'])
647
self.assertStatusContains('kind changed:\n file \(file => directory\)')
648
tree.rename_one('file', 'directory')
649
self.assertStatusContains('renamed:\n file/ => directory/\n' \
650
'modified:\n directory/\n')
652
self.assertStatusContains('removed:\n file\n')
654
603
def test_kind_change_short(self):
655
604
tree = self.make_branch_and_tree('.')
656
605
self.build_tree(['file'])
658
607
tree.commit('added file')
660
609
self.build_tree(['file/'])
661
self.assertStatusContains('K file => file/',
610
self.assertStatusContains('K file => file/')
663
611
tree.rename_one('file', 'directory')
664
self.assertStatusContains('RK file => directory/',
612
self.assertStatusContains('RK file => directory/')
666
613
rmdir('directory')
667
self.assertStatusContains('RD file => directory',
614
self.assertStatusContains('RD file => directory')
670
616
def test_status_illegal_revision_specifiers(self):
671
617
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
705
651
class TestStatusEncodings(TestCaseWithTransport):
708
654
TestCaseWithTransport.setUp(self)
709
655
self.user_encoding = osutils._cached_user_encoding
710
656
self.stdout = sys.stdout
712
658
def tearDown(self):
713
osutils._cached_user_encoding = self.user_encoding
659
bzrlib.user_encoding = self.user_encoding
714
660
sys.stdout = self.stdout
715
661
TestCaseWithTransport.tearDown(self)