~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

[merge] bzr.dev 2255, resolve conflicts, update copyrights

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
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
41
41
class BranchStatus(TestCaseWithTransport):
42
42
    
43
43
    def assertStatus(self, output_lines, working_tree,
44
 
        revision=None):
 
44
        revision=None, short=False):
45
45
        """Run status in working_tree and look for output.
46
46
        
47
47
        :param output_lines: The lines to look for.
48
48
        :param working_tree: The tree to run status in.
49
49
        """
50
 
        output_string = self.status_string(working_tree, revision)
 
50
        output_string = self.status_string(working_tree, revision, short)
51
51
        self.assertEqual(output_lines, output_string.splitlines(True))
52
52
    
53
 
    def status_string(self, wt, revision=None):
 
53
    def status_string(self, wt, revision=None, short=False):
54
54
        # use a real file rather than StringIO because it doesn't handle
55
55
        # Unicode very well.
56
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
57
 
        show_tree_status(wt, to_file=tof, revision=revision)
 
57
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
58
58
        tof.seek(0)
59
59
        return tof.read().decode('utf-8')
60
60
 
75
75
                '  hello.c\n',
76
76
            ],
77
77
            wt)
 
78
        self.assertStatus([
 
79
                '?  bye.c\n',
 
80
                '?  hello.c\n',
 
81
            ],
 
82
            wt, short=True)
78
83
 
79
84
        # add a commit to allow showing pending merges.
80
85
        wt.commit('create a parent to allow testing merge output')
88
93
                '  pending@pending-0-0\n',
89
94
            ],
90
95
            wt)
 
96
        self.assertStatus([
 
97
                '?  bye.c\n',
 
98
                '?  hello.c\n',
 
99
                'P  pending@pending-0-0\n',
 
100
            ],
 
101
            wt, short=True)
91
102
 
92
103
    def test_branch_status_revisions(self):
93
104
        """Tests branch status with revisions"""
154
165
        wt.add('test.c')
155
166
        wt.commit('testing')
156
167
        
 
168
        self.assertStatus([
 
169
                'unknown:\n',
 
170
                '  bye.c\n',
 
171
                '  dir2\n',
 
172
                '  directory/hello.c\n'
 
173
                ],
 
174
                wt)
 
175
 
 
176
        self.assertStatus([
 
177
                '?  bye.c\n',
 
178
                '?  dir2\n',
 
179
                '?  directory/hello.c\n'
 
180
                ],
 
181
                wt, short=True)
 
182
 
157
183
        tof = StringIO()
158
 
        show_tree_status(wt, to_file=tof)
159
 
        tof.seek(0)
160
 
        self.assertEquals(tof.readlines(),
161
 
                          ['unknown:\n',
162
 
                           '  bye.c\n',
163
 
                           '  dir2\n',
164
 
                           '  directory/hello.c\n'
165
 
                           ])
166
 
 
167
184
        self.assertRaises(errors.PathsDoNotExist,
168
185
                          show_tree_status,
169
186
                          wt, specific_files=['bye.c','test.c','absent.c'], 
177
194
                           '  directory/hello.c\n'
178
195
                           ])
179
196
        tof = StringIO()
 
197
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
 
198
                         short=True)
 
199
        tof.seek(0)
 
200
        self.assertEquals(tof.readlines(), ['?  directory/hello.c\n'])
 
201
 
 
202
        tof = StringIO()
180
203
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
181
204
        tof.seek(0)
182
205
        self.assertEquals(tof.readlines(),
183
206
                          ['unknown:\n',
184
207
                           '  dir2\n'
185
208
                           ])
 
209
        tof = StringIO()
 
210
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
 
211
        tof.seek(0)
 
212
        self.assertEquals(tof.readlines(), ['?  dir2\n'])
186
213
 
187
214
    def test_status_nonexistent_file(self):
188
215
        # files that don't exist in either the basis tree or working tree
191
218
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
192
219
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
193
220
 
 
221
    def test_status_out_of_date(self):
 
222
        """Simulate status of out-of-date tree after remote push"""
 
223
        tree = self.make_branch_and_tree('.')
 
224
        self.build_tree_contents([('a', 'foo\n')])
 
225
        tree.lock_write()
 
226
        try:
 
227
            tree.add(['a'])
 
228
            tree.commit('add test file')
 
229
            # simulate what happens after a remote push
 
230
            tree.set_last_revision("0")
 
231
            out, err = self.run_bzr('status')
 
232
            self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
233
                             err)
 
234
        finally:
 
235
            tree.unlock()
 
236
 
194
237
 
195
238
class CheckoutStatus(BranchStatus):
196
239
 
210
253
 
211
254
    def test_status(self):
212
255
        self.run_bzr("init")
 
256
 
213
257
        self.build_tree(['hello.txt'])
214
258
        result = self.run_bzr("status")[0]
215
259
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
260
        result = self.run_bzr("status","--short")[0]
 
261
        self.assert_("?  hello.txt\n" in result, result)
 
262
 
216
263
        self.run_bzr("add", "hello.txt")
217
264
        result = self.run_bzr("status")[0]
218
265
        self.assert_("added:\n  hello.txt\n" in result, result)
 
266
        result = self.run_bzr("status","--short")[0]
 
267
        self.assert_("A  hello.txt\n" in result, result)
 
268
 
219
269
        self.run_bzr("commit", "-m", "added")
220
270
        result = self.run_bzr("status", "-r", "0..1")[0]
221
271
        self.assert_("added:\n  hello.txt\n" in result, result)
 
272
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
 
273
        self.assert_("A  hello.txt\n" in result, result)
 
274
 
222
275
        self.build_tree(['world.txt'])
223
276
        result = self.run_bzr("status", "-r", "0")[0]
224
277
        self.assert_("added:\n  hello.txt\n" \
225
278
                     "unknown:\n  world.txt\n" in result, result)
226
 
 
227
279
        result2 = self.run_bzr("status", "-r", "0..")[0]
228
280
        self.assertEquals(result2, result)
 
281
        result = self.run_bzr("status", "--short", "-r", "0")[0]
 
282
        self.assert_("A  hello.txt\n" \
 
283
                     "?  world.txt\n" in result, result)
 
284
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
285
        self.assertEquals(result2, result)
229
286
 
230
287
 
231
288
class TestStatusEncodings(TestCaseWithTransport):