/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
915 by Martin Pool
- add simple test case for bzr status
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
915 by Martin Pool
- add simple test case for bzr status
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
915 by Martin Pool
- add simple test case for bzr status
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
915 by Martin Pool
- add simple test case for bzr status
16
17
"""Tests of status command.
18
19
Most of these depend on the particular formatting used.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
20
As such they really are blackbox tests even though some of the
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
21
tests are not using self.capture. If we add tests for the programmatic
22
interface later, they will be non blackbox tests.
915 by Martin Pool
- add simple test case for bzr status
23
"""
24
1685.1.80 by Wouter van Heyst
more code cleanup
25
import codecs
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
26
from os import mkdir, chdir, rmdir, unlink
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
27
import sys
1185.33.71 by Martin Pool
Status tests include unicode character.
28
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
29
from ... import (
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
30
    conflicts,
31
    errors,
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
32
    osutils,
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
33
    status,
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
34
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
35
from breezy.bzr import (
36
    bzrdir,
37
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
38
import breezy.branch
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
39
from ...osutils import pathjoin
40
from ...revisionspec import RevisionSpec
41
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
42
    BytesIO,
43
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
44
from ...status import show_tree_status
45
from .. import TestCaseWithTransport, TestSkipped
46
from ...workingtree import WorkingTree
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
47
915 by Martin Pool
- add simple test case for bzr status
48
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
49
class BranchStatus(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
50
5508.1.1 by John Arbash Meinel
Fix bug #662053, 'bzr status' shouldn't fail
51
    def setUp(self):
52
        super(BranchStatus, self).setUp()
53
        # As TestCase.setUp clears all hooks, we install this default
54
        # post_status hook handler for the test.
55
        status.hooks.install_named_hook('post_status',
56
            status._show_shelve_summary,
6622.1.29 by Jelmer Vernooij
Fix some more tests.
57
            'brz status')
5508.1.1 by John Arbash Meinel
Fix bug #662053, 'bzr status' shouldn't fail
58
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
59
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
60
        revision=None, short=False, pending=True, verbose=False):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
61
        """Run status in working_tree and look for output.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
62
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
63
        :param expected_lines: The lines to look for.
1927.2.3 by Robert Collins
review comment application - paired with Martin.
64
        :param working_tree: The tree to run status in.
65
        """
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
66
        output_string = self.status_string(working_tree, specific_files, revision, short,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
67
                pending, verbose)
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
68
        self.assertEqual(expected_lines, output_string.splitlines(True))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
69
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
70
    def status_string(self, wt, specific_files=None, revision=None,
71
        short=False, pending=True, verbose=False):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
72
        uio = self.make_utf8_encoded_stringio()
73
        show_tree_status(wt, specific_files=specific_files, to_file=uio,
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
74
                revision=revision, short=short, show_pending=pending,
75
                verbose=verbose)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
76
        return uio.getvalue().decode('utf-8')
1927.2.3 by Robert Collins
review comment application - paired with Martin.
77
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
78
    def test_branch_status(self):
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
79
        """Test basic branch status"""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
80
        wt = self.make_branch_and_tree('.')
1927.2.3 by Robert Collins
review comment application - paired with Martin.
81
82
        # status with no commits or files - it must
83
        # work and show no output. We do this with no
84
        # commits to be sure that it's not going to fail
85
        # as a corner case.
86
        self.assertStatus([], wt)
87
88
        self.build_tree(['hello.c', 'bye.c'])
89
        self.assertStatus([
90
                'unknown:\n',
91
                '  bye.c\n',
92
                '  hello.c\n',
93
            ],
94
            wt)
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
95
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
96
                '?   bye.c\n',
97
                '?   hello.c\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
98
            ],
99
            wt, short=True)
1927.2.3 by Robert Collins
review comment application - paired with Martin.
100
101
        # add a commit to allow showing pending merges.
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
102
        wt.commit('create a parent to allow testing merge output')
915 by Martin Pool
- add simple test case for bzr status
103
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
104
        wt.add_parent_tree_id('pending@pending-0-0')
1927.2.3 by Robert Collins
review comment application - paired with Martin.
105
        self.assertStatus([
106
                'unknown:\n',
107
                '  bye.c\n',
108
                '  hello.c\n',
3936.2.3 by Ian Clatworthy
feedback from jameinel
109
                'pending merge tips: (use -v to see all merge revisions)\n',
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
110
                '  (ghost) pending@pending-0-0\n',
111
            ],
112
            wt)
113
        self.assertStatus([
114
                'unknown:\n',
115
                '  bye.c\n',
116
                '  hello.c\n',
1927.2.3 by Robert Collins
review comment application - paired with Martin.
117
                'pending merges:\n',
3377.3.41 by John Arbash Meinel
Fix up a couple of the tests
118
                '  (ghost) pending@pending-0-0\n',
1927.2.3 by Robert Collins
review comment application - paired with Martin.
119
            ],
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
120
            wt, verbose=True)
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
121
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
122
                '?   bye.c\n',
123
                '?   hello.c\n',
3377.3.41 by John Arbash Meinel
Fix up a couple of the tests
124
                'P   (ghost) pending@pending-0-0\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
125
            ],
126
            wt, short=True)
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
127
        self.assertStatus([
128
                'unknown:\n',
129
                '  bye.c\n',
130
                '  hello.c\n',
131
            ],
132
            wt, pending=False)
133
        self.assertStatus([
134
                '?   bye.c\n',
135
                '?   hello.c\n',
136
            ],
137
            wt, short=True, pending=False)
915 by Martin Pool
- add simple test case for bzr status
138
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
139
    def test_branch_status_revisions(self):
140
        """Tests branch status with revisions"""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
141
        wt = self.make_branch_and_tree('.')
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
142
143
        self.build_tree(['hello.c', 'bye.c'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
144
        wt.add('hello.c')
145
        wt.add('bye.c')
146
        wt.commit('Test message')
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
147
1948.4.36 by John Arbash Meinel
[merge] bzr.dev 1978
148
        revs = [RevisionSpec.from_string('0')]
1927.2.3 by Robert Collins
review comment application - paired with Martin.
149
        self.assertStatus([
150
                'added:\n',
151
                '  bye.c\n',
152
                '  hello.c\n'
153
            ],
154
            wt,
155
            revision=revs)
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
156
157
        self.build_tree(['more.c'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
158
        wt.add('more.c')
159
        wt.commit('Another test message')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
160
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
161
        revs.append(RevisionSpec.from_string('1'))
1927.2.3 by Robert Collins
review comment application - paired with Martin.
162
        self.assertStatus([
163
                'added:\n',
164
                '  bye.c\n',
165
                '  hello.c\n',
166
            ],
167
            wt,
168
            revision=revs)
1185.12.27 by Aaron Bentley
Use line log for pending merges
169
170
    def test_pending(self):
1185.33.71 by Martin Pool
Status tests include unicode character.
171
        """Pending merges display works, including Unicode"""
1185.12.27 by Aaron Bentley
Use line log for pending merges
172
        mkdir("./branch")
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
173
        wt = self.make_branch_and_tree('branch')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
174
        b = wt.branch
175
        wt.commit("Empty commit 1")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
176
        b_2_dir = b.controldir.sprout('./copy')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
177
        b_2 = b_2_dir.open_branch()
178
        wt2 = b_2_dir.open_workingtree()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
179
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
1551.15.70 by Aaron Bentley
Avoid using builtins.merge
180
        wt2.merge_from_branch(wt.branch)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
181
        message = self.status_string(wt2, verbose=True)
2296.1.1 by Martin Pool
Make tests for truncation of status output more robust on wide terminals.
182
        self.assertStartsWith(message, "pending merges:\n")
183
        self.assertEndsWith(message, "Empty commit 2\n")
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
184
        wt2.commit("merged")
1185.16.88 by mbp at sourcefrog
Make commit message long enough in test for pending merges
185
        # must be long to make sure we see elipsis at the end
2296.1.1 by Martin Pool
Make tests for truncation of status output more robust on wide terminals.
186
        wt.commit("Empty commit 3 " +
187
                   "blah blah blah blah " * 100)
1551.15.70 by Aaron Bentley
Avoid using builtins.merge
188
        wt2.merge_from_branch(wt.branch)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
189
        message = self.status_string(wt2, verbose=True)
2296.1.1 by Martin Pool
Make tests for truncation of status output more robust on wide terminals.
190
        self.assertStartsWith(message, "pending merges:\n")
6614.1.1 by Vincent Ladeuil
Fix assert_ being deprecated by using assertTrue.
191
        self.assertTrue("Empty commit 3" in message)
2296.1.1 by Martin Pool
Make tests for truncation of status output more robust on wide terminals.
192
        self.assertEndsWith(message, "...\n")
1185.12.27 by Aaron Bentley
Use line log for pending merges
193
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
194
    def test_tree_status_ignores(self):
195
        """Tests branch status with ignores"""
196
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
197
        self.run_bzr('ignore *~')
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
198
        wt.commit('commit .bzrignore')
199
        self.build_tree(['foo.c', 'foo.c~'])
200
        self.assertStatus([
201
                'unknown:\n',
202
                '  foo.c\n',
203
                ],
204
                wt)
205
        self.assertStatus([
206
                '?   foo.c\n',
207
                ],
208
                wt, short=True)
209
210
    def test_tree_status_specific_files(self):
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
211
        """Tests branch status with given specific files"""
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
212
        wt = self.make_branch_and_tree('.')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
213
        b = wt.branch
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
214
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
215
        self.build_tree(['directory/','directory/hello.c',
216
                         'bye.c','test.c','dir2/',
217
                         'missing.c'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
218
        wt.add('directory')
219
        wt.add('test.c')
220
        wt.commit('testing')
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
221
        wt.add('missing.c')
222
        unlink('missing.c')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
223
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
224
        self.assertStatus([
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
225
                'missing:\n',
226
                '  missing.c\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
227
                'unknown:\n',
228
                '  bye.c\n',
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
229
                '  dir2/\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
230
                '  directory/hello.c\n'
231
                ],
232
                wt)
233
234
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
235
                '?   bye.c\n',
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
236
                '?   dir2/\n',
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
237
                '+!  missing.c\n',
1551.10.7 by Aaron Bentley
Use new-style output for status
238
                '?   directory/hello.c\n'
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
239
                ],
240
                wt, short=True)
241
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
242
        tof = BytesIO()
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
243
        self.assertRaises(errors.PathsDoNotExist,
244
                          show_tree_status,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
245
                          wt, specific_files=['bye.c','test.c','absent.c'],
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
246
                          to_file=tof)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
247
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
248
        tof = BytesIO()
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
249
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
250
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
251
        self.assertEqual(tof.readlines(),
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
252
                          ['unknown:\n',
253
                           '  directory/hello.c\n'
254
                           ])
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
255
        tof = BytesIO()
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
256
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
257
                         short=True)
258
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
259
        self.assertEqual(tof.readlines(), ['?   directory/hello.c\n'])
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
260
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
261
        tof = BytesIO()
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
262
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
263
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
264
        self.assertEqual(tof.readlines(),
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
265
                          ['unknown:\n',
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
266
                           '  dir2/\n'
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
267
                           ])
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
268
        tof = BytesIO()
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
269
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
270
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
271
        self.assertEqual(tof.readlines(), ['?   dir2/\n'])
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
272
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
273
        tof = BytesIO()
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
274
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
2761.1.2 by Aaron Bentley
Fix line wrapping
275
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
                         short=True, revision=revs)
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
277
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
278
        self.assertEqual(tof.readlines(), ['+N  test.c\n'])
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
279
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
280
        tof = BytesIO()
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
281
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
283
        self.assertEqual(tof.readlines(),
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
284
                          ['missing:\n',
285
                           '  missing.c\n'])
286
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
287
        tof = BytesIO()
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
288
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
289
                         short=True)
290
        tof.seek(0)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
291
        self.assertEqual(tof.readlines(),
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
292
                          ['+!  missing.c\n'])
293
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
294
    def test_specific_files_conflicts(self):
295
        tree = self.make_branch_and_tree('.')
296
        self.build_tree(['dir2/'])
297
        tree.add('dir2')
298
        tree.commit('added dir2')
299
        tree.set_conflicts(conflicts.ConflictList(
300
            [conflicts.ContentsConflict('foo')]))
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
301
        tof = BytesIO()
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
302
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
303
        self.assertEqualDiff('', tof.getvalue())
304
        tree.set_conflicts(conflicts.ConflictList(
305
            [conflicts.ContentsConflict('dir2')]))
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
306
        tof = BytesIO()
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
307
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
308
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
309
                             tof.getvalue())
310
311
        tree.set_conflicts(conflicts.ConflictList(
312
            [conflicts.ContentsConflict('dir2/file1')]))
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
313
        tof = BytesIO()
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
314
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
315
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
316
                             tof.getvalue())
317
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
318
    def _prepare_nonexistent(self):
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
319
        wt = self.make_branch_and_tree('.')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
320
        self.assertStatus([], wt)
321
        self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
322
        wt.add('FILE_A')
323
        wt.add('FILE_B')
324
        wt.add('FILE_C')
325
        wt.add('FILE_D')
326
        wt.add('FILE_E')
327
        wt.commit('Create five empty files.')
5861.2.5 by Wouter van Heyst
Fix remaining failing blackbox tests under pypy due to refcount/flush interaction.
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.')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
330
        unlink('FILE_E')  # FILE_E will be versioned but missing
5861.2.5 by Wouter van Heyst
Fix remaining failing blackbox tests under pypy due to refcount/flush interaction.
331
        with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
332
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
333
        open('UNVERSIONED_BUT_EXISTING', 'w')
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
334
        return wt
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
335
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
336
    def test_status_nonexistent_file(self):
337
        # files that don't exist in either the basis tree or working tree
338
        # should give an error
339
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
340
        self.assertStatus([
341
            'removed:\n',
342
            '  FILE_E\n',
343
            'added:\n',
344
            '  FILE_Q\n',
345
            'modified:\n',
346
            '  FILE_B\n',
347
            '  FILE_C\n',
348
            'unknown:\n',
349
            '  UNVERSIONED_BUT_EXISTING\n',
350
            ],
351
            wt)
352
        self.assertStatus([
353
            ' M  FILE_B\n',
354
            ' M  FILE_C\n',
355
            ' D  FILE_E\n',
356
            '+N  FILE_Q\n',
357
            '?   UNVERSIONED_BUT_EXISTING\n',
358
            ],
359
            wt, short=True)
360
361
        # Okay, everything's looking good with the existent files.
362
        # Let's see what happens when we throw in non-existent files.
363
6622.1.29 by Jelmer Vernooij
Fix some more tests.
364
        # brz st [--short] NONEXISTENT '
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
365
        expected = [
366
          'nonexistent:\n',
367
          '  NONEXISTENT\n',
368
          ]
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
369
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
370
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
371
        self.assertContainsRe(err,
372
                              r'.*ERROR: Path\(s\) do not exist: '
373
                              'NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
374
        expected = [
375
          'X:   NONEXISTENT\n',
376
          ]
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
377
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
378
        self.assertContainsRe(err,
379
                              r'.*ERROR: Path\(s\) do not exist: '
380
                              'NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
381
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
382
    def test_status_nonexistent_file_with_others(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
383
        # brz st [--short] NONEXISTENT ...others..
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
384
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
385
        expected = [
386
          'removed:\n',
387
          '  FILE_E\n',
388
          'modified:\n',
389
          '  FILE_B\n',
390
          '  FILE_C\n',
391
          'nonexistent:\n',
392
          '  NONEXISTENT\n',
393
          ]
394
        out, err = self.run_bzr('status NONEXISTENT '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
395
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
396
                                retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
397
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
398
        self.assertContainsRe(err,
399
                              r'.*ERROR: Path\(s\) do not exist: '
400
                              'NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
401
        expected = [
402
          ' D  FILE_E\n',
403
          ' M  FILE_C\n',
404
          ' M  FILE_B\n',
405
          'X   NONEXISTENT\n',
406
          ]
407
        out, err = self.run_bzr('status --short NONEXISTENT '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
408
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
409
                                retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
410
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
411
        self.assertContainsRe(err,
412
                              r'.*ERROR: Path\(s\) do not exist: '
413
                              'NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
414
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
415
    def test_status_multiple_nonexistent_files(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
416
        # brz st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
417
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
418
        expected = [
419
          'removed:\n',
420
          '  FILE_E\n',
421
          'modified:\n',
422
          '  FILE_B\n',
423
          '  FILE_C\n',
424
          'nonexistent:\n',
425
          '  ANOTHER_NONEXISTENT\n',
426
          '  NONEXISTENT\n',
427
          ]
428
        out, err = self.run_bzr('status NONEXISTENT '
429
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
430
                                'FILE_C FILE_D FILE_E', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
431
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
432
        self.assertContainsRe(err,
433
                              r'.*ERROR: Path\(s\) do not exist: '
434
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
435
        expected = [
436
          ' D  FILE_E\n',
437
          ' M  FILE_C\n',
438
          ' M  FILE_B\n',
439
          'X   ANOTHER_NONEXISTENT\n',
440
          'X   NONEXISTENT\n',
441
          ]
442
        out, err = self.run_bzr('status --short NONEXISTENT '
443
                                'FILE_A FILE_B ANOTHER_NONEXISTENT '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
444
                                'FILE_C FILE_D FILE_E', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
445
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
446
        self.assertContainsRe(err,
447
                              r'.*ERROR: Path\(s\) do not exist: '
448
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
449
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
450
    def test_status_nonexistent_file_with_unversioned(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
451
        # brz st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
452
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
453
        expected = [
454
          'removed:\n',
455
          '  FILE_E\n',
456
          'added:\n',
457
          '  FILE_Q\n',
458
          'modified:\n',
459
          '  FILE_B\n',
460
          '  FILE_C\n',
461
          'unknown:\n',
462
          '  UNVERSIONED_BUT_EXISTING\n',
463
          'nonexistent:\n',
464
          '  NONEXISTENT\n',
465
          ]
466
        out, err = self.run_bzr('status NONEXISTENT '
467
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
468
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
469
        self.assertEqual(expected, out.splitlines(True))
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
470
        self.assertContainsRe(err,
471
                              r'.*ERROR: Path\(s\) do not exist: '
472
                              'NONEXISTENT.*')
6619.3.18 by Jelmer Vernooij
Run 2to3 idioms fixer.
473
        expected = sorted([
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
474
          '+N  FILE_Q\n',
475
          '?   UNVERSIONED_BUT_EXISTING\n',
476
          ' D  FILE_E\n',
477
          ' M  FILE_C\n',
478
          ' M  FILE_B\n',
479
          'X   NONEXISTENT\n',
6619.3.18 by Jelmer Vernooij
Run 2to3 idioms fixer.
480
          ])
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
481
        out, err = self.run_bzr('status --short NONEXISTENT '
482
                                'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
483
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
5861.2.7 by Wouter van Heyst
Paper over different sorting order in pypy by sorting th expected and actual lists.
484
        actual = out.splitlines(True)
485
        actual.sort()
486
        self.assertEqual(expected, actual)
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
487
        self.assertContainsRe(err,
488
                              r'.*ERROR: Path\(s\) do not exist: '
489
                              'NONEXISTENT.*')
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
490
2091.4.2 by wang
add tests for "diff" and "status"
491
    def test_status_out_of_date(self):
492
        """Simulate status of out-of-date tree after remote push"""
493
        tree = self.make_branch_and_tree('.')
494
        self.build_tree_contents([('a', 'foo\n')])
495
        tree.lock_write()
496
        try:
497
            tree.add(['a'])
498
            tree.commit('add test file')
499
            # simulate what happens after a remote push
500
            tree.set_last_revision("0")
501
        finally:
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
502
            # before run another commands we should unlock tree
2091.4.2 by wang
add tests for "diff" and "status"
503
            tree.unlock()
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
504
        out, err = self.run_bzr('status')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
505
        self.assertEqual("working tree is out of date, run 'brz update'\n",
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
506
                         err)
2091.4.2 by wang
add tests for "diff" and "status"
507
5137.2.2 by Arnaud Jeansen
Add a unit test for LP: #40103 (status on an ignored file)
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
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
515
        self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
5137.2.2 by Arnaud Jeansen
Add a unit test for LP: #40103 (status on an ignored file)
516
        result = self.run_bzr('status')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
517
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
5137.2.3 by Arnaud Jeansen
Rework unit test according to feedback
518
        short_result = self.run_bzr('status --short')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
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")
5137.2.2 by Arnaud Jeansen
Add a unit test for LP: #40103 (status on an ignored file)
540
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
541
    def test_status_write_lock(self):
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
542
        """Test that status works without fetching history and
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
543
        having a write lock.
544
545
        See https://bugs.launchpad.net/bzr/+bug/149270
546
        """
547
        mkdir('branch1')
548
        wt = self.make_branch_and_tree('branch1')
549
        b = wt.branch
550
        wt.commit('Empty commit 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
551
        wt2 = b.controldir.sprout('branch2').open_workingtree()
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
552
        wt2.commit('Empty commit 2')
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
553
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
554
        self.assertEqual('', out)
555
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
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',
6622.1.29 by Jelmer Vernooij
Fix some more tests.
568
                '1 shelf exists. See "brz shelve --list" for details.\n',
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
569
            ],
570
            wt)
571
        self.run_bzr(['shelve', '--all', '-m', 'bar'])
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
572
        self.build_tree(['eggs.c', 'spam.c'])
573
        wt.add('eggs.c')
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
574
        wt.add('spam.c')
575
        self.assertStatus([
576
                'added:\n',
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
577
                '  eggs.c\n',
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
578
                '  spam.c\n',
6622.1.29 by Jelmer Vernooij
Fix some more tests.
579
                '2 shelves exist. See "brz shelve --list" for details.\n',
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
580
            ],
581
            wt)
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
582
        self.assertStatus([
583
                'added:\n',
584
                '  spam.c\n',
585
            ],
586
            wt,
587
            specific_files=['spam.c'])
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
588
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
589
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
590
class CheckoutStatus(BranchStatus):
1551.2.12 by Aaron Bentley
whitespace fixups
591
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
592
    def setUp(self):
593
        super(CheckoutStatus, self).setUp()
594
        mkdir('codir')
595
        chdir('codir')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
596
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
597
    def make_branch_and_tree(self, relpath):
598
        source = self.make_branch(pathjoin('..', relpath))
599
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
6437.7.3 by Jelmer Vernooij
Use ControlDir.set_branch_reference.
600
        checkout.set_branch_reference(source)
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
601
        return checkout.create_workingtree()
602
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
603
1534.4.54 by Robert Collins
Merge from integration.
604
class TestStatus(TestCaseWithTransport):
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
605
2318.2.1 by Kent Gibson
Apply status versioned patch
606
    def test_status_plain(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
607
        tree = self.make_branch_and_tree('.')
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
608
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
609
        self.build_tree(['hello.txt'])
610
        result = self.run_bzr("status")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
611
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
612
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
613
        tree.add("hello.txt")
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
614
        result = self.run_bzr("status")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
615
        self.assertContainsRe(result, "added:\n  hello.txt\n")
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
616
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
617
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
618
        result = self.run_bzr("status -r 0..1")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
619
        self.assertContainsRe(result, "added:\n  hello.txt\n")
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
620
2745.4.3 by Lukáš Lalinsky
Change -C to -c.
621
        result = self.run_bzr("status -c 1")[0]
2745.4.1 by Lukáš Lalinsky
New option -C/--change for diff and status to show changes in one revision. (#56299)
622
        self.assertContainsRe(result, "added:\n  hello.txt\n")
623
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
624
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
625
        result = self.run_bzr("status -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
626
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
627
                                      "unknown:\n  world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
628
        result2 = self.run_bzr("status -r 0..")[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
629
        self.assertEqual(result2, result)
2318.2.1 by Kent Gibson
Apply status versioned patch
630
631
    def test_status_short(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
632
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
633
634
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
635
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
636
        self.assertContainsRe(result, "[?]   hello.txt\n")
637
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
638
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
639
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
640
        self.assertContainsRe(result, "[+]N  hello.txt\n")
641
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
642
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
643
        result = self.run_bzr("status --short -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
644
        self.assertContainsRe(result, "[+]N  hello.txt\n")
645
646
        self.build_tree(['world.txt'])
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
647
        result = self.run_bzr("status -S -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
648
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
649
                                      "[?]   world.txt\n")
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
650
        result2 = self.run_bzr("status -S -r 0..")[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
651
        self.assertEqual(result2, result)
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
652
2318.2.1 by Kent Gibson
Apply status versioned patch
653
    def test_status_versioned(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
654
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
655
656
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
657
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
658
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
659
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
660
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
661
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
662
        self.assertContainsRe(result, "added:\n  hello.txt\n")
663
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
664
        tree.commit("added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
665
        result = self.run_bzr("status --versioned -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
666
        self.assertContainsRe(result, "added:\n  hello.txt\n")
667
668
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
669
        result = self.run_bzr("status --versioned -r 0")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
670
        self.assertContainsRe(result, "added:\n  hello.txt\n")
671
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
672
        result2 = self.run_bzr("status --versioned -r 0..")[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
673
        self.assertEqual(result2, result)
2318.2.1 by Kent Gibson
Apply status versioned patch
674
2663.1.7 by Daniel Watkins
Capitalised short names.
675
    def test_status_SV(self):
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
676
        tree = self.make_branch_and_tree('.')
677
678
        self.build_tree(['hello.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
679
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
680
        self.assertNotContainsRe(result, "hello.txt")
681
682
        tree.add("hello.txt")
2663.1.7 by Daniel Watkins
Capitalised short names.
683
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
684
        self.assertContainsRe(result, "[+]N  hello.txt\n")
685
686
        tree.commit(message="added")
2663.1.7 by Daniel Watkins
Capitalised short names.
687
        result = self.run_bzr("status -SV -r 0..1")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
688
        self.assertContainsRe(result, "[+]N  hello.txt\n")
689
690
        self.build_tree(['world.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
691
        result = self.run_bzr("status -SV -r 0")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
692
        self.assertContainsRe(result, "[+]N  hello.txt\n")
693
2663.1.7 by Daniel Watkins
Capitalised short names.
694
        result2 = self.run_bzr("status -SV -r 0..")[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
695
        self.assertEqual(result2, result)
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
696
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
697
    def assertStatusContains(self, pattern, short=False):
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
698
        """Run status, and assert it contains the given pattern"""
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
699
        if short:
700
            result = self.run_bzr("status --short")[0]
701
        else:
702
            result = self.run_bzr("status")[0]
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
703
        self.assertContainsRe(result, pattern)
704
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
705
    def test_kind_change_plain(self):
706
        tree = self.make_branch_and_tree('.')
707
        self.build_tree(['file'])
708
        tree.add('file')
709
        tree.commit('added file')
710
        unlink('file')
711
        self.build_tree(['file/'])
712
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
713
        tree.rename_one('file', 'directory')
5076.3.2 by Arnaud Jeansen
Formatting : handle long strings similarly to other tests
714
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
715
                                  'modified:\n  directory/\n')
716
        rmdir('directory')
717
        self.assertStatusContains('removed:\n  file\n')
718
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
719
    def test_kind_change_short(self):
720
        tree = self.make_branch_and_tree('.')
721
        self.build_tree(['file'])
722
        tree.add('file')
723
        tree.commit('added file')
724
        unlink('file')
725
        self.build_tree(['file/'])
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
726
        self.assertStatusContains('K  file => file/',
727
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
728
        tree.rename_one('file', 'directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
729
        self.assertStatusContains('RK  file => directory/',
730
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
731
        rmdir('directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
732
        self.assertStatusContains('RD  file => directory',
733
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
734
2745.4.1 by Lukáš Lalinsky
New option -C/--change for diff and status to show changes in one revision. (#56299)
735
    def test_status_illegal_revision_specifiers(self):
736
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
737
        self.assertContainsRe(err, 'one or two revision specifiers')
738
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
739
    def test_status_no_pending(self):
740
        a_tree = self.make_branch_and_tree('a')
741
        self.build_tree(['a/a'])
742
        a_tree.add('a')
743
        a_tree.commit('a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
744
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
745
        self.build_tree(['b/b'])
746
        b_tree.add('b')
747
        b_tree.commit('b')
748
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
749
        self.run_bzr('merge ../b', working_dir='a')
750
        out, err = self.run_bzr('status --no-pending', working_dir='a')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
751
        self.assertEqual(out, "added:\n  b\n")
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
752
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
753
    def test_pending_specific_files(self):
754
        """With a specific file list, pending merges are not shown."""
755
        tree = self.make_branch_and_tree('tree')
756
        self.build_tree_contents([('tree/a', 'content of a\n')])
757
        tree.add('a')
758
        r1_id = tree.commit('one')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
759
        alt = tree.controldir.sprout('alt').open_workingtree()
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
760
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
761
        alt_id = alt.commit('alt')
762
        tree.merge_from_branch(alt.branch)
3655.2.1 by Lukáš Lalinský
Fix test_pending_specific_files
763
        output = self.make_utf8_encoded_stringio()
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
764
        show_tree_status(tree, to_file=output)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
765
        self.assertContainsRe(output.getvalue(), 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
766
        out, err = self.run_bzr('status tree/a')
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
767
        self.assertNotContainsRe(out, 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
768
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
769
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
770
class TestStatusEncodings(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
771
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
772
    def make_uncommitted_tree(self):
773
        """Build a branch with uncommitted unicode named changes in the cwd."""
774
        working_tree = self.make_branch_and_tree(u'.')
775
        filename = u'hell\u00d8'
776
        try:
777
            self.build_tree_contents([(filename, 'contents of hello')])
778
        except UnicodeEncodeError:
779
            raise TestSkipped("can't build unicode working tree in "
780
                "filesystem encoding %s" % sys.getfilesystemencoding())
781
        working_tree.add(filename)
782
        return working_tree
783
784
    def test_stdout_ascii(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
785
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
786
        working_tree = self.make_uncommitted_tree()
787
        stdout, stderr = self.run_bzr("status")
788
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
789
        self.assertEqual(stdout, """\
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
790
added:
791
  hell?
792
""")
793
794
    def test_stdout_latin1(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
795
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
796
        working_tree = self.make_uncommitted_tree()
797
        stdout, stderr = self.run_bzr('status')
798
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
799
        self.assertEqual(stdout, u"""\
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
800
added:
801
  hell\u00d8
802
""".encode('latin-1'))
803