~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-02-25 06:17:27 UTC
  • mfrom: (5055 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5057.
  • Revision ID: mbp@sourcefrog.net-20100225061727-4sd9lt0qmdc6087t
merge news

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
33
33
    conflicts,
34
34
    errors,
35
35
    osutils,
36
 
    status,
37
36
    )
38
37
import bzrlib.branch
39
38
from bzrlib.osutils import pathjoin
45
44
 
46
45
class BranchStatus(TestCaseWithTransport):
47
46
 
48
 
    def setUp(self):
49
 
        super(BranchStatus, self).setUp()
50
 
        # As TestCase.setUp clears all hooks, we install this default
51
 
        # post_status hook handler for the test.
52
 
        status.hooks.install_named_hook('post_status',
53
 
            status._show_shelve_summary,
54
 
            'bzr status')
55
 
 
56
47
    def assertStatus(self, expected_lines, working_tree,
57
48
        revision=None, short=False, pending=True, verbose=False):
58
49
        """Run status in working_tree and look for output.
211
202
        wt = self.make_branch_and_tree('.')
212
203
        b = wt.branch
213
204
 
214
 
        self.build_tree(['directory/','directory/hello.c',
215
 
                         'bye.c','test.c','dir2/',
216
 
                         'missing.c'])
 
205
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
217
206
        wt.add('directory')
218
207
        wt.add('test.c')
219
208
        wt.commit('testing')
220
 
        wt.add('missing.c')
221
 
        unlink('missing.c')
222
209
 
223
210
        self.assertStatus([
224
 
                'missing:\n',
225
 
                '  missing.c\n',
226
211
                'unknown:\n',
227
212
                '  bye.c\n',
228
213
                '  dir2/\n',
233
218
        self.assertStatus([
234
219
                '?   bye.c\n',
235
220
                '?   dir2/\n',
236
 
                '+!  missing.c\n',
237
221
                '?   directory/hello.c\n'
238
222
                ],
239
223
                wt, short=True)
276
260
        tof.seek(0)
277
261
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
278
262
 
279
 
        tof = StringIO()
280
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
281
 
        tof.seek(0)
282
 
        self.assertEquals(tof.readlines(),
283
 
                          ['missing:\n',
284
 
                           '  missing.c\n'])
285
 
 
286
 
        tof = StringIO()
287
 
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
288
 
                         short=True)
289
 
        tof.seek(0)
290
 
        self.assertEquals(tof.readlines(),
291
 
                          ['+!  missing.c\n'])
292
 
 
293
263
    def test_specific_files_conflicts(self):
294
264
        tree = self.make_branch_and_tree('.')
295
265
        self.build_tree(['dir2/'])
324
294
        wt.add('FILE_D')
325
295
        wt.add('FILE_E')
326
296
        wt.commit('Create five empty files.')
327
 
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
328
 
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
 
297
        open('FILE_B', 'w').write('Modification to file FILE_B.')
 
298
        open('FILE_C', 'w').write('Modification to file FILE_C.')
329
299
        unlink('FILE_E')  # FILE_E will be versioned but missing
330
 
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
 
300
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
331
301
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
332
302
        open('UNVERSIONED_BUT_EXISTING', 'w')
333
303
        return wt
477
447
          ' M  FILE_B\n',
478
448
          'X   NONEXISTENT\n',
479
449
          ]
480
 
        expected.sort()
481
450
        out, err = self.run_bzr('status --short NONEXISTENT '
482
451
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
483
452
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
484
 
        actual = out.splitlines(True)
485
 
        actual.sort()
486
 
        self.assertEqual(expected, actual)
 
453
        self.assertEqual(expected, out.splitlines(True))
487
454
        self.assertContainsRe(err,
488
455
                              r'.*ERROR: Path\(s\) do not exist: '
489
456
                              'NONEXISTENT.*')
505
472
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
506
473
                         err)
507
474
 
508
 
    def test_status_on_ignored(self):
509
 
        """Tests branch status on an unversioned file which is considered ignored.
510
 
 
511
 
        See https://bugs.launchpad.net/bzr/+bug/40103
512
 
        """
513
 
        tree = self.make_branch_and_tree('.')
514
 
 
515
 
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
516
 
        result = self.run_bzr('status')[0]
517
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
518
 
        short_result = self.run_bzr('status --short')[0]
519
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
520
 
 
521
 
        result = self.run_bzr('status test1.c')[0]
522
 
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
523
 
        short_result = self.run_bzr('status --short test1.c')[0]
524
 
        self.assertContainsRe(short_result, "\?   test1.c\n")
525
 
 
526
 
        result = self.run_bzr('status test1.c~')[0]
527
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
528
 
        short_result = self.run_bzr('status --short test1.c~')[0]
529
 
        self.assertContainsRe(short_result, "I   test1.c~\n")
530
 
 
531
 
        result = self.run_bzr('status test1.c~ test2.c~')[0]
532
 
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
533
 
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
534
 
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
535
 
 
536
 
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
537
 
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
538
 
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
539
 
        self.assertContainsRe(short_result, "\?   test1.c\nI   test1.c~\nI   test2.c~\n")
540
 
 
541
475
    def test_status_write_lock(self):
542
476
        """Test that status works without fetching history and
543
477
        having a write lock.
553
487
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
554
488
        self.assertEqual('', out)
555
489
 
556
 
    def test_status_with_shelves(self):
557
 
        """Ensure that _show_shelve_summary handler works.
558
 
        """
559
 
        wt = self.make_branch_and_tree('.')
560
 
        self.build_tree(['hello.c'])
561
 
        wt.add('hello.c')
562
 
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
563
 
        self.build_tree(['bye.c'])
564
 
        wt.add('bye.c')
565
 
        self.assertStatus([
566
 
                'added:\n',
567
 
                '  bye.c\n',
568
 
                '1 shelf exists. See "bzr shelve --list" for details.\n',
569
 
            ],
570
 
            wt)
571
 
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
572
 
        self.build_tree(['spam.c'])
573
 
        wt.add('spam.c')
574
 
        self.assertStatus([
575
 
                'added:\n',
576
 
                '  spam.c\n',
577
 
                '2 shelves exist. See "bzr shelve --list" for details.\n',
578
 
            ],
579
 
            wt)
580
 
 
581
490
 
582
491
class CheckoutStatus(BranchStatus):
583
492
 
589
498
    def make_branch_and_tree(self, relpath):
590
499
        source = self.make_branch(pathjoin('..', relpath))
591
500
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
592
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
593
 
            target_branch=source)
 
501
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
594
502
        return checkout.create_workingtree()
595
503
 
596
504
 
637
545
        self.assertContainsRe(result, "[+]N  hello.txt\n")
638
546
 
639
547
        self.build_tree(['world.txt'])
640
 
        result = self.run_bzr("status -S -r 0")[0]
 
548
        result = self.run_bzr("status --short -r 0")[0]
641
549
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
642
550
                                      "[?]   world.txt\n")
643
 
        result2 = self.run_bzr("status -S -r 0..")[0]
 
551
        result2 = self.run_bzr("status --short -r 0..")[0]
644
552
        self.assertEquals(result2, result)
645
553
 
646
554
    def test_status_versioned(self):
687
595
        result2 = self.run_bzr("status -SV -r 0..")[0]
688
596
        self.assertEquals(result2, result)
689
597
 
690
 
    def assertStatusContains(self, pattern, short=False):
 
598
    def assertStatusContains(self, pattern):
691
599
        """Run status, and assert it contains the given pattern"""
692
 
        if short:
693
 
            result = self.run_bzr("status --short")[0]
694
 
        else:
695
 
            result = self.run_bzr("status")[0]
 
600
        result = self.run_bzr("status --short")[0]
696
601
        self.assertContainsRe(result, pattern)
697
602
 
698
 
    def test_kind_change_plain(self):
699
 
        tree = self.make_branch_and_tree('.')
700
 
        self.build_tree(['file'])
701
 
        tree.add('file')
702
 
        tree.commit('added file')
703
 
        unlink('file')
704
 
        self.build_tree(['file/'])
705
 
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
706
 
        tree.rename_one('file', 'directory')
707
 
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
708
 
                                  'modified:\n  directory/\n')
709
 
        rmdir('directory')
710
 
        self.assertStatusContains('removed:\n  file\n')
711
 
 
712
603
    def test_kind_change_short(self):
713
604
        tree = self.make_branch_and_tree('.')
714
605
        self.build_tree(['file'])
716
607
        tree.commit('added file')
717
608
        unlink('file')
718
609
        self.build_tree(['file/'])
719
 
        self.assertStatusContains('K  file => file/',
720
 
                                   short=True)
 
610
        self.assertStatusContains('K  file => file/')
721
611
        tree.rename_one('file', 'directory')
722
 
        self.assertStatusContains('RK  file => directory/',
723
 
                                   short=True)
 
612
        self.assertStatusContains('RK  file => directory/')
724
613
        rmdir('directory')
725
 
        self.assertStatusContains('RD  file => directory',
726
 
                                   short=True)
 
614
        self.assertStatusContains('RD  file => directory')
727
615
 
728
616
    def test_status_illegal_revision_specifiers(self):
729
617
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
762
650
 
763
651
class TestStatusEncodings(TestCaseWithTransport):
764
652
 
 
653
    def setUp(self):
 
654
        TestCaseWithTransport.setUp(self)
 
655
        self.user_encoding = osutils._cached_user_encoding
 
656
        self.stdout = sys.stdout
 
657
 
 
658
    def tearDown(self):
 
659
        osutils._cached_user_encoding = self.user_encoding
 
660
        sys.stdout = self.stdout
 
661
        TestCaseWithTransport.tearDown(self)
 
662
 
765
663
    def make_uncommitted_tree(self):
766
664
        """Build a branch with uncommitted unicode named changes in the cwd."""
767
665
        working_tree = self.make_branch_and_tree(u'.')
775
673
        return working_tree
776
674
 
777
675
    def test_stdout_ascii(self):
778
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
 
676
        sys.stdout = StringIO()
 
677
        osutils._cached_user_encoding = 'ascii'
779
678
        working_tree = self.make_uncommitted_tree()
780
679
        stdout, stderr = self.run_bzr("status")
781
680
 
785
684
""")
786
685
 
787
686
    def test_stdout_latin1(self):
788
 
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
 
687
        sys.stdout = StringIO()
 
688
        osutils._cached_user_encoding = 'latin-1'
789
689
        working_tree = self.make_uncommitted_tree()
790
690
        stdout, stderr = self.run_bzr('status')
791
691