46
41
class BranchStatus(TestCaseWithTransport):
48
43
def assertStatus(self, expected_lines, working_tree,
49
revision=None, short=False, pending=True, verbose=False):
44
revision=None, short=False):
50
45
"""Run status in working_tree and look for output.
52
47
:param expected_lines: The lines to look for.
53
48
:param working_tree: The tree to run status in.
55
output_string = self.status_string(working_tree, revision, short,
50
output_string = self.status_string(working_tree, revision, short)
57
51
self.assertEqual(expected_lines, output_string.splitlines(True))
59
def status_string(self, wt, revision=None, short=False, pending=True,
53
def status_string(self, wt, revision=None, short=False):
61
54
# use a real file rather than StringIO because it doesn't handle
62
55
# Unicode very well.
63
56
tof = codecs.getwriter('utf-8')(TemporaryFile())
64
show_tree_status(wt, to_file=tof, revision=revision, short=short,
65
show_pending=pending, verbose=verbose)
57
show_tree_status(wt, to_file=tof, revision=revision, short=short)
67
59
return tof.read().decode('utf-8')
255
228
self.assertEquals(tof.readlines(), ['? dir2/\n'])
258
revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
259
show_tree_status(wt, specific_files=['test.c'], to_file=tof,
260
short=True, revision=revs)
262
self.assertEquals(tof.readlines(), ['+N test.c\n'])
264
def test_specific_files_conflicts(self):
265
tree = self.make_branch_and_tree('.')
266
self.build_tree(['dir2/'])
268
tree.commit('added dir2')
269
tree.set_conflicts(conflicts.ConflictList(
270
[conflicts.ContentsConflict('foo')]))
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')]))
277
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
278
self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n',
281
tree.set_conflicts(conflicts.ConflictList(
282
[conflicts.ContentsConflict('dir2/file1')]))
284
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
285
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
288
def _prepare_nonexistent(self):
289
wt = self.make_branch_and_tree('.')
290
self.assertStatus([], wt)
291
self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', '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.')
300
unlink('FILE_E') # FILE_E will be versioned but missing
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')
306
230
def test_status_nonexistent_file(self):
307
231
# files that don't exist in either the basis tree or working tree
308
232
# should give an error
309
wt = self._prepare_nonexistent()
319
' UNVERSIONED_BUT_EXISTING\n',
327
'? UNVERSIONED_BUT_EXISTING\n',
331
# Okay, everything's looking good with the existent files.
332
# Let's see what happens when we throw in non-existent files.
334
# bzr st [--short] NONEXISTENT '
339
out, err = self.run_bzr('status NONEXISTENT', retcode=3)
340
self.assertEqual(expected, out.splitlines(True))
341
self.assertContainsRe(err,
342
r'.*ERROR: Path\(s\) do not exist: '
347
out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
348
self.assertContainsRe(err,
349
r'.*ERROR: Path\(s\) do not exist: '
352
def test_status_nonexistent_file_with_others(self):
353
# bzr st [--short] NONEXISTENT ...others..
354
wt = self._prepare_nonexistent()
364
out, err = self.run_bzr('status NONEXISTENT '
365
'FILE_A FILE_B FILE_C FILE_D FILE_E',
367
self.assertEqual(expected, out.splitlines(True))
368
self.assertContainsRe(err,
369
r'.*ERROR: Path\(s\) do not exist: '
377
out, err = self.run_bzr('status --short NONEXISTENT '
378
'FILE_A FILE_B FILE_C FILE_D FILE_E',
380
self.assertEqual(expected, out.splitlines(True))
381
self.assertContainsRe(err,
382
r'.*ERROR: Path\(s\) do not exist: '
385
def test_status_multiple_nonexistent_files(self):
386
# bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
387
wt = self._prepare_nonexistent()
395
' ANOTHER_NONEXISTENT\n',
398
out, err = self.run_bzr('status NONEXISTENT '
399
'FILE_A FILE_B ANOTHER_NONEXISTENT '
400
'FILE_C FILE_D FILE_E', retcode=3)
401
self.assertEqual(expected, out.splitlines(True))
402
self.assertContainsRe(err,
403
r'.*ERROR: Path\(s\) do not exist: '
404
'ANOTHER_NONEXISTENT NONEXISTENT.*')
409
'X ANOTHER_NONEXISTENT\n',
412
out, err = self.run_bzr('status --short NONEXISTENT '
413
'FILE_A FILE_B ANOTHER_NONEXISTENT '
414
'FILE_C FILE_D FILE_E', retcode=3)
415
self.assertEqual(expected, out.splitlines(True))
416
self.assertContainsRe(err,
417
r'.*ERROR: Path\(s\) do not exist: '
418
'ANOTHER_NONEXISTENT NONEXISTENT.*')
420
def test_status_nonexistent_file_with_unversioned(self):
421
# bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
422
wt = self._prepare_nonexistent()
432
' UNVERSIONED_BUT_EXISTING\n',
436
out, err = self.run_bzr('status NONEXISTENT '
437
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
438
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
439
self.assertEqual(expected, out.splitlines(True))
440
self.assertContainsRe(err,
441
r'.*ERROR: Path\(s\) do not exist: '
445
'? UNVERSIONED_BUT_EXISTING\n',
451
out, err = self.run_bzr('status --short NONEXISTENT '
452
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
453
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
454
self.assertEqual(expected, out.splitlines(True))
455
self.assertContainsRe(err,
456
r'.*ERROR: Path\(s\) do not exist: '
233
wt = self.make_branch_and_tree('.')
234
out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
235
self.assertContainsRe(err, r'do not exist.*does-not-exist')
459
237
def test_status_out_of_date(self):
460
238
"""Simulate status of out-of-date tree after remote push"""
473
251
self.assertEqual("working tree is out of date, run 'bzr update'\n",
476
def test_status_on_ignored(self):
477
"""Tests branch status on an unversioned file which is considered ignored.
479
See https://bugs.launchpad.net/bzr/+bug/40103
481
tree = self.make_branch_and_tree('.')
483
self.build_tree(['test1.c', 'test1.c~', 'test2.c~'])
484
result = self.run_bzr('status')[0]
485
self.assertContainsRe(result, "unknown:\n test1.c\n")
486
short_result = self.run_bzr('status --short')[0]
487
self.assertContainsRe(short_result, "\? test1.c\n")
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")
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")
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")
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")
509
def test_status_write_lock(self):
510
"""Test that status works without fetching history and
513
See https://bugs.launchpad.net/bzr/+bug/149270
516
wt = self.make_branch_and_tree('branch1')
518
wt.commit('Empty commit 1')
519
wt2 = b.bzrdir.sprout('branch2').open_workingtree()
520
wt2.commit('Empty commit 2')
521
out, err = self.run_bzr('status branch1 -rbranch:branch2')
522
self.assertEqual('', out)
524
def test_status_with_shelves(self):
525
"""Ensure that _show_shelve_summary handler works.
527
wt = self.make_branch_and_tree('.')
528
self.build_tree(['hello.c'])
530
self.run_bzr(['shelve', '--all', '-m', 'foo'])
531
self.build_tree(['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,
541
'1 shelves exist. See "bzr shelve --list" for details.\n',
546
255
class CheckoutStatus(BranchStatus):
549
258
super(CheckoutStatus, self).setUp()
553
262
def make_branch_and_tree(self, relpath):
554
263
source = self.make_branch(pathjoin('..', relpath))
555
264
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
556
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
557
target_branch=source)
265
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
558
266
return checkout.create_workingtree()
561
269
class TestStatus(TestCaseWithTransport):
563
271
def test_status_plain(self):
564
tree = self.make_branch_and_tree('.')
566
274
self.build_tree(['hello.txt'])
567
275
result = self.run_bzr("status")[0]
568
276
self.assertContainsRe(result, "unknown:\n hello.txt\n")
570
tree.add("hello.txt")
278
self.run_bzr("add", "hello.txt")
571
279
result = self.run_bzr("status")[0]
572
280
self.assertContainsRe(result, "added:\n hello.txt\n")
574
tree.commit(message="added")
575
result = self.run_bzr("status -r 0..1")[0]
576
self.assertContainsRe(result, "added:\n hello.txt\n")
578
result = self.run_bzr("status -c 1")[0]
282
self.run_bzr("commit", "-m", "added")
283
result = self.run_bzr("status", "-r", "0..1")[0]
579
284
self.assertContainsRe(result, "added:\n hello.txt\n")
581
286
self.build_tree(['world.txt'])
582
result = self.run_bzr("status -r 0")[0]
287
result = self.run_bzr("status", "-r", "0")[0]
583
288
self.assertContainsRe(result, "added:\n hello.txt\n" \
584
289
"unknown:\n world.txt\n")
585
result2 = self.run_bzr("status -r 0..")[0]
290
result2 = self.run_bzr("status", "-r", "0..")[0]
586
291
self.assertEquals(result2, result)
588
293
def test_status_short(self):
589
tree = self.make_branch_and_tree('.')
591
296
self.build_tree(['hello.txt'])
592
result = self.run_bzr("status --short")[0]
297
result = self.run_bzr("status","--short")[0]
593
298
self.assertContainsRe(result, "[?] hello.txt\n")
595
tree.add("hello.txt")
596
result = self.run_bzr("status --short")[0]
300
self.run_bzr("add", "hello.txt")
301
result = self.run_bzr("status","--short")[0]
597
302
self.assertContainsRe(result, "[+]N hello.txt\n")
599
tree.commit(message="added")
600
result = self.run_bzr("status --short -r 0..1")[0]
304
self.run_bzr("commit", "-m", "added")
305
result = self.run_bzr("status", "--short", "-r", "0..1")[0]
601
306
self.assertContainsRe(result, "[+]N hello.txt\n")
603
308
self.build_tree(['world.txt'])
604
result = self.run_bzr("status --short -r 0")[0]
309
result = self.run_bzr("status", "--short", "-r", "0")[0]
605
310
self.assertContainsRe(result, "[+]N hello.txt\n" \
606
311
"[?] world.txt\n")
607
result2 = self.run_bzr("status --short -r 0..")[0]
312
result2 = self.run_bzr("status", "--short", "-r", "0..")[0]
608
313
self.assertEquals(result2, result)
610
315
def test_status_versioned(self):
611
tree = self.make_branch_and_tree('.')
613
318
self.build_tree(['hello.txt'])
614
result = self.run_bzr("status --versioned")[0]
319
result = self.run_bzr("status", "--versioned")[0]
615
320
self.assertNotContainsRe(result, "unknown:\n hello.txt\n")
617
tree.add("hello.txt")
618
result = self.run_bzr("status --versioned")[0]
322
self.run_bzr("add", "hello.txt")
323
result = self.run_bzr("status", "--versioned")[0]
619
324
self.assertContainsRe(result, "added:\n hello.txt\n")
622
result = self.run_bzr("status --versioned -r 0..1")[0]
326
self.run_bzr("commit", "-m", "added")
327
result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
623
328
self.assertContainsRe(result, "added:\n hello.txt\n")
625
330
self.build_tree(['world.txt'])
626
result = self.run_bzr("status --versioned -r 0")[0]
331
result = self.run_bzr("status", "--versioned", "-r", "0")[0]
627
332
self.assertContainsRe(result, "added:\n hello.txt\n")
628
333
self.assertNotContainsRe(result, "unknown:\n world.txt\n")
629
result2 = self.run_bzr("status --versioned -r 0..")[0]
630
self.assertEquals(result2, result)
632
def test_status_SV(self):
633
tree = self.make_branch_and_tree('.')
635
self.build_tree(['hello.txt'])
636
result = self.run_bzr("status -SV")[0]
637
self.assertNotContainsRe(result, "hello.txt")
639
tree.add("hello.txt")
640
result = self.run_bzr("status -SV")[0]
641
self.assertContainsRe(result, "[+]N hello.txt\n")
643
tree.commit(message="added")
644
result = self.run_bzr("status -SV -r 0..1")[0]
645
self.assertContainsRe(result, "[+]N hello.txt\n")
647
self.build_tree(['world.txt'])
648
result = self.run_bzr("status -SV -r 0")[0]
649
self.assertContainsRe(result, "[+]N hello.txt\n")
651
result2 = self.run_bzr("status -SV -r 0..")[0]
652
self.assertEquals(result2, result)
654
def assertStatusContains(self, pattern, short=False):
334
result2 = self.run_bzr("status", "--versioned", "-r", "0..")[0]
335
self.assertEquals(result2, result)
337
def assertStatusContains(self, pattern):
655
338
"""Run status, and assert it contains the given pattern"""
657
result = self.run_bzr("status --short")[0]
659
result = self.run_bzr("status")[0]
339
result = self.run_bzr("status", "--short")[0]
660
340
self.assertContainsRe(result, pattern)
662
def test_kind_change_plain(self):
663
tree = self.make_branch_and_tree('.')
664
self.build_tree(['file'])
666
tree.commit('added file')
668
self.build_tree(['file/'])
669
self.assertStatusContains('kind changed:\n file \(file => directory\)')
670
tree.rename_one('file', 'directory')
671
self.assertStatusContains('renamed:\n file/ => directory/\n' \
672
'modified:\n directory/\n')
674
self.assertStatusContains('removed:\n file\n')
676
342
def test_kind_change_short(self):
677
343
tree = self.make_branch_and_tree('.')
678
344
self.build_tree(['file'])
680
346
tree.commit('added file')
682
348
self.build_tree(['file/'])
683
self.assertStatusContains('K file => file/',
349
self.assertStatusContains('K file => file/')
685
350
tree.rename_one('file', 'directory')
686
self.assertStatusContains('RK file => directory/',
351
self.assertStatusContains('RK file => directory/')
688
352
rmdir('directory')
689
self.assertStatusContains('RD file => directory',
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')
696
def test_status_no_pending(self):
697
a_tree = self.make_branch_and_tree('a')
698
self.build_tree(['a/a'])
701
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
702
self.build_tree(['b/b'])
706
self.run_bzr('merge ../b', working_dir='a')
707
out, err = self.run_bzr('status --no-pending', working_dir='a')
708
self.assertEquals(out, "added:\n b\n")
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')])
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)
720
output = self.make_utf8_encoded_stringio()
721
show_tree_status(tree, to_file=output)
722
self.assertContainsRe(output.getvalue(), 'pending merge')
723
out, err = self.run_bzr('status tree/a')
724
self.assertNotContainsRe(out, 'pending merge')
353
self.assertStatusContains('RD file => directory')
727
356
class TestStatusEncodings(TestCaseWithTransport):
359
TestCaseWithTransport.setUp(self)
360
self.user_encoding = bzrlib.user_encoding
361
self.stdout = sys.stdout
364
bzrlib.user_encoding = self.user_encoding
365
sys.stdout = self.stdout
366
TestCaseWithTransport.tearDown(self)
729
368
def make_uncommitted_tree(self):
730
369
"""Build a branch with uncommitted unicode named changes in the cwd."""