~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil, Patch Queue Manager, Jelmer Vernooij
  • Date: 2017-01-17 16:20:41 UTC
  • mfrom: (6619.1.2 trunk)
  • Revision ID: tarmac-20170117162041-oo62uk1qsmgc9j31
Merge 2.7 into trunk including fixes for bugs #1622039, #1644003, #1579093 and #1645017. [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2012, 2016 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,
36
37
    )
37
38
import bzrlib.branch
38
39
from bzrlib.osutils import pathjoin
44
45
 
45
46
class BranchStatus(TestCaseWithTransport):
46
47
 
47
 
    def assertStatus(self, expected_lines, working_tree,
 
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
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
48
57
        revision=None, short=False, pending=True, verbose=False):
49
58
        """Run status in working_tree and look for output.
50
59
 
51
60
        :param expected_lines: The lines to look for.
52
61
        :param working_tree: The tree to run status in.
53
62
        """
54
 
        output_string = self.status_string(working_tree, revision, short,
 
63
        output_string = self.status_string(working_tree, specific_files, revision, short,
55
64
                pending, verbose)
56
65
        self.assertEqual(expected_lines, output_string.splitlines(True))
57
66
 
58
 
    def status_string(self, wt, revision=None, short=False, pending=True,
59
 
        verbose=False):
 
67
    def status_string(self, wt, specific_files=None, revision=None,
 
68
        short=False, pending=True, verbose=False):
60
69
        # use a real file rather than StringIO because it doesn't handle
61
70
        # Unicode very well.
62
71
        tof = codecs.getwriter('utf-8')(TemporaryFile())
63
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
 
                show_pending=pending, verbose=verbose)
 
72
        show_tree_status(wt, specific_files=specific_files, to_file=tof,
 
73
                revision=revision, short=short, show_pending=pending,
 
74
                verbose=verbose)
65
75
        tof.seek(0)
66
76
        return tof.read().decode('utf-8')
67
77
 
178
188
        wt2.merge_from_branch(wt.branch)
179
189
        message = self.status_string(wt2, verbose=True)
180
190
        self.assertStartsWith(message, "pending merges:\n")
181
 
        self.assert_("Empty commit 3" in message)
 
191
        self.assertTrue("Empty commit 3" in message)
182
192
        self.assertEndsWith(message, "...\n")
183
193
 
184
194
    def test_tree_status_ignores(self):
202
212
        wt = self.make_branch_and_tree('.')
203
213
        b = wt.branch
204
214
 
205
 
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
 
215
        self.build_tree(['directory/','directory/hello.c',
 
216
                         'bye.c','test.c','dir2/',
 
217
                         'missing.c'])
206
218
        wt.add('directory')
207
219
        wt.add('test.c')
208
220
        wt.commit('testing')
 
221
        wt.add('missing.c')
 
222
        unlink('missing.c')
209
223
 
210
224
        self.assertStatus([
 
225
                'missing:\n',
 
226
                '  missing.c\n',
211
227
                'unknown:\n',
212
228
                '  bye.c\n',
213
229
                '  dir2/\n',
218
234
        self.assertStatus([
219
235
                '?   bye.c\n',
220
236
                '?   dir2/\n',
 
237
                '+!  missing.c\n',
221
238
                '?   directory/hello.c\n'
222
239
                ],
223
240
                wt, short=True)
231
248
        tof = StringIO()
232
249
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
233
250
        tof.seek(0)
234
 
        self.assertEquals(tof.readlines(),
 
251
        self.assertEqual(tof.readlines(),
235
252
                          ['unknown:\n',
236
253
                           '  directory/hello.c\n'
237
254
                           ])
239
256
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
240
257
                         short=True)
241
258
        tof.seek(0)
242
 
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
 
259
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
243
260
 
244
261
        tof = StringIO()
245
262
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
246
263
        tof.seek(0)
247
 
        self.assertEquals(tof.readlines(),
 
264
        self.assertEqual(tof.readlines(),
248
265
                          ['unknown:\n',
249
266
                           '  dir2/\n'
250
267
                           ])
251
268
        tof = StringIO()
252
269
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
253
270
        tof.seek(0)
254
 
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
 
271
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
255
272
 
256
273
        tof = StringIO()
257
274
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
258
275
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
259
276
                         short=True, revision=revs)
260
277
        tof.seek(0)
261
 
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
 
278
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
 
279
 
 
280
        tof = StringIO()
 
281
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
 
282
        tof.seek(0)
 
283
        self.assertEqual(tof.readlines(),
 
284
                          ['missing:\n',
 
285
                           '  missing.c\n'])
 
286
 
 
287
        tof = StringIO()
 
288
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
 
289
                         short=True)
 
290
        tof.seek(0)
 
291
        self.assertEqual(tof.readlines(),
 
292
                          ['+!  missing.c\n'])
262
293
 
263
294
    def test_specific_files_conflicts(self):
264
295
        tree = self.make_branch_and_tree('.')
294
325
        wt.add('FILE_D')
295
326
        wt.add('FILE_E')
296
327
        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.')
 
328
        with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
 
329
        with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
299
330
        unlink('FILE_E')  # FILE_E will be versioned but missing
300
 
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
 
331
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
332
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
302
333
        open('UNVERSIONED_BUT_EXISTING', 'w')
303
334
        return wt
447
478
          ' M  FILE_B\n',
448
479
          'X   NONEXISTENT\n',
449
480
          ]
 
481
        expected.sort()
450
482
        out, err = self.run_bzr('status --short NONEXISTENT '
451
483
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
484
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
 
        self.assertEqual(expected, out.splitlines(True))
 
485
        actual = out.splitlines(True)
 
486
        actual.sort()
 
487
        self.assertEqual(expected, actual)
454
488
        self.assertContainsRe(err,
455
489
                              r'.*ERROR: Path\(s\) do not exist: '
456
490
                              'NONEXISTENT.*')
520
554
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
521
555
        self.assertEqual('', out)
522
556
 
 
557
    def test_status_with_shelves(self):
 
558
        """Ensure that _show_shelve_summary handler works.
 
559
        """
 
560
        wt = self.make_branch_and_tree('.')
 
561
        self.build_tree(['hello.c'])
 
562
        wt.add('hello.c')
 
563
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
 
564
        self.build_tree(['bye.c'])
 
565
        wt.add('bye.c')
 
566
        self.assertStatus([
 
567
                'added:\n',
 
568
                '  bye.c\n',
 
569
                '1 shelf exists. See "bzr shelve --list" for details.\n',
 
570
            ],
 
571
            wt)
 
572
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
 
573
        self.build_tree(['eggs.c', 'spam.c'])
 
574
        wt.add('eggs.c')
 
575
        wt.add('spam.c')
 
576
        self.assertStatus([
 
577
                'added:\n',
 
578
                '  eggs.c\n',
 
579
                '  spam.c\n',
 
580
                '2 shelves exist. See "bzr shelve --list" for details.\n',
 
581
            ],
 
582
            wt)
 
583
        self.assertStatus([
 
584
                'added:\n',
 
585
                '  spam.c\n',
 
586
            ],
 
587
            wt,
 
588
            specific_files=['spam.c'])
 
589
 
523
590
 
524
591
class CheckoutStatus(BranchStatus):
525
592
 
531
598
    def make_branch_and_tree(self, relpath):
532
599
        source = self.make_branch(pathjoin('..', relpath))
533
600
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
534
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
535
 
            target_branch=source)
 
601
        checkout.set_branch_reference(source)
536
602
        return checkout.create_workingtree()
537
603
 
538
604
 
561
627
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
562
628
                                      "unknown:\n  world.txt\n")
563
629
        result2 = self.run_bzr("status -r 0..")[0]
564
 
        self.assertEquals(result2, result)
 
630
        self.assertEqual(result2, result)
565
631
 
566
632
    def test_status_short(self):
567
633
        tree = self.make_branch_and_tree('.')
579
645
        self.assertContainsRe(result, "[+]N  hello.txt\n")
580
646
 
581
647
        self.build_tree(['world.txt'])
582
 
        result = self.run_bzr("status --short -r 0")[0]
 
648
        result = self.run_bzr("status -S -r 0")[0]
583
649
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
584
650
                                      "[?]   world.txt\n")
585
 
        result2 = self.run_bzr("status --short -r 0..")[0]
586
 
        self.assertEquals(result2, result)
 
651
        result2 = self.run_bzr("status -S -r 0..")[0]
 
652
        self.assertEqual(result2, result)
587
653
 
588
654
    def test_status_versioned(self):
589
655
        tree = self.make_branch_and_tree('.')
605
671
        self.assertContainsRe(result, "added:\n  hello.txt\n")
606
672
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
607
673
        result2 = self.run_bzr("status --versioned -r 0..")[0]
608
 
        self.assertEquals(result2, result)
 
674
        self.assertEqual(result2, result)
609
675
 
610
676
    def test_status_SV(self):
611
677
        tree = self.make_branch_and_tree('.')
627
693
        self.assertContainsRe(result, "[+]N  hello.txt\n")
628
694
 
629
695
        result2 = self.run_bzr("status -SV -r 0..")[0]
630
 
        self.assertEquals(result2, result)
 
696
        self.assertEqual(result2, result)
631
697
 
632
698
    def assertStatusContains(self, pattern, short=False):
633
699
        """Run status, and assert it contains the given pattern"""
683
749
 
684
750
        self.run_bzr('merge ../b', working_dir='a')
685
751
        out, err = self.run_bzr('status --no-pending', working_dir='a')
686
 
        self.assertEquals(out, "added:\n  b\n")
 
752
        self.assertEqual(out, "added:\n  b\n")
687
753
 
688
754
    def test_pending_specific_files(self):
689
755
        """With a specific file list, pending merges are not shown."""
721
787
        working_tree = self.make_uncommitted_tree()
722
788
        stdout, stderr = self.run_bzr("status")
723
789
 
724
 
        self.assertEquals(stdout, """\
 
790
        self.assertEqual(stdout, """\
725
791
added:
726
792
  hell?
727
793
""")
731
797
        working_tree = self.make_uncommitted_tree()
732
798
        stdout, stderr = self.run_bzr('status')
733
799
 
734
 
        self.assertEquals(stdout, u"""\
 
800
        self.assertEqual(stdout, u"""\
735
801
added:
736
802
  hell\u00d8
737
803
""".encode('latin-1'))