~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2009-01-28 18:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3968.
  • Revision ID: jelmer@samba.org-20090128184255-bdmklkvm83ltk191
Update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import sys
29
29
from tempfile import TemporaryFile
30
30
 
31
 
from bzrlib import bzrdir, errors
 
31
from bzrlib import (
 
32
    bzrdir,
 
33
    conflicts,
 
34
    errors,
 
35
    osutils,
 
36
    )
32
37
import bzrlib.branch
33
 
from bzrlib.builtins import merge
34
38
from bzrlib.osutils import pathjoin
35
39
from bzrlib.revisionspec import RevisionSpec
36
40
from bzrlib.status import show_tree_status
40
44
 
41
45
class BranchStatus(TestCaseWithTransport):
42
46
    
43
 
    def assertStatus(self, output_lines, working_tree,
44
 
        revision=None, short=False):
 
47
    def assertStatus(self, expected_lines, working_tree,
 
48
        revision=None, short=False, pending=True, verbose=False):
45
49
        """Run status in working_tree and look for output.
46
50
        
47
 
        :param output_lines: The lines to look for.
 
51
        :param expected_lines: The lines to look for.
48
52
        :param working_tree: The tree to run status in.
49
53
        """
50
 
        output_string = self.status_string(working_tree, revision, short)
51
 
        self.assertEqual(output_lines, output_string.splitlines(True))
 
54
        output_string = self.status_string(working_tree, revision, short,
 
55
                pending, verbose)
 
56
        self.assertEqual(expected_lines, output_string.splitlines(True))
52
57
    
53
 
    def status_string(self, wt, revision=None, short=False):
 
58
    def status_string(self, wt, revision=None, short=False, pending=True,
 
59
        verbose=False):
54
60
        # use a real file rather than StringIO because it doesn't handle
55
61
        # Unicode very well.
56
62
        tof = codecs.getwriter('utf-8')(TemporaryFile())
57
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
 
63
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
 
64
                show_pending=pending, verbose=verbose)
58
65
        tof.seek(0)
59
66
        return tof.read().decode('utf-8')
60
67
 
89
96
                'unknown:\n',
90
97
                '  bye.c\n',
91
98
                '  hello.c\n',
 
99
                'pending merge tips: (use -v to see all merge revisions)\n',
 
100
                '  (ghost) pending@pending-0-0\n',
 
101
            ],
 
102
            wt)
 
103
        self.assertStatus([
 
104
                'unknown:\n',
 
105
                '  bye.c\n',
 
106
                '  hello.c\n',
92
107
                'pending merges:\n',
93
 
                '  pending@pending-0-0\n',
 
108
                '  (ghost) pending@pending-0-0\n',
94
109
            ],
95
 
            wt)
 
110
            wt, verbose=True)
96
111
        self.assertStatus([
97
112
                '?   bye.c\n',
98
113
                '?   hello.c\n',
99
 
                'P   pending@pending-0-0\n',
 
114
                'P   (ghost) pending@pending-0-0\n',
100
115
            ],
101
116
            wt, short=True)
 
117
        self.assertStatus([
 
118
                'unknown:\n',
 
119
                '  bye.c\n',
 
120
                '  hello.c\n',
 
121
            ],
 
122
            wt, pending=False)
 
123
        self.assertStatus([
 
124
                '?   bye.c\n',
 
125
                '?   hello.c\n',
 
126
            ],
 
127
            wt, short=True, pending=False)
102
128
 
103
129
    def test_branch_status_revisions(self):
104
130
        """Tests branch status with revisions"""
141
167
        b_2 = b_2_dir.open_branch()
142
168
        wt2 = b_2_dir.open_workingtree()
143
169
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
144
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
145
 
        message = self.status_string(wt2)
 
170
        wt2.merge_from_branch(wt.branch)
 
171
        message = self.status_string(wt2, verbose=True)
146
172
        self.assertStartsWith(message, "pending merges:\n")
147
173
        self.assertEndsWith(message, "Empty commit 2\n")
148
174
        wt2.commit("merged")
149
175
        # must be long to make sure we see elipsis at the end
150
176
        wt.commit("Empty commit 3 " +
151
177
                   "blah blah blah blah " * 100)
152
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
153
 
        message = self.status_string(wt2)
 
178
        wt2.merge_from_branch(wt.branch)
 
179
        message = self.status_string(wt2, verbose=True)
154
180
        self.assertStartsWith(message, "pending merges:\n")
155
181
        self.assert_("Empty commit 3" in message)
156
182
        self.assertEndsWith(message, "...\n")
157
183
 
158
 
    def test_branch_status_specific_files(self): 
 
184
    def test_tree_status_ignores(self):
 
185
        """Tests branch status with ignores"""
 
186
        wt = self.make_branch_and_tree('.')
 
187
        self.run_bzr('ignore *~')
 
188
        wt.commit('commit .bzrignore')
 
189
        self.build_tree(['foo.c', 'foo.c~'])
 
190
        self.assertStatus([
 
191
                'unknown:\n',
 
192
                '  foo.c\n',
 
193
                ],
 
194
                wt)
 
195
        self.assertStatus([
 
196
                '?   foo.c\n',
 
197
                ],
 
198
                wt, short=True)
 
199
 
 
200
    def test_tree_status_specific_files(self):
159
201
        """Tests branch status with given specific files"""
160
202
        wt = self.make_branch_and_tree('.')
161
203
        b = wt.branch
168
210
        self.assertStatus([
169
211
                'unknown:\n',
170
212
                '  bye.c\n',
171
 
                '  dir2\n',
 
213
                '  dir2/\n',
172
214
                '  directory/hello.c\n'
173
215
                ],
174
216
                wt)
175
217
 
176
218
        self.assertStatus([
177
219
                '?   bye.c\n',
178
 
                '?   dir2\n',
 
220
                '?   dir2/\n',
179
221
                '?   directory/hello.c\n'
180
222
                ],
181
223
                wt, short=True)
204
246
        tof.seek(0)
205
247
        self.assertEquals(tof.readlines(),
206
248
                          ['unknown:\n',
207
 
                           '  dir2\n'
 
249
                           '  dir2/\n'
208
250
                           ])
209
251
        tof = StringIO()
210
252
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
211
253
        tof.seek(0)
212
 
        self.assertEquals(tof.readlines(), ['?   dir2\n'])
 
254
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
 
255
 
 
256
        tof = StringIO()
 
257
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
 
258
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
 
259
                         short=True, revision=revs)
 
260
        tof.seek(0)
 
261
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
 
262
 
 
263
    def test_specific_files_conflicts(self):
 
264
        tree = self.make_branch_and_tree('.')
 
265
        self.build_tree(['dir2/'])
 
266
        tree.add('dir2')
 
267
        tree.commit('added dir2')
 
268
        tree.set_conflicts(conflicts.ConflictList(
 
269
            [conflicts.ContentsConflict('foo')]))
 
270
        tof = StringIO()
 
271
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
272
        self.assertEqualDiff('', tof.getvalue())
 
273
        tree.set_conflicts(conflicts.ConflictList(
 
274
            [conflicts.ContentsConflict('dir2')]))
 
275
        tof = StringIO()
 
276
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
277
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
 
278
                             tof.getvalue())
 
279
 
 
280
        tree.set_conflicts(conflicts.ConflictList(
 
281
            [conflicts.ContentsConflict('dir2/file1')]))
 
282
        tof = StringIO()
 
283
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
284
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
 
285
                             tof.getvalue())
213
286
 
214
287
    def test_status_nonexistent_file(self):
215
288
        # files that don't exist in either the basis tree or working tree
216
289
        # should give an error
217
290
        wt = self.make_branch_and_tree('.')
218
 
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
 
291
        out, err = self.run_bzr('status does-not-exist', retcode=3)
219
292
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
220
293
 
221
294
    def test_status_out_of_date(self):
228
301
            tree.commit('add test file')
229
302
            # simulate what happens after a remote push
230
303
            tree.set_last_revision("0")
231
 
            out, err = self.run_bzr('status')
232
 
            self.assertEqual("working tree is out of date, run 'bzr update'\n",
233
 
                             err)
234
304
        finally:
 
305
            # before run another commands we should unlock tree
235
306
            tree.unlock()
 
307
        out, err = self.run_bzr('status')
 
308
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
309
                         err)
 
310
 
 
311
    def test_status_write_lock(self):
 
312
        """Test that status works without fetching history and
 
313
        having a write lock.
 
314
 
 
315
        See https://bugs.launchpad.net/bzr/+bug/149270
 
316
        """
 
317
        mkdir('branch1')
 
318
        wt = self.make_branch_and_tree('branch1')
 
319
        b = wt.branch
 
320
        wt.commit('Empty commit 1')
 
321
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
 
322
        wt2.commit('Empty commit 2')
 
323
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
 
324
        self.assertEqual('', out)
236
325
 
237
326
 
238
327
class CheckoutStatus(BranchStatus):
251
340
 
252
341
class TestStatus(TestCaseWithTransport):
253
342
 
254
 
    def test_status(self):
255
 
        self.run_bzr("init")
 
343
    def test_status_plain(self):
 
344
        tree = self.make_branch_and_tree('.')
256
345
 
257
346
        self.build_tree(['hello.txt'])
258
347
        result = self.run_bzr("status")[0]
259
 
        self.assert_("unknown:\n  hello.txt\n" in result, result)
260
 
        result = self.run_bzr("status","--short")[0]
261
 
        self.assertContainsRe(result, "[?]   hello.txt\n")
 
348
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
262
349
 
263
 
        self.run_bzr("add", "hello.txt")
 
350
        tree.add("hello.txt")
264
351
        result = self.run_bzr("status")[0]
265
352
        self.assertContainsRe(result, "added:\n  hello.txt\n")
266
 
        result = self.run_bzr("status","--short")[0]
267
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
268
 
 
269
 
        self.run_bzr("commit", "-m", "added")
270
 
        result = self.run_bzr("status", "-r", "0..1")[0]
271
 
        self.assertContainsRe(result, "added:\n  hello.txt\n")
272
 
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
273
 
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
353
 
 
354
        tree.commit(message="added")
 
355
        result = self.run_bzr("status -r 0..1")[0]
 
356
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
357
 
 
358
        result = self.run_bzr("status -c 1")[0]
 
359
        self.assertContainsRe(result, "added:\n  hello.txt\n")
274
360
 
275
361
        self.build_tree(['world.txt'])
276
 
        result = self.run_bzr("status", "-r", "0")[0]
 
362
        result = self.run_bzr("status -r 0")[0]
277
363
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
278
364
                                      "unknown:\n  world.txt\n")
279
 
        result2 = self.run_bzr("status", "-r", "0..")[0]
 
365
        result2 = self.run_bzr("status -r 0..")[0]
280
366
        self.assertEquals(result2, result)
281
 
        result = self.run_bzr("status", "--short", "-r", "0")[0]
 
367
 
 
368
    def test_status_short(self):
 
369
        tree = self.make_branch_and_tree('.')
 
370
 
 
371
        self.build_tree(['hello.txt'])
 
372
        result = self.run_bzr("status --short")[0]
 
373
        self.assertContainsRe(result, "[?]   hello.txt\n")
 
374
 
 
375
        tree.add("hello.txt")
 
376
        result = self.run_bzr("status --short")[0]
 
377
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
378
 
 
379
        tree.commit(message="added")
 
380
        result = self.run_bzr("status --short -r 0..1")[0]
 
381
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
382
 
 
383
        self.build_tree(['world.txt'])
 
384
        result = self.run_bzr("status --short -r 0")[0]
282
385
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
283
386
                                      "[?]   world.txt\n")
284
 
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
387
        result2 = self.run_bzr("status --short -r 0..")[0]
 
388
        self.assertEquals(result2, result)
 
389
 
 
390
    def test_status_versioned(self):
 
391
        tree = self.make_branch_and_tree('.')
 
392
 
 
393
        self.build_tree(['hello.txt'])
 
394
        result = self.run_bzr("status --versioned")[0]
 
395
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
 
396
 
 
397
        tree.add("hello.txt")
 
398
        result = self.run_bzr("status --versioned")[0]
 
399
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
400
 
 
401
        tree.commit("added")
 
402
        result = self.run_bzr("status --versioned -r 0..1")[0]
 
403
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
404
 
 
405
        self.build_tree(['world.txt'])
 
406
        result = self.run_bzr("status --versioned -r 0")[0]
 
407
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
408
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
 
409
        result2 = self.run_bzr("status --versioned -r 0..")[0]
 
410
        self.assertEquals(result2, result)
 
411
 
 
412
    def test_status_SV(self):
 
413
        tree = self.make_branch_and_tree('.')
 
414
 
 
415
        self.build_tree(['hello.txt'])
 
416
        result = self.run_bzr("status -SV")[0]
 
417
        self.assertNotContainsRe(result, "hello.txt")
 
418
 
 
419
        tree.add("hello.txt")
 
420
        result = self.run_bzr("status -SV")[0]
 
421
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
422
 
 
423
        tree.commit(message="added")
 
424
        result = self.run_bzr("status -SV -r 0..1")[0]
 
425
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
426
 
 
427
        self.build_tree(['world.txt'])
 
428
        result = self.run_bzr("status -SV -r 0")[0]
 
429
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
430
 
 
431
        result2 = self.run_bzr("status -SV -r 0..")[0]
285
432
        self.assertEquals(result2, result)
286
433
 
287
434
    def assertStatusContains(self, pattern):
288
435
        """Run status, and assert it contains the given pattern"""
289
 
        result = self.run_bzr("status", "--short")[0]
 
436
        result = self.run_bzr("status --short")[0]
290
437
        self.assertContainsRe(result, pattern)
291
438
 
292
439
    def test_kind_change_short(self):
302
449
        rmdir('directory')
303
450
        self.assertStatusContains('RD  file => directory')
304
451
 
 
452
    def test_status_illegal_revision_specifiers(self):
 
453
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
 
454
        self.assertContainsRe(err, 'one or two revision specifiers')
 
455
 
 
456
    def test_status_no_pending(self):
 
457
        a_tree = self.make_branch_and_tree('a')
 
458
        self.build_tree(['a/a'])
 
459
        a_tree.add('a')
 
460
        a_tree.commit('a')
 
461
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
462
        self.build_tree(['b/b'])
 
463
        b_tree.add('b')
 
464
        b_tree.commit('b')
 
465
 
 
466
        self.run_bzr('merge ../b', working_dir='a')
 
467
        out, err = self.run_bzr('status --no-pending', working_dir='a')
 
468
        self.assertEquals(out, "added:\n  b\n")
 
469
 
 
470
    def test_pending_specific_files(self):
 
471
        """With a specific file list, pending merges are not shown."""
 
472
        tree = self.make_branch_and_tree('tree')
 
473
        self.build_tree_contents([('tree/a', 'content of a\n')])
 
474
        tree.add('a')
 
475
        r1_id = tree.commit('one')
 
476
        alt = tree.bzrdir.sprout('alt').open_workingtree()
 
477
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
 
478
        alt_id = alt.commit('alt')
 
479
        tree.merge_from_branch(alt.branch)
 
480
        output = self.make_utf8_encoded_stringio()
 
481
        show_tree_status(tree, to_file=output)
 
482
        self.assertContainsRe(output.getvalue(), 'pending merge')
 
483
        out, err = self.run_bzr('status tree/a')
 
484
        self.assertNotContainsRe(out, 'pending merge')
 
485
 
305
486
 
306
487
class TestStatusEncodings(TestCaseWithTransport):
307
488
    
308
489
    def setUp(self):
309
490
        TestCaseWithTransport.setUp(self)
310
 
        self.user_encoding = bzrlib.user_encoding
 
491
        self.user_encoding = osutils._cached_user_encoding
311
492
        self.stdout = sys.stdout
312
493
 
313
494
    def tearDown(self):
329
510
 
330
511
    def test_stdout_ascii(self):
331
512
        sys.stdout = StringIO()
332
 
        bzrlib.user_encoding = 'ascii'
 
513
        osutils._cached_user_encoding = 'ascii'
333
514
        working_tree = self.make_uncommitted_tree()
334
515
        stdout, stderr = self.run_bzr("status")
335
516
 
340
521
 
341
522
    def test_stdout_latin1(self):
342
523
        sys.stdout = StringIO()
343
 
        bzrlib.user_encoding = 'latin-1'
 
524
        osutils._cached_user_encoding = 'latin-1'
344
525
        working_tree = self.make_uncommitted_tree()
345
526
        stdout, stderr = self.run_bzr('status')
346
527