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