1
# Copyright (C) 2005 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Tests of status command.
20
Most of these depend on the particular formatting used.
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
35
class BranchStatus(TestCaseInTempDir):
37
def test_branch_status(self):
38
"""Test basic branch status"""
39
from bzrlib.status import show_status
40
from bzrlib.branch import Branch
42
b = Branch.initialize(u'.')
46
show_status(b, to_file=tof)
47
self.assertEquals(tof.getvalue(), "")
50
self.build_tree(['hello.c', 'bye.c'])
51
b.working_tree().add_pending_merge('pending@pending-0-0')
52
show_status(b, to_file=tof)
54
self.assertEquals(tof.readlines(),
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(),