~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_status.py

Fix status to work with checkouts

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
 
27
27
from cStringIO import StringIO
28
 
from os import mkdir
 
28
from os import mkdir, chdir
29
29
from tempfile import TemporaryFile
30
30
import codecs
31
31
 
 
32
import bzrlib.branch
32
33
from bzrlib.builtins import merge
 
34
import bzrlib.bzrdir as bzrdir
 
35
from bzrlib.osutils import pathjoin
33
36
from bzrlib.revisionspec import RevisionSpec
34
 
from bzrlib.status import show_status
 
37
from bzrlib.status import show_tree_status
35
38
from bzrlib.tests import TestCaseWithTransport
36
39
from bzrlib.workingtree import WorkingTree
37
40
 
45
48
 
46
49
        # status with nothing
47
50
        tof = StringIO()
48
 
        show_status(b, to_file=tof)
 
51
        show_tree_status(wt, to_file=tof)
49
52
        self.assertEquals(tof.getvalue(), "")
50
53
 
51
54
        tof = StringIO()
52
55
        self.build_tree(['hello.c', 'bye.c'])
53
56
        wt.add_pending_merge('pending@pending-0-0')
54
 
        show_status(b, to_file=tof)
 
57
        show_tree_status(wt, to_file=tof)
55
58
        tof.seek(0)
56
59
        self.assertEquals(tof.readlines(),
57
60
                          ['unknown:\n',
76
79
        revs =[]
77
80
        revs.append(RevisionSpec(0))
78
81
        
79
 
        show_status(b, to_file=tof, revision=revs)
 
82
        show_tree_status(wt, to_file=tof, revision=revs)
80
83
        
81
84
        tof.seek(0)
82
85
        self.assertEquals(tof.readlines(),
90
93
        
91
94
        tof = StringIO()
92
95
        revs.append(RevisionSpec(1))
93
 
        
94
 
        show_status(b, to_file=tof, revision=revs)
 
96
      
 
97
 
 
98
 
 
99
 
 
100
        show_tree_status(wt, to_file=tof, revision=revs)
95
101
        
96
102
        tof.seek(0)
97
103
        self.assertEquals(tof.readlines(),
99
105
                           '  bye.c\n',
100
106
                           '  hello.c\n'])
101
107
 
102
 
    def status_string(self, branch):
 
108
    def status_string(self, wt):
103
109
        # use a real file rather than StringIO because it doesn't handle
104
110
        # Unicode very well.
105
111
        tof = codecs.getwriter('utf-8')(TemporaryFile())
106
 
        show_status(branch, to_file=tof)
 
112
        show_tree_status(wt, to_file=tof)
107
113
        tof.seek(0)
108
114
        return tof.read().decode('utf-8')
109
115
 
118
124
        wt2 = b_2_dir.open_workingtree()
119
125
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
120
126
        merge(["./branch", -1], [None, None], this_dir = './copy')
121
 
        message = self.status_string(b_2)
 
127
        message = self.status_string(wt2)
122
128
        self.assert_(message.startswith("pending merges:\n"))
123
129
        self.assert_(message.endswith("Empty commit 2\n")) 
124
130
        wt2.commit("merged")
126
132
        wt.commit("Empty commit 3 " + 
127
133
                   "blah blah blah blah " * 10)
128
134
        merge(["./branch", -1], [None, None], this_dir = './copy')
129
 
        message = self.status_string(b_2)
 
135
        message = self.status_string(wt2)
130
136
        self.assert_(message.startswith("pending merges:\n"))
131
137
        self.assert_("Empty commit 3" in message)
132
138
        self.assert_(message.endswith("...\n")) 
142
148
        wt.commit('testing')
143
149
        
144
150
        tof = StringIO()
145
 
        show_status(b, to_file=tof)
 
151
        show_tree_status(wt, to_file=tof)
146
152
        tof.seek(0)
147
153
        self.assertEquals(tof.readlines(),
148
154
                          ['unknown:\n',
152
158
                           ])
153
159
 
154
160
        tof = StringIO()
155
 
        show_status(b, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
 
161
        show_tree_status(wt, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
156
162
        tof.seek(0)
157
163
        self.assertEquals(tof.readlines(),
158
164
                          ['unknown:\n',
160
166
                           ])
161
167
        
162
168
        tof = StringIO()
163
 
        show_status(b, specific_files=['directory'], to_file=tof)
 
169
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
164
170
        tof.seek(0)
165
171
        self.assertEquals(tof.readlines(),
166
172
                          ['unknown:\n',
167
173
                           '  directory/hello.c\n'
168
174
                           ])
169
175
        tof = StringIO()
170
 
        show_status(b, specific_files=['dir2'], to_file=tof)
 
176
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
171
177
        tof.seek(0)
172
178
        self.assertEquals(tof.readlines(),
173
179
                          ['unknown:\n',
174
180
                           '  dir2\n'
175
181
                           ])
176
182
 
 
183
class CheckoutStatus(BranchStatus):
 
184
    def setUp(self):
 
185
        super(CheckoutStatus, self).setUp()
 
186
        mkdir('codir')
 
187
        chdir('codir')
 
188
        
 
189
    def make_branch_and_tree(self, relpath):
 
190
        source = self.make_branch(pathjoin('..', relpath))
 
191
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
 
192
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
193
        return checkout.create_workingtree()
 
194
 
177
195
 
178
196
class TestStatus(TestCaseWithTransport):
179
197