~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2008-12-09 22:26:40 UTC
  • mto: This revision was merged to the branch mainline in revision 3888.
  • Revision ID: john@arbash-meinel.com-20081209222640-u3iece2ixcd0q7lj
Add a FIFOSizeCache which is constrained based on the size of the values.

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
41
45
class BranchStatus(TestCaseWithTransport):
42
46
    
43
47
    def assertStatus(self, expected_lines, working_tree,
44
 
        revision=None, short=False):
 
48
        revision=None, short=False, pending=True):
45
49
        """Run status in working_tree and look for output.
46
50
        
47
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)
 
54
        output_string = self.status_string(working_tree, revision, short,
 
55
                pending)
51
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):
54
59
        # use a real file rather than StringIO because it doesn't handle
55
60
        # Unicode very well.
56
61
        tof = codecs.getwriter('utf-8')(TemporaryFile())
57
 
        show_tree_status(wt, to_file=tof, revision=revision, short=short)
 
62
        show_tree_status(wt, to_file=tof, revision=revision, short=short,
 
63
                show_pending=pending)
58
64
        tof.seek(0)
59
65
        return tof.read().decode('utf-8')
60
66
 
90
96
                '  bye.c\n',
91
97
                '  hello.c\n',
92
98
                'pending merges:\n',
93
 
                '  pending@pending-0-0\n',
 
99
                '  (ghost) pending@pending-0-0\n',
94
100
            ],
95
101
            wt)
96
102
        self.assertStatus([
97
103
                '?   bye.c\n',
98
104
                '?   hello.c\n',
99
 
                'P   pending@pending-0-0\n',
 
105
                'P   (ghost) pending@pending-0-0\n',
100
106
            ],
101
107
            wt, short=True)
 
108
        self.assertStatus([
 
109
                'unknown:\n',
 
110
                '  bye.c\n',
 
111
                '  hello.c\n',
 
112
            ],
 
113
            wt, pending=False)
 
114
        self.assertStatus([
 
115
                '?   bye.c\n',
 
116
                '?   hello.c\n',
 
117
            ],
 
118
            wt, short=True, pending=False)
102
119
 
103
120
    def test_branch_status_revisions(self):
104
121
        """Tests branch status with revisions"""
141
158
        b_2 = b_2_dir.open_branch()
142
159
        wt2 = b_2_dir.open_workingtree()
143
160
        wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
144
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
161
        wt2.merge_from_branch(wt.branch)
145
162
        message = self.status_string(wt2)
146
163
        self.assertStartsWith(message, "pending merges:\n")
147
164
        self.assertEndsWith(message, "Empty commit 2\n")
149
166
        # must be long to make sure we see elipsis at the end
150
167
        wt.commit("Empty commit 3 " +
151
168
                   "blah blah blah blah " * 100)
152
 
        merge(["./branch", -1], [None, None], this_dir = './copy')
 
169
        wt2.merge_from_branch(wt.branch)
153
170
        message = self.status_string(wt2)
154
171
        self.assertStartsWith(message, "pending merges:\n")
155
172
        self.assert_("Empty commit 3" in message)
158
175
    def test_tree_status_ignores(self):
159
176
        """Tests branch status with ignores"""
160
177
        wt = self.make_branch_and_tree('.')
161
 
        self.run_bzr('ignore', '*~')
 
178
        self.run_bzr('ignore *~')
162
179
        wt.commit('commit .bzrignore')
163
180
        self.build_tree(['foo.c', 'foo.c~'])
164
181
        self.assertStatus([
227
244
        tof.seek(0)
228
245
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])
229
246
 
 
247
        tof = StringIO()
 
248
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
 
249
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
 
250
                         short=True, revision=revs)
 
251
        tof.seek(0)
 
252
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
 
253
 
 
254
    def test_specific_files_conflicts(self):
 
255
        tree = self.make_branch_and_tree('.')
 
256
        self.build_tree(['dir2/'])
 
257
        tree.add('dir2')
 
258
        tree.commit('added dir2')
 
259
        tree.set_conflicts(conflicts.ConflictList(
 
260
            [conflicts.ContentsConflict('foo')]))
 
261
        tof = StringIO()
 
262
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
263
        self.assertEqualDiff('', tof.getvalue())
 
264
        tree.set_conflicts(conflicts.ConflictList(
 
265
            [conflicts.ContentsConflict('dir2')]))
 
266
        tof = StringIO()
 
267
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
268
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2\n',
 
269
                             tof.getvalue())
 
270
 
 
271
        tree.set_conflicts(conflicts.ConflictList(
 
272
            [conflicts.ContentsConflict('dir2/file1')]))
 
273
        tof = StringIO()
 
274
        show_tree_status(tree, specific_files=['dir2'], to_file=tof)
 
275
        self.assertEqualDiff('conflicts:\n  Contents conflict in dir2/file1\n',
 
276
                             tof.getvalue())
 
277
 
230
278
    def test_status_nonexistent_file(self):
231
279
        # files that don't exist in either the basis tree or working tree
232
280
        # should give an error
233
281
        wt = self.make_branch_and_tree('.')
234
 
        out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
 
282
        out, err = self.run_bzr('status does-not-exist', retcode=3)
235
283
        self.assertContainsRe(err, r'do not exist.*does-not-exist')
236
284
 
237
285
    def test_status_out_of_date(self):
244
292
            tree.commit('add test file')
245
293
            # simulate what happens after a remote push
246
294
            tree.set_last_revision("0")
247
 
            out, err = self.run_bzr('status')
248
 
            self.assertEqual("working tree is out of date, run 'bzr update'\n",
249
 
                             err)
250
295
        finally:
 
296
            # before run another commands we should unlock tree
251
297
            tree.unlock()
 
298
        out, err = self.run_bzr('status')
 
299
        self.assertEqual("working tree is out of date, run 'bzr update'\n",
 
300
                         err)
 
301
 
 
302
    def test_status_write_lock(self):
 
303
        """Test that status works without fetching history and
 
304
        having a write lock.
 
305
 
 
306
        See https://bugs.launchpad.net/bzr/+bug/149270
 
307
        """
 
308
        mkdir('branch1')
 
309
        wt = self.make_branch_and_tree('branch1')
 
310
        b = wt.branch
 
311
        wt.commit('Empty commit 1')
 
312
        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
 
313
        wt2.commit('Empty commit 2')
 
314
        out, err = self.run_bzr('status branch1 -rbranch:branch2')
 
315
        self.assertEqual('', out)
252
316
 
253
317
 
254
318
class CheckoutStatus(BranchStatus):
268
332
class TestStatus(TestCaseWithTransport):
269
333
 
270
334
    def test_status_plain(self):
271
 
        self.run_bzr("init")
 
335
        tree = self.make_branch_and_tree('.')
272
336
 
273
337
        self.build_tree(['hello.txt'])
274
338
        result = self.run_bzr("status")[0]
275
339
        self.assertContainsRe(result, "unknown:\n  hello.txt\n")
276
340
 
277
 
        self.run_bzr("add", "hello.txt")
 
341
        tree.add("hello.txt")
278
342
        result = self.run_bzr("status")[0]
279
343
        self.assertContainsRe(result, "added:\n  hello.txt\n")
280
344
 
281
 
        self.run_bzr("commit", "-m", "added")
282
 
        result = self.run_bzr("status", "-r", "0..1")[0]
 
345
        tree.commit(message="added")
 
346
        result = self.run_bzr("status -r 0..1")[0]
 
347
        self.assertContainsRe(result, "added:\n  hello.txt\n")
 
348
 
 
349
        result = self.run_bzr("status -c 1")[0]
283
350
        self.assertContainsRe(result, "added:\n  hello.txt\n")
284
351
 
285
352
        self.build_tree(['world.txt'])
286
 
        result = self.run_bzr("status", "-r", "0")[0]
 
353
        result = self.run_bzr("status -r 0")[0]
287
354
        self.assertContainsRe(result, "added:\n  hello.txt\n" \
288
355
                                      "unknown:\n  world.txt\n")
289
 
        result2 = self.run_bzr("status", "-r", "0..")[0]
 
356
        result2 = self.run_bzr("status -r 0..")[0]
290
357
        self.assertEquals(result2, result)
291
358
 
292
359
    def test_status_short(self):
293
 
        self.run_bzr("init")
 
360
        tree = self.make_branch_and_tree('.')
294
361
 
295
362
        self.build_tree(['hello.txt'])
296
 
        result = self.run_bzr("status","--short")[0]
 
363
        result = self.run_bzr("status --short")[0]
297
364
        self.assertContainsRe(result, "[?]   hello.txt\n")
298
365
 
299
 
        self.run_bzr("add", "hello.txt")
300
 
        result = self.run_bzr("status","--short")[0]
 
366
        tree.add("hello.txt")
 
367
        result = self.run_bzr("status --short")[0]
301
368
        self.assertContainsRe(result, "[+]N  hello.txt\n")
302
369
 
303
 
        self.run_bzr("commit", "-m", "added")
304
 
        result = self.run_bzr("status", "--short", "-r", "0..1")[0]
 
370
        tree.commit(message="added")
 
371
        result = self.run_bzr("status --short -r 0..1")[0]
305
372
        self.assertContainsRe(result, "[+]N  hello.txt\n")
306
373
 
307
374
        self.build_tree(['world.txt'])
308
 
        result = self.run_bzr("status", "--short", "-r", "0")[0]
 
375
        result = self.run_bzr("status --short -r 0")[0]
309
376
        self.assertContainsRe(result, "[+]N  hello.txt\n" \
310
377
                                      "[?]   world.txt\n")
311
 
        result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
 
378
        result2 = self.run_bzr("status --short -r 0..")[0]
312
379
        self.assertEquals(result2, result)
313
380
 
314
381
    def test_status_versioned(self):
315
 
        self.run_bzr("init")
 
382
        tree = self.make_branch_and_tree('.')
316
383
 
317
384
        self.build_tree(['hello.txt'])
318
 
        result = self.run_bzr("status", "--versioned")[0]
 
385
        result = self.run_bzr("status --versioned")[0]
319
386
        self.assertNotContainsRe(result, "unknown:\n  hello.txt\n")
320
387
 
321
 
        self.run_bzr("add", "hello.txt")
322
 
        result = self.run_bzr("status", "--versioned")[0]
 
388
        tree.add("hello.txt")
 
389
        result = self.run_bzr("status --versioned")[0]
323
390
        self.assertContainsRe(result, "added:\n  hello.txt\n")
324
391
 
325
 
        self.run_bzr("commit", "-m", "added")
326
 
        result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
 
392
        tree.commit("added")
 
393
        result = self.run_bzr("status --versioned -r 0..1")[0]
327
394
        self.assertContainsRe(result, "added:\n  hello.txt\n")
328
395
 
329
396
        self.build_tree(['world.txt'])
330
 
        result = self.run_bzr("status", "--versioned", "-r", "0")[0]
 
397
        result = self.run_bzr("status --versioned -r 0")[0]
331
398
        self.assertContainsRe(result, "added:\n  hello.txt\n")
332
399
        self.assertNotContainsRe(result, "unknown:\n  world.txt\n")
333
 
        result2 = self.run_bzr("status", "--versioned", "-r", "0..")[0]
 
400
        result2 = self.run_bzr("status --versioned -r 0..")[0]
 
401
        self.assertEquals(result2, result)
 
402
 
 
403
    def test_status_SV(self):
 
404
        tree = self.make_branch_and_tree('.')
 
405
 
 
406
        self.build_tree(['hello.txt'])
 
407
        result = self.run_bzr("status -SV")[0]
 
408
        self.assertNotContainsRe(result, "hello.txt")
 
409
 
 
410
        tree.add("hello.txt")
 
411
        result = self.run_bzr("status -SV")[0]
 
412
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
413
 
 
414
        tree.commit(message="added")
 
415
        result = self.run_bzr("status -SV -r 0..1")[0]
 
416
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
417
 
 
418
        self.build_tree(['world.txt'])
 
419
        result = self.run_bzr("status -SV -r 0")[0]
 
420
        self.assertContainsRe(result, "[+]N  hello.txt\n")
 
421
 
 
422
        result2 = self.run_bzr("status -SV -r 0..")[0]
334
423
        self.assertEquals(result2, result)
335
424
 
336
425
    def assertStatusContains(self, pattern):
337
426
        """Run status, and assert it contains the given pattern"""
338
 
        result = self.run_bzr("status", "--short")[0]
 
427
        result = self.run_bzr("status --short")[0]
339
428
        self.assertContainsRe(result, pattern)
340
429
 
341
430
    def test_kind_change_short(self):
351
440
        rmdir('directory')
352
441
        self.assertStatusContains('RD  file => directory')
353
442
 
 
443
    def test_status_illegal_revision_specifiers(self):
 
444
        out, err = self.run_bzr('status -r 1..23..123', retcode=3)
 
445
        self.assertContainsRe(err, 'one or two revision specifiers')
 
446
 
 
447
    def test_status_no_pending(self):
 
448
        a_tree = self.make_branch_and_tree('a')
 
449
        self.build_tree(['a/a'])
 
450
        a_tree.add('a')
 
451
        a_tree.commit('a')
 
452
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
453
        self.build_tree(['b/b'])
 
454
        b_tree.add('b')
 
455
        b_tree.commit('b')
 
456
 
 
457
        self.run_bzr('merge ../b', working_dir='a')
 
458
        out, err = self.run_bzr('status --no-pending', working_dir='a')
 
459
        self.assertEquals(out, "added:\n  b\n")
 
460
 
 
461
    def test_pending_specific_files(self):
 
462
        """With a specific file list, pending merges are not shown."""
 
463
        tree = self.make_branch_and_tree('tree')
 
464
        self.build_tree_contents([('tree/a', 'content of a\n')])
 
465
        tree.add('a')
 
466
        r1_id = tree.commit('one')
 
467
        alt = tree.bzrdir.sprout('alt').open_workingtree()
 
468
        self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
 
469
        alt_id = alt.commit('alt')
 
470
        tree.merge_from_branch(alt.branch)
 
471
        output = self.make_utf8_encoded_stringio()
 
472
        show_tree_status(tree, to_file=output)
 
473
        self.assertContainsRe(output.getvalue(), 'pending merges:')
 
474
        out, err = self.run_bzr('status tree/a')
 
475
        self.assertNotContainsRe(out, 'pending merges:')
 
476
 
354
477
 
355
478
class TestStatusEncodings(TestCaseWithTransport):
356
479
    
357
480
    def setUp(self):
358
481
        TestCaseWithTransport.setUp(self)
359
 
        self.user_encoding = bzrlib.user_encoding
 
482
        self.user_encoding = osutils._cached_user_encoding
360
483
        self.stdout = sys.stdout
361
484
 
362
485
    def tearDown(self):
378
501
 
379
502
    def test_stdout_ascii(self):
380
503
        sys.stdout = StringIO()
381
 
        bzrlib.user_encoding = 'ascii'
 
504
        osutils._cached_user_encoding = 'ascii'
382
505
        working_tree = self.make_uncommitted_tree()
383
506
        stdout, stderr = self.run_bzr("status")
384
507
 
389
512
 
390
513
    def test_stdout_latin1(self):
391
514
        sys.stdout = StringIO()
392
 
        bzrlib.user_encoding = 'latin-1'
 
515
        osutils._cached_user_encoding = 'latin-1'
393
516
        working_tree = self.make_uncommitted_tree()
394
517
        stdout, stderr = self.run_bzr('status')
395
518