45
41
class BranchStatus(TestCaseWithTransport):
47
43
def assertStatus(self, expected_lines, working_tree,
48
revision=None, short=False, pending=True, verbose=False):
44
revision=None, short=False):
49
45
"""Run status in working_tree and look for output.
51
47
:param expected_lines: The lines to look for.
52
48
:param working_tree: The tree to run status in.
54
output_string = self.status_string(working_tree, revision, short,
50
output_string = self.status_string(working_tree, revision, short)
56
51
self.assertEqual(expected_lines, output_string.splitlines(True))
58
def status_string(self, wt, revision=None, short=False, pending=True,
53
def status_string(self, wt, revision=None, short=False):
60
54
# use a real file rather than StringIO because it doesn't handle
61
55
# Unicode very well.
62
56
tof = codecs.getwriter('utf-8')(TemporaryFile())
63
show_tree_status(wt, to_file=tof, revision=revision, short=short,
64
show_pending=pending, verbose=verbose)
57
show_tree_status(wt, to_file=tof, revision=revision, short=short)
66
59
return tof.read().decode('utf-8')
167
141
b_2 = b_2_dir.open_branch()
168
142
wt2 = b_2_dir.open_workingtree()
169
143
wt.commit(u"\N{TIBETAN DIGIT TWO} Empty commit 2")
170
wt2.merge_from_branch(wt.branch)
171
message = self.status_string(wt2, verbose=True)
144
merge(["./branch", -1], [None, None], this_dir = './copy')
145
message = self.status_string(wt2)
172
146
self.assertStartsWith(message, "pending merges:\n")
173
147
self.assertEndsWith(message, "Empty commit 2\n")
174
148
wt2.commit("merged")
175
149
# must be long to make sure we see elipsis at the end
176
150
wt.commit("Empty commit 3 " +
177
151
"blah blah blah blah " * 100)
178
wt2.merge_from_branch(wt.branch)
179
message = self.status_string(wt2, verbose=True)
152
merge(["./branch", -1], [None, None], this_dir = './copy')
153
message = self.status_string(wt2)
180
154
self.assertStartsWith(message, "pending merges:\n")
181
155
self.assert_("Empty commit 3" in message)
182
156
self.assertEndsWith(message, "...\n")
254
228
self.assertEquals(tof.readlines(), ['? dir2/\n'])
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)
261
self.assertEquals(tof.readlines(), ['+N test.c\n'])
263
def test_specific_files_conflicts(self):
264
tree = self.make_branch_and_tree('.')
265
self.build_tree(['dir2/'])
267
tree.commit('added dir2')
268
tree.set_conflicts(conflicts.ConflictList(
269
[conflicts.ContentsConflict('foo')]))
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')]))
276
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
277
self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n',
280
tree.set_conflicts(conflicts.ConflictList(
281
[conflicts.ContentsConflict('dir2/file1')]))
283
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
284
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
287
def _prepare_nonexistent(self):
288
wt = self.make_branch_and_tree('.')
289
self.assertStatus([], wt)
290
self.build_tree(['FILE_A', 'FILE_B', 'FILE_C', 'FILE_D', 'FILE_E', ])
296
wt.commit('Create five empty files.')
297
open('FILE_B', 'w').write('Modification to file FILE_B.')
298
open('FILE_C', 'w').write('Modification to file FILE_C.')
299
unlink('FILE_E') # FILE_E will be versioned but missing
300
open('FILE_Q', 'w').write('FILE_Q is added but not committed.')
301
wt.add('FILE_Q') # FILE_Q will be added but not committed
302
open('UNVERSIONED_BUT_EXISTING', 'w')
305
230
def test_status_nonexistent_file(self):
306
231
# files that don't exist in either the basis tree or working tree
307
232
# should give an error
308
wt = self._prepare_nonexistent()
318
' UNVERSIONED_BUT_EXISTING\n',
326
'? UNVERSIONED_BUT_EXISTING\n',
330
# Okay, everything's looking good with the existent files.
331
# Let's see what happens when we throw in non-existent files.
333
# bzr st [--short] NONEXISTENT '
338
out, err = self.run_bzr('status NONEXISTENT', retcode=3)
339
self.assertEqual(expected, out.splitlines(True))
340
self.assertContainsRe(err,
341
r'.*ERROR: Path\(s\) do not exist: '
346
out, err = self.run_bzr('status --short NONEXISTENT', retcode=3)
347
self.assertContainsRe(err,
348
r'.*ERROR: Path\(s\) do not exist: '
351
def test_status_nonexistent_file_with_others(self):
352
# bzr st [--short] NONEXISTENT ...others..
353
wt = self._prepare_nonexistent()
363
out, err = self.run_bzr('status NONEXISTENT '
364
'FILE_A FILE_B FILE_C FILE_D FILE_E',
366
self.assertEqual(expected, out.splitlines(True))
367
self.assertContainsRe(err,
368
r'.*ERROR: Path\(s\) do not exist: '
376
out, err = self.run_bzr('status --short NONEXISTENT '
377
'FILE_A FILE_B FILE_C FILE_D FILE_E',
379
self.assertEqual(expected, out.splitlines(True))
380
self.assertContainsRe(err,
381
r'.*ERROR: Path\(s\) do not exist: '
384
def test_status_multiple_nonexistent_files(self):
385
# bzr st [--short] NONEXISTENT ... ANOTHER_NONEXISTENT ...
386
wt = self._prepare_nonexistent()
394
' ANOTHER_NONEXISTENT\n',
397
out, err = self.run_bzr('status NONEXISTENT '
398
'FILE_A FILE_B ANOTHER_NONEXISTENT '
399
'FILE_C FILE_D FILE_E', retcode=3)
400
self.assertEqual(expected, out.splitlines(True))
401
self.assertContainsRe(err,
402
r'.*ERROR: Path\(s\) do not exist: '
403
'ANOTHER_NONEXISTENT NONEXISTENT.*')
408
'X ANOTHER_NONEXISTENT\n',
411
out, err = self.run_bzr('status --short NONEXISTENT '
412
'FILE_A FILE_B ANOTHER_NONEXISTENT '
413
'FILE_C FILE_D FILE_E', retcode=3)
414
self.assertEqual(expected, out.splitlines(True))
415
self.assertContainsRe(err,
416
r'.*ERROR: Path\(s\) do not exist: '
417
'ANOTHER_NONEXISTENT NONEXISTENT.*')
419
def test_status_nonexistent_file_with_unversioned(self):
420
# bzr st [--short] NONEXISTENT A B UNVERSIONED_BUT_EXISTING C D E Q
421
wt = self._prepare_nonexistent()
431
' UNVERSIONED_BUT_EXISTING\n',
435
out, err = self.run_bzr('status NONEXISTENT '
436
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
437
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
438
self.assertEqual(expected, out.splitlines(True))
439
self.assertContainsRe(err,
440
r'.*ERROR: Path\(s\) do not exist: '
444
'? UNVERSIONED_BUT_EXISTING\n',
450
out, err = self.run_bzr('status --short NONEXISTENT '
451
'FILE_A FILE_B UNVERSIONED_BUT_EXISTING '
452
'FILE_C FILE_D FILE_E FILE_Q', retcode=3)
453
self.assertEqual(expected, out.splitlines(True))
454
self.assertContainsRe(err,
455
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')
458
237
def test_status_out_of_date(self):
459
238
"""Simulate status of out-of-date tree after remote push"""
573
334
result2 = self.run_bzr("status --versioned -r 0..")[0]
574
335
self.assertEquals(result2, result)
576
def test_status_SV(self):
577
tree = self.make_branch_and_tree('.')
579
self.build_tree(['hello.txt'])
580
result = self.run_bzr("status -SV")[0]
581
self.assertNotContainsRe(result, "hello.txt")
583
tree.add("hello.txt")
584
result = self.run_bzr("status -SV")[0]
585
self.assertContainsRe(result, "[+]N hello.txt\n")
587
tree.commit(message="added")
588
result = self.run_bzr("status -SV -r 0..1")[0]
589
self.assertContainsRe(result, "[+]N hello.txt\n")
591
self.build_tree(['world.txt'])
592
result = self.run_bzr("status -SV -r 0")[0]
593
self.assertContainsRe(result, "[+]N hello.txt\n")
595
result2 = self.run_bzr("status -SV -r 0..")[0]
596
self.assertEquals(result2, result)
598
337
def assertStatusContains(self, pattern):
599
338
"""Run status, and assert it contains the given pattern"""
600
339
result = self.run_bzr("status --short")[0]
613
352
rmdir('directory')
614
353
self.assertStatusContains('RD file => directory')
616
def test_status_illegal_revision_specifiers(self):
617
out, err = self.run_bzr('status -r 1..23..123', retcode=3)
618
self.assertContainsRe(err, 'one or two revision specifiers')
620
def test_status_no_pending(self):
621
a_tree = self.make_branch_and_tree('a')
622
self.build_tree(['a/a'])
625
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
626
self.build_tree(['b/b'])
630
self.run_bzr('merge ../b', working_dir='a')
631
out, err = self.run_bzr('status --no-pending', working_dir='a')
632
self.assertEquals(out, "added:\n b\n")
634
def test_pending_specific_files(self):
635
"""With a specific file list, pending merges are not shown."""
636
tree = self.make_branch_and_tree('tree')
637
self.build_tree_contents([('tree/a', 'content of a\n')])
639
r1_id = tree.commit('one')
640
alt = tree.bzrdir.sprout('alt').open_workingtree()
641
self.build_tree_contents([('alt/a', 'content of a\nfrom alt\n')])
642
alt_id = alt.commit('alt')
643
tree.merge_from_branch(alt.branch)
644
output = self.make_utf8_encoded_stringio()
645
show_tree_status(tree, to_file=output)
646
self.assertContainsRe(output.getvalue(), 'pending merge')
647
out, err = self.run_bzr('status tree/a')
648
self.assertNotContainsRe(out, 'pending merge')
651
356
class TestStatusEncodings(TestCaseWithTransport):
654
359
TestCaseWithTransport.setUp(self)
655
self.user_encoding = osutils._cached_user_encoding
360
self.user_encoding = bzrlib.user_encoding
656
361
self.stdout = sys.stdout
658
363
def tearDown(self):