~bzr-pqm/bzr/bzr.dev

4597.9.2 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2005-2010 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
1185.33.71 by Martin Pool
Status tests include unicode character.
25
from cStringIO import StringIO
1685.1.80 by Wouter van Heyst
more code cleanup
26
import codecs
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
27
from os import mkdir, chdir, rmdir, unlink
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
28
import sys
1185.33.71 by Martin Pool
Status tests include unicode character.
29
from tempfile import TemporaryFile
30
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
31
from bzrlib import (
32
    bzrdir,
33
    conflicts,
34
    errors,
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
35
    osutils,
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
36
    status,
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
37
    )
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
38
import bzrlib.branch
39
from bzrlib.osutils import pathjoin
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
40
from bzrlib.revisionspec import RevisionSpec
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
41
from bzrlib.status import show_tree_status
1685.1.75 by Wouter van Heyst
more tests handle LANG=C
42
from bzrlib.tests import TestCaseWithTransport, TestSkipped
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
43
from bzrlib.workingtree import WorkingTree
44
915 by Martin Pool
- add simple test case for bzr status
45
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.
46
class BranchStatus(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
47
5508.1.1 by John Arbash Meinel
Fix bug #662053, 'bzr status' shouldn't fail
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
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
56
    def assertStatus(self, expected_lines, working_tree, specific_files=None,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
57
        revision=None, short=False, pending=True, verbose=False):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
58
        """Run status in working_tree and look for output.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
59
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
60
        :param expected_lines: The lines to look for.
1927.2.3 by Robert Collins
review comment application - paired with Martin.
61
        :param working_tree: The tree to run status in.
62
        """
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
63
        output_string = self.status_string(working_tree, specific_files, revision, short,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
64
                pending, verbose)
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
65
        self.assertEqual(expected_lines, output_string.splitlines(True))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
66
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
67
    def status_string(self, wt, specific_files=None, revision=None,
68
        short=False, pending=True, verbose=False):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
69
        # use a real file rather than StringIO because it doesn't handle
70
        # Unicode very well.
71
        tof = codecs.getwriter('utf-8')(TemporaryFile())
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
72
        show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
                revision=revision, short=short, show_pending=pending,
74
                verbose=verbose)
1927.2.3 by Robert Collins
review comment application - paired with Martin.
75
        tof.seek(0)
76
        return tof.read().decode('utf-8')
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")
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.
176
        b_2_dir = b.bzrdir.sprout('./copy')
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")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
191
        self.assert_("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
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
242
        tof = StringIO()
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
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
248
        tof = StringIO()
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)
251
        self.assertEquals(tof.readlines(),
252
                          ['unknown:\n',
253
                           '  directory/hello.c\n'
254
                           ])
255
        tof = StringIO()
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)
1551.10.7 by Aaron Bentley
Use new-style output for status
259
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
260
261
        tof = StringIO()
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)
264
        self.assertEquals(tof.readlines(),
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
                           ])
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
268
        tof = StringIO()
269
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
270
        tof.seek(0)
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
271
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
272
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
273
        tof = StringIO()
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)
278
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
279
5504.5.1 by Rory Yorke
Show missing files in bzr status (bug 134168).
280
        tof = StringIO()
281
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
282
        tof.seek(0)
283
        self.assertEquals(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.assertEquals(tof.readlines(),
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')]))
301
        tof = StringIO()
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')]))
306
        tof = StringIO()
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')]))
313
        tof = StringIO()
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
364
        # bzr st [--short] NONEXISTENT '
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):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
383
        # bzr 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):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
416
        # bzr 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):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
451
        # bzr 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.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
473
        expected = [
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',
480
          ]
5861.2.7 by Wouter van Heyst
Paper over different sorting order in pypy by sorting th expected and actual lists.
481
        expected.sort()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
482
        out, err = self.run_bzr('status --short NONEXISTENT '
483
                                '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
484
                                '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.
485
        actual = out.splitlines(True)
486
        actual.sort()
487
        self.assertEqual(expected, actual)
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
488
        self.assertContainsRe(err,
489
                              r'.*ERROR: Path\(s\) do not exist: '
490
                              'NONEXISTENT.*')
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
491
2091.4.2 by wang
add tests for "diff" and "status"
492
    def test_status_out_of_date(self):
493
        """Simulate status of out-of-date tree after remote push"""
494
        tree = self.make_branch_and_tree('.')
495
        self.build_tree_contents([('a', 'foo\n')])
496
        tree.lock_write()
497
        try:
498
            tree.add(['a'])
499
            tree.commit('add test file')
500
            # simulate what happens after a remote push
501
            tree.set_last_revision("0")
502
        finally:
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
503
            # before run another commands we should unlock tree
2091.4.2 by wang
add tests for "diff" and "status"
504
            tree.unlock()
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
505
        out, err = self.run_bzr('status')
506
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
507
                         err)
2091.4.2 by wang
add tests for "diff" and "status"
508
5137.2.2 by Arnaud Jeansen
Add a unit test for LP: #40103 (status on an ignored file)
509
    def test_status_on_ignored(self):
510
        """Tests branch status on an unversioned file which is considered ignored.
511
512
        See https://bugs.launchpad.net/bzr/+bug/40103
513
        """
514
        tree = self.make_branch_and_tree('.')
515
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
516
        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)
517
        result = self.run_bzr('status')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
518
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
5137.2.3 by Arnaud Jeansen
Rework unit test according to feedback
519
        short_result = self.run_bzr('status --short')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
520
        self.assertContainsRe(short_result, "\?   test1.c\n")
521
522
        result = self.run_bzr('status test1.c')[0]
523
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
524
        short_result = self.run_bzr('status --short test1.c')[0]
525
        self.assertContainsRe(short_result, "\?   test1.c\n")
526
527
        result = self.run_bzr('status test1.c~')[0]
528
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
529
        short_result = self.run_bzr('status --short test1.c~')[0]
530
        self.assertContainsRe(short_result, "I   test1.c~\n")
531
532
        result = self.run_bzr('status test1.c~ test2.c~')[0]
533
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
534
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
535
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
536
537
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
538
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
539
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
540
        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)
541
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
542
    def test_status_write_lock(self):
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
543
        """Test that status works without fetching history and
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
544
        having a write lock.
545
546
        See https://bugs.launchpad.net/bzr/+bug/149270
547
        """
548
        mkdir('branch1')
549
        wt = self.make_branch_and_tree('branch1')
550
        b = wt.branch
551
        wt.commit('Empty commit 1')
552
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
553
        wt2.commit('Empty commit 2')
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
554
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
555
        self.assertEqual('', out)
556
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
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',
5609.11.2 by Alexander Belchenko
correct singular form, thanks John
569
                '1 shelf exists. See "bzr shelve --list" for details.\n',
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
570
            ],
571
            wt)
572
        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
573
        self.build_tree(['eggs.c', 'spam.c'])
574
        wt.add('eggs.c')
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
575
        wt.add('spam.c')
576
        self.assertStatus([
577
                'added:\n',
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
578
                '  eggs.c\n',
5609.11.1 by Alexander Belchenko
use proper plural form to print status message about existing shelves.
579
                '  spam.c\n',
580
                '2 shelves exist. See "bzr shelve --list" for details.\n',
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
581
            ],
582
            wt)
6282.4.3 by Francis Devereux
Test that shelf summary is not included in status when files are specified
583
        self.assertStatus([
584
                'added:\n',
585
                '  spam.c\n',
586
            ],
587
            wt,
588
            specific_files=['spam.c'])
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
589
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
590
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
591
class CheckoutStatus(BranchStatus):
1551.2.12 by Aaron Bentley
whitespace fixups
592
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
593
    def setUp(self):
594
        super(CheckoutStatus, self).setUp()
595
        mkdir('codir')
596
        chdir('codir')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
597
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
598
    def make_branch_and_tree(self, relpath):
599
        source = self.make_branch(pathjoin('..', relpath))
600
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
6437.7.3 by Jelmer Vernooij
Use ControlDir.set_branch_reference.
601
        checkout.set_branch_reference(source)
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
602
        return checkout.create_workingtree()
603
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
604
1534.4.54 by Robert Collins
Merge from integration.
605
class TestStatus(TestCaseWithTransport):
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
606
2318.2.1 by Kent Gibson
Apply status versioned patch
607
    def test_status_plain(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
608
        tree = self.make_branch_and_tree('.')
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
609
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
610
        self.build_tree(['hello.txt'])
611
        result = self.run_bzr("status")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
612
        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.
613
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
614
        tree.add("hello.txt")
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
615
        result = self.run_bzr("status")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
616
        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.
617
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
618
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
619
        result = self.run_bzr("status -r 0..1")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
620
        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.
621
2745.4.3 by Lukáš Lalinsky
Change -C to -c.
622
        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)
623
        self.assertContainsRe(result, "added:\n  hello.txt\n")
624
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
625
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
626
        result = self.run_bzr("status -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
627
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
628
                                      "unknown:\n  world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
629
        result2 = self.run_bzr("status -r 0..")[0]
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
630
        self.assertEquals(result2, result)
2318.2.1 by Kent Gibson
Apply status versioned patch
631
632
    def test_status_short(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
633
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
634
635
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
636
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
637
        self.assertContainsRe(result, "[?]   hello.txt\n")
638
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
639
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
640
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
641
        self.assertContainsRe(result, "[+]N  hello.txt\n")
642
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
643
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
644
        result = self.run_bzr("status --short -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
645
        self.assertContainsRe(result, "[+]N  hello.txt\n")
646
647
        self.build_tree(['world.txt'])
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
648
        result = self.run_bzr("status -S -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
649
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
650
                                      "[?]   world.txt\n")
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
651
        result2 = self.run_bzr("status -S -r 0..")[0]
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
652
        self.assertEquals(result2, result)
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
653
2318.2.1 by Kent Gibson
Apply status versioned patch
654
    def test_status_versioned(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
655
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
656
657
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
658
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
659
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
660
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
661
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
662
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
663
        self.assertContainsRe(result, "added:\n  hello.txt\n")
664
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
665
        tree.commit("added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
666
        result = self.run_bzr("status --versioned -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
667
        self.assertContainsRe(result, "added:\n  hello.txt\n")
668
669
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
670
        result = self.run_bzr("status --versioned -r 0")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
671
        self.assertContainsRe(result, "added:\n  hello.txt\n")
672
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
673
        result2 = self.run_bzr("status --versioned -r 0..")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
674
        self.assertEquals(result2, result)
675
2663.1.7 by Daniel Watkins
Capitalised short names.
676
    def test_status_SV(self):
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
677
        tree = self.make_branch_and_tree('.')
678
679
        self.build_tree(['hello.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
680
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
681
        self.assertNotContainsRe(result, "hello.txt")
682
683
        tree.add("hello.txt")
2663.1.7 by Daniel Watkins
Capitalised short names.
684
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
685
        self.assertContainsRe(result, "[+]N  hello.txt\n")
686
687
        tree.commit(message="added")
2663.1.7 by Daniel Watkins
Capitalised short names.
688
        result = self.run_bzr("status -SV -r 0..1")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
689
        self.assertContainsRe(result, "[+]N  hello.txt\n")
690
691
        self.build_tree(['world.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
692
        result = self.run_bzr("status -SV -r 0")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
693
        self.assertContainsRe(result, "[+]N  hello.txt\n")
694
2663.1.7 by Daniel Watkins
Capitalised short names.
695
        result2 = self.run_bzr("status -SV -r 0..")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
696
        self.assertEquals(result2, result)
697
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
698
    def assertStatusContains(self, pattern, short=False):
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
699
        """Run status, and assert it contains the given pattern"""
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
700
        if short:
701
            result = self.run_bzr("status --short")[0]
702
        else:
703
            result = self.run_bzr("status")[0]
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
704
        self.assertContainsRe(result, pattern)
705
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
706
    def test_kind_change_plain(self):
707
        tree = self.make_branch_and_tree('.')
708
        self.build_tree(['file'])
709
        tree.add('file')
710
        tree.commit('added file')
711
        unlink('file')
712
        self.build_tree(['file/'])
713
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
714
        tree.rename_one('file', 'directory')
5076.3.2 by Arnaud Jeansen
Formatting : handle long strings similarly to other tests
715
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
716
                                  'modified:\n  directory/\n')
717
        rmdir('directory')
718
        self.assertStatusContains('removed:\n  file\n')
719
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
720
    def test_kind_change_short(self):
721
        tree = self.make_branch_and_tree('.')
722
        self.build_tree(['file'])
723
        tree.add('file')
724
        tree.commit('added file')
725
        unlink('file')
726
        self.build_tree(['file/'])
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
727
        self.assertStatusContains('K  file => file/',
728
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
729
        tree.rename_one('file', 'directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
730
        self.assertStatusContains('RK  file => directory/',
731
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
732
        rmdir('directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
733
        self.assertStatusContains('RD  file => directory',
734
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
735
2745.4.1 by Lukáš Lalinsky
New option -C/--change for diff and status to show changes in one revision. (#56299)
736
    def test_status_illegal_revision_specifiers(self):
737
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
738
        self.assertContainsRe(err, 'one or two revision specifiers')
739
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
740
    def test_status_no_pending(self):
741
        a_tree = self.make_branch_and_tree('a')
742
        self.build_tree(['a/a'])
743
        a_tree.add('a')
744
        a_tree.commit('a')
745
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
746
        self.build_tree(['b/b'])
747
        b_tree.add('b')
748
        b_tree.commit('b')
749
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
750
        self.run_bzr('merge ../b', working_dir='a')
751
        out, err = self.run_bzr('status --no-pending', working_dir='a')
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
752
        self.assertEquals(out, "added:\n  b\n")
753
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
754
    def test_pending_specific_files(self):
755
        """With a specific file list, pending merges are not shown."""
756
        tree = self.make_branch_and_tree('tree')
757
        self.build_tree_contents([('tree/a', 'content of a\n')])
758
        tree.add('a')
759
        r1_id = tree.commit('one')
760
        alt = tree.bzrdir.sprout('alt').open_workingtree()
761
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
762
        alt_id = alt.commit('alt')
763
        tree.merge_from_branch(alt.branch)
3655.2.1 by Lukáš Lalinský
Fix test_pending_specific_files
764
        output = self.make_utf8_encoded_stringio()
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
765
        show_tree_status(tree, to_file=output)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
766
        self.assertContainsRe(output.getvalue(), 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
767
        out, err = self.run_bzr('status tree/a')
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
768
        self.assertNotContainsRe(out, 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
769
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
770
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
771
class TestStatusEncodings(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
772
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
773
    def make_uncommitted_tree(self):
774
        """Build a branch with uncommitted unicode named changes in the cwd."""
775
        working_tree = self.make_branch_and_tree(u'.')
776
        filename = u'hell\u00d8'
777
        try:
778
            self.build_tree_contents([(filename, 'contents of hello')])
779
        except UnicodeEncodeError:
780
            raise TestSkipped("can't build unicode working tree in "
781
                "filesystem encoding %s" % sys.getfilesystemencoding())
782
        working_tree.add(filename)
783
        return working_tree
784
785
    def test_stdout_ascii(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
786
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
787
        working_tree = self.make_uncommitted_tree()
788
        stdout, stderr = self.run_bzr("status")
789
790
        self.assertEquals(stdout, """\
791
added:
792
  hell?
793
""")
794
795
    def test_stdout_latin1(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
796
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
797
        working_tree = self.make_uncommitted_tree()
798
        stdout, stderr = self.run_bzr('status')
799
800
        self.assertEquals(stdout, u"""\
801
added:
802
  hell\u00d8
803
""".encode('latin-1'))
804