22
22
interface later, they will be non blackbox tests.
25
from cStringIO import StringIO
27
26
from os import mkdir, chdir, rmdir, unlink
29
from tempfile import TemporaryFile
38
from bzrlib.osutils import pathjoin
39
from bzrlib.revisionspec import RevisionSpec
40
from bzrlib.status import show_tree_status
41
from bzrlib.tests import TestCaseWithTransport, TestSkipped
42
from bzrlib.workingtree import WorkingTree
35
from breezy.bzr import (
39
from ...osutils import pathjoin
40
from ...revisionspec import RevisionSpec
41
from ...sixish import (
44
from ...status import show_tree_status
45
from .. import TestCaseWithTransport, TestSkipped
46
from ...workingtree import WorkingTree
45
49
class BranchStatus(TestCaseWithTransport):
47
def assertStatus(self, expected_lines, working_tree,
52
super(BranchStatus, self).setUp()
53
# As TestCase.setUp clears all hooks, we install this default
54
# post_status hook handler for the test.
55
status.hooks.install_named_hook('post_status',
56
status._show_shelve_summary,
59
def assertStatus(self, expected_lines, working_tree, specific_files=None,
48
60
revision=None, short=False, pending=True, verbose=False):
49
61
"""Run status in working_tree and look for output.
51
63
:param expected_lines: The lines to look for.
52
64
:param working_tree: The tree to run status in.
54
output_string = self.status_string(working_tree, revision, short,
66
output_string = self.status_string(working_tree, specific_files, revision, short,
56
68
self.assertEqual(expected_lines, output_string.splitlines(True))
58
def status_string(self, wt, revision=None, short=False, pending=True,
60
# use a real file rather than StringIO because it doesn't handle
62
tof = codecs.getwriter('utf-8')(TemporaryFile())
63
show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
show_pending=pending, verbose=verbose)
66
return tof.read().decode('utf-8')
70
def status_string(self, wt, specific_files=None, revision=None,
71
short=False, pending=True, verbose=False):
72
uio = self.make_utf8_encoded_stringio()
73
show_tree_status(wt, specific_files=specific_files, to_file=uio,
74
revision=revision, short=short, show_pending=pending,
76
return uio.getvalue().decode('utf-8')
68
78
def test_branch_status(self):
69
79
"""Test basic branch status"""
218
234
self.assertStatus([
221
238
'? directory/hello.c\n'
226
243
self.assertRaises(errors.PathsDoNotExist,
227
244
show_tree_status,
228
245
wt, specific_files=['bye.c','test.c','absent.c'],
232
249
show_tree_status(wt, specific_files=['directory'], to_file=tof)
234
self.assertEquals(tof.readlines(),
251
self.assertEqual(tof.readlines(),
236
253
' directory/hello.c\n'
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('.')
267
298
tree.commit('added dir2')
268
299
tree.set_conflicts(conflicts.ConflictList(
269
300
[conflicts.ContentsConflict('foo')]))
271
302
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
272
303
self.assertEqualDiff('', tof.getvalue())
273
304
tree.set_conflicts(conflicts.ConflictList(
274
305
[conflicts.ContentsConflict('dir2')]))
276
307
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
277
308
self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n',
280
311
tree.set_conflicts(conflicts.ConflictList(
281
312
[conflicts.ContentsConflict('dir2/file1')]))
283
314
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
284
315
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
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')
439
470
self.assertContainsRe(err,
440
471
r'.*ERROR: Path\(s\) do not exist: '
444
475
'? UNVERSIONED_BUT_EXISTING\n',
448
479
'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: '
515
548
wt = self.make_branch_and_tree('branch1')
517
550
wt.commit('Empty commit 1')
518
wt2 = b.bzrdir.sprout('branch2').open_workingtree()
551
wt2 = b.controldir.sprout('branch2').open_workingtree()
519
552
wt2.commit('Empty commit 2')
520
553
out, err = self.run_bzr('status branch1 -rbranch:branch2')
521
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 "brz shelve --list" for details.\n',
571
self.run_bzr(['shelve', '--all', '-m', 'bar'])
572
self.build_tree(['eggs.c', 'spam.c'])
579
'2 shelves exist. See "brz shelve --list" for details.\n',
587
specific_files=['spam.c'])
524
590
class CheckoutStatus(BranchStatus):
579
644
self.assertContainsRe(result, "[+]N hello.txt\n")
581
646
self.build_tree(['world.txt'])
582
result = self.run_bzr("status --short -r 0")[0]
647
result = self.run_bzr("status -S -r 0")[0]
583
648
self.assertContainsRe(result, "[+]N hello.txt\n" \
584
649
"[?] world.txt\n")
585
result2 = self.run_bzr("status --short -r 0..")[0]
586
self.assertEquals(result2, result)
650
result2 = self.run_bzr("status -S -r 0..")[0]
651
self.assertEqual(result2, result)
588
653
def test_status_versioned(self):
589
654
tree = self.make_branch_and_tree('.')
676
741
self.build_tree(['a/a'])
678
743
a_tree.commit('a')
679
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
744
b_tree = a_tree.controldir.sprout('b').open_workingtree()
680
745
self.build_tree(['b/b'])
682
747
b_tree.commit('b')
684
749
self.run_bzr('merge ../b', working_dir='a')
685
750
out, err = self.run_bzr('status --no-pending', working_dir='a')
686
self.assertEquals(out, "added:\n b\n")
751
self.assertEqual(out, "added:\n b\n")
688
753
def test_pending_specific_files(self):
689
754
"""With a specific file list, pending merges are not shown."""
727
782
return working_tree
729
784
def test_stdout_ascii(self):
730
sys.stdout = StringIO()
731
osutils._cached_user_encoding = 'ascii'
785
self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
732
786
working_tree = self.make_uncommitted_tree()
733
787
stdout, stderr = self.run_bzr("status")
735
self.assertEquals(stdout, """\
789
self.assertEqual(stdout, """\
740
794
def test_stdout_latin1(self):
741
sys.stdout = StringIO()
742
osutils._cached_user_encoding = 'latin-1'
795
self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
743
796
working_tree = self.make_uncommitted_tree()
744
797
stdout, stderr = self.run_bzr('status')
746
self.assertEquals(stdout, u"""\
799
self.assertEqual(stdout, u"""\
749
802
""".encode('latin-1'))