24
from bzrlib.selftest import TestCaseInTempDir
24
from cStringIO import StringIO
26
from tempfile import TemporaryFile
29
from bzrlib.tests import TestCaseInTempDir
30
from bzrlib.revisionspec import RevisionSpec
31
from bzrlib.merge import merge
32
from bzrlib.status import show_status
33
from bzrlib.branch import Branch
26
35
class BranchStatus(TestCaseInTempDir):
28
37
def test_branch_status(self):
29
"""Basic 'bzr mkdir' operation"""
30
from cStringIO import StringIO
38
"""Test basic branch status"""
31
39
from bzrlib.status import show_status
32
40
from bzrlib.branch import Branch
34
b = Branch('.', init=True)
42
b = Branch.initialize(u'.')
36
44
# status with nothing
51
59
' pending@pending-0-0\n'
62
def test_branch_status_revisions(self):
63
"""Tests branch status with revisions"""
65
b = Branch.initialize(u'.')
68
self.build_tree(['hello.c', 'bye.c'])
69
b.working_tree().add('hello.c')
70
b.working_tree().add('bye.c')
71
b.working_tree().commit('Test message')
75
revs.append(RevisionSpec(0))
77
show_status(b, to_file=tof, revision=revs)
80
self.assertEquals(tof.readlines(),
85
self.build_tree(['more.c'])
86
b.working_tree().add('more.c')
87
b.working_tree().commit('Another test message')
90
revs.append(RevisionSpec(1))
92
show_status(b, to_file=tof, revision=revs)
95
self.assertEquals(tof.readlines(),
100
def status_string(self, branch):
101
# use a real file rather than StringIO because it doesn't handle
103
tof = codecs.getwriter('utf-8')(TemporaryFile())
104
show_status(branch, to_file=tof)
106
return tof.read().decode('utf-8')
108
def test_pending(self):
109
"""Pending merges display works, including Unicode"""
111
b = Branch.initialize('./branch')
112
b.working_tree().commit("Empty commit 1")
113
b_2 = b.clone('./copy')
114
b.working_tree().commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
115
merge(["./branch", -1], [None, None], this_dir = './copy')
116
message = self.status_string(b_2)
117
self.assert_(message.startswith("pending merges:\n"))
118
self.assert_(message.endswith("Empty commit 2\n"))
119
b_2.working_tree().commit("merged")
120
# must be long to make sure we see elipsis at the end
121
b.working_tree().commit("Empty commit 3 " +
122
"blah blah blah blah " * 10)
123
merge(["./branch", -1], [None, None], this_dir = './copy')
124
message = self.status_string(b_2)
125
self.assert_(message.startswith("pending merges:\n"))
126
self.assert_("Empty commit 3" in message)
127
self.assert_(message.endswith("...\n"))
129
def test_branch_status_specific_files(self):
130
"""Tests branch status with given specific files"""
131
from cStringIO import StringIO
132
from bzrlib.status import show_status
133
from bzrlib.branch import Branch
135
b = Branch.initialize(u'.')
137
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
138
b.working_tree().add('directory')
139
b.working_tree().add('test.c')
140
b.working_tree().commit('testing')
143
show_status(b, to_file=tof)
145
self.assertEquals(tof.readlines(),
149
' directory/hello.c\n'
153
show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
155
self.assertEquals(tof.readlines(),
161
show_status(b, specific_files=['directory'], to_file=tof)
163
self.assertEquals(tof.readlines(),
165
' directory/hello.c\n'
168
show_status(b, specific_files=['dir2'], to_file=tof)
170
self.assertEquals(tof.readlines(),