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
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
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.
211
202
wt = self.make_branch_and_tree('.')
214
self.build_tree(['directory/','directory/hello.c',
215
'bye.c','test.c','dir2/',
205
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
217
206
wt.add('directory')
219
208
wt.commit('testing')
223
210
self.assertStatus([
277
261
self.assertEquals(tof.readlines(), ['+N test.c\n'])
280
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
self.assertEquals(tof.readlines(),
287
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
290
self.assertEquals(tof.readlines(),
293
263
def test_specific_files_conflicts(self):
294
264
tree = self.make_branch_and_tree('.')
295
265
self.build_tree(['dir2/'])
326
296
wt.commit('Create five empty files.')
327
with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
328
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.')
329
299
unlink('FILE_E') # FILE_E will be versioned but missing
330
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.')
331
301
wt.add('FILE_Q') # FILE_Q will be added but not committed
332
302
open('UNVERSIONED_BUT_EXISTING', 'w')
478
448
'X NONEXISTENT\n',
481
450
out, err = self.run_bzr('status --short NONEXISTENT '
482
451
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
483
452
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
484
actual = out.splitlines(True)
486
self.assertEqual(expected, actual)
453
self.assertEqual(expected, out.splitlines(True))
487
454
self.assertContainsRe(err,
488
455
r'.*ERROR: Path\(s\) do not exist: '
505
472
self.assertEqual("working tree is out of date, run 'bzr update'\n",
508
def test_status_on_ignored(self):
509
"""Tests branch status on an unversioned file which is considered ignored.
511
See https://bugs.launchpad.net/bzr/+bug/40103
513
tree = self.make_branch_and_tree('.')
515
self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
516
result = self.run_bzr('status')[0]
517
self.assertContainsRe(result, "unknown:\n test1.c\n")
518
short_result = self.run_bzr('status --short')[0]
519
self.assertContainsRe(short_result, "\? test1.c\n")
521
result = self.run_bzr('status test1.c')[0]
522
self.assertContainsRe(result, "unknown:\n test1.c\n")
523
short_result = self.run_bzr('status --short test1.c')[0]
524
self.assertContainsRe(short_result, "\? test1.c\n")
526
result = self.run_bzr('status test1.c~')[0]
527
self.assertContainsRe(result, "ignored:\n test1.c~\n")
528
short_result = self.run_bzr('status --short test1.c~')[0]
529
self.assertContainsRe(short_result, "I test1.c~\n")
531
result = self.run_bzr('status test1.c~ test2.c~')[0]
532
self.assertContainsRe(result, "ignored:\n test1.c~\n test2.c~\n")
533
short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
534
self.assertContainsRe(short_result, "I test1.c~\nI test2.c~\n")
536
result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
537
self.assertContainsRe(result, "unknown:\n test1.c\nignored:\n test1.c~\n test2.c~\n")
538
short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
539
self.assertContainsRe(short_result, "\? test1.c\nI test1.c~\nI test2.c~\n")
541
475
def test_status_write_lock(self):
542
476
"""Test that status works without fetching history and
543
477
having a write lock.
553
487
out, err = self.run_bzr('status branch1 -rbranch:branch2')
554
488
self.assertEqual('', out)
556
def test_status_with_shelves(self):
557
"""Ensure that _show_shelve_summary handler works.
559
wt = self.make_branch_and_tree('.')
560
self.build_tree(['hello.c'])
562
self.run_bzr(['shelve', '--all', '-m', 'foo'])
563
self.build_tree(['bye.c'])
568
'1 shelf exists. See "bzr shelve --list" for details.\n',
571
self.run_bzr(['shelve', '--all', '-m', 'bar'])
572
self.build_tree(['spam.c'])
577
'2 shelves exist. See "bzr shelve --list" for details.\n',
582
491
class CheckoutStatus(BranchStatus):
589
498
def make_branch_and_tree(self, relpath):
590
499
source = self.make_branch(pathjoin('..', relpath))
591
500
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
592
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
593
target_branch=source)
501
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
594
502
return checkout.create_workingtree()
637
545
self.assertContainsRe(result, "[+]N hello.txt\n")
639
547
self.build_tree(['world.txt'])
640
result = self.run_bzr("status -S -r 0")[0]
548
result = self.run_bzr("status --short -r 0")[0]
641
549
self.assertContainsRe(result, "[+]N hello.txt\n" \
642
550
"[?] world.txt\n")
643
result2 = self.run_bzr("status -S -r 0..")[0]
551
result2 = self.run_bzr("status --short -r 0..")[0]
644
552
self.assertEquals(result2, result)
646
554
def test_status_versioned(self):
687
595
result2 = self.run_bzr("status -SV -r 0..")[0]
688
596
self.assertEquals(result2, result)
690
def assertStatusContains(self, pattern, short=False):
598
def assertStatusContains(self, pattern):
691
599
"""Run status, and assert it contains the given pattern"""
693
result = self.run_bzr("status --short")[0]
695
result = self.run_bzr("status")[0]
600
result = self.run_bzr("status --short")[0]
696
601
self.assertContainsRe(result, pattern)
698
def test_kind_change_plain(self):
699
tree = self.make_branch_and_tree('.')
700
self.build_tree(['file'])
702
tree.commit('added file')
704
self.build_tree(['file/'])
705
self.assertStatusContains('kind changed:\n file \(file => directory\)')
706
tree.rename_one('file', 'directory')
707
self.assertStatusContains('renamed:\n file/ => directory/\n' \
708
'modified:\n directory/\n')
710
self.assertStatusContains('removed:\n file\n')
712
603
def test_kind_change_short(self):
713
604
tree = self.make_branch_and_tree('.')
714
605
self.build_tree(['file'])
716
607
tree.commit('added file')
718
609
self.build_tree(['file/'])
719
self.assertStatusContains('K file => file/',
610
self.assertStatusContains('K file => file/')
721
611
tree.rename_one('file', 'directory')
722
self.assertStatusContains('RK file => directory/',
612
self.assertStatusContains('RK file => directory/')
724
613
rmdir('directory')
725
self.assertStatusContains('RD file => directory',
614
self.assertStatusContains('RD file => directory')
728
616
def test_status_illegal_revision_specifiers(self):
729
617
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
763
651
class TestStatusEncodings(TestCaseWithTransport):
654
TestCaseWithTransport.setUp(self)
655
self.user_encoding = osutils._cached_user_encoding
656
self.stdout = sys.stdout
659
bzrlib.user_encoding = self.user_encoding
660
sys.stdout = self.stdout
661
TestCaseWithTransport.tearDown(self)
765
663
def make_uncommitted_tree(self):
766
664
"""Build a branch with uncommitted unicode named changes in the cwd."""
767
665
working_tree = self.make_branch_and_tree(u'.')
775
673
return working_tree
777
675
def test_stdout_ascii(self):
778
self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
676
sys.stdout = StringIO()
677
osutils._cached_user_encoding = 'ascii'
779
678
working_tree = self.make_uncommitted_tree()
780
679
stdout, stderr = self.run_bzr("status")
787
686
def test_stdout_latin1(self):
788
self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
687
sys.stdout = StringIO()
688
osutils._cached_user_encoding = 'latin-1'
789
689
working_tree = self.make_uncommitted_tree()
790
690
stdout, stderr = self.run_bzr('status')