/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 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
 
    
 
46
 
43
47
    def assertStatus(self, expected_lines, working_tree,
44
 
        revision=None, short=False):
 
48
        revision=None, short=False, pending=True, verbose=False):
45
49
        """Run status in working_tree and look for output.
46
 
        
 
50
 
47
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, short)
 
54
        output_string = self.status_string(working_tree, revision, short,
 
55
                pending, verbose)
51
56
        self.assertEqual(expected_lines, output_string.splitlines(True))
52
 
    
53
 
    def status_string(self, wt, revision=None, short=False):
 
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, short=short)
 
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
 
89
96
                'unknown:\n',
90
97
                '  bye.c\n',
91
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',
92
107
                'pending merges:\n',
93
 
                '  pending@pending-0-0\n',
 
108
                '  (ghost) pending@pending-0-0\n',
94
109
            ],
95
 
            wt)
 
110
            wt, verbose=True)
96
111
        self.assertStatus([
97
112
                '?   bye.c\n',
98
113
                '?   hello.c\n',
99
 
                'P   pending@pending-0-0\n',
 
114
                'P   (ghost) pending@pending-0-0\n',
100
115
            ],
101
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)
102
128
 
103
129
    def test_branch_status_revisions(self):
104
130
        """Tests branch status with revisions"""
121
147
        self.build_tree(['more.c'])
122
148
        wt.add('more.c')
123
149
        wt.commit('Another test message')
124
 
        
 
150
 
125
151
        revs.append(RevisionSpec.from_string('1'))
126
152
        self.assertStatus([
127
153
                'added:\n',
141
167
        b_2 = b_2_dir.open_branch()
142
168
        wt2 = b_2_dir.open_workingtree()
143
169
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
144
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
145
 
        message = self.status_string(wt2)
 
170
        wt2.merge_from_branch(wt.branch)
 
171
        message = self.status_string(wt2, verbose=True)
146
172
        self.assertStartsWith(message, "pending merges:\n")
147
173
        self.assertEndsWith(message, "Empty commit 2\n")
148
174
        wt2.commit("merged")
149
175
        # must be long to make sure we see elipsis at the end
150
176
        wt.commit("Empty commit 3 " +
151
177
                   "blah blah blah blah " * 100)
152
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
153
 
        message = self.status_string(wt2)
 
178
        wt2.merge_from_branch(wt.branch)
 
179
        message = self.status_string(wt2, verbose=True)
154
180
        self.assertStartsWith(message, "pending merges:\n")
155
181
        self.assert_("Empty commit 3" in message)
156
182
        self.assertEndsWith(message, "...\n")
158
184
    def test_tree_status_ignores(self):
159
185
        """Tests branch status with ignores"""
160
186
        wt = self.make_branch_and_tree('.')
161
 
        self.run_bzr('ignore', '*~')
 
187
        self.run_bzr('ignore *~')
162
188
        wt.commit('commit .bzrignore')
163
189
        self.build_tree(['foo.c', 'foo.c~'])
164
190
        self.assertStatus([
180
206
        wt.add('directory')
181
207
        wt.add('test.c')
182
208
        wt.commit('testing')
183
 
        
 
209
 
184
210
        self.assertStatus([
185
211
                'unknown:\n',
186
212
                '  bye.c\n',
199
225
        tof = StringIO()
200
226
        self.assertRaises(errors.PathsDoNotExist,
201
227
                          show_tree_status,
202
 
                          wt, specific_files=['bye.c','test.c','absent.c'], 
 
228
                          wt, specific_files=['bye.c','test.c','absent.c'],
203
229
                          to_file=tof)
204
 
        
 
230
 
205
231
        tof = StringIO()
206
232
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
207
233
        tof.seek(0)
227
253
        tof.seek(0)
228
254
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
229
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
 
304
 
230
305
    def test_status_nonexistent_file(self):
231
306
        # files that don't exist in either the basis tree or working tree
232
307
        # should give an error
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')
 
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.*')
236
457
 
237
458
    def test_status_out_of_date(self):
238
459
        """Simulate status of out-of-date tree after remote push"""
251
472
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
252
473
                         err)
253
474
 
 
475
    def test_status_on_ignored(self):
 
476
        """Tests branch status on an unversioned file which is considered ignored.
 
477
 
 
478
        See https://bugs.launchpad.net/bzr/+bug/40103
 
479
        """
 
480
        tree = self.make_branch_and_tree('.')
 
481
 
 
482
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
 
483
        result = self.run_bzr('status')[0]
 
484
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
 
485
        short_result = self.run_bzr('status --short')[0]
 
486
        self.assertContainsRe(short_result, "\?   test1.c\n")
 
487
 
 
488
        result = self.run_bzr('status test1.c')[0]
 
489
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
 
490
        short_result = self.run_bzr('status --short test1.c')[0]
 
491
        self.assertContainsRe(short_result, "\?   test1.c\n")
 
492
 
 
493
        result = self.run_bzr('status test1.c~')[0]
 
494
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
 
495
        short_result = self.run_bzr('status --short test1.c~')[0]
 
496
        self.assertContainsRe(short_result, "I   test1.c~\n")
 
497
 
 
498
        result = self.run_bzr('status test1.c~ test2.c~')[0]
 
499
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
 
500
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
 
501
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
 
502
 
 
503
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
 
504
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
 
505
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
 
506
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
 
507
 
 
508
    def test_status_write_lock(self):
 
509
        """Test that status works without fetching history and
 
510
        having a write lock.
 
511
 
 
512
        See https://bugs.launchpad.net/bzr/+bug/149270
 
513
        """
 
514
        mkdir('branch1')
 
515
        wt = self.make_branch_and_tree('branch1')
 
516
        b = wt.branch
 
517
        wt.commit('Empty commit 1')
 
518
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
 
519
        wt2.commit('Empty commit 2')
 
520
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
 
521
        self.assertEqual('', out)
 
522
 
254
523
 
255
524
class CheckoutStatus(BranchStatus):
256
525
 
258
527
        super(CheckoutStatus, self).setUp()
259
528
        mkdir('codir')
260
529
        chdir('codir')
261
 
        
 
530
 
262
531
    def make_branch_and_tree(self, relpath):
263
532
        source = self.make_branch(pathjoin('..', relpath))
264
533
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
265
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
534
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
 
535
            target_branch=source)
266
536
        return checkout.create_workingtree()
267
537
 
268
538
 
269
539
class TestStatus(TestCaseWithTransport):
270
540
 
271
541
    def test_status_plain(self):
272
 
        self.run_bzr("init")
 
542
        tree = self.make_branch_and_tree('.')
273
543
 
274
544
        self.build_tree(['hello.txt'])
275
545
        result = self.run_bzr("status")[0]
276
546
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
277
547
 
278
 
        self.run_bzr("add", "hello.txt")
 
548
        tree.add("hello.txt")
279
549
        result = self.run_bzr("status")[0]
280
550
        self.assertContainsRe(result, "added:\n  hello.txt\n")
281
551
 
282
 
        self.run_bzr("commit", "-m", "added")
283
 
        result = self.run_bzr("status", "-r", "0..1")[0]
 
552
        tree.commit(message="added")
 
553
        result = self.run_bzr("status -r 0..1")[0]
 
554
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
555
 
 
556
        result = self.run_bzr("status -c 1")[0]
284
557
        self.assertContainsRe(result, "added:\n  hello.txt\n")
285
558
 
286
559
        self.build_tree(['world.txt'])
287
 
        result = self.run_bzr("status", "-r", "0")[0]
 
560
        result = self.run_bzr("status -r 0")[0]
288
561
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
289
562
                                      "unknown:\n  world.txt\n")
290
 
        result2 = self.run_bzr("status", "-r", "0..")[0]
 
563
        result2 = self.run_bzr("status -r 0..")[0]
291
564
        self.assertEquals(result2, result)
292
565
 
293
566
    def test_status_short(self):
294
 
        self.run_bzr("init")
 
567
        tree = self.make_branch_and_tree('.')
295
568
 
296
569
        self.build_tree(['hello.txt'])
297
 
        result = self.run_bzr("status","--short")[0]
 
570
        result = self.run_bzr("status --short")[0]
298
571
        self.assertContainsRe(result, "[?]   hello.txt\n")
299
572
 
300
 
        self.run_bzr("add", "hello.txt")
301
 
        result = self.run_bzr("status","--short")[0]
 
573
        tree.add("hello.txt")
 
574
        result = self.run_bzr("status --short")[0]
302
575
        self.assertContainsRe(result, "[+]N  hello.txt\n")
303
576
 
304
 
        self.run_bzr("commit", "-m", "added")
305
 
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
 
577
        tree.commit(message="added")
 
578
        result = self.run_bzr("status --short -r 0..1")[0]
306
579
        self.assertContainsRe(result, "[+]N  hello.txt\n")
307
580
 
308
581
        self.build_tree(['world.txt'])
309
 
        result = self.run_bzr("status", "--short", "-r", "0")[0]
 
582
        result = self.run_bzr("status --short -r 0")[0]
310
583
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
311
584
                                      "[?]   world.txt\n")
312
 
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
585
        result2 = self.run_bzr("status --short -r 0..")[0]
313
586
        self.assertEquals(result2, result)
314
587
 
315
588
    def test_status_versioned(self):
316
 
        self.run_bzr("init")
 
589
        tree = self.make_branch_and_tree('.')
317
590
 
318
591
        self.build_tree(['hello.txt'])
319
 
        result = self.run_bzr("status", "--versioned")[0]
 
592
        result = self.run_bzr("status --versioned")[0]
320
593
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
321
594
 
322
 
        self.run_bzr("add", "hello.txt")
323
 
        result = self.run_bzr("status", "--versioned")[0]
 
595
        tree.add("hello.txt")
 
596
        result = self.run_bzr("status --versioned")[0]
324
597
        self.assertContainsRe(result, "added:\n  hello.txt\n")
325
598
 
326
 
        self.run_bzr("commit", "-m", "added")
327
 
        result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
 
599
        tree.commit("added")
 
600
        result = self.run_bzr("status --versioned -r 0..1")[0]
328
601
        self.assertContainsRe(result, "added:\n  hello.txt\n")
329
602
 
330
603
        self.build_tree(['world.txt'])
331
 
        result = self.run_bzr("status", "--versioned", "-r", "0")[0]
 
604
        result = self.run_bzr("status --versioned -r 0")[0]
332
605
        self.assertContainsRe(result, "added:\n  hello.txt\n")
333
606
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
334
 
        result2 = self.run_bzr("status", "--versioned", "-r", "0..")[0]
335
 
        self.assertEquals(result2, result)
336
 
 
337
 
    def assertStatusContains(self, pattern):
 
607
        result2 = self.run_bzr("status --versioned -r 0..")[0]
 
608
        self.assertEquals(result2, result)
 
609
 
 
610
    def test_status_SV(self):
 
611
        tree = self.make_branch_and_tree('.')
 
612
 
 
613
        self.build_tree(['hello.txt'])
 
614
        result = self.run_bzr("status -SV")[0]
 
615
        self.assertNotContainsRe(result, "hello.txt")
 
616
 
 
617
        tree.add("hello.txt")
 
618
        result = self.run_bzr("status -SV")[0]
 
619
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
620
 
 
621
        tree.commit(message="added")
 
622
        result = self.run_bzr("status -SV -r 0..1")[0]
 
623
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
624
 
 
625
        self.build_tree(['world.txt'])
 
626
        result = self.run_bzr("status -SV -r 0")[0]
 
627
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
628
 
 
629
        result2 = self.run_bzr("status -SV -r 0..")[0]
 
630
        self.assertEquals(result2, result)
 
631
 
 
632
    def assertStatusContains(self, pattern, short=False):
338
633
        """Run status, and assert it contains the given pattern"""
339
 
        result = self.run_bzr("status", "--short")[0]
 
634
        if short:
 
635
            result = self.run_bzr("status --short")[0]
 
636
        else:
 
637
            result = self.run_bzr("status")[0]
340
638
        self.assertContainsRe(result, pattern)
341
639
 
 
640
    def test_kind_change_plain(self):
 
641
        tree = self.make_branch_and_tree('.')
 
642
        self.build_tree(['file'])
 
643
        tree.add('file')
 
644
        tree.commit('added file')
 
645
        unlink('file')
 
646
        self.build_tree(['file/'])
 
647
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
 
648
        tree.rename_one('file', 'directory')
 
649
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
 
650
                                  'modified:\n  directory/\n')
 
651
        rmdir('directory')
 
652
        self.assertStatusContains('removed:\n  file\n')
 
653
 
342
654
    def test_kind_change_short(self):
343
655
        tree = self.make_branch_and_tree('.')
344
656
        self.build_tree(['file'])
346
658
        tree.commit('added file')
347
659
        unlink('file')
348
660
        self.build_tree(['file/'])
349
 
        self.assertStatusContains('K  file => file/')
 
661
        self.assertStatusContains('K  file => file/',
 
662
                                   short=True)
350
663
        tree.rename_one('file', 'directory')
351
 
        self.assertStatusContains('RK  file => directory/')
 
664
        self.assertStatusContains('RK  file => directory/',
 
665
                                   short=True)
352
666
        rmdir('directory')
353
 
        self.assertStatusContains('RD  file => directory')
 
667
        self.assertStatusContains('RD  file => directory',
 
668
                                   short=True)
 
669
 
 
670
    def test_status_illegal_revision_specifiers(self):
 
671
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
 
672
        self.assertContainsRe(err, 'one or two revision specifiers')
 
673
 
 
674
    def test_status_no_pending(self):
 
675
        a_tree = self.make_branch_and_tree('a')
 
676
        self.build_tree(['a/a'])
 
677
        a_tree.add('a')
 
678
        a_tree.commit('a')
 
679
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
680
        self.build_tree(['b/b'])
 
681
        b_tree.add('b')
 
682
        b_tree.commit('b')
 
683
 
 
684
        self.run_bzr('merge ../b', working_dir='a')
 
685
        out, err = self.run_bzr('status --no-pending', working_dir='a')
 
686
        self.assertEquals(out, "added:\n  b\n")
 
687
 
 
688
    def test_pending_specific_files(self):
 
689
        """With a specific file list, pending merges are not shown."""
 
690
        tree = self.make_branch_and_tree('tree')
 
691
        self.build_tree_contents([('tree/a', 'content of a\n')])
 
692
        tree.add('a')
 
693
        r1_id = tree.commit('one')
 
694
        alt = tree.bzrdir.sprout('alt').open_workingtree()
 
695
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
 
696
        alt_id = alt.commit('alt')
 
697
        tree.merge_from_branch(alt.branch)
 
698
        output = self.make_utf8_encoded_stringio()
 
699
        show_tree_status(tree, to_file=output)
 
700
        self.assertContainsRe(output.getvalue(), 'pending merge')
 
701
        out, err = self.run_bzr('status tree/a')
 
702
        self.assertNotContainsRe(out, 'pending merge')
354
703
 
355
704
 
356
705
class TestStatusEncodings(TestCaseWithTransport):
357
 
    
 
706
 
358
707
    def setUp(self):
359
708
        TestCaseWithTransport.setUp(self)
360
 
        self.user_encoding = bzrlib.user_encoding
 
709
        self.user_encoding = osutils._cached_user_encoding
361
710
        self.stdout = sys.stdout
362
711
 
363
712
    def tearDown(self):
364
 
        bzrlib.user_encoding = self.user_encoding
 
713
        osutils._cached_user_encoding = self.user_encoding
365
714
        sys.stdout = self.stdout
366
715
        TestCaseWithTransport.tearDown(self)
367
716
 
379
728
 
380
729
    def test_stdout_ascii(self):
381
730
        sys.stdout = StringIO()
382
 
        bzrlib.user_encoding = 'ascii'
 
731
        osutils._cached_user_encoding = 'ascii'
383
732
        working_tree = self.make_uncommitted_tree()
384
733
        stdout, stderr = self.run_bzr("status")
385
734
 
390
739
 
391
740
    def test_stdout_latin1(self):
392
741
        sys.stdout = StringIO()
393
 
        bzrlib.user_encoding = 'latin-1'
 
742
        osutils._cached_user_encoding = 'latin-1'
394
743
        working_tree = self.make_uncommitted_tree()
395
744
        stdout, stderr = self.run_bzr('status')
396
745