1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005-2010 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
45
46
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,
47
56
def assertStatus(self, expected_lines, working_tree,
48
57
revision=None, short=False, pending=True, verbose=False):
49
58
"""Run status in working_tree and look for output.
202
211
wt = self.make_branch_and_tree('.')
205
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
214
self.build_tree(['directory/','directory/hello.c',
215
'bye.c','test.c','dir2/',
206
217
wt.add('directory')
208
219
wt.commit('testing')
210
223
self.assertStatus([
261
277
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(),
263
293
def test_specific_files_conflicts(self):
264
294
tree = self.make_branch_and_tree('.')
265
295
self.build_tree(['dir2/'])
296
326
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.')
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.')
299
329
unlink('FILE_E') # FILE_E will be versioned but missing
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
330
with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
331
wt.add('FILE_Q') # FILE_Q will be added but not committed
302
332
open('UNVERSIONED_BUT_EXISTING', 'w')
448
478
'X NONEXISTENT\n',
450
481
out, err = self.run_bzr('status --short NONEXISTENT '
451
482
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
483
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
self.assertEqual(expected, out.splitlines(True))
484
actual = out.splitlines(True)
486
self.assertEqual(expected, actual)
454
487
self.assertContainsRe(err,
455
488
r'.*ERROR: Path\(s\) do not exist: '
472
505
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")
475
541
def test_status_write_lock(self):
476
542
"""Test that status works without fetching history and
477
543
having a write lock.
487
553
out, err = self.run_bzr('status branch1 -rbranch:branch2')
488
554
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',
491
582
class CheckoutStatus(BranchStatus):
498
589
def make_branch_and_tree(self, relpath):
499
590
source = self.make_branch(pathjoin('..', relpath))
500
591
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
501
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
592
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
593
target_branch=source)
502
594
return checkout.create_workingtree()
545
637
self.assertContainsRe(result, "[+]N hello.txt\n")
547
639
self.build_tree(['world.txt'])
548
result = self.run_bzr("status --short -r 0")[0]
640
result = self.run_bzr("status -S -r 0")[0]
549
641
self.assertContainsRe(result, "[+]N hello.txt\n" \
550
642
"[?] world.txt\n")
551
result2 = self.run_bzr("status --short -r 0..")[0]
643
result2 = self.run_bzr("status -S -r 0..")[0]
552
644
self.assertEquals(result2, result)
554
646
def test_status_versioned(self):
595
687
result2 = self.run_bzr("status -SV -r 0..")[0]
596
688
self.assertEquals(result2, result)
598
def assertStatusContains(self, pattern):
690
def assertStatusContains(self, pattern, short=False):
599
691
"""Run status, and assert it contains the given pattern"""
600
result = self.run_bzr("status --short")[0]
693
result = self.run_bzr("status --short")[0]
695
result = self.run_bzr("status")[0]
601
696
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')
603
712
def test_kind_change_short(self):
604
713
tree = self.make_branch_and_tree('.')
605
714
self.build_tree(['file'])
607
716
tree.commit('added file')
609
718
self.build_tree(['file/'])
610
self.assertStatusContains('K file => file/')
719
self.assertStatusContains('K file => file/',
611
721
tree.rename_one('file', 'directory')
612
self.assertStatusContains('RK file => directory/')
722
self.assertStatusContains('RK file => directory/',
613
724
rmdir('directory')
614
self.assertStatusContains('RD file => directory')
725
self.assertStatusContains('RD file => directory',
616
728
def test_status_illegal_revision_specifiers(self):
617
729
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
651
763
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)
663
765
def make_uncommitted_tree(self):
664
766
"""Build a branch with uncommitted unicode named changes in the cwd."""
665
767
working_tree = self.make_branch_and_tree(u'.')
673
775
return working_tree
675
777
def test_stdout_ascii(self):
676
sys.stdout = StringIO()
677
osutils._cached_user_encoding = 'ascii'
778
self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
678
779
working_tree = self.make_uncommitted_tree()
679
780
stdout, stderr = self.run_bzr("status")
686
787
def test_stdout_latin1(self):
687
sys.stdout = StringIO()
688
osutils._cached_user_encoding = 'latin-1'
788
self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
689
789
working_tree = self.make_uncommitted_tree()
690
790
stdout, stderr = self.run_bzr('status')