46
46
class BranchStatus(TestCaseWithTransport):
49
super(BranchStatus, self).setUp()
50
# As TestCase.setUp clears all hooks, we install this default
51
# post_status hook handler for the test.
52
status.hooks.install_named_hook('post_status',
53
status._show_shelve_summary,
56
def assertStatus(self, expected_lines, working_tree, specific_files=None,
48
def assertStatus(self, expected_lines, working_tree,
57
49
revision=None, short=False, pending=True, verbose=False):
58
50
"""Run status in working_tree and look for output.
60
52
:param expected_lines: The lines to look for.
61
53
:param working_tree: The tree to run status in.
63
output_string = self.status_string(working_tree, specific_files, revision, short,
55
output_string = self.status_string(working_tree, revision, short,
65
57
self.assertEqual(expected_lines, output_string.splitlines(True))
67
def status_string(self, wt, specific_files=None, revision=None,
68
short=False, pending=True, verbose=False):
59
def status_string(self, wt, revision=None, short=False, pending=True,
69
61
# use a real file rather than StringIO because it doesn't handle
70
62
# Unicode very well.
71
63
tof = codecs.getwriter('utf-8')(TemporaryFile())
72
show_tree_status(wt, specific_files=specific_files, to_file=tof,
73
revision=revision, short=short, show_pending=pending,
64
show_tree_status(wt, to_file=tof, revision=revision, short=short,
65
show_pending=pending, verbose=verbose)
76
67
return tof.read().decode('utf-8')
188
179
wt2.merge_from_branch(wt.branch)
189
180
message = self.status_string(wt2, verbose=True)
190
181
self.assertStartsWith(message, "pending merges:\n")
191
self.assertTrue("Empty commit 3" in message)
182
self.assert_("Empty commit 3" in message)
192
183
self.assertEndsWith(message, "...\n")
194
185
def test_tree_status_ignores(self):
212
203
wt = self.make_branch_and_tree('.')
215
self.build_tree(['directory/','directory/hello.c',
216
'bye.c','test.c','dir2/',
206
self.build_tree(['directory/','directory/hello.c', 'bye.c','test.c','dir2/'])
218
207
wt.add('directory')
220
209
wt.commit('testing')
224
211
self.assertStatus([
256
240
show_tree_status(wt, specific_files=['directory'], to_file=tof,
259
self.assertEqual(tof.readlines(), ['? directory/hello.c\n'])
243
self.assertEquals(tof.readlines(), ['? directory/hello.c\n'])
262
246
show_tree_status(wt, specific_files=['dir2'], to_file=tof)
264
self.assertEqual(tof.readlines(),
248
self.assertEquals(tof.readlines(),
269
253
show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
271
self.assertEqual(tof.readlines(), ['? dir2/\n'])
255
self.assertEquals(tof.readlines(), ['? dir2/\n'])
274
258
revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
275
259
show_tree_status(wt, specific_files=['test.c'], to_file=tof,
276
260
short=True, revision=revs)
278
self.assertEqual(tof.readlines(), ['+N test.c\n'])
281
show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
283
self.assertEqual(tof.readlines(),
288
show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
291
self.assertEqual(tof.readlines(),
262
self.assertEquals(tof.readlines(), ['+N test.c\n'])
294
264
def test_specific_files_conflicts(self):
295
265
tree = self.make_branch_and_tree('.')
327
297
wt.commit('Create five empty files.')
328
with open('FILE_B', 'w') as f: f.write('Modification to file FILE_B.')
329
with open('FILE_C', 'w') as f: f.write('Modification to file FILE_C.')
298
open('FILE_B', 'w').write('Modification to file FILE_B.')
299
open('FILE_C', 'w').write('Modification to file FILE_C.')
330
300
unlink('FILE_E') # FILE_E will be versioned but missing
331
with open('FILE_Q', 'w') as f: f.write('FILE_Q is added but not committed.')
301
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
332
302
wt.add('FILE_Q') # FILE_Q will be added but not committed
333
303
open('UNVERSIONED_BUT_EXISTING', 'w')
479
449
'X NONEXISTENT\n',
482
451
out, err = self.run_bzr('status --short NONEXISTENT '
483
452
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
484
453
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
485
actual = out.splitlines(True)
487
self.assertEqual(expected, actual)
454
self.assertEqual(expected, out.splitlines(True))
488
455
self.assertContainsRe(err,
489
456
r'.*ERROR: Path\(s\) do not exist: '
563
530
self.run_bzr(['shelve', '--all', '-m', 'foo'])
564
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,
566
538
self.assertStatus([
569
'1 shelf exists. See "bzr shelve --list" for details.\n',
572
self.run_bzr(['shelve', '--all', '-m', 'bar'])
573
self.build_tree(['eggs.c', 'spam.c'])
580
'2 shelves exist. See "bzr shelve --list" for details.\n',
588
specific_files=['spam.c'])
541
'1 shelves exist. See "bzr shelve --list" for details.\n',
591
546
class CheckoutStatus(BranchStatus):
598
553
def make_branch_and_tree(self, relpath):
599
554
source = self.make_branch(pathjoin('..', relpath))
600
555
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
601
checkout.set_branch_reference(source)
556
bzrlib.branch.BranchReferenceFormat().initialize(checkout,
557
target_branch=source)
602
558
return checkout.create_workingtree()
627
583
self.assertContainsRe(result, "added:\n hello.txt\n" \
628
584
"unknown:\n world.txt\n")
629
585
result2 = self.run_bzr("status -r 0..")[0]
630
self.assertEqual(result2, result)
586
self.assertEquals(result2, result)
632
588
def test_status_short(self):
633
589
tree = self.make_branch_and_tree('.')
645
601
self.assertContainsRe(result, "[+]N hello.txt\n")
647
603
self.build_tree(['world.txt'])
648
result = self.run_bzr("status -S -r 0")[0]
604
result = self.run_bzr("status --short -r 0")[0]
649
605
self.assertContainsRe(result, "[+]N hello.txt\n" \
650
606
"[?] world.txt\n")
651
result2 = self.run_bzr("status -S -r 0..")[0]
652
self.assertEqual(result2, result)
607
result2 = self.run_bzr("status --short -r 0..")[0]
608
self.assertEquals(result2, result)
654
610
def test_status_versioned(self):
655
611
tree = self.make_branch_and_tree('.')
671
627
self.assertContainsRe(result, "added:\n hello.txt\n")
672
628
self.assertNotContainsRe(result, "unknown:\n world.txt\n")
673
629
result2 = self.run_bzr("status --versioned -r 0..")[0]
674
self.assertEqual(result2, result)
630
self.assertEquals(result2, result)
676
632
def test_status_SV(self):
677
633
tree = self.make_branch_and_tree('.')
693
649
self.assertContainsRe(result, "[+]N hello.txt\n")
695
651
result2 = self.run_bzr("status -SV -r 0..")[0]
696
self.assertEqual(result2, result)
652
self.assertEquals(result2, result)
698
654
def assertStatusContains(self, pattern, short=False):
699
655
"""Run status, and assert it contains the given pattern"""
750
706
self.run_bzr('merge ../b', working_dir='a')
751
707
out, err = self.run_bzr('status --no-pending', working_dir='a')
752
self.assertEqual(out, "added:\n b\n")
708
self.assertEquals(out, "added:\n b\n")
754
710
def test_pending_specific_files(self):
755
711
"""With a specific file list, pending merges are not shown."""