41
45
class BranchStatus(TestCaseWithTransport):
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.
47
51
:param expected_lines: The lines to look for.
48
52
:param working_tree: The tree to run status in.
50
output_string = self.status_string(working_tree, revision, short)
54
output_string = self.status_string(working_tree, revision, short,
51
56
self.assertEqual(expected_lines, output_string.splitlines(True))
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,
59
65
return tof.read().decode('utf-8')
228
245
self.assertEquals(tof.readlines(), ['? dir2/\n'])
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)
252
self.assertEquals(tof.readlines(), ['+N test.c\n'])
254
def test_specific_files_conflicts(self):
255
tree = self.make_branch_and_tree('.')
256
self.build_tree(['dir2/'])
258
tree.commit('added dir2')
259
tree.set_conflicts(conflicts.ConflictList(
260
[conflicts.ContentsConflict('foo')]))
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')]))
267
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
268
self.assertEqualDiff('conflicts:\n Contents conflict in dir2\n',
271
tree.set_conflicts(conflicts.ConflictList(
272
[conflicts.ContentsConflict('dir2/file1')]))
274
show_tree_status(tree, specific_files=['dir2'], to_file=tof)
275
self.assertEqualDiff('conflicts:\n Contents conflict in dir2/file1\n',
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')
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",
296
# before run another commands we should unlock tree
298
out, err = self.run_bzr('status')
299
self.assertEqual("working tree is out of date, run 'bzr update'\n",
302
def test_status_write_lock(self):
303
"""Test that status works without fetching history and
306
See https://bugs.launchpad.net/bzr/+bug/149270
309
wt = self.make_branch_and_tree('branch1')
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)
254
318
class CheckoutStatus(BranchStatus):
268
332
class TestStatus(TestCaseWithTransport):
270
334
def test_status_plain(self):
335
tree = self.make_branch_and_tree('.')
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")
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")
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")
349
result = self.run_bzr("status -c 1")[0]
283
350
self.assertContainsRe(result, "added:\n hello.txt\n")
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)
292
359
def test_status_short(self):
360
tree = self.make_branch_and_tree('.')
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")
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")
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")
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)
314
381
def test_status_versioned(self):
382
tree = self.make_branch_and_tree('.')
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")
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")
325
self.run_bzr("commit", "-m", "added")
326
result = self.run_bzr("status", "--versioned", "-r", "0..1")[0]
393
result = self.run_bzr("status --versioned -r 0..1")[0]
327
394
self.assertContainsRe(result, "added:\n hello.txt\n")
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)
403
def test_status_SV(self):
404
tree = self.make_branch_and_tree('.')
406
self.build_tree(['hello.txt'])
407
result = self.run_bzr("status -SV")[0]
408
self.assertNotContainsRe(result, "hello.txt")
410
tree.add("hello.txt")
411
result = self.run_bzr("status -SV")[0]
412
self.assertContainsRe(result, "[+]N hello.txt\n")
414
tree.commit(message="added")
415
result = self.run_bzr("status -SV -r 0..1")[0]
416
self.assertContainsRe(result, "[+]N hello.txt\n")
418
self.build_tree(['world.txt'])
419
result = self.run_bzr("status -SV -r 0")[0]
420
self.assertContainsRe(result, "[+]N hello.txt\n")
422
result2 = self.run_bzr("status -SV -r 0..")[0]
334
423
self.assertEquals(result2, result)
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)
341
430
def test_kind_change_short(self):
351
440
rmdir('directory')
352
441
self.assertStatusContains('RD file => directory')
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')
447
def test_status_no_pending(self):
448
a_tree = self.make_branch_and_tree('a')
449
self.build_tree(['a/a'])
452
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
453
self.build_tree(['b/b'])
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")
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')])
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:')
355
478
class TestStatusEncodings(TestCaseWithTransport):
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
362
485
def tearDown(self):