~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
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
48
    def assertStatus(self, expected_lines, working_tree,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
49
        revision=None, short=False, pending=True, verbose=False):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
50
        """Run status in working_tree and look for output.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
51
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
52
        :param expected_lines: The lines to look for.
1927.2.3 by Robert Collins
review comment application - paired with Martin.
53
        :param working_tree: The tree to run status in.
54
        """
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
55
        output_string = self.status_string(working_tree, revision, short,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
56
                pending, verbose)
2255.7.60 by Robert Collins
Make the assertStatus blackbox helper clearer.
57
        self.assertEqual(expected_lines, output_string.splitlines(True))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
58
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
59
    def status_string(self, wt, revision=None, short=False, pending=True,
60
        verbose=False):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
61
        # use a real file rather than StringIO because it doesn't handle
62
        # Unicode very well.
63
        tof = codecs.getwriter('utf-8')(TemporaryFile())
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
64
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
65
                show_pending=pending, verbose=verbose)
1927.2.3 by Robert Collins
review comment application - paired with Martin.
66
        tof.seek(0)
67
        return tof.read().decode('utf-8')
68
1836.1.16 by John Arbash Meinel
Cleanup some tests which don't expect .bazaar/ to show up. Some still fail.
69
    def test_branch_status(self):
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
70
        """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.
71
        wt = self.make_branch_and_tree('.')
1927.2.3 by Robert Collins
review comment application - paired with Martin.
72
73
        # status with no commits or files - it must
74
        # work and show no output. We do this with no
75
        # commits to be sure that it's not going to fail
76
        # as a corner case.
77
        self.assertStatus([], wt)
78
79
        self.build_tree(['hello.c', 'bye.c'])
80
        self.assertStatus([
81
                'unknown:\n',
82
                '  bye.c\n',
83
                '  hello.c\n',
84
            ],
85
            wt)
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
86
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
87
                '?   bye.c\n',
88
                '?   hello.c\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
89
            ],
90
            wt, short=True)
1927.2.3 by Robert Collins
review comment application - paired with Martin.
91
92
        # 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.
93
        wt.commit('create a parent to allow testing merge output')
915 by Martin Pool
- add simple test case for bzr status
94
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
95
        wt.add_parent_tree_id('pending@pending-0-0')
1927.2.3 by Robert Collins
review comment application - paired with Martin.
96
        self.assertStatus([
97
                'unknown:\n',
98
                '  bye.c\n',
99
                '  hello.c\n',
3936.2.3 by Ian Clatworthy
feedback from jameinel
100
                'pending merge tips: (use -v to see all merge revisions)\n',
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
101
                '  (ghost) pending@pending-0-0\n',
102
            ],
103
            wt)
104
        self.assertStatus([
105
                'unknown:\n',
106
                '  bye.c\n',
107
                '  hello.c\n',
1927.2.3 by Robert Collins
review comment application - paired with Martin.
108
                'pending merges:\n',
3377.3.41 by John Arbash Meinel
Fix up a couple of the tests
109
                '  (ghost) pending@pending-0-0\n',
1927.2.3 by Robert Collins
review comment application - paired with Martin.
110
            ],
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
111
            wt, verbose=True)
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
112
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
113
                '?   bye.c\n',
114
                '?   hello.c\n',
3377.3.41 by John Arbash Meinel
Fix up a couple of the tests
115
                'P   (ghost) pending@pending-0-0\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
116
            ],
117
            wt, short=True)
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
118
        self.assertStatus([
119
                'unknown:\n',
120
                '  bye.c\n',
121
                '  hello.c\n',
122
            ],
123
            wt, pending=False)
124
        self.assertStatus([
125
                '?   bye.c\n',
126
                '?   hello.c\n',
127
            ],
128
            wt, short=True, pending=False)
915 by Martin Pool
- add simple test case for bzr status
129
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
130
    def test_branch_status_revisions(self):
131
        """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.
132
        wt = self.make_branch_and_tree('.')
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
133
134
        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.
135
        wt.add('hello.c')
136
        wt.add('bye.c')
137
        wt.commit('Test message')
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
138
1948.4.36 by John Arbash Meinel
[merge] bzr.dev 1978
139
        revs = [RevisionSpec.from_string('0')]
1927.2.3 by Robert Collins
review comment application - paired with Martin.
140
        self.assertStatus([
141
                'added:\n',
142
                '  bye.c\n',
143
                '  hello.c\n'
144
            ],
145
            wt,
146
            revision=revs)
1185.1.35 by Robert Collins
Heikki Paajanen's status -r patch
147
148
        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.
149
        wt.add('more.c')
150
        wt.commit('Another test message')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
151
1948.4.33 by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin)
152
        revs.append(RevisionSpec.from_string('1'))
1927.2.3 by Robert Collins
review comment application - paired with Martin.
153
        self.assertStatus([
154
                'added:\n',
155
                '  bye.c\n',
156
                '  hello.c\n',
157
            ],
158
            wt,
159
            revision=revs)
1185.12.27 by Aaron Bentley
Use line log for pending merges
160
161
    def test_pending(self):
1185.33.71 by Martin Pool
Status tests include unicode character.
162
        """Pending merges display works, including Unicode"""
1185.12.27 by Aaron Bentley
Use line log for pending merges
163
        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.
164
        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.
165
        b = wt.branch
166
        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.
167
        b_2_dir = b.bzrdir.sprout('./copy')
168
        b_2 = b_2_dir.open_branch()
169
        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.
170
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
1551.15.70 by Aaron Bentley
Avoid using builtins.merge
171
        wt2.merge_from_branch(wt.branch)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
172
        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.
173
        self.assertStartsWith(message, "pending merges:\n")
174
        self.assertEndsWith(message, "Empty commit 2\n")
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
175
        wt2.commit("merged")
1185.16.88 by mbp at sourcefrog
Make commit message long enough in test for pending merges
176
        # 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.
177
        wt.commit("Empty commit 3 " +
178
                   "blah blah blah blah " * 100)
1551.15.70 by Aaron Bentley
Avoid using builtins.merge
179
        wt2.merge_from_branch(wt.branch)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
180
        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.
181
        self.assertStartsWith(message, "pending merges:\n")
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
182
        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.
183
        self.assertEndsWith(message, "...\n")
1185.12.27 by Aaron Bentley
Use line log for pending merges
184
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
185
    def test_tree_status_ignores(self):
186
        """Tests branch status with ignores"""
187
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
188
        self.run_bzr('ignore *~')
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
189
        wt.commit('commit .bzrignore')
190
        self.build_tree(['foo.c', 'foo.c~'])
191
        self.assertStatus([
192
                'unknown:\n',
193
                '  foo.c\n',
194
                ],
195
                wt)
196
        self.assertStatus([
197
                '?   foo.c\n',
198
                ],
199
                wt, short=True)
200
201
    def test_tree_status_specific_files(self):
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
202
        """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.
203
        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.
204
        b = wt.branch
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
205
206
        self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
207
        wt.add('directory')
208
        wt.add('test.c')
209
        wt.commit('testing')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
210
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
211
        self.assertStatus([
212
                'unknown:\n',
213
                '  bye.c\n',
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
214
                '  dir2/\n',
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
215
                '  directory/hello.c\n'
216
                ],
217
                wt)
218
219
        self.assertStatus([
1551.10.7 by Aaron Bentley
Use new-style output for status
220
                '?   bye.c\n',
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
221
                '?   dir2/\n',
1551.10.7 by Aaron Bentley
Use new-style output for status
222
                '?   directory/hello.c\n'
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
223
                ],
224
                wt, short=True)
225
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
226
        tof = StringIO()
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
227
        self.assertRaises(errors.PathsDoNotExist,
228
                          show_tree_status,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
229
                          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
230
                          to_file=tof)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
231
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
232
        tof = StringIO()
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
233
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
234
        tof.seek(0)
235
        self.assertEquals(tof.readlines(),
236
                          ['unknown:\n',
237
                           '  directory/hello.c\n'
238
                           ])
239
        tof = StringIO()
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
240
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
241
                         short=True)
242
        tof.seek(0)
1551.10.7 by Aaron Bentley
Use new-style output for status
243
        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.
244
245
        tof = StringIO()
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
246
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
247
        tof.seek(0)
248
        self.assertEquals(tof.readlines(),
249
                          ['unknown:\n',
2255.7.91 by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan.
250
                           '  dir2/\n'
1399 by Robert Collins
Patch from Heikki Paajanen testing status on specific files
251
                           ])
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
252
        tof = StringIO()
253
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
254
        tof.seek(0)
2255.7.97 by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short.
255
        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)
256
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
257
        tof = StringIO()
258
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
2761.1.2 by Aaron Bentley
Fix line wrapping
259
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
260
                         short=True, revision=revs)
2748.2.1 by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts.
261
        tof.seek(0)
262
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
263
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
264
    def test_specific_files_conflicts(self):
265
        tree = self.make_branch_and_tree('.')
266
        self.build_tree(['dir2/'])
267
        tree.add('dir2')
268
        tree.commit('added dir2')
269
        tree.set_conflicts(conflicts.ConflictList(
270
            [conflicts.ContentsConflict('foo')]))
271
        tof = StringIO()
272
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
273
        self.assertEqualDiff('', tof.getvalue())
274
        tree.set_conflicts(conflicts.ConflictList(
275
            [conflicts.ContentsConflict('dir2')]))
276
        tof = StringIO()
277
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
278
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
279
                             tof.getvalue())
280
281
        tree.set_conflicts(conflicts.ConflictList(
282
            [conflicts.ContentsConflict('dir2/file1')]))
283
        tof = StringIO()
284
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
285
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
286
                             tof.getvalue())
287
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
288
    def _prepare_nonexistent(self):
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
289
        wt = self.make_branch_and_tree('.')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
290
        self.assertStatus([], wt)
291
        self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
292
        wt.add('FILE_A')
293
        wt.add('FILE_B')
294
        wt.add('FILE_C')
295
        wt.add('FILE_D')
296
        wt.add('FILE_E')
297
        wt.commit('Create five empty files.')
298
        open('FILE_B', 'w').write('Modification to file FILE_B.')
299
        open('FILE_C', 'w').write('Modification to file FILE_C.')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
300
        unlink('FILE_E')  # FILE_E will be versioned but missing
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
301
        open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
302
        wt.add('FILE_Q')  # FILE_Q will be added but not committed
303
        open('UNVERSIONED_BUT_EXISTING', 'w')
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
304
        return wt
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
305
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
306
    def test_status_nonexistent_file(self):
307
        # files that don't exist in either the basis tree or working tree
308
        # should give an error
309
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
310
        self.assertStatus([
311
            'removed:\n',
312
            '  FILE_E\n',
313
            'added:\n',
314
            '  FILE_Q\n',
315
            'modified:\n',
316
            '  FILE_B\n',
317
            '  FILE_C\n',
318
            'unknown:\n',
319
            '  UNVERSIONED_BUT_EXISTING\n',
320
            ],
321
            wt)
322
        self.assertStatus([
323
            ' M  FILE_B\n',
324
            ' M  FILE_C\n',
325
            ' D  FILE_E\n',
326
            '+N  FILE_Q\n',
327
            '?   UNVERSIONED_BUT_EXISTING\n',
328
            ],
329
            wt, short=True)
330
331
        # Okay, everything's looking good with the existent files.
332
        # Let's see what happens when we throw in non-existent files.
333
334
        # bzr st [--short] NONEXISTENT '
335
        expected = [
336
          'nonexistent:\n',
337
          '  NONEXISTENT\n',
338
          ]
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
339
        out, err = self.run_bzr('status NONEXISTENT', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
340
        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
341
        self.assertContainsRe(err,
342
                              r'.*ERROR: Path\(s\) do not exist: '
343
                              'NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
344
        expected = [
345
          'X:   NONEXISTENT\n',
346
          ]
3930.2.13 by Karl Fogel
Part of bug #306394: Raise an error (code 3) when status is invoked on
347
        out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
348
        self.assertContainsRe(err,
349
                              r'.*ERROR: Path\(s\) do not exist: '
350
                              'NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
351
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
352
    def test_status_nonexistent_file_with_others(self):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
353
        # bzr st [--short] NONEXISTENT ...others..
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
354
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
355
        expected = [
356
          'removed:\n',
357
          '  FILE_E\n',
358
          'modified:\n',
359
          '  FILE_B\n',
360
          '  FILE_C\n',
361
          'nonexistent:\n',
362
          '  NONEXISTENT\n',
363
          ]
364
        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
365
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
366
                                retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
367
        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
368
        self.assertContainsRe(err,
369
                              r'.*ERROR: Path\(s\) do not exist: '
370
                              'NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
371
        expected = [
372
          ' D  FILE_E\n',
373
          ' M  FILE_C\n',
374
          ' M  FILE_B\n',
375
          'X   NONEXISTENT\n',
376
          ]
377
        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
378
                                'FILE_A FILE_B FILE_C FILE_D FILE_E',
379
                                retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
380
        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
381
        self.assertContainsRe(err,
382
                              r'.*ERROR: Path\(s\) do not exist: '
383
                              'NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
384
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
385
    def test_status_multiple_nonexistent_files(self):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
386
        # bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
387
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
388
        expected = [
389
          'removed:\n',
390
          '  FILE_E\n',
391
          'modified:\n',
392
          '  FILE_B\n',
393
          '  FILE_C\n',
394
          'nonexistent:\n',
395
          '  ANOTHER_NONEXISTENT\n',
396
          '  NONEXISTENT\n',
397
          ]
398
        out, err = self.run_bzr('status NONEXISTENT '
399
                                '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
400
                                'FILE_C FILE_D FILE_E', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
401
        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
402
        self.assertContainsRe(err,
403
                              r'.*ERROR: Path\(s\) do not exist: '
404
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
405
        expected = [
406
          ' D  FILE_E\n',
407
          ' M  FILE_C\n',
408
          ' M  FILE_B\n',
409
          'X   ANOTHER_NONEXISTENT\n',
410
          'X   NONEXISTENT\n',
411
          ]
412
        out, err = self.run_bzr('status --short NONEXISTENT '
413
                                '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
414
                                'FILE_C FILE_D FILE_E', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
415
        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
416
        self.assertContainsRe(err,
417
                              r'.*ERROR: Path\(s\) do not exist: '
418
                              'ANOTHER_NONEXISTENT NONEXISTENT.*')
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
419
3930.2.17 by Ian Clatworthy
split tests as suggested by Jelmer's review
420
    def test_status_nonexistent_file_with_unversioned(self):
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
421
        # 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
422
        wt = self._prepare_nonexistent()
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
423
        expected = [
424
          'removed:\n',
425
          '  FILE_E\n',
426
          'added:\n',
427
          '  FILE_Q\n',
428
          'modified:\n',
429
          '  FILE_B\n',
430
          '  FILE_C\n',
431
          'unknown:\n',
432
          '  UNVERSIONED_BUT_EXISTING\n',
433
          'nonexistent:\n',
434
          '  NONEXISTENT\n',
435
          ]
436
        out, err = self.run_bzr('status NONEXISTENT '
437
                                '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
438
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
439
        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
440
        self.assertContainsRe(err,
441
                              r'.*ERROR: Path\(s\) do not exist: '
442
                              'NONEXISTENT.*')
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
443
        expected = [
444
          '+N  FILE_Q\n',
445
          '?   UNVERSIONED_BUT_EXISTING\n',
446
          ' D  FILE_E\n',
447
          ' M  FILE_C\n',
448
          ' M  FILE_B\n',
449
          'X   NONEXISTENT\n',
450
          ]
451
        out, err = self.run_bzr('status --short NONEXISTENT '
452
                                '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
453
                                'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
3930.2.12 by Karl Fogel
Part of bug #306394: Add regression tests.
454
        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
455
        self.assertContainsRe(err,
456
                              r'.*ERROR: Path\(s\) do not exist: '
457
                              'NONEXISTENT.*')
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
458
2091.4.2 by wang
add tests for "diff" and "status"
459
    def test_status_out_of_date(self):
460
        """Simulate status of out-of-date tree after remote push"""
461
        tree = self.make_branch_and_tree('.')
462
        self.build_tree_contents([('a', 'foo\n')])
463
        tree.lock_write()
464
        try:
465
            tree.add(['a'])
466
            tree.commit('add test file')
467
            # simulate what happens after a remote push
468
            tree.set_last_revision("0")
469
        finally:
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
470
            # before run another commands we should unlock tree
2091.4.2 by wang
add tests for "diff" and "status"
471
            tree.unlock()
2408.1.7 by Alexander Belchenko
Fix blackbox test_status_out_of_date: unlock WT before next command running
472
        out, err = self.run_bzr('status')
473
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
474
                         err)
2091.4.2 by wang
add tests for "diff" and "status"
475
5137.2.2 by Arnaud Jeansen
Add a unit test for LP: #40103 (status on an ignored file)
476
    def test_status_on_ignored(self):
477
        """Tests branch status on an unversioned file which is considered ignored.
478
479
        See https://bugs.launchpad.net/bzr/+bug/40103
480
        """
481
        tree = self.make_branch_and_tree('.')
482
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
483
        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)
484
        result = self.run_bzr('status')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
485
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
5137.2.3 by Arnaud Jeansen
Rework unit test according to feedback
486
        short_result = self.run_bzr('status --short')[0]
5137.2.4 by Arnaud Jeansen
Make new unit test easier to read wrt. sorting
487
        self.assertContainsRe(short_result, "\?   test1.c\n")
488
489
        result = self.run_bzr('status test1.c')[0]
490
        self.assertContainsRe(result, "unknown:\n  test1.c\n")
491
        short_result = self.run_bzr('status --short test1.c')[0]
492
        self.assertContainsRe(short_result, "\?   test1.c\n")
493
494
        result = self.run_bzr('status test1.c~')[0]
495
        self.assertContainsRe(result, "ignored:\n  test1.c~\n")
496
        short_result = self.run_bzr('status --short test1.c~')[0]
497
        self.assertContainsRe(short_result, "I   test1.c~\n")
498
499
        result = self.run_bzr('status test1.c~ test2.c~')[0]
500
        self.assertContainsRe(result, "ignored:\n  test1.c~\n  test2.c~\n")
501
        short_result = self.run_bzr('status --short test1.c~ test2.c~')[0]
502
        self.assertContainsRe(short_result, "I   test1.c~\nI   test2.c~\n")
503
504
        result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
505
        self.assertContainsRe(result, "unknown:\n  test1.c\nignored:\n  test1.c~\n  test2.c~\n")
506
        short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
507
        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)
508
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
509
    def test_status_write_lock(self):
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
510
        """Test that status works without fetching history and
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
511
        having a write lock.
512
513
        See https://bugs.launchpad.net/bzr/+bug/149270
514
        """
515
        mkdir('branch1')
516
        wt = self.make_branch_and_tree('branch1')
517
        b = wt.branch
518
        wt.commit('Empty commit 1')
519
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
3732.1.1 by Ian Clatworthy
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
520
        wt2.commit('Empty commit 2')
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
521
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
522
        self.assertEqual('', out)
523
5418.4.2 by Parth Malwankar
blackbox test for shelve summary in status
524
    def test_status_with_shelves(self):
525
        """Ensure that _show_shelve_summary handler works.
526
        """
527
        wt = self.make_branch_and_tree('.')
528
        self.build_tree(['hello.c'])
529
        wt.add('hello.c')
530
        self.run_bzr(['shelve', '--all', '-m', 'foo'])
531
        self.build_tree(['bye.c'])
532
        wt.add('bye.c')
533
        # As TestCase.setUp clears all hooks, we install this default
534
        # post_status hook handler for the test.
535
        status.hooks.install_named_hook('post_status',
536
            status._show_shelve_summary,
537
            'bzr status')
538
        self.assertStatus([
539
                'added:\n',
540
                '  bye.c\n',
541
                '1 shelves exist. See "bzr shelve --list" for details.\n',
542
            ],
543
            wt)
544
1662.1.9 by Martin Pool
Give a clear error for bzr status of an unversioned, nonexistent file. (Malone #3619)
545
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
546
class CheckoutStatus(BranchStatus):
1551.2.12 by Aaron Bentley
whitespace fixups
547
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
548
    def setUp(self):
549
        super(CheckoutStatus, self).setUp()
550
        mkdir('codir')
551
        chdir('codir')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
552
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
553
    def make_branch_and_tree(self, relpath):
554
        source = self.make_branch(pathjoin('..', relpath))
555
        checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
556
        bzrlib.branch.BranchReferenceFormat().initialize(checkout,
557
            target_branch=source)
1551.2.9 by Aaron Bentley
Fix status to work with checkouts
558
        return checkout.create_workingtree()
559
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
560
1534.4.54 by Robert Collins
Merge from integration.
561
class TestStatus(TestCaseWithTransport):
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
562
2318.2.1 by Kent Gibson
Apply status versioned patch
563
    def test_status_plain(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
564
        tree = self.make_branch_and_tree('.')
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
565
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
566
        self.build_tree(['hello.txt'])
567
        result = self.run_bzr("status")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
568
        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.
569
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
570
        tree.add("hello.txt")
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
571
        result = self.run_bzr("status")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
572
        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.
573
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
574
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
575
        result = self.run_bzr("status -r 0..1")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
576
        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.
577
2745.4.3 by Lukáš Lalinsky
Change -C to -c.
578
        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)
579
        self.assertContainsRe(result, "added:\n  hello.txt\n")
580
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
581
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
582
        result = self.run_bzr("status -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
583
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
584
                                      "unknown:\n  world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
585
        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)
586
        self.assertEquals(result2, result)
2318.2.1 by Kent Gibson
Apply status versioned patch
587
588
    def test_status_short(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
589
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
590
591
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
592
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
593
        self.assertContainsRe(result, "[?]   hello.txt\n")
594
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
595
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
596
        result = self.run_bzr("status --short")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
597
        self.assertContainsRe(result, "[+]N  hello.txt\n")
598
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
599
        tree.commit(message="added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
600
        result = self.run_bzr("status --short -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
601
        self.assertContainsRe(result, "[+]N  hello.txt\n")
602
603
        self.build_tree(['world.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
604
        result = self.run_bzr("status --short -r 0")[0]
1551.10.7 by Aaron Bentley
Use new-style output for status
605
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
606
                                      "[?]   world.txt\n")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
607
        result2 = self.run_bzr("status --short -r 0..")[0]
2147.2.2 by Keir Mierle
Fix spacing error and add tests for status --short command flag.
608
        self.assertEquals(result2, result)
1185.50.69 by John Arbash Meinel
[merge] bzr.robey, small fixes (--lsprof-file, log, status, http parsing, parmiko)
609
2318.2.1 by Kent Gibson
Apply status versioned patch
610
    def test_status_versioned(self):
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
611
        tree = self.make_branch_and_tree('.')
2318.2.1 by Kent Gibson
Apply status versioned patch
612
613
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
614
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
615
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
616
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
617
        tree.add("hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
618
        result = self.run_bzr("status --versioned")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
619
        self.assertContainsRe(result, "added:\n  hello.txt\n")
620
2664.7.1 by Daniel Watkins
tests.blackbox.test_status now uses internals where appropriate.
621
        tree.commit("added")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
622
        result = self.run_bzr("status --versioned -r 0..1")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
623
        self.assertContainsRe(result, "added:\n  hello.txt\n")
624
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 --versioned -r 0")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
627
        self.assertContainsRe(result, "added:\n  hello.txt\n")
628
        self.assertNotContainsRe(result, "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 --versioned -r 0..")[0]
2318.2.1 by Kent Gibson
Apply status versioned patch
630
        self.assertEquals(result2, result)
631
2663.1.7 by Daniel Watkins
Capitalised short names.
632
    def test_status_SV(self):
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
633
        tree = self.make_branch_and_tree('.')
634
635
        self.build_tree(['hello.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
636
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
637
        self.assertNotContainsRe(result, "hello.txt")
638
639
        tree.add("hello.txt")
2663.1.7 by Daniel Watkins
Capitalised short names.
640
        result = self.run_bzr("status -SV")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
641
        self.assertContainsRe(result, "[+]N  hello.txt\n")
642
643
        tree.commit(message="added")
2663.1.7 by Daniel Watkins
Capitalised short names.
644
        result = self.run_bzr("status -SV -r 0..1")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
645
        self.assertContainsRe(result, "[+]N  hello.txt\n")
646
647
        self.build_tree(['world.txt'])
2663.1.7 by Daniel Watkins
Capitalised short names.
648
        result = self.run_bzr("status -SV -r 0")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
649
        self.assertContainsRe(result, "[+]N  hello.txt\n")
650
2663.1.7 by Daniel Watkins
Capitalised short names.
651
        result2 = self.run_bzr("status -SV -r 0..")[0]
2663.1.3 by Daniel Watkins
Added test for 'status --quiet'.
652
        self.assertEquals(result2, result)
653
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
654
    def assertStatusContains(self, pattern, short=False):
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
655
        """Run status, and assert it contains the given pattern"""
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
656
        if short:
657
            result = self.run_bzr("status --short")[0]
658
        else:
659
            result = self.run_bzr("status")[0]
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
660
        self.assertContainsRe(result, pattern)
661
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
662
    def test_kind_change_plain(self):
663
        tree = self.make_branch_and_tree('.')
664
        self.build_tree(['file'])
665
        tree.add('file')
666
        tree.commit('added file')
667
        unlink('file')
668
        self.build_tree(['file/'])
669
        self.assertStatusContains('kind changed:\n  file \(file => directory\)')
670
        tree.rename_one('file', 'directory')
5076.3.2 by Arnaud Jeansen
Formatting : handle long strings similarly to other tests
671
        self.assertStatusContains('renamed:\n  file/ => directory/\n' \
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
672
                                  'modified:\n  directory/\n')
673
        rmdir('directory')
674
        self.assertStatusContains('removed:\n  file\n')
675
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
676
    def test_kind_change_short(self):
677
        tree = self.make_branch_and_tree('.')
678
        self.build_tree(['file'])
679
        tree.add('file')
680
        tree.commit('added file')
681
        unlink('file')
682
        self.build_tree(['file/'])
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
683
        self.assertStatusContains('K  file => file/',
684
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
685
        tree.rename_one('file', 'directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
686
        self.assertStatusContains('RK  file => directory/',
687
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
688
        rmdir('directory')
5076.3.1 by Arnaud Jeansen
Add test to the status for kind-changed elements
689
        self.assertStatusContains('RD  file => directory',
690
                                   short=True)
1551.10.9 by Aaron Bentley
Add test cases for status with kind change
691
2745.4.1 by Lukáš Lalinsky
New option -C/--change for diff and status to show changes in one revision. (#56299)
692
    def test_status_illegal_revision_specifiers(self):
693
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
694
        self.assertContainsRe(err, 'one or two revision specifiers')
695
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
696
    def test_status_no_pending(self):
697
        a_tree = self.make_branch_and_tree('a')
698
        self.build_tree(['a/a'])
699
        a_tree.add('a')
700
        a_tree.commit('a')
701
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
702
        self.build_tree(['b/b'])
703
        b_tree.add('b')
704
        b_tree.commit('b')
705
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
706
        self.run_bzr('merge ../b', working_dir='a')
707
        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)
708
        self.assertEquals(out, "added:\n  b\n")
709
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
710
    def test_pending_specific_files(self):
711
        """With a specific file list, pending merges are not shown."""
712
        tree = self.make_branch_and_tree('tree')
713
        self.build_tree_contents([('tree/a', 'content of a\n')])
714
        tree.add('a')
715
        r1_id = tree.commit('one')
716
        alt = tree.bzrdir.sprout('alt').open_workingtree()
717
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
718
        alt_id = alt.commit('alt')
719
        tree.merge_from_branch(alt.branch)
3655.2.1 by Lukáš Lalinský
Fix test_pending_specific_files
720
        output = self.make_utf8_encoded_stringio()
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
721
        show_tree_status(tree, to_file=output)
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
722
        self.assertContainsRe(output.getvalue(), 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
723
        out, err = self.run_bzr('status tree/a')
3936.2.1 by Ian Clatworthy
verbose flag for status - code & tests
724
        self.assertNotContainsRe(out, 'pending merge')
3636.1.1 by Robert Collins
Stop passing specific_file lists to show_tree_status when the specific
725
3270.6.1 by James Westby
Add --no-pending to status to not show the pending merges. (#202830)
726
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
727
class TestStatusEncodings(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
728
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
729
    def make_uncommitted_tree(self):
730
        """Build a branch with uncommitted unicode named changes in the cwd."""
731
        working_tree = self.make_branch_and_tree(u'.')
732
        filename = u'hell\u00d8'
733
        try:
734
            self.build_tree_contents([(filename, 'contents of hello')])
735
        except UnicodeEncodeError:
736
            raise TestSkipped("can't build unicode working tree in "
737
                "filesystem encoding %s" % sys.getfilesystemencoding())
738
        working_tree.add(filename)
739
        return working_tree
740
741
    def test_stdout_ascii(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
742
        self.overrideAttr(osutils, '_cached_user_encoding', 'ascii')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
743
        working_tree = self.make_uncommitted_tree()
744
        stdout, stderr = self.run_bzr("status")
745
746
        self.assertEquals(stdout, """\
747
added:
748
  hell?
749
""")
750
751
    def test_stdout_latin1(self):
4986.2.5 by Martin Pool
Change status blackbox encoding tests to use overrideAttr.
752
        self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
1685.1.6 by John Arbash Meinel
Merged test_status.py.moved into test_status.py
753
        working_tree = self.make_uncommitted_tree()
754
        stdout, stderr = self.run_bzr('status')
755
756
        self.assertEquals(stdout, u"""\
757
added:
758
  hell\u00d8
759
""".encode('latin-1'))
760