~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Aaron Bentley
  • Date: 2009-03-10 04:55:49 UTC
  • mto: This revision was merged to the branch mainline in revision 4112.
  • Revision ID: aaron@aaronbentley.com-20090310045549-j5jmgq190872oem7
Remove locking decorator

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
17
17
"""Tests of status command.
18
18
 
19
19
Most of these depend on the particular formatting used.
20
 
As such they really are blackbox tests even though some of the 
 
20
As such they really are blackbox tests even though some of the
21
21
tests are not using self.capture. If we add tests for the programmatic
22
22
interface later, they will be non blackbox tests.
23
23
"""
24
24
 
25
25
from cStringIO import StringIO
26
26
import codecs
27
 
from os import mkdir, chdir
 
27
from os import mkdir, chdir, rmdir, unlink
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
31
 
from bzrlib import bzrdir, errors
 
31
from bzrlib import (
 
32
    bzrdir,
 
33
    conflicts,
 
34
    errors,
 
35
    osutils,
 
36
    )
32
37
import bzrlib.branch
33
 
from bzrlib.builtins import merge
34
38
from bzrlib.osutils import pathjoin
35
39
from bzrlib.revisionspec import RevisionSpec
36
40
from bzrlib.status import show_tree_status
39
43
 
40
44
 
41
45
class BranchStatus(TestCaseWithTransport):
42
 
    
43
 
    def assertStatus(self, output_lines, working_tree,
44
 
        revision=None):
 
46
 
 
47
    def assertStatus(self, expected_lines, working_tree,
 
48
        revision=None, short=False, pending=True, verbose=False):
45
49
        """Run status in working_tree and look for output.
46
 
        
47
 
        :param output_lines: The lines to look for.
 
50
 
 
51
        :param expected_lines: The lines to look for.
48
52
        :param working_tree: The tree to run status in.
49
53
        """
50
 
        output_string = self.status_string(working_tree, revision)
51
 
        self.assertEqual(output_lines, output_string.splitlines(True))
52
 
    
53
 
    def status_string(self, wt, revision=None):
 
54
        output_string = self.status_string(working_tree, revision, short,
 
55
                pending, verbose)
 
56
        self.assertEqual(expected_lines, output_string.splitlines(True))
 
57
 
 
58
    def status_string(self, wt, revision=None, short=False, pending=True,
 
59
        verbose=False):
54
60
        # use a real file rather than StringIO because it doesn't handle
55
61
        # Unicode very well.
56
62
        tof = codecs.getwriter('utf-8')(TemporaryFile())
57
 
        show_tree_status(wt, to_file=tof, revision=revision)
 
63
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
 
64
                show_pending=pending, verbose=verbose)
58
65
        tof.seek(0)
59
66
        return tof.read().decode('utf-8')
60
67
 
75
82
                '  hello.c\n',
76
83
            ],
77
84
            wt)
 
85
        self.assertStatus([
 
86
                '?   bye.c\n',
 
87
                '?   hello.c\n',
 
88
            ],
 
89
            wt, short=True)
78
90
 
79
91
        # add a commit to allow showing pending merges.
80
92
        wt.commit('create a parent to allow testing merge output')
84
96
                'unknown:\n',
85
97
                '  bye.c\n',
86
98
                '  hello.c\n',
 
99
                'pending merge tips: (use -v to see all merge revisions)\n',
 
100
                '  (ghost) pending@pending-0-0\n',
 
101
            ],
 
102
            wt)
 
103
        self.assertStatus([
 
104
                'unknown:\n',
 
105
                '  bye.c\n',
 
106
                '  hello.c\n',
87
107
                'pending merges:\n',
88
 
                '  pending@pending-0-0\n',
89
 
            ],
90
 
            wt)
 
108
                '  (ghost) pending@pending-0-0\n',
 
109
            ],
 
110
            wt, verbose=True)
 
111
        self.assertStatus([
 
112
                '?   bye.c\n',
 
113
                '?   hello.c\n',
 
114
                'P   (ghost) pending@pending-0-0\n',
 
115
            ],
 
116
            wt, short=True)
 
117
        self.assertStatus([
 
118
                'unknown:\n',
 
119
                '  bye.c\n',
 
120
                '  hello.c\n',
 
121
            ],
 
122
            wt, pending=False)
 
123
        self.assertStatus([
 
124
                '?   bye.c\n',
 
125
                '?   hello.c\n',
 
126
            ],
 
127
            wt, short=True, pending=False)
91
128
 
92
129
    def test_branch_status_revisions(self):
93
130
        """Tests branch status with revisions"""
110
147
        self.build_tree(['more.c'])
111
148
        wt.add('more.c')
112
149
        wt.commit('Another test message')
113
 
        
 
150
 
114
151
        revs.append(RevisionSpec.from_string('1'))
115
152
        self.assertStatus([
116
153
                'added:\n',
130
167
        b_2 = b_2_dir.open_branch()
131
168
        wt2 = b_2_dir.open_workingtree()
132
169
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
133
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
134
 
        message = self.status_string(wt2)
135
 
        self.assert_(message.startswith("pending merges:\n"))
136
 
        self.assert_(message.endswith("Empty commit 2\n")) 
 
170
        wt2.merge_from_branch(wt.branch)
 
171
        message = self.status_string(wt2, verbose=True)
 
172
        self.assertStartsWith(message, "pending merges:\n")
 
173
        self.assertEndsWith(message, "Empty commit 2\n")
137
174
        wt2.commit("merged")
138
175
        # must be long to make sure we see elipsis at the end
139
 
        wt.commit("Empty commit 3 " + 
140
 
                   "blah blah blah blah " * 10)
141
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
142
 
        message = self.status_string(wt2)
143
 
        self.assert_(message.startswith("pending merges:\n"))
 
176
        wt.commit("Empty commit 3 " +
 
177
                   "blah blah blah blah " * 100)
 
178
        wt2.merge_from_branch(wt.branch)
 
179
        message = self.status_string(wt2, verbose=True)
 
180
        self.assertStartsWith(message, "pending merges:\n")
144
181
        self.assert_("Empty commit 3" in message)
145
 
        self.assert_(message.endswith("...\n")) 
146
 
 
147
 
    def test_branch_status_specific_files(self): 
 
182
        self.assertEndsWith(message, "...\n")
 
183
 
 
184
    def test_tree_status_ignores(self):
 
185
        """Tests branch status with ignores"""
 
186
        wt = self.make_branch_and_tree('.')
 
187
        self.run_bzr('ignore *~')
 
188
        wt.commit('commit .bzrignore')
 
189
        self.build_tree(['foo.c', 'foo.c~'])
 
190
        self.assertStatus([
 
191
                'unknown:\n',
 
192
                '  foo.c\n',
 
193
                ],
 
194
                wt)
 
195
        self.assertStatus([
 
196
                '?   foo.c\n',
 
197
                ],
 
198
                wt, short=True)
 
199
 
 
200
    def test_tree_status_specific_files(self):
148
201
        """Tests branch status with given specific files"""
149
202
        wt = self.make_branch_and_tree('.')
150
203
        b = wt.branch
153
206
        wt.add('directory')
154
207
        wt.add('test.c')
155
208
        wt.commit('testing')
156
 
        
 
209
 
 
210
        self.assertStatus([
 
211
                'unknown:\n',
 
212
                '  bye.c\n',
 
213
                '  dir2/\n',
 
214
                '  directory/hello.c\n'
 
215
                ],
 
216
                wt)
 
217
 
 
218
        self.assertStatus([
 
219
                '?   bye.c\n',
 
220
                '?   dir2/\n',
 
221
                '?   directory/hello.c\n'
 
222
                ],
 
223
                wt, short=True)
 
224
 
157
225
        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
226
        self.assertRaises(errors.PathsDoNotExist,
168
227
                          show_tree_status,
169
 
                          wt, specific_files=['bye.c','test.c','absent.c'], 
 
228
                          wt, specific_files=['bye.c','test.c','absent.c'],
170
229
                          to_file=tof)
171
 
        
 
230
 
172
231
        tof = StringIO()
173
232
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
174
233
        tof.seek(0)
177
236
                           '  directory/hello.c\n'
178
237
                           ])
179
238
        tof = StringIO()
 
239
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
 
240
                         short=True)
 
241
        tof.seek(0)
 
242
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
 
243
 
 
244
        tof = StringIO()
180
245
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
181
246
        tof.seek(0)
182
247
        self.assertEquals(tof.readlines(),
183
248
                          ['unknown:\n',
184
 
                           '  dir2\n'
 
249
                           '  dir2/\n'
185
250
                           ])
 
251
        tof = StringIO()
 
252
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
 
253
        tof.seek(0)
 
254
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
 
255
 
 
256
        tof = StringIO()
 
257
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
 
258
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
 
259
                         short=True, revision=revs)
 
260
        tof.seek(0)
 
261
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
 
262
 
 
263
    def test_specific_files_conflicts(self):
 
264
        tree = self.make_branch_and_tree('.')
 
265
        self.build_tree(['dir2/'])
 
266
        tree.add('dir2')
 
267
        tree.commit('added dir2')
 
268
        tree.set_conflicts(conflicts.ConflictList(
 
269
            [conflicts.ContentsConflict('foo')]))
 
270
        tof = StringIO()
 
271
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
272
        self.assertEqualDiff('', tof.getvalue())
 
273
        tree.set_conflicts(conflicts.ConflictList(
 
274
            [conflicts.ContentsConflict('dir2')]))
 
275
        tof = StringIO()
 
276
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
277
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
 
278
                             tof.getvalue())
 
279
 
 
280
        tree.set_conflicts(conflicts.ConflictList(
 
281
            [conflicts.ContentsConflict('dir2/file1')]))
 
282
        tof = StringIO()
 
283
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
284
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
 
285
                             tof.getvalue())
 
286
 
 
287
    def _prepare_nonexistent(self):
 
288
        wt = self.make_branch_and_tree('.')
 
289
        self.assertStatus([], wt)
 
290
        self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
 
291
        wt.add('FILE_A')
 
292
        wt.add('FILE_B')
 
293
        wt.add('FILE_C')
 
294
        wt.add('FILE_D')
 
295
        wt.add('FILE_E')
 
296
        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.')
 
299
        unlink('FILE_E')  # FILE_E will be versioned but missing
 
300
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
 
301
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
 
302
        open('UNVERSIONED_BUT_EXISTING', 'w')
 
303
        return wt
186
304
 
187
305
    def test_status_nonexistent_file(self):
188
306
        # files that don't exist in either the basis tree or working tree
189
307
        # should give an error
190
 
        wt = self.make_branch_and_tree('.')
191
 
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
192
 
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
 
308
        wt = self._prepare_nonexistent()
 
309
        self.assertStatus([
 
310
            'removed:\n',
 
311
            '  FILE_E\n',
 
312
            'added:\n',
 
313
            '  FILE_Q\n',
 
314
            'modified:\n',
 
315
            '  FILE_B\n',
 
316
            '  FILE_C\n',
 
317
            'unknown:\n',
 
318
            '  UNVERSIONED_BUT_EXISTING\n',
 
319
            ],
 
320
            wt)
 
321
        self.assertStatus([
 
322
            ' M  FILE_B\n',
 
323
            ' M  FILE_C\n',
 
324
            ' D  FILE_E\n',
 
325
            '+N  FILE_Q\n',
 
326
            '?   UNVERSIONED_BUT_EXISTING\n',
 
327
            ],
 
328
            wt, short=True)
 
329
 
 
330
        # Okay, everything's looking good with the existent files.
 
331
        # Let's see what happens when we throw in non-existent files.
 
332
 
 
333
        # bzr st [--short] NONEXISTENT '
 
334
        expected = [
 
335
          'nonexistent:\n',
 
336
          '  NONEXISTENT\n',
 
337
          ]
 
338
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
 
339
        self.assertEqual(expected, out.splitlines(True))
 
340
        self.assertContainsRe(err,
 
341
                              r'.*ERROR: Path\(s\) do not exist: '
 
342
                              'NONEXISTENT.*')
 
343
        expected = [
 
344
          'X:   NONEXISTENT\n',
 
345
          ]
 
346
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
 
347
        self.assertContainsRe(err,
 
348
                              r'.*ERROR: Path\(s\) do not exist: '
 
349
                              'NONEXISTENT.*')
 
350
 
 
351
    def test_status_nonexistent_file_with_others(self):
 
352
        # bzr st [--short] NONEXISTENT ...others..
 
353
        wt = self._prepare_nonexistent()
 
354
        expected = [
 
355
          'removed:\n',
 
356
          '  FILE_E\n',
 
357
          'modified:\n',
 
358
          '  FILE_B\n',
 
359
          '  FILE_C\n',
 
360
          'nonexistent:\n',
 
361
          '  NONEXISTENT\n',
 
362
          ]
 
363
        out, err = self.run_bzr('status NONEXISTENT '
 
364
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
 
365
                                retcode=3)
 
366
        self.assertEqual(expected, out.splitlines(True))
 
367
        self.assertContainsRe(err,
 
368
                              r'.*ERROR: Path\(s\) do not exist: '
 
369
                              'NONEXISTENT.*')
 
370
        expected = [
 
371
          ' D  FILE_E\n',
 
372
          ' M  FILE_C\n',
 
373
          ' M  FILE_B\n',
 
374
          'X   NONEXISTENT\n',
 
375
          ]
 
376
        out, err = self.run_bzr('status --short NONEXISTENT '
 
377
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
 
378
                                retcode=3)
 
379
        self.assertEqual(expected, out.splitlines(True))
 
380
        self.assertContainsRe(err,
 
381
                              r'.*ERROR: Path\(s\) do not exist: '
 
382
                              'NONEXISTENT.*')
 
383
 
 
384
    def test_status_multiple_nonexistent_files(self):
 
385
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
 
386
        wt = self._prepare_nonexistent()
 
387
        expected = [
 
388
          'removed:\n',
 
389
          '  FILE_E\n',
 
390
          'modified:\n',
 
391
          '  FILE_B\n',
 
392
          '  FILE_C\n',
 
393
          'nonexistent:\n',
 
394
          '  ANOTHER_NONEXISTENT\n',
 
395
          '  NONEXISTENT\n',
 
396
          ]
 
397
        out, err = self.run_bzr('status NONEXISTENT '
 
398
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
 
399
                                'FILE_C FILE_D FILE_E', retcode=3)
 
400
        self.assertEqual(expected, out.splitlines(True))
 
401
        self.assertContainsRe(err,
 
402
                              r'.*ERROR: Path\(s\) do not exist: '
 
403
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
 
404
        expected = [
 
405
          ' D  FILE_E\n',
 
406
          ' M  FILE_C\n',
 
407
          ' M  FILE_B\n',
 
408
          'X   ANOTHER_NONEXISTENT\n',
 
409
          'X   NONEXISTENT\n',
 
410
          ]
 
411
        out, err = self.run_bzr('status --short NONEXISTENT '
 
412
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
 
413
                                'FILE_C FILE_D FILE_E', retcode=3)
 
414
        self.assertEqual(expected, out.splitlines(True))
 
415
        self.assertContainsRe(err,
 
416
                              r'.*ERROR: Path\(s\) do not exist: '
 
417
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
 
418
 
 
419
    def test_status_nonexistent_file_with_unversioned(self):
 
420
        # bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
 
421
        wt = self._prepare_nonexistent()
 
422
        expected = [
 
423
          'removed:\n',
 
424
          '  FILE_E\n',
 
425
          'added:\n',
 
426
          '  FILE_Q\n',
 
427
          'modified:\n',
 
428
          '  FILE_B\n',
 
429
          '  FILE_C\n',
 
430
          'unknown:\n',
 
431
          '  UNVERSIONED_BUT_EXISTING\n',
 
432
          'nonexistent:\n',
 
433
          '  NONEXISTENT\n',
 
434
          ]
 
435
        out, err = self.run_bzr('status NONEXISTENT '
 
436
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
 
437
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
 
438
        self.assertEqual(expected, out.splitlines(True))
 
439
        self.assertContainsRe(err,
 
440
                              r'.*ERROR: Path\(s\) do not exist: '
 
441
                              'NONEXISTENT.*')
 
442
        expected = [
 
443
          '+N  FILE_Q\n',
 
444
          '?   UNVERSIONED_BUT_EXISTING\n',
 
445
          ' D  FILE_E\n',
 
446
          ' M  FILE_C\n',
 
447
          ' M  FILE_B\n',
 
448
          'X   NONEXISTENT\n',
 
449
          ]
 
450
        out, err = self.run_bzr('status --short NONEXISTENT '
 
451
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
 
452
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
 
453
        self.assertEqual(expected, out.splitlines(True))
 
454
        self.assertContainsRe(err,
 
455
                              r'.*ERROR: Path\(s\) do not exist: '
 
456
                              'NONEXISTENT.*')
 
457
 
 
458
    def test_status_out_of_date(self):
 
459
        """Simulate status of out-of-date tree after remote push"""
 
460
        tree = self.make_branch_and_tree('.')
 
461
        self.build_tree_contents([('a', 'foo\n')])
 
462
        tree.lock_write()
 
463
        try:
 
464
            tree.add(['a'])
 
465
            tree.commit('add test file')
 
466
            # simulate what happens after a remote push
 
467
            tree.set_last_revision("0")
 
468
        finally:
 
469
            # before run another commands we should unlock tree
 
470
            tree.unlock()
 
471
        out, err = self.run_bzr('status')
 
472
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
473
                         err)
 
474
 
 
475
    def test_status_write_lock(self):
 
476
        """Test that status works without fetching history and
 
477
        having a write lock.
 
478
 
 
479
        See https://bugs.launchpad.net/bzr/+bug/149270
 
480
        """
 
481
        mkdir('branch1')
 
482
        wt = self.make_branch_and_tree('branch1')
 
483
        b = wt.branch
 
484
        wt.commit('Empty commit 1')
 
485
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
 
486
        wt2.commit('Empty commit 2')
 
487
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
 
488
        self.assertEqual('', out)
193
489
 
194
490
 
195
491
class CheckoutStatus(BranchStatus):
198
494
        super(CheckoutStatus, self).setUp()
199
495
        mkdir('codir')
200
496
        chdir('codir')
201
 
        
 
497
 
202
498
    def make_branch_and_tree(self, relpath):
203
499
        source = self.make_branch(pathjoin('..', relpath))
204
500
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
208
504
 
209
505
class TestStatus(TestCaseWithTransport):
210
506
 
211
 
    def test_status(self):
212
 
        self.run_bzr("init")
213
 
        self.build_tree(['hello.txt'])
214
 
        result = self.run_bzr("status")[0]
215
 
        self.assert_("unknown:\n  hello.txt\n" in result, result)
216
 
        self.run_bzr("add", "hello.txt")
217
 
        result = self.run_bzr("status")[0]
218
 
        self.assert_("added:\n  hello.txt\n" in result, result)
219
 
        self.run_bzr("commit", "-m", "added")
220
 
        result = self.run_bzr("status", "-r", "0..1")[0]
221
 
        self.assert_("added:\n  hello.txt\n" in result, result)
222
 
        self.build_tree(['world.txt'])
223
 
        result = self.run_bzr("status", "-r", "0")[0]
224
 
        self.assert_("added:\n  hello.txt\n" \
225
 
                     "unknown:\n  world.txt\n" in result, result)
226
 
 
227
 
        result2 = self.run_bzr("status", "-r", "0..")[0]
228
 
        self.assertEquals(result2, result)
 
507
    def test_status_plain(self):
 
508
        tree = self.make_branch_and_tree('.')
 
509
 
 
510
        self.build_tree(['hello.txt'])
 
511
        result = self.run_bzr("status")[0]
 
512
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
 
513
 
 
514
        tree.add("hello.txt")
 
515
        result = self.run_bzr("status")[0]
 
516
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
517
 
 
518
        tree.commit(message="added")
 
519
        result = self.run_bzr("status -r 0..1")[0]
 
520
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
521
 
 
522
        result = self.run_bzr("status -c 1")[0]
 
523
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
524
 
 
525
        self.build_tree(['world.txt'])
 
526
        result = self.run_bzr("status -r 0")[0]
 
527
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
 
528
                                      "unknown:\n  world.txt\n")
 
529
        result2 = self.run_bzr("status -r 0..")[0]
 
530
        self.assertEquals(result2, result)
 
531
 
 
532
    def test_status_short(self):
 
533
        tree = self.make_branch_and_tree('.')
 
534
 
 
535
        self.build_tree(['hello.txt'])
 
536
        result = self.run_bzr("status --short")[0]
 
537
        self.assertContainsRe(result, "[?]   hello.txt\n")
 
538
 
 
539
        tree.add("hello.txt")
 
540
        result = self.run_bzr("status --short")[0]
 
541
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
542
 
 
543
        tree.commit(message="added")
 
544
        result = self.run_bzr("status --short -r 0..1")[0]
 
545
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
546
 
 
547
        self.build_tree(['world.txt'])
 
548
        result = self.run_bzr("status --short -r 0")[0]
 
549
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
 
550
                                      "[?]   world.txt\n")
 
551
        result2 = self.run_bzr("status --short -r 0..")[0]
 
552
        self.assertEquals(result2, result)
 
553
 
 
554
    def test_status_versioned(self):
 
555
        tree = self.make_branch_and_tree('.')
 
556
 
 
557
        self.build_tree(['hello.txt'])
 
558
        result = self.run_bzr("status --versioned")[0]
 
559
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
 
560
 
 
561
        tree.add("hello.txt")
 
562
        result = self.run_bzr("status --versioned")[0]
 
563
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
564
 
 
565
        tree.commit("added")
 
566
        result = self.run_bzr("status --versioned -r 0..1")[0]
 
567
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
568
 
 
569
        self.build_tree(['world.txt'])
 
570
        result = self.run_bzr("status --versioned -r 0")[0]
 
571
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
572
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
 
573
        result2 = self.run_bzr("status --versioned -r 0..")[0]
 
574
        self.assertEquals(result2, result)
 
575
 
 
576
    def test_status_SV(self):
 
577
        tree = self.make_branch_and_tree('.')
 
578
 
 
579
        self.build_tree(['hello.txt'])
 
580
        result = self.run_bzr("status -SV")[0]
 
581
        self.assertNotContainsRe(result, "hello.txt")
 
582
 
 
583
        tree.add("hello.txt")
 
584
        result = self.run_bzr("status -SV")[0]
 
585
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
586
 
 
587
        tree.commit(message="added")
 
588
        result = self.run_bzr("status -SV -r 0..1")[0]
 
589
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
590
 
 
591
        self.build_tree(['world.txt'])
 
592
        result = self.run_bzr("status -SV -r 0")[0]
 
593
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
594
 
 
595
        result2 = self.run_bzr("status -SV -r 0..")[0]
 
596
        self.assertEquals(result2, result)
 
597
 
 
598
    def assertStatusContains(self, pattern):
 
599
        """Run status, and assert it contains the given pattern"""
 
600
        result = self.run_bzr("status --short")[0]
 
601
        self.assertContainsRe(result, pattern)
 
602
 
 
603
    def test_kind_change_short(self):
 
604
        tree = self.make_branch_and_tree('.')
 
605
        self.build_tree(['file'])
 
606
        tree.add('file')
 
607
        tree.commit('added file')
 
608
        unlink('file')
 
609
        self.build_tree(['file/'])
 
610
        self.assertStatusContains('K  file => file/')
 
611
        tree.rename_one('file', 'directory')
 
612
        self.assertStatusContains('RK  file => directory/')
 
613
        rmdir('directory')
 
614
        self.assertStatusContains('RD  file => directory')
 
615
 
 
616
    def test_status_illegal_revision_specifiers(self):
 
617
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
 
618
        self.assertContainsRe(err, 'one or two revision specifiers')
 
619
 
 
620
    def test_status_no_pending(self):
 
621
        a_tree = self.make_branch_and_tree('a')
 
622
        self.build_tree(['a/a'])
 
623
        a_tree.add('a')
 
624
        a_tree.commit('a')
 
625
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
626
        self.build_tree(['b/b'])
 
627
        b_tree.add('b')
 
628
        b_tree.commit('b')
 
629
 
 
630
        self.run_bzr('merge ../b', working_dir='a')
 
631
        out, err = self.run_bzr('status --no-pending', working_dir='a')
 
632
        self.assertEquals(out, "added:\n  b\n")
 
633
 
 
634
    def test_pending_specific_files(self):
 
635
        """With a specific file list, pending merges are not shown."""
 
636
        tree = self.make_branch_and_tree('tree')
 
637
        self.build_tree_contents([('tree/a', 'content of a\n')])
 
638
        tree.add('a')
 
639
        r1_id = tree.commit('one')
 
640
        alt = tree.bzrdir.sprout('alt').open_workingtree()
 
641
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
 
642
        alt_id = alt.commit('alt')
 
643
        tree.merge_from_branch(alt.branch)
 
644
        output = self.make_utf8_encoded_stringio()
 
645
        show_tree_status(tree, to_file=output)
 
646
        self.assertContainsRe(output.getvalue(), 'pending merge')
 
647
        out, err = self.run_bzr('status tree/a')
 
648
        self.assertNotContainsRe(out, 'pending merge')
229
649
 
230
650
 
231
651
class TestStatusEncodings(TestCaseWithTransport):
232
 
    
 
652
 
233
653
    def setUp(self):
234
654
        TestCaseWithTransport.setUp(self)
235
 
        self.user_encoding = bzrlib.user_encoding
 
655
        self.user_encoding = osutils._cached_user_encoding
236
656
        self.stdout = sys.stdout
237
657
 
238
658
    def tearDown(self):
254
674
 
255
675
    def test_stdout_ascii(self):
256
676
        sys.stdout = StringIO()
257
 
        bzrlib.user_encoding = 'ascii'
 
677
        osutils._cached_user_encoding = 'ascii'
258
678
        working_tree = self.make_uncommitted_tree()
259
679
        stdout, stderr = self.run_bzr("status")
260
680
 
265
685
 
266
686
    def test_stdout_latin1(self):
267
687
        sys.stdout = StringIO()
268
 
        bzrlib.user_encoding = 'latin-1'
 
688
        osutils._cached_user_encoding = 'latin-1'
269
689
        working_tree = self.make_uncommitted_tree()
270
690
        stdout, stderr = self.run_bzr('status')
271
691