45
46
class BranchStatus(TestCaseWithTransport):
47
def assertStatus(self, expected_lines, working_tree,
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,
48
57
revision=None, short=False, pending=True, verbose=False):
49
58
"""Run status in working_tree and look for output.
51
60
:param expected_lines: The lines to look for.
52
61
:param working_tree: The tree to run status in.
54
output_string = self.status_string(working_tree, revision, short,
63
output_string = self.status_string(working_tree, specific_files, revision, short,
56
65
self.assertEqual(expected_lines, output_string.splitlines(True))
58
def status_string(self, wt, revision=None, short=False, pending=True,
67
def status_string(self, wt, specific_files=None, revision=None,
68
short=False, pending=True, verbose=False):
60
69
# use a real file rather than StringIO because it doesn't handle
61
70
# Unicode very well.
62
71
tof = codecs.getwriter('utf-8')(TemporaryFile())
63
show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
show_pending=pending, verbose=verbose)
72
show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
revision=revision, short=short, show_pending=pending,
66
76
return tof.read().decode('utf-8')
178
188
wt2.merge_from_branch(wt.branch)
179
189
message = self.status_string(wt2, verbose=True)
180
190
self.assertStartsWith(message, "pending merges:\n")
181
self.assert_("Empty commit 3" in message)
191
self.assertTrue("Empty commit 3" in message)
182
192
self.assertEndsWith(message, "...\n")
184
194
def test_tree_status_ignores(self):
202
212
wt = self.make_branch_and_tree('.')
205
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
215
self.build_tree(['directory/','directory/hello.c',
216
'bye.c','test.c','dir2/',
206
218
wt.add('directory')
208
220
wt.commit('testing')
210
224
self.assertStatus([
239
256
show_tree_status(wt, specific_files=['directory'], to_file=tof,
242
self.assertEquals(tof.readlines(), ['? directory/hello.c\n'])
259
self.assertEqual(tof.readlines(), ['? directory/hello.c\n'])
245
262
show_tree_status(wt, specific_files=['dir2'], to_file=tof)
247
self.assertEquals(tof.readlines(),
264
self.assertEqual(tof.readlines(),
252
269
show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
254
self.assertEquals(tof.readlines(), ['? dir2/\n'])
271
self.assertEqual(tof.readlines(), ['? dir2/\n'])
257
274
revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
258
275
show_tree_status(wt, specific_files=['test.c'], to_file=tof,
259
276
short=True, revision=revs)
261
self.assertEquals(tof.readlines(), ['+N test.c\n'])
278
self.assertEqual(tof.readlines(), ['+N test.c\n'])
281
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
283
self.assertEqual(tof.readlines(),
288
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
291
self.assertEqual(tof.readlines(),
263
294
def test_specific_files_conflicts(self):
264
295
tree = self.make_branch_and_tree('.')
296
327
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.')
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.')
299
330
unlink('FILE_E') # FILE_E will be versioned but missing
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
331
with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
332
wt.add('FILE_Q') # FILE_Q will be added but not committed
302
333
open('UNVERSIONED_BUT_EXISTING', 'w')
448
479
'X NONEXISTENT\n',
450
482
out, err = self.run_bzr('status --short NONEXISTENT '
451
483
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
484
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
self.assertEqual(expected, out.splitlines(True))
485
actual = out.splitlines(True)
487
self.assertEqual(expected, actual)
454
488
self.assertContainsRe(err,
455
489
r'.*ERROR: Path\(s\) do not exist: '
472
506
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")
475
542
def test_status_write_lock(self):
476
543
"""Test that status works without fetching history and
477
544
having a write lock.
487
554
out, err = self.run_bzr('status branch1 -rbranch:branch2')
488
555
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'])
491
591
class CheckoutStatus(BranchStatus):
498
598
def make_branch_and_tree(self, relpath):
499
599
source = self.make_branch(pathjoin('..', relpath))
500
600
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
501
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
502
target_branch=source)
601
checkout.set_branch_reference(source)
503
602
return checkout.create_workingtree()
528
627
self.assertContainsRe(result, "added:\n hello.txt\n" \
529
628
"unknown:\n world.txt\n")
530
629
result2 = self.run_bzr("status -r 0..")[0]
531
self.assertEquals(result2, result)
630
self.assertEqual(result2, result)
533
632
def test_status_short(self):
534
633
tree = self.make_branch_and_tree('.')
546
645
self.assertContainsRe(result, "[+]N hello.txt\n")
548
647
self.build_tree(['world.txt'])
549
result = self.run_bzr("status --short -r 0")[0]
648
result = self.run_bzr("status -S -r 0")[0]
550
649
self.assertContainsRe(result, "[+]N hello.txt\n" \
551
650
"[?] world.txt\n")
552
result2 = self.run_bzr("status --short -r 0..")[0]
553
self.assertEquals(result2, result)
651
result2 = self.run_bzr("status -S -r 0..")[0]
652
self.assertEqual(result2, result)
555
654
def test_status_versioned(self):
556
655
tree = self.make_branch_and_tree('.')
572
671
self.assertContainsRe(result, "added:\n hello.txt\n")
573
672
self.assertNotContainsRe(result, "unknown:\n world.txt\n")
574
673
result2 = self.run_bzr("status --versioned -r 0..")[0]
575
self.assertEquals(result2, result)
674
self.assertEqual(result2, result)
577
676
def test_status_SV(self):
578
677
tree = self.make_branch_and_tree('.')
594
693
self.assertContainsRe(result, "[+]N hello.txt\n")
596
695
result2 = self.run_bzr("status -SV -r 0..")[0]
597
self.assertEquals(result2, result)
696
self.assertEqual(result2, result)
599
698
def assertStatusContains(self, pattern, short=False):
600
699
"""Run status, and assert it contains the given pattern"""
651
750
self.run_bzr('merge ../b', working_dir='a')
652
751
out, err = self.run_bzr('status --no-pending', working_dir='a')
653
self.assertEquals(out, "added:\n b\n")
752
self.assertEqual(out, "added:\n b\n")
655
754
def test_pending_specific_files(self):
656
755
"""With a specific file list, pending merges are not shown."""
672
771
class TestStatusEncodings(TestCaseWithTransport):
675
TestCaseWithTransport.setUp(self)
676
self.user_encoding = osutils._cached_user_encoding
677
self.stdout = sys.stdout
680
osutils._cached_user_encoding = self.user_encoding
681
sys.stdout = self.stdout
682
TestCaseWithTransport.tearDown(self)
684
773
def make_uncommitted_tree(self):
685
774
"""Build a branch with uncommitted unicode named changes in the cwd."""
686
775
working_tree = self.make_branch_and_tree(u'.')
694
783
return working_tree
696
785
def test_stdout_ascii(self):
697
sys.stdout = StringIO()
698
osutils._cached_user_encoding = 'ascii'
786
self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
699
787
working_tree = self.make_uncommitted_tree()
700
788
stdout, stderr = self.run_bzr("status")
702
self.assertEquals(stdout, """\
790
self.assertEqual(stdout, """\
707
795
def test_stdout_latin1(self):
708
sys.stdout = StringIO()
709
osutils._cached_user_encoding = 'latin-1'
796
self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
710
797
working_tree = self.make_uncommitted_tree()
711
798
stdout, stderr = self.run_bzr('status')
713
self.assertEquals(stdout, u"""\
800
self.assertEqual(stdout, u"""\
716
803
""".encode('latin-1'))