~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
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
"""
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
31
 
from bzrlib import (
32
 
    bzrdir,
33
 
    conflicts,
34
 
    errors,
35
 
    osutils,
36
 
    status,
37
 
    )
 
31
from bzrlib import bzrdir, errors
38
32
import bzrlib.branch
 
33
from bzrlib.builtins import merge
39
34
from bzrlib.osutils import pathjoin
40
35
from bzrlib.revisionspec import RevisionSpec
41
36
from bzrlib.status import show_tree_status
44
39
 
45
40
 
46
41
class BranchStatus(TestCaseWithTransport):
47
 
 
 
42
    
48
43
    def assertStatus(self, expected_lines, working_tree,
49
 
        revision=None, short=False, pending=True, verbose=False):
 
44
        revision=None, short=False):
50
45
        """Run status in working_tree and look for output.
51
 
 
 
46
        
52
47
        :param expected_lines: The lines to look for.
53
48
        :param working_tree: The tree to run status in.
54
49
        """
55
 
        output_string = self.status_string(working_tree, revision, short,
56
 
                pending, verbose)
 
50
        output_string = self.status_string(working_tree, revision, short)
57
51
        self.assertEqual(expected_lines, output_string.splitlines(True))
58
 
 
59
 
    def status_string(self, wt, revision=None, short=False, pending=True,
60
 
        verbose=False):
 
52
    
 
53
    def status_string(self, wt, revision=None, short=False):
61
54
        # use a real file rather than StringIO because it doesn't handle
62
55
        # Unicode very well.
63
56
        tof = codecs.getwriter('utf-8')(TemporaryFile())
64
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
65
 
                show_pending=pending, verbose=verbose)
 
57
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
66
58
        tof.seek(0)
67
59
        return tof.read().decode('utf-8')
68
60
 
97
89
                'unknown:\n',
98
90
                '  bye.c\n',
99
91
                '  hello.c\n',
100
 
                'pending merge tips: (use -v to see all merge revisions)\n',
101
 
                '  (ghost) pending@pending-0-0\n',
102
 
            ],
103
 
            wt)
104
 
        self.assertStatus([
105
 
                'unknown:\n',
106
 
                '  bye.c\n',
107
 
                '  hello.c\n',
108
92
                'pending merges:\n',
109
 
                '  (ghost) pending@pending-0-0\n',
 
93
                '  pending@pending-0-0\n',
110
94
            ],
111
 
            wt, verbose=True)
 
95
            wt)
112
96
        self.assertStatus([
113
97
                '?   bye.c\n',
114
98
                '?   hello.c\n',
115
 
                'P   (ghost) pending@pending-0-0\n',
 
99
                'P   pending@pending-0-0\n',
116
100
            ],
117
101
            wt, short=True)
118
 
        self.assertStatus([
119
 
                'unknown:\n',
120
 
                '  bye.c\n',
121
 
                '  hello.c\n',
122
 
            ],
123
 
            wt, pending=False)
124
 
        self.assertStatus([
125
 
                '?   bye.c\n',
126
 
                '?   hello.c\n',
127
 
            ],
128
 
            wt, short=True, pending=False)
129
102
 
130
103
    def test_branch_status_revisions(self):
131
104
        """Tests branch status with revisions"""
148
121
        self.build_tree(['more.c'])
149
122
        wt.add('more.c')
150
123
        wt.commit('Another test message')
151
 
 
 
124
        
152
125
        revs.append(RevisionSpec.from_string('1'))
153
126
        self.assertStatus([
154
127
                'added:\n',
168
141
        b_2 = b_2_dir.open_branch()
169
142
        wt2 = b_2_dir.open_workingtree()
170
143
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
171
 
        wt2.merge_from_branch(wt.branch)
172
 
        message = self.status_string(wt2, verbose=True)
 
144
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
145
        message = self.status_string(wt2)
173
146
        self.assertStartsWith(message, "pending merges:\n")
174
147
        self.assertEndsWith(message, "Empty commit 2\n")
175
148
        wt2.commit("merged")
176
149
        # must be long to make sure we see elipsis at the end
177
150
        wt.commit("Empty commit 3 " +
178
151
                   "blah blah blah blah " * 100)
179
 
        wt2.merge_from_branch(wt.branch)
180
 
        message = self.status_string(wt2, verbose=True)
 
152
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
153
        message = self.status_string(wt2)
181
154
        self.assertStartsWith(message, "pending merges:\n")
182
155
        self.assert_("Empty commit 3" in message)
183
156
        self.assertEndsWith(message, "...\n")
185
158
    def test_tree_status_ignores(self):
186
159
        """Tests branch status with ignores"""
187
160
        wt = self.make_branch_and_tree('.')
188
 
        self.run_bzr('ignore *~')
 
161
        self.run_bzr('ignore', '*~')
189
162
        wt.commit('commit .bzrignore')
190
163
        self.build_tree(['foo.c', 'foo.c~'])
191
164
        self.assertStatus([
207
180
        wt.add('directory')
208
181
        wt.add('test.c')
209
182
        wt.commit('testing')
210
 
 
 
183
        
211
184
        self.assertStatus([
212
185
                'unknown:\n',
213
186
                '  bye.c\n',
226
199
        tof = StringIO()
227
200
        self.assertRaises(errors.PathsDoNotExist,
228
201
                          show_tree_status,
229
 
                          wt, specific_files=['bye.c','test.c','absent.c'],
 
202
                          wt, specific_files=['bye.c','test.c','absent.c'], 
230
203
                          to_file=tof)
231
 
 
 
204
        
232
205
        tof = StringIO()
233
206
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
234
207
        tof.seek(0)
254
227
        tof.seek(0)
255
228
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
256
229
 
257
 
        tof = StringIO()
258
 
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
259
 
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
260
 
                         short=True, revision=revs)
261
 
        tof.seek(0)
262
 
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
263
 
 
264
 
    def test_specific_files_conflicts(self):
265
 
        tree = self.make_branch_and_tree('.')
266
 
        self.build_tree(['dir2/'])
267
 
        tree.add('dir2')
268
 
        tree.commit('added dir2')
269
 
        tree.set_conflicts(conflicts.ConflictList(
270
 
            [conflicts.ContentsConflict('foo')]))
271
 
        tof = StringIO()
272
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
273
 
        self.assertEqualDiff('', tof.getvalue())
274
 
        tree.set_conflicts(conflicts.ConflictList(
275
 
            [conflicts.ContentsConflict('dir2')]))
276
 
        tof = StringIO()
277
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
278
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
279
 
                             tof.getvalue())
280
 
 
281
 
        tree.set_conflicts(conflicts.ConflictList(
282
 
            [conflicts.ContentsConflict('dir2/file1')]))
283
 
        tof = StringIO()
284
 
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
285
 
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
286
 
                             tof.getvalue())
287
 
 
288
 
    def _prepare_nonexistent(self):
289
 
        wt = self.make_branch_and_tree('.')
290
 
        self.assertStatus([], wt)
291
 
        self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
292
 
        wt.add('FILE_A')
293
 
        wt.add('FILE_B')
294
 
        wt.add('FILE_C')
295
 
        wt.add('FILE_D')
296
 
        wt.add('FILE_E')
297
 
        wt.commit('Create five empty files.')
298
 
        open('FILE_B', 'w').write('Modification to file FILE_B.')
299
 
        open('FILE_C', 'w').write('Modification to file FILE_C.')
300
 
        unlink('FILE_E')  # FILE_E will be versioned but missing
301
 
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
302
 
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
303
 
        open('UNVERSIONED_BUT_EXISTING', 'w')
304
 
        return wt
305
 
 
306
230
    def test_status_nonexistent_file(self):
307
231
        # files that don't exist in either the basis tree or working tree
308
232
        # should give an error
309
 
        wt = self._prepare_nonexistent()
310
 
        self.assertStatus([
311
 
            'removed:\n',
312
 
            '  FILE_E\n',
313
 
            'added:\n',
314
 
            '  FILE_Q\n',
315
 
            'modified:\n',
316
 
            '  FILE_B\n',
317
 
            '  FILE_C\n',
318
 
            'unknown:\n',
319
 
            '  UNVERSIONED_BUT_EXISTING\n',
320
 
            ],
321
 
            wt)
322
 
        self.assertStatus([
323
 
            ' M  FILE_B\n',
324
 
            ' M  FILE_C\n',
325
 
            ' D  FILE_E\n',
326
 
            '+N  FILE_Q\n',
327
 
            '?   UNVERSIONED_BUT_EXISTING\n',
328
 
            ],
329
 
            wt, short=True)
330
 
 
331
 
        # Okay, everything's looking good with the existent files.
332
 
        # Let's see what happens when we throw in non-existent files.
333
 
 
334
 
        # bzr st [--short] NONEXISTENT '
335
 
        expected = [
336
 
          'nonexistent:\n',
337
 
          '  NONEXISTENT\n',
338
 
          ]
339
 
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
340
 
        self.assertEqual(expected, out.splitlines(True))
341
 
        self.assertContainsRe(err,
342
 
                              r'.*ERROR: Path\(s\) do not exist: '
343
 
                              'NONEXISTENT.*')
344
 
        expected = [
345
 
          'X:   NONEXISTENT\n',
346
 
          ]
347
 
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
348
 
        self.assertContainsRe(err,
349
 
                              r'.*ERROR: Path\(s\) do not exist: '
350
 
                              'NONEXISTENT.*')
351
 
 
352
 
    def test_status_nonexistent_file_with_others(self):
353
 
        # bzr st [--short] NONEXISTENT ...others..
354
 
        wt = self._prepare_nonexistent()
355
 
        expected = [
356
 
          'removed:\n',
357
 
          '  FILE_E\n',
358
 
          'modified:\n',
359
 
          '  FILE_B\n',
360
 
          '  FILE_C\n',
361
 
          'nonexistent:\n',
362
 
          '  NONEXISTENT\n',
363
 
          ]
364
 
        out, err = self.run_bzr('status NONEXISTENT '
365
 
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
366
 
                                retcode=3)
367
 
        self.assertEqual(expected, out.splitlines(True))
368
 
        self.assertContainsRe(err,
369
 
                              r'.*ERROR: Path\(s\) do not exist: '
370
 
                              'NONEXISTENT.*')
371
 
        expected = [
372
 
          ' D  FILE_E\n',
373
 
          ' M  FILE_C\n',
374
 
          ' M  FILE_B\n',
375
 
          'X   NONEXISTENT\n',
376
 
          ]
377
 
        out, err = self.run_bzr('status --short NONEXISTENT '
378
 
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
379
 
                                retcode=3)
380
 
        self.assertEqual(expected, out.splitlines(True))
381
 
        self.assertContainsRe(err,
382
 
                              r'.*ERROR: Path\(s\) do not exist: '
383
 
                              'NONEXISTENT.*')
384
 
 
385
 
    def test_status_multiple_nonexistent_files(self):
386
 
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
387
 
        wt = self._prepare_nonexistent()
388
 
        expected = [
389
 
          'removed:\n',
390
 
          '  FILE_E\n',
391
 
          'modified:\n',
392
 
          '  FILE_B\n',
393
 
          '  FILE_C\n',
394
 
          'nonexistent:\n',
395
 
          '  ANOTHER_NONEXISTENT\n',
396
 
          '  NONEXISTENT\n',
397
 
          ]
398
 
        out, err = self.run_bzr('status NONEXISTENT '
399
 
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
400
 
                                'FILE_C FILE_D FILE_E', retcode=3)
401
 
        self.assertEqual(expected, out.splitlines(True))
402
 
        self.assertContainsRe(err,
403
 
                              r'.*ERROR: Path\(s\) do not exist: '
404
 
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
405
 
        expected = [
406
 
          ' D  FILE_E\n',
407
 
          ' M  FILE_C\n',
408
 
          ' M  FILE_B\n',
409
 
          'X   ANOTHER_NONEXISTENT\n',
410
 
          'X   NONEXISTENT\n',
411
 
          ]
412
 
        out, err = self.run_bzr('status --short NONEXISTENT '
413
 
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
414
 
                                'FILE_C FILE_D FILE_E', retcode=3)
415
 
        self.assertEqual(expected, out.splitlines(True))
416
 
        self.assertContainsRe(err,
417
 
                              r'.*ERROR: Path\(s\) do not exist: '
418
 
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
419
 
 
420
 
    def test_status_nonexistent_file_with_unversioned(self):
421
 
        # bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
422
 
        wt = self._prepare_nonexistent()
423
 
        expected = [
424
 
          'removed:\n',
425
 
          '  FILE_E\n',
426
 
          'added:\n',
427
 
          '  FILE_Q\n',
428
 
          'modified:\n',
429
 
          '  FILE_B\n',
430
 
          '  FILE_C\n',
431
 
          'unknown:\n',
432
 
          '  UNVERSIONED_BUT_EXISTING\n',
433
 
          'nonexistent:\n',
434
 
          '  NONEXISTENT\n',
435
 
          ]
436
 
        out, err = self.run_bzr('status NONEXISTENT '
437
 
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
438
 
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
439
 
        self.assertEqual(expected, out.splitlines(True))
440
 
        self.assertContainsRe(err,
441
 
                              r'.*ERROR: Path\(s\) do not exist: '
442
 
                              'NONEXISTENT.*')
443
 
        expected = [
444
 
          '+N  FILE_Q\n',
445
 
          '?   UNVERSIONED_BUT_EXISTING\n',
446
 
          ' D  FILE_E\n',
447
 
          ' M  FILE_C\n',
448
 
          ' M  FILE_B\n',
449
 
          'X   NONEXISTENT\n',
450
 
          ]
451
 
        out, err = self.run_bzr('status --short NONEXISTENT '
452
 
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
453
 
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
454
 
        self.assertEqual(expected, out.splitlines(True))
455
 
        self.assertContainsRe(err,
456
 
                              r'.*ERROR: Path\(s\) do not exist: '
457
 
                              'NONEXISTENT.*')
 
233
        wt = self.make_branch_and_tree('.')
 
234
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
 
235
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
458
236
 
459
237
    def test_status_out_of_date(self):
460
238
        """Simulate status of out-of-date tree after remote push"""
473
251
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
474
252
                         err)
475
253
 
476
 
    def test_status_on_ignored(self):
477
 
        """Tests branch status on an unversioned file which is considered ignored.
478
 
 
479
 
        See https://bugs.launchpad.net/bzr/+bug/40103
480
 
        """
481
 
        tree = self.make_branch_and_tree('.')
482
 
 
483
 
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
484
 
        result = self.run_bzr('status')[0]
485
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
486
 
        short_result = self.run_bzr('status --short')[0]
487
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
488
 
 
489
 
        result = self.run_bzr('status test1.c')[0]
490
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
491
 
        short_result = self.run_bzr('status --short test1.c')[0]
492
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
493
 
 
494
 
        result = self.run_bzr('status test1.c~')[0]
495
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
496
 
        short_result = self.run_bzr('status --short test1.c~')[0]
497
 
        self.assertContainsRe(short_result, "I   test1.c~\n")
498
 
 
499
 
        result = self.run_bzr('status test1.c~ test2.c~')[0]
500
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
501
 
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
502
 
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
503
 
 
504
 
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
505
 
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
506
 
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
507
 
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
508
 
 
509
 
    def test_status_write_lock(self):
510
 
        """Test that status works without fetching history and
511
 
        having a write lock.
512
 
 
513
 
        See https://bugs.launchpad.net/bzr/+bug/149270
514
 
        """
515
 
        mkdir('branch1')
516
 
        wt = self.make_branch_and_tree('branch1')
517
 
        b = wt.branch
518
 
        wt.commit('Empty commit 1')
519
 
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
520
 
        wt2.commit('Empty commit 2')
521
 
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
522
 
        self.assertEqual('', out)
523
 
 
524
 
    def test_status_with_shelves(self):
525
 
        """Ensure that _show_shelve_summary handler works.
526
 
        """
527
 
        wt = self.make_branch_and_tree('.')
528
 
        self.build_tree(['hello.c'])
529
 
        wt.add('hello.c')
530
 
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
531
 
        self.build_tree(['bye.c'])
532
 
        wt.add('bye.c')
533
 
        # As TestCase.setUp clears all hooks, we install this default
534
 
        # post_status hook handler for the test.
535
 
        status.hooks.install_named_hook('post_status',
536
 
            status._show_shelve_summary,
537
 
            'bzr status')
538
 
        self.assertStatus([
539
 
                'added:\n',
540
 
                '  bye.c\n',
541
 
                '1 shelves exist. See "bzr shelve --list" for details.\n',
542
 
            ],
543
 
            wt)
544
 
 
545
254
 
546
255
class CheckoutStatus(BranchStatus):
547
256
 
549
258
        super(CheckoutStatus, self).setUp()
550
259
        mkdir('codir')
551
260
        chdir('codir')
552
 
 
 
261
        
553
262
    def make_branch_and_tree(self, relpath):
554
263
        source = self.make_branch(pathjoin('..', relpath))
555
264
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
556
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
557
 
            target_branch=source)
 
265
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
558
266
        return checkout.create_workingtree()
559
267
 
560
268
 
561
269
class TestStatus(TestCaseWithTransport):
562
270
 
563
271
    def test_status_plain(self):
564
 
        tree = self.make_branch_and_tree('.')
 
272
        self.run_bzr("init")
565
273
 
566
274
        self.build_tree(['hello.txt'])
567
275
        result = self.run_bzr("status")[0]
568
276
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
569
277
 
570
 
        tree.add("hello.txt")
 
278
        self.run_bzr("add", "hello.txt")
571
279
        result = self.run_bzr("status")[0]
572
280
        self.assertContainsRe(result, "added:\n  hello.txt\n")
573
281
 
574
 
        tree.commit(message="added")
575
 
        result = self.run_bzr("status -r 0..1")[0]
576
 
        self.assertContainsRe(result, "added:\n  hello.txt\n")
577
 
 
578
 
        result = self.run_bzr("status -c 1")[0]
 
282
        self.run_bzr("commit", "-m", "added")
 
283
        result = self.run_bzr("status", "-r", "0..1")[0]
579
284
        self.assertContainsRe(result, "added:\n  hello.txt\n")
580
285
 
581
286
        self.build_tree(['world.txt'])
582
 
        result = self.run_bzr("status -r 0")[0]
 
287
        result = self.run_bzr("status", "-r", "0")[0]
583
288
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
584
289
                                      "unknown:\n  world.txt\n")
585
 
        result2 = self.run_bzr("status -r 0..")[0]
 
290
        result2 = self.run_bzr("status", "-r", "0..")[0]
586
291
        self.assertEquals(result2, result)
587
292
 
588
293
    def test_status_short(self):
589
 
        tree = self.make_branch_and_tree('.')
 
294
        self.run_bzr("init")
590
295
 
591
296
        self.build_tree(['hello.txt'])
592
 
        result = self.run_bzr("status --short")[0]
 
297
        result = self.run_bzr("status","--short")[0]
593
298
        self.assertContainsRe(result, "[?]   hello.txt\n")
594
299
 
595
 
        tree.add("hello.txt")
596
 
        result = self.run_bzr("status --short")[0]
 
300
        self.run_bzr("add", "hello.txt")
 
301
        result = self.run_bzr("status","--short")[0]
597
302
        self.assertContainsRe(result, "[+]N  hello.txt\n")
598
303
 
599
 
        tree.commit(message="added")
600
 
        result = self.run_bzr("status --short -r 0..1")[0]
 
304
        self.run_bzr("commit", "-m", "added")
 
305
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
601
306
        self.assertContainsRe(result, "[+]N  hello.txt\n")
602
307
 
603
308
        self.build_tree(['world.txt'])
604
 
        result = self.run_bzr("status --short -r 0")[0]
 
309
        result = self.run_bzr("status", "--short", "-r", "0")[0]
605
310
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
606
311
                                      "[?]   world.txt\n")
607
 
        result2 = self.run_bzr("status --short -r 0..")[0]
 
312
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
608
313
        self.assertEquals(result2, result)
609
314
 
610
315
    def test_status_versioned(self):
611
 
        tree = self.make_branch_and_tree('.')
 
316
        self.run_bzr("init")
612
317
 
613
318
        self.build_tree(['hello.txt'])
614
 
        result = self.run_bzr("status --versioned")[0]
 
319
        result = self.run_bzr("status", "--versioned")[0]
615
320
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
616
321
 
617
 
        tree.add("hello.txt")
618
 
        result = self.run_bzr("status --versioned")[0]
 
322
        self.run_bzr("add", "hello.txt")
 
323
        result = self.run_bzr("status", "--versioned")[0]
619
324
        self.assertContainsRe(result, "added:\n  hello.txt\n")
620
325
 
621
 
        tree.commit("added")
622
 
        result = self.run_bzr("status --versioned -r 0..1")[0]
 
326
        self.run_bzr("commit", "-m", "added")
 
327
        result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
623
328
        self.assertContainsRe(result, "added:\n  hello.txt\n")
624
329
 
625
330
        self.build_tree(['world.txt'])
626
 
        result = self.run_bzr("status --versioned -r 0")[0]
 
331
        result = self.run_bzr("status", "--versioned", "-r", "0")[0]
627
332
        self.assertContainsRe(result, "added:\n  hello.txt\n")
628
333
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
629
 
        result2 = self.run_bzr("status --versioned -r 0..")[0]
630
 
        self.assertEquals(result2, result)
631
 
 
632
 
    def test_status_SV(self):
633
 
        tree = self.make_branch_and_tree('.')
634
 
 
635
 
        self.build_tree(['hello.txt'])
636
 
        result = self.run_bzr("status -SV")[0]
637
 
        self.assertNotContainsRe(result, "hello.txt")
638
 
 
639
 
        tree.add("hello.txt")
640
 
        result = self.run_bzr("status -SV")[0]
641
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
642
 
 
643
 
        tree.commit(message="added")
644
 
        result = self.run_bzr("status -SV -r 0..1")[0]
645
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
646
 
 
647
 
        self.build_tree(['world.txt'])
648
 
        result = self.run_bzr("status -SV -r 0")[0]
649
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
650
 
 
651
 
        result2 = self.run_bzr("status -SV -r 0..")[0]
652
 
        self.assertEquals(result2, result)
653
 
 
654
 
    def assertStatusContains(self, pattern, short=False):
 
334
        result2 = self.run_bzr("status", "--versioned", "-r", "0..")[0]
 
335
        self.assertEquals(result2, result)
 
336
 
 
337
    def assertStatusContains(self, pattern):
655
338
        """Run status, and assert it contains the given pattern"""
656
 
        if short:
657
 
            result = self.run_bzr("status --short")[0]
658
 
        else:
659
 
            result = self.run_bzr("status")[0]
 
339
        result = self.run_bzr("status", "--short")[0]
660
340
        self.assertContainsRe(result, pattern)
661
341
 
662
 
    def test_kind_change_plain(self):
663
 
        tree = self.make_branch_and_tree('.')
664
 
        self.build_tree(['file'])
665
 
        tree.add('file')
666
 
        tree.commit('added file')
667
 
        unlink('file')
668
 
        self.build_tree(['file/'])
669
 
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
670
 
        tree.rename_one('file', 'directory')
671
 
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
672
 
                                  'modified:\n  directory/\n')
673
 
        rmdir('directory')
674
 
        self.assertStatusContains('removed:\n  file\n')
675
 
 
676
342
    def test_kind_change_short(self):
677
343
        tree = self.make_branch_and_tree('.')
678
344
        self.build_tree(['file'])
680
346
        tree.commit('added file')
681
347
        unlink('file')
682
348
        self.build_tree(['file/'])
683
 
        self.assertStatusContains('K  file => file/',
684
 
                                   short=True)
 
349
        self.assertStatusContains('K  file => file/')
685
350
        tree.rename_one('file', 'directory')
686
 
        self.assertStatusContains('RK  file => directory/',
687
 
                                   short=True)
 
351
        self.assertStatusContains('RK  file => directory/')
688
352
        rmdir('directory')
689
 
        self.assertStatusContains('RD  file => directory',
690
 
                                   short=True)
691
 
 
692
 
    def test_status_illegal_revision_specifiers(self):
693
 
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
694
 
        self.assertContainsRe(err, 'one or two revision specifiers')
695
 
 
696
 
    def test_status_no_pending(self):
697
 
        a_tree = self.make_branch_and_tree('a')
698
 
        self.build_tree(['a/a'])
699
 
        a_tree.add('a')
700
 
        a_tree.commit('a')
701
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
702
 
        self.build_tree(['b/b'])
703
 
        b_tree.add('b')
704
 
        b_tree.commit('b')
705
 
 
706
 
        self.run_bzr('merge ../b', working_dir='a')
707
 
        out, err = self.run_bzr('status --no-pending', working_dir='a')
708
 
        self.assertEquals(out, "added:\n  b\n")
709
 
 
710
 
    def test_pending_specific_files(self):
711
 
        """With a specific file list, pending merges are not shown."""
712
 
        tree = self.make_branch_and_tree('tree')
713
 
        self.build_tree_contents([('tree/a', 'content of a\n')])
714
 
        tree.add('a')
715
 
        r1_id = tree.commit('one')
716
 
        alt = tree.bzrdir.sprout('alt').open_workingtree()
717
 
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
718
 
        alt_id = alt.commit('alt')
719
 
        tree.merge_from_branch(alt.branch)
720
 
        output = self.make_utf8_encoded_stringio()
721
 
        show_tree_status(tree, to_file=output)
722
 
        self.assertContainsRe(output.getvalue(), 'pending merge')
723
 
        out, err = self.run_bzr('status tree/a')
724
 
        self.assertNotContainsRe(out, 'pending merge')
 
353
        self.assertStatusContains('RD  file => directory')
725
354
 
726
355
 
727
356
class TestStatusEncodings(TestCaseWithTransport):
 
357
    
 
358
    def setUp(self):
 
359
        TestCaseWithTransport.setUp(self)
 
360
        self.user_encoding = bzrlib.user_encoding
 
361
        self.stdout = sys.stdout
 
362
 
 
363
    def tearDown(self):
 
364
        bzrlib.user_encoding = self.user_encoding
 
365
        sys.stdout = self.stdout
 
366
        TestCaseWithTransport.tearDown(self)
728
367
 
729
368
    def make_uncommitted_tree(self):
730
369
        """Build a branch with uncommitted unicode named changes in the cwd."""
739
378
        return working_tree
740
379
 
741
380
    def test_stdout_ascii(self):
742
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
 
381
        sys.stdout = StringIO()
 
382
        bzrlib.user_encoding = 'ascii'
743
383
        working_tree = self.make_uncommitted_tree()
744
384
        stdout, stderr = self.run_bzr("status")
745
385
 
749
389
""")
750
390
 
751
391
    def test_stdout_latin1(self):
752
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
 
392
        sys.stdout = StringIO()
 
393
        bzrlib.user_encoding = 'latin-1'
753
394
        working_tree = self.make_uncommitted_tree()
754
395
        stdout, stderr = self.run_bzr('status')
755
396