55
55
# As TestCase.setUp clears all hooks, we install this default
56
56
# post_status hook handler for the test.
57
57
status.hooks.install_named_hook('post_status',
58
status._show_shelve_summary,
58
status._show_shelve_summary,
61
61
def assertStatus(self, expected_lines, working_tree, specific_files=None,
62
revision=None, short=False, pending=True, verbose=False):
62
revision=None, short=False, pending=True, verbose=False):
63
63
"""Run status in working_tree and look for output.
65
65
:param expected_lines: The lines to look for.
66
66
:param working_tree: The tree to run status in.
68
68
output_string = self.status_string(working_tree, specific_files, revision, short,
70
70
self.assertEqual(expected_lines, output_string.splitlines(True))
72
72
def status_string(self, wt, specific_files=None, revision=None,
73
short=False, pending=True, verbose=False):
73
short=False, pending=True, verbose=False):
74
74
uio = self.make_utf8_encoded_stringio()
75
75
show_tree_status(wt, specific_files=specific_files, to_file=uio,
76
revision=revision, short=short, show_pending=pending,
76
revision=revision, short=short, show_pending=pending,
78
78
return uio.getvalue().decode('utf-8')
80
80
def test_branch_status(self):
106
106
wt.add_parent_tree_id(b'pending@pending-0-0')
107
107
self.assertStatus([
111
'pending merge tips: (use -v to see all merge revisions)\n',
112
' (ghost) pending@pending-0-0\n',
111
'pending merge tips: (use -v to see all merge revisions)\n',
112
' (ghost) pending@pending-0-0\n',
115
115
self.assertStatus([
120
' (ghost) pending@pending-0-0\n',
120
' (ghost) pending@pending-0-0\n',
122
122
wt, verbose=True)
123
123
self.assertStatus([
126
'P (ghost) pending@pending-0-0\n',
126
'P (ghost) pending@pending-0-0\n',
129
129
self.assertStatus([
134
134
wt, pending=False)
135
135
self.assertStatus([
139
139
wt, short=True, pending=False)
185
185
self.assertEndsWith(message, "Empty commit 2\n")
186
186
wt2.commit("merged")
187
187
# must be long to make sure we see elipsis at the end
188
wt.commit("Empty commit 3 " +
189
"blah blah blah blah " * 100)
188
wt.commit("Empty commit 3 "
189
+ "blah blah blah blah " * 100)
190
190
wt2.merge_from_branch(wt.branch)
191
191
message = self.status_string(wt2, verbose=True)
192
192
self.assertStartsWith(message, "pending merges:\n")
200
200
wt.commit('commit .bzrignore')
201
201
self.build_tree(['foo.c', 'foo.c~'])
202
202
self.assertStatus([
207
207
self.assertStatus([
212
212
def test_tree_status_specific_files(self):
213
213
"""Tests branch status with given specific files"""
251
251
show_tree_status(wt, specific_files=['directory'], to_file=tof)
253
253
self.assertEqual(tof.readlines(),
255
' directory/hello.c\n'
255
' directory/hello.c\n'
258
258
show_tree_status(wt, specific_files=['directory'], to_file=tof,
264
264
show_tree_status(wt, specific_files=['dir2'], to_file=tof)
266
266
self.assertEqual(tof.readlines(),
271
271
show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
283
283
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
285
285
self.assertEqual(tof.readlines(),
290
290
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
293
293
self.assertEqual(tof.readlines(),
296
296
def test_specific_files_conflicts(self):
297
297
tree = self.make_branch_and_tree('.')
329
329
wt.commit('Create five empty files.')
330
with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
331
with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
330
with open('FILE_B', 'w') as f:
331
f.write('Modification to file FILE_B.')
332
with open('FILE_C', 'w') as f:
333
f.write('Modification to file FILE_C.')
332
334
unlink('FILE_E') # FILE_E will be versioned but missing
333
with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
335
with open('FILE_Q', 'w') as f:
336
f.write('FILE_Q is added but not committed.')
334
337
wt.add('FILE_Q') # FILE_Q will be added but not committed
335
338
open('UNVERSIONED_BUT_EXISTING', 'w')
366
369
# brz st [--short] NONEXISTENT '
371
374
out, err = self.run_bzr('status NONEXISTENT', retcode=3)
372
375
self.assertEqual(expected, out.splitlines(True))
373
376
self.assertContainsRe(err,
374
377
r'.*ERROR: Path\(s\) do not exist: '
379
382
out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
380
383
self.assertContainsRe(err,
381
384
r'.*ERROR: Path\(s\) do not exist: '
385
388
# brz st [--short] NONEXISTENT ...others..
386
389
wt = self._prepare_nonexistent()
396
399
out, err = self.run_bzr('status NONEXISTENT '
397
400
'FILE_A FILE_B FILE_C FILE_D FILE_E',
418
421
# brz st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
419
422
wt = self._prepare_nonexistent()
427
' ANOTHER_NONEXISTENT\n',
430
' ANOTHER_NONEXISTENT\n',
430
433
out, err = self.run_bzr('status NONEXISTENT '
431
434
'FILE_A FILE_B ANOTHER_NONEXISTENT '
432
435
'FILE_C FILE_D FILE_E', retcode=3)
435
438
r'.*ERROR: Path\(s\) do not exist: '
436
439
'ANOTHER_NONEXISTENT NONEXISTENT.*')
441
'X ANOTHER_NONEXISTENT\n',
444
'X ANOTHER_NONEXISTENT\n',
444
447
out, err = self.run_bzr('status --short NONEXISTENT '
445
448
'FILE_A FILE_B ANOTHER_NONEXISTENT '
446
449
'FILE_C FILE_D FILE_E', retcode=3)
453
456
# brz st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
454
457
wt = self._prepare_nonexistent()
464
' UNVERSIONED_BUT_EXISTING\n',
467
' UNVERSIONED_BUT_EXISTING\n',
468
471
out, err = self.run_bzr('status NONEXISTENT '
469
472
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
470
473
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
473
476
r'.*ERROR: Path\(s\) do not exist: '
475
478
expected = sorted([
477
'? UNVERSIONED_BUT_EXISTING\n',
480
'? UNVERSIONED_BUT_EXISTING\n',
483
486
out, err = self.run_bzr('status --short NONEXISTENT '
484
487
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
485
488
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
536
539
self.assertContainsRe(short_result, "I test1.c~\nI test2.c~\n")
538
541
result = self.run_bzr('status test1.c test1.c~ test2.c~')[0]
539
self.assertContainsRe(result, "unknown:\n test1.c\nignored:\n test1.c~\n test2.c~\n")
540
short_result = self.run_bzr('status --short test1.c test1.c~ test2.c~')[0]
541
self.assertContainsRe(short_result, "\\? test1.c\nI test1.c~\nI test2.c~\n")
542
self.assertContainsRe(
543
result, "unknown:\n test1.c\nignored:\n test1.c~\n test2.c~\n")
544
short_result = self.run_bzr(
545
'status --short test1.c test1.c~ test2.c~')[0]
546
self.assertContainsRe(
547
short_result, "\\? test1.c\nI test1.c~\nI test2.c~\n")
543
549
def test_status_write_lock(self):
544
550
"""Test that status works without fetching history and
565
571
self.build_tree(['bye.c'])
567
573
self.assertStatus([
570
'1 shelf exists. See "brz shelve --list" for details.\n',
576
'1 shelf exists. See "brz shelve --list" for details.\n',
573
579
self.run_bzr(['shelve', '--all', '-m', 'bar'])
626
632
self.build_tree(['world.txt'])
627
633
result = self.run_bzr("status -r 0")[0]
628
self.assertContainsRe(result, "added:\n hello.txt\n" \
634
self.assertContainsRe(result, "added:\n hello.txt\n"
629
635
"unknown:\n world.txt\n")
630
636
result2 = self.run_bzr("status -r 0..")[0]
631
637
self.assertEqual(result2, result)
648
654
self.build_tree(['world.txt'])
649
655
result = self.run_bzr("status -S -r 0")[0]
650
self.assertContainsRe(result, "[+]N hello.txt\n" \
656
self.assertContainsRe(result, "[+]N hello.txt\n"
651
657
"[?] world.txt\n")
652
658
result2 = self.run_bzr("status -S -r 0..")[0]
653
659
self.assertEqual(result2, result)
711
717
tree.commit('added file')
713
719
self.build_tree(['file/'])
714
self.assertStatusContains('kind changed:\n file \\(file => directory\\)')
720
self.assertStatusContains(
721
'kind changed:\n file \\(file => directory\\)')
715
722
tree.rename_one('file', 'directory')
716
self.assertStatusContains('renamed:\n file/ => directory/\n' \
723
self.assertStatusContains('renamed:\n file/ => directory/\n'
717
724
'modified:\n directory/\n')
718
725
rmdir('directory')
719
726
self.assertStatusContains('removed:\n file\n')
727
734
self.build_tree(['file/'])
728
735
self.assertStatusContains('K file => file/',
730
737
tree.rename_one('file', 'directory')
731
738
self.assertStatusContains('RK file => directory/',
733
740
rmdir('directory')
734
741
self.assertStatusContains('RD file => directory',
737
744
def test_status_illegal_revision_specifiers(self):
738
745
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
779
786
self.build_tree_contents([(filename, b'contents of hello')])
780
787
except UnicodeEncodeError:
781
788
raise TestSkipped("can't build unicode working tree in "
782
"filesystem encoding %s" % sys.getfilesystemencoding())
789
"filesystem encoding %s" % sys.getfilesystemencoding())
783
790
working_tree.add(filename)
784
791
return working_tree