1
# Copyright (C) 2005-2012, 2016 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
53
53
status._show_shelve_summary,
56
def assertStatus(self, expected_lines, working_tree, specific_files=None,
56
def assertStatus(self, expected_lines, working_tree,
57
57
revision=None, short=False, pending=True, verbose=False):
58
58
"""Run status in working_tree and look for output.
60
60
:param expected_lines: The lines to look for.
61
61
:param working_tree: The tree to run status in.
63
output_string = self.status_string(working_tree, specific_files, revision, short,
63
output_string = self.status_string(working_tree, revision, short,
65
65
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):
67
def status_string(self, wt, revision=None, short=False, pending=True,
69
69
# use a real file rather than StringIO because it doesn't handle
70
70
# Unicode very well.
71
71
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,
72
show_tree_status(wt, to_file=tof, revision=revision, short=short,
73
show_pending=pending, verbose=verbose)
76
75
return tof.read().decode('utf-8')
188
187
wt2.merge_from_branch(wt.branch)
189
188
message = self.status_string(wt2, verbose=True)
190
189
self.assertStartsWith(message, "pending merges:\n")
191
self.assertTrue("Empty commit 3" in message)
190
self.assert_("Empty commit 3" in message)
192
191
self.assertEndsWith(message, "...\n")
194
193
def test_tree_status_ignores(self):
249
248
show_tree_status(wt, specific_files=['directory'], to_file=tof)
251
self.assertEqual(tof.readlines(),
250
self.assertEquals(tof.readlines(),
253
252
' directory/hello.c\n'
256
255
show_tree_status(wt, specific_files=['directory'], to_file=tof,
259
self.assertEqual(tof.readlines(), ['? directory/hello.c\n'])
258
self.assertEquals(tof.readlines(), ['? directory/hello.c\n'])
262
261
show_tree_status(wt, specific_files=['dir2'], to_file=tof)
264
self.assertEqual(tof.readlines(),
263
self.assertEquals(tof.readlines(),
269
268
show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
271
self.assertEqual(tof.readlines(), ['? dir2/\n'])
270
self.assertEquals(tof.readlines(), ['? dir2/\n'])
274
273
revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
275
274
show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
275
short=True, revision=revs)
278
self.assertEqual(tof.readlines(), ['+N test.c\n'])
277
self.assertEquals(tof.readlines(), ['+N test.c\n'])
281
280
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
283
self.assertEqual(tof.readlines(),
282
self.assertEquals(tof.readlines(),
288
287
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
291
self.assertEqual(tof.readlines(),
290
self.assertEquals(tof.readlines(),
292
291
['+! missing.c\n'])
294
293
def test_specific_files_conflicts(self):
572
571
self.run_bzr(['shelve', '--all', '-m', 'bar'])
573
self.build_tree(['eggs.c', 'spam.c'])
572
self.build_tree(['spam.c'])
576
574
self.assertStatus([
580
577
'2 shelves exist. See "bzr shelve --list" for details.\n',
588
specific_files=['spam.c'])
591
582
class CheckoutStatus(BranchStatus):
598
589
def make_branch_and_tree(self, relpath):
599
590
source = self.make_branch(pathjoin('..', relpath))
600
591
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
601
checkout.set_branch_reference(source)
592
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
593
target_branch=source)
602
594
return checkout.create_workingtree()
627
619
self.assertContainsRe(result, "added:\n hello.txt\n" \
628
620
"unknown:\n world.txt\n")
629
621
result2 = self.run_bzr("status -r 0..")[0]
630
self.assertEqual(result2, result)
622
self.assertEquals(result2, result)
632
624
def test_status_short(self):
633
625
tree = self.make_branch_and_tree('.')
649
641
self.assertContainsRe(result, "[+]N hello.txt\n" \
650
642
"[?] world.txt\n")
651
643
result2 = self.run_bzr("status -S -r 0..")[0]
652
self.assertEqual(result2, result)
644
self.assertEquals(result2, result)
654
646
def test_status_versioned(self):
655
647
tree = self.make_branch_and_tree('.')
671
663
self.assertContainsRe(result, "added:\n hello.txt\n")
672
664
self.assertNotContainsRe(result, "unknown:\n world.txt\n")
673
665
result2 = self.run_bzr("status --versioned -r 0..")[0]
674
self.assertEqual(result2, result)
666
self.assertEquals(result2, result)
676
668
def test_status_SV(self):
677
669
tree = self.make_branch_and_tree('.')
693
685
self.assertContainsRe(result, "[+]N hello.txt\n")
695
687
result2 = self.run_bzr("status -SV -r 0..")[0]
696
self.assertEqual(result2, result)
688
self.assertEquals(result2, result)
698
690
def assertStatusContains(self, pattern, short=False):
699
691
"""Run status, and assert it contains the given pattern"""
750
742
self.run_bzr('merge ../b', working_dir='a')
751
743
out, err = self.run_bzr('status --no-pending', working_dir='a')
752
self.assertEqual(out, "added:\n b\n")
744
self.assertEquals(out, "added:\n b\n")
754
746
def test_pending_specific_files(self):
755
747
"""With a specific file list, pending merges are not shown."""
787
779
working_tree = self.make_uncommitted_tree()
788
780
stdout, stderr = self.run_bzr("status")
790
self.assertEqual(stdout, """\
782
self.assertEquals(stdout, """\
797
789
working_tree = self.make_uncommitted_tree()
798
790
stdout, stderr = self.run_bzr('status')
800
self.assertEqual(stdout, u"""\
792
self.assertEquals(stdout, u"""\
803
795
""".encode('latin-1'))