1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz log."""
20
from __future__ import absolute_import
32
from breezy.tests import (
36
from breezy.tests.matchers import ContainsNoVfsCalls
39
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
41
def make_minimal_branch(self, path='.', format=None):
42
tree = self.make_branch_and_tree(path, format=format)
43
self.build_tree([path + '/hello.txt'])
45
tree.commit(message='message1')
48
def make_linear_branch(self, path='.', format=None):
49
tree = self.make_branch_and_tree(path, format=format)
51
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
53
tree.commit(message='message1')
54
tree.add('goodbye.txt')
55
tree.commit(message='message2')
57
tree.commit(message='message3')
60
def make_merged_branch(self, path='.', format=None):
61
tree = self.make_linear_branch(path, format)
62
tree2 = tree.controldir.sprout('tree2',
63
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
64
tree2.commit(message='tree2 message2')
65
tree2.commit(message='tree2 message3')
66
tree.merge_from_branch(tree2.branch)
67
tree.commit(message='merge')
71
class TestLogWithLogCatcher(TestLog):
74
super(TestLogWithLogCatcher, self).setUp()
75
# Capture log formatter creations
76
class MyLogFormatter(test_log.LogCatcher):
78
def __new__(klass, *args, **kwargs):
79
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
80
# Always return our own log formatter
81
return self.log_catcher
82
# Break cycle with closure over self on cleanup by removing method
83
self.addCleanup(setattr, MyLogFormatter, "__new__", None)
86
# Always return our own log formatter class hijacking the
87
# default behavior (which requires setting up a config
90
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
92
def get_captured_revisions(self):
93
return self.log_catcher.revisions
95
def assertLogRevnos(self, args, expected_revnos, working_dir='.',
97
actual_out, actual_err = self.run_bzr(['log'] + args,
98
working_dir=working_dir)
99
self.assertEqual(out, actual_out)
100
self.assertEqual(err, actual_err)
101
self.assertEqual(expected_revnos,
102
[r.revno for r in self.get_captured_revisions()])
104
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
106
self.run_bzr(['log'] + args, working_dir=working_dir)
107
self.assertEqual(expected_revnos_and_depths,
108
[(r.revno, r.merge_depth)
109
for r in self.get_captured_revisions()])
112
class TestLogRevSpecs(TestLogWithLogCatcher):
114
def test_log_no_revspec(self):
115
self.make_linear_branch()
116
self.assertLogRevnos([], ['3', '2', '1'])
118
def test_log_null_end_revspec(self):
119
self.make_linear_branch()
120
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
122
def test_log_null_begin_revspec(self):
123
self.make_linear_branch()
124
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
126
def test_log_null_both_revspecs(self):
127
self.make_linear_branch()
128
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
130
def test_log_negative_begin_revspec_full_log(self):
131
self.make_linear_branch()
132
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
134
def test_log_negative_both_revspec_full_log(self):
135
self.make_linear_branch()
136
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
138
def test_log_negative_both_revspec_partial(self):
139
self.make_linear_branch()
140
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
142
def test_log_negative_begin_revspec(self):
143
self.make_linear_branch()
144
self.assertLogRevnos(['-r-2..'], ['3', '2'])
146
def test_log_positive_revspecs(self):
147
self.make_linear_branch()
148
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
150
def test_log_dotted_revspecs(self):
151
self.make_merged_branch()
152
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
154
def test_log_limit(self):
155
tree = self.make_branch_and_tree('.')
156
# We want more commits than our batch size starts at
157
for pos in range(10):
158
tree.commit("%s" % pos)
159
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
161
def test_log_limit_short(self):
162
self.make_linear_branch()
163
self.assertLogRevnos(['-l', '2'], ['3', '2'])
165
def test_log_change_revno(self):
166
self.make_linear_branch()
167
self.assertLogRevnos(['-c1'], ['1'])
169
def test_branch_revspec(self):
170
foo = self.make_branch_and_tree('foo')
171
bar = self.make_branch_and_tree('bar')
172
self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
175
foo.commit(message='foo')
176
bar.commit(message='bar')
177
self.run_bzr('log -r branch:../bar', working_dir='foo')
178
self.assertEqual([bar.branch.get_rev_id(1)],
180
for r in self.get_captured_revisions()])
183
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
185
def test_exclude_common_ancestry_simple_revnos(self):
186
self.make_linear_branch()
187
self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
191
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
194
super(TestLogMergedLinearAncestry, self).setUp()
195
# FIXME: Using a MemoryTree would be even better here (but until we
196
# stop calling run_bzr, there is no point) --vila 100118.
197
builder = branchbuilder.BranchBuilder(self.get_transport())
198
builder.start_series()
216
builder.build_snapshot('1', None, [
217
('add', ('', 'root-id', 'directory', ''))])
218
builder.build_snapshot('2', ['1'], [])
220
builder.build_snapshot('1.1.1', ['1'], [])
221
# merge branch into mainline
222
builder.build_snapshot('3', ['2', '1.1.1'], [])
223
# new commits in branch
224
builder.build_snapshot('1.1.2', ['1.1.1'], [])
225
builder.build_snapshot('1.1.3', ['1.1.2'], [])
226
# merge branch into mainline
227
builder.build_snapshot('4', ['3', '1.1.3'], [])
228
# merge mainline into branch
229
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
230
# merge branch into mainline
231
builder.build_snapshot('5', ['4', '1.1.4'], [])
232
builder.build_snapshot('5.1.1', ['5'], [])
233
builder.build_snapshot('6', ['5', '5.1.1'], [])
234
builder.finish_series()
237
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
238
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
239
def test_n0_forward(self):
240
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
241
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
244
# starting from 1.1.4 we follow the left-hand ancestry
245
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
246
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
248
def test_n1_forward(self):
249
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
250
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
252
def test_fallback_when_end_rev_is_not_on_mainline(self):
253
self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
254
# We don't get 1.1.1 because we say -n1
255
['5.1.1', '5', '4', '3'])
258
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
261
super(Test_GenerateAllRevisions, self).setUp()
262
builder = self.make_branch_with_many_merges()
263
b = builder.get_branch()
265
self.addCleanup(b.unlock)
268
def make_branch_with_many_merges(self, path='.', format=None):
269
builder = branchbuilder.BranchBuilder(self.get_transport())
270
builder.start_series()
271
# The graph below may look a bit complicated (and it may be but I've
272
# banged my head enough on it) but the bug requires at least dotted
273
# revnos *and* merged revisions below that.
287
builder.build_snapshot('1', None, [
288
('add', ('', 'root-id', 'directory', ''))])
289
builder.build_snapshot('2', ['1'], [])
290
builder.build_snapshot('1.1.1', ['1'], [])
291
builder.build_snapshot('2.1.1', ['2'], [])
292
builder.build_snapshot('3', ['2', '1.1.1'], [])
293
builder.build_snapshot('2.1.2', ['2.1.1'], [])
294
builder.build_snapshot('2.2.1', ['2.1.1'], [])
295
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
296
builder.build_snapshot('4', ['3', '2.1.3'], [])
297
builder.build_snapshot('5', ['4', '2.1.2'], [])
298
builder.finish_series()
301
def test_not_an_ancestor(self):
302
self.assertRaises(errors.BzrCommandError,
303
log._generate_all_revisions,
304
self.branch, '1.1.1', '2.1.3', 'reverse',
305
delayed_graph_generation=True)
307
def test_wrong_order(self):
308
self.assertRaises(errors.BzrCommandError,
309
log._generate_all_revisions,
310
self.branch, '5', '2.1.3', 'reverse',
311
delayed_graph_generation=True)
313
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
314
revs = log._generate_all_revisions(
315
self.branch, None, '2.1.3',
316
'reverse', delayed_graph_generation=True)
319
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
321
def test_log_revno_n_path_wrong_namespace(self):
322
self.make_linear_branch('branch1')
323
self.make_linear_branch('branch2')
324
# There is no guarantee that a path exist between two arbitrary
326
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
328
def test_log_revno_n_path_correct_order(self):
329
self.make_linear_branch('branch2')
330
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
333
def test_log_revno_n_path(self):
334
self.make_linear_branch('branch2')
335
self.assertLogRevnos(['-rrevno:1:branch2'],
337
rev_props = self.log_catcher.revisions[0].rev.properties
338
self.assertEqual('branch2', rev_props['branch-nick'])
341
class TestLogErrors(TestLog):
343
def test_log_zero_revspec(self):
344
self.make_minimal_branch()
345
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
348
def test_log_zero_begin_revspec(self):
349
self.make_linear_branch()
350
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
353
def test_log_zero_end_revspec(self):
354
self.make_linear_branch()
355
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
358
def test_log_nonexistent_revno(self):
359
self.make_minimal_branch()
360
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
361
"does not exist in branch:"],
364
def test_log_nonexistent_dotted_revno(self):
365
self.make_minimal_branch()
366
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
367
"does not exist in branch:"],
368
['log', '-r123.123'])
370
def test_log_change_nonexistent_revno(self):
371
self.make_minimal_branch()
372
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
373
"does not exist in branch:"],
376
def test_log_change_nonexistent_dotted_revno(self):
377
self.make_minimal_branch()
378
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
379
"does not exist in branch:"],
380
['log', '-c123.123'])
382
def test_log_change_single_revno_only(self):
383
self.make_minimal_branch()
384
self.run_bzr_error(['brz: ERROR: Option --change does not'
385
' accept revision ranges'],
386
['log', '--change', '2..3'])
388
def test_log_change_incompatible_with_revision(self):
389
self.run_bzr_error(['brz: ERROR: --revision and --change'
390
' are mutually exclusive'],
391
['log', '--change', '2', '--revision', '3'])
393
def test_log_nonexistent_file(self):
394
self.make_minimal_branch()
395
# files that don't exist in either the basis tree or working tree
396
# should give an error
397
out, err = self.run_bzr('log does-not-exist', retcode=3)
398
self.assertContainsRe(err,
399
'Path unknown at end or start of revision range: '
402
def test_log_reversed_revspecs(self):
403
self.make_linear_branch()
404
self.run_bzr_error(('brz: ERROR: Start revision must be older than '
405
'the end revision.\n',),
408
def test_log_reversed_dotted_revspecs(self):
409
self.make_merged_branch()
410
self.run_bzr_error(('brz: ERROR: Start revision not found in '
411
'history of end revision.\n',),
414
def test_log_bad_message_re(self):
415
"""Bad --message argument gives a sensible message
417
See https://bugs.launchpad.net/bzr/+bug/251352
419
self.make_minimal_branch()
420
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
421
self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
422
self.assertNotContainsRe(err, "Unprintable exception")
423
self.assertEqual(out, '')
425
def test_log_unsupported_timezone(self):
426
self.make_linear_branch()
427
self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
428
'options are "utc", "original", "local".'],
429
['log', '--timezone', 'foo'])
431
def test_log_exclude_ancestry_no_range(self):
432
self.make_linear_branch()
433
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
434
' requires -r with two revisions'],
435
['log', '--exclude-common-ancestry'])
437
def test_log_exclude_ancestry_single_revision(self):
438
self.make_merged_branch()
439
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
440
' requires two different revisions'],
441
['log', '--exclude-common-ancestry',
444
class TestLogTags(TestLog):
446
def test_log_with_tags(self):
447
tree = self.make_linear_branch(format='dirstate-tags')
449
branch.tags.set_tag('tag1', branch.get_rev_id(1))
450
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
451
branch.tags.set_tag('tag3', branch.last_revision())
453
log = self.run_bzr("log -r-1")[0]
454
self.assertTrue('tags: tag3' in log)
456
log = self.run_bzr("log -r1")[0]
457
# I guess that we can't know the order of tags in the output
458
# since dicts are unordered, need to check both possibilities
459
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
461
def test_merged_log_with_tags(self):
462
branch1_tree = self.make_linear_branch('branch1',
463
format='dirstate-tags')
464
branch1 = branch1_tree.branch
465
branch2_tree = branch1_tree.controldir.sprout('branch2').open_workingtree()
466
branch1_tree.commit(message='foobar', allow_pointless=True)
467
branch1.tags.set_tag('tag1', branch1.last_revision())
468
# tags don't propagate if we don't merge
469
self.run_bzr('merge ../branch1', working_dir='branch2')
470
branch2_tree.commit(message='merge branch 1')
471
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
472
self.assertContainsRe(log, r' tags: tag1')
473
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
474
self.assertContainsRe(log, r'tags: tag1')
477
class TestLogSignatures(TestLog):
479
def test_log_with_signatures(self):
480
self.requireFeature(features.gpg)
482
tree = self.make_linear_branch(format='dirstate-tags')
484
log = self.run_bzr("log --signatures")[0]
485
self.assertTrue('signature: no signature' in log)
487
def test_log_without_signatures(self):
488
self.requireFeature(features.gpg)
490
tree = self.make_linear_branch(format='dirstate-tags')
492
log = self.run_bzr("log")[0]
493
self.assertFalse('signature: no signature' in log)
496
class TestLogVerbose(TestLog):
499
super(TestLogVerbose, self).setUp()
500
self.make_minimal_branch()
502
def assertUseShortDeltaFormat(self, cmd):
503
log = self.run_bzr(cmd)[0]
504
# Check that we use the short status format
505
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
506
self.assertNotContainsRe(log, '(?m)^\s*added:$')
508
def assertUseLongDeltaFormat(self, cmd):
509
log = self.run_bzr(cmd)[0]
510
# Check that we use the long status format
511
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
512
self.assertContainsRe(log, '(?m)^\s*added:$')
514
def test_log_short_verbose(self):
515
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
517
def test_log_s_verbose(self):
518
self.assertUseShortDeltaFormat(['log', '-S', '-v'])
520
def test_log_short_verbose_verbose(self):
521
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
523
def test_log_long_verbose(self):
524
# Check that we use the long status format, ignoring the verbosity
526
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
528
def test_log_long_verbose_verbose(self):
529
# Check that we use the long status format, ignoring the verbosity
531
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
534
class TestLogMerges(TestLogWithLogCatcher):
537
super(TestLogMerges, self).setUp()
538
self.make_branches_with_merges()
540
def make_branches_with_merges(self):
541
level0 = self.make_branch_and_tree('level0')
542
self.wt_commit(level0, 'in branch level0')
543
level1 = level0.controldir.sprout('level1').open_workingtree()
544
self.wt_commit(level1, 'in branch level1')
545
level2 = level1.controldir.sprout('level2').open_workingtree()
546
self.wt_commit(level2, 'in branch level2')
547
level1.merge_from_branch(level2.branch)
548
self.wt_commit(level1, 'merge branch level2')
549
level0.merge_from_branch(level1.branch)
550
self.wt_commit(level0, 'merge branch level1')
552
def test_merges_are_indented_by_level(self):
553
self.run_bzr(['log', '-n0'], working_dir='level0')
554
revnos_and_depth = [(r.revno, r.merge_depth)
555
for r in self.get_captured_revisions()]
556
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
558
[(r.revno, r.merge_depth)
559
for r in self.get_captured_revisions()])
561
def test_force_merge_revisions_off(self):
562
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
564
def test_force_merge_revisions_on(self):
565
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
566
working_dir='level0')
568
def test_include_merged(self):
569
# Confirm --include-merged gives the same output as -n0
570
expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
571
self.assertLogRevnos(['--include-merged'],
572
expected, working_dir='level0')
573
self.assertLogRevnos(['--include-merged'],
574
expected, working_dir='level0')
576
def test_force_merge_revisions_N(self):
577
self.assertLogRevnos(['-n2'],
578
['2', '1.1.2', '1.1.1', '1'],
579
working_dir='level0')
581
def test_merges_single_merge_rev(self):
582
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
583
[('1.1.2', 0), ('1.2.1', 1)],
584
working_dir='level0')
586
def test_merges_partial_range(self):
587
self.assertLogRevnosAndDepths(
588
['-n0', '-r1.1.1..1.1.2'],
589
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
590
working_dir='level0')
592
def test_merges_partial_range_ignore_before_lower_bound(self):
593
"""Dont show revisions before the lower bound's merged revs"""
594
self.assertLogRevnosAndDepths(
595
['-n0', '-r1.1.2..2'],
596
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
597
working_dir='level0')
599
def test_omit_merges_with_sidelines(self):
600
self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
601
working_dir='level0')
603
def test_omit_merges_without_sidelines(self):
604
self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
605
working_dir='level0')
608
class TestLogDiff(TestLogWithLogCatcher):
610
# FIXME: We need specific tests for each LogFormatter about how the diffs
611
# are displayed: --long indent them by depth, --short use a fixed
612
# indent and --line does't display them. -- vila 10019
615
super(TestLogDiff, self).setUp()
616
self.make_branch_with_diffs()
618
def make_branch_with_diffs(self):
619
level0 = self.make_branch_and_tree('level0')
620
self.build_tree(['level0/file1', 'level0/file2'])
623
self.wt_commit(level0, 'in branch level0')
625
level1 = level0.controldir.sprout('level1').open_workingtree()
626
self.build_tree_contents([('level1/file2', 'hello\n')])
627
self.wt_commit(level1, 'in branch level1')
628
level0.merge_from_branch(level1.branch)
629
self.wt_commit(level0, 'merge branch level1')
631
def _diff_file1_revno1(self):
632
return """=== added file 'file1'
633
--- file1\t1970-01-01 00:00:00 +0000
634
+++ file1\t2005-11-22 00:00:00 +0000
636
+contents of level0/file1
640
def _diff_file2_revno2(self):
641
return """=== modified file 'file2'
642
--- file2\t2005-11-22 00:00:00 +0000
643
+++ file2\t2005-11-22 00:00:01 +0000
645
-contents of level0/file2
650
def _diff_file2_revno1_1_1(self):
651
return """=== modified file 'file2'
652
--- file2\t2005-11-22 00:00:00 +0000
653
+++ file2\t2005-11-22 00:00:01 +0000
655
-contents of level0/file2
660
def _diff_file2_revno1(self):
661
return """=== added file 'file2'
662
--- file2\t1970-01-01 00:00:00 +0000
663
+++ file2\t2005-11-22 00:00:00 +0000
665
+contents of level0/file2
669
def assertLogRevnosAndDiff(self, args, expected,
671
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
672
expected_revnos_and_depths = [
673
(revno, depth) for revno, depth, diff in expected]
674
# Check the revnos and depths first to make debugging easier
675
self.assertEqual(expected_revnos_and_depths,
676
[(r.revno, r.merge_depth)
677
for r in self.get_captured_revisions()])
678
# Now check the diffs, adding the revno in case of failure
679
fmt = 'In revno %s\n%s'
680
for expected_rev, actual_rev in zip(expected,
681
self.get_captured_revisions()):
682
revno, depth, expected_diff = expected_rev
683
actual_diff = actual_rev.diff
684
self.assertEqualDiff(fmt % (revno, expected_diff),
685
fmt % (revno, actual_diff))
687
def test_log_diff_with_merges(self):
688
self.assertLogRevnosAndDiff(
690
[('2', 0, self._diff_file2_revno2()),
691
('1.1.1', 1, self._diff_file2_revno1_1_1()),
692
('1', 0, self._diff_file1_revno1()
693
+ self._diff_file2_revno1())],
694
working_dir='level0')
697
def test_log_diff_file1(self):
698
self.assertLogRevnosAndDiff(['-n0', 'file1'],
699
[('1', 0, self._diff_file1_revno1())],
700
working_dir='level0')
702
def test_log_diff_file2(self):
703
self.assertLogRevnosAndDiff(['-n1', 'file2'],
704
[('2', 0, self._diff_file2_revno2()),
705
('1', 0, self._diff_file2_revno1())],
706
working_dir='level0')
709
class TestLogUnicodeDiff(TestLog):
711
def test_log_show_diff_non_ascii(self):
712
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
713
message = u'Message with \xb5'
714
body = 'Body with \xb5\n'
715
wt = self.make_branch_and_tree('.')
716
self.build_tree_contents([('foo', body)])
718
wt.commit(message=message)
719
# check that command won't fail with unicode error
720
# don't care about exact output because we have other tests for this
721
out,err = self.run_bzr('log -p --long')
722
self.assertNotEqual('', out)
723
self.assertEqual('', err)
724
out,err = self.run_bzr('log -p --short')
725
self.assertNotEqual('', out)
726
self.assertEqual('', err)
727
out,err = self.run_bzr('log -p --line')
728
self.assertNotEqual('', out)
729
self.assertEqual('', err)
732
class TestLogEncodings(tests.TestCaseInTempDir):
735
_message = u'Message with \xb5'
737
# Encodings which can encode mu
742
'cp437', # Common windows encoding
743
'cp1251', # Russian windows encoding
744
'cp1258', # Common windows encoding
746
# Encodings which cannot encode mu
754
super(TestLogEncodings, self).setUp()
755
self.overrideAttr(osutils, '_cached_user_encoding')
757
def create_branch(self):
760
self.build_tree_contents([('a', 'some stuff\n')])
762
brz(['commit', '-m', self._message])
764
def try_encoding(self, encoding, fail=False):
767
self.assertRaises(UnicodeEncodeError,
768
self._mu.encode, encoding)
769
encoded_msg = self._message.encode(encoding, 'replace')
771
encoded_msg = self._message.encode(encoding)
773
old_encoding = osutils._cached_user_encoding
774
# This test requires that 'run_bzr' uses the current
775
# breezy, because we override user_encoding, and expect
778
osutils._cached_user_encoding = 'ascii'
779
# We should be able to handle any encoding
780
out, err = brz('log', encoding=encoding)
782
# Make sure we wrote mu as we expected it to exist
783
self.assertNotEqual(-1, out.find(encoded_msg))
784
out_unicode = out.decode(encoding)
785
self.assertNotEqual(-1, out_unicode.find(self._message))
787
self.assertNotEqual(-1, out.find('Message with ?'))
789
osutils._cached_user_encoding = old_encoding
791
def test_log_handles_encoding(self):
794
for encoding in self.good_encodings:
795
self.try_encoding(encoding)
797
def test_log_handles_bad_encoding(self):
800
for encoding in self.bad_encodings:
801
self.try_encoding(encoding, fail=True)
803
def test_stdout_encoding(self):
805
osutils._cached_user_encoding = "cp1251"
808
self.build_tree(['a'])
810
brz(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
811
stdout, stderr = self.run_bzr('log', encoding='cp866')
813
message = stdout.splitlines()[-1]
815
# explanation of the check:
816
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
817
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
818
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
819
# This test should check that output of log command
820
# encoded to sys.stdout.encoding
821
test_in_cp866 = '\x92\xa5\xe1\xe2'
822
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
823
# Make sure the log string is encoded in cp866
824
self.assertEqual(test_in_cp866, message[2:])
825
# Make sure the cp1251 string is not found anywhere
826
self.assertEqual(-1, stdout.find(test_in_cp1251))
829
class TestLogFile(TestLogWithLogCatcher):
831
def test_log_local_branch_file(self):
832
"""We should be able to log files in local treeless branches"""
833
tree = self.make_branch_and_tree('tree')
834
self.build_tree(['tree/file'])
836
tree.commit('revision 1')
837
tree.controldir.destroy_workingtree()
838
self.run_bzr('log tree/file')
840
def prepare_tree(self, complex=False):
841
# The complex configuration includes deletes and renames
842
tree = self.make_branch_and_tree('parent')
843
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
845
tree.commit('add file1')
847
tree.commit('add file2')
849
tree.commit('add file3')
850
child_tree = tree.controldir.sprout('child').open_workingtree()
851
self.build_tree_contents([('child/file2', 'hello')])
852
child_tree.commit(message='branch 1')
853
tree.merge_from_branch(child_tree.branch)
854
tree.commit(message='merge child branch')
857
tree.commit('remove file2')
858
tree.rename_one('file3', 'file4')
859
tree.commit('file3 is now called file4')
861
tree.commit('remove file1')
864
# FIXME: It would be good to parametrize the following tests against all
865
# formatters. But the revisions selection is not *currently* part of the
866
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
867
def test_log_file1(self):
869
self.assertLogRevnos(['-n0', 'file1'], ['1'])
871
def test_log_file2(self):
874
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
875
# file2 in a merge revision
876
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
877
# file2 in a mainline revision
878
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
879
# file2 since a revision
880
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
881
# file2 up to a revision
882
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
884
def test_log_file3(self):
886
self.assertLogRevnos(['-n0', 'file3'], ['3'])
888
def test_log_file_historical_missing(self):
889
# Check logging a deleted file gives an error if the
890
# file isn't found at the end or start of the revision range
891
self.prepare_tree(complex=True)
892
err_msg = "Path unknown at end or start of revision range: file2"
893
err = self.run_bzr('log file2', retcode=3)[1]
894
self.assertContainsRe(err, err_msg)
896
def test_log_file_historical_end(self):
897
# Check logging a deleted file is ok if the file existed
898
# at the end the revision range
899
self.prepare_tree(complex=True)
900
self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
902
def test_log_file_historical_start(self):
903
# Check logging a deleted file is ok if the file existed
904
# at the start of the revision range
905
self.prepare_tree(complex=True)
906
self.assertLogRevnos(['file1'], ['1'])
908
def test_log_file_renamed(self):
909
"""File matched against revision range, not current tree."""
910
self.prepare_tree(complex=True)
912
# Check logging a renamed file gives an error by default
913
err_msg = "Path unknown at end or start of revision range: file3"
914
err = self.run_bzr('log file3', retcode=3)[1]
915
self.assertContainsRe(err, err_msg)
917
# Check we can see a renamed file if we give the right end revision
918
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
921
class TestLogMultiple(TestLogWithLogCatcher):
923
def prepare_tree(self):
924
tree = self.make_branch_and_tree('parent')
931
'parent/dir1/dir2/file3',
934
tree.commit('add file1')
936
tree.commit('add file2')
937
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
938
tree.commit('add file3')
940
tree.commit('add file4')
941
tree.add('dir1/file5')
942
tree.commit('add file5')
943
child_tree = tree.controldir.sprout('child').open_workingtree()
944
self.build_tree_contents([('child/file2', 'hello')])
945
child_tree.commit(message='branch 1')
946
tree.merge_from_branch(child_tree.branch)
947
tree.commit(message='merge child branch')
950
def test_log_files(self):
951
"""The log for multiple file should only list revs for those files"""
953
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
954
['6', '5.1.1', '3', '2', '1'])
956
def test_log_directory(self):
957
"""The log for a directory should show all nested files."""
959
self.assertLogRevnos(['dir1'], ['5', '3'])
961
def test_log_nested_directory(self):
962
"""The log for a directory should show all nested files."""
964
self.assertLogRevnos(['dir1/dir2'], ['3'])
966
def test_log_in_nested_directory(self):
967
"""The log for a directory should show all nested files."""
970
self.assertLogRevnos(['.'], ['5', '3'])
972
def test_log_files_and_directories(self):
973
"""Logging files and directories together should be fine."""
975
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
977
def test_log_files_and_dirs_in_nested_directory(self):
978
"""The log for a directory should show all nested files."""
981
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
984
class MainlineGhostTests(TestLogWithLogCatcher):
987
super(MainlineGhostTests, self).setUp()
988
tree = self.make_branch_and_tree('')
989
tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
991
tree.commit('msg1', rev_id='rev1')
992
tree.commit('msg2', rev_id='rev2')
994
def test_log_range(self):
995
self.assertLogRevnos(["-r1..2"], ["2", "1"])
997
def test_log_norange(self):
998
self.assertLogRevnos([], ["2", "1"])
1000
def test_log_range_open_begin(self):
1001
(stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
1002
self.assertEqual(["2", "1"],
1003
[r.revno for r in self.get_captured_revisions()])
1004
self.assertEqual("brz: ERROR: Further revision history missing.\n",
1007
def test_log_range_open_end(self):
1008
self.assertLogRevnos(["-r1.."], ["2", "1"])
1011
class TestLogMatch(TestLogWithLogCatcher):
1013
def prepare_tree(self):
1014
tree = self.make_branch_and_tree('')
1016
['/hello.txt', '/goodbye.txt'])
1017
tree.add('hello.txt')
1018
tree.commit(message='message1', committer='committer1', authors=['author1'])
1019
tree.add('goodbye.txt')
1020
tree.commit(message='message2', committer='committer2', authors=['author2'])
1022
def test_message(self):
1024
self.assertLogRevnos(["-m", "message1"], ["1"])
1025
self.assertLogRevnos(["-m", "message2"], ["2"])
1026
self.assertLogRevnos(["-m", "message"], ["2", "1"])
1027
self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
1028
self.assertLogRevnos(["--match-message", "message1"], ["1"])
1029
self.assertLogRevnos(["--match-message", "message2"], ["2"])
1030
self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
1031
self.assertLogRevnos(["--match-message", "message1",
1032
"--match-message", "message2"], ["2", "1"])
1033
self.assertLogRevnos(["--message", "message1"], ["1"])
1034
self.assertLogRevnos(["--message", "message2"], ["2"])
1035
self.assertLogRevnos(["--message", "message"], ["2", "1"])
1036
self.assertLogRevnos(["--match-message", "message1",
1037
"--message", "message2"], ["2", "1"])
1038
self.assertLogRevnos(["--message", "message1",
1039
"--match-message", "message2"], ["2", "1"])
1041
def test_committer(self):
1043
self.assertLogRevnos(["-m", "committer1"], ["1"])
1044
self.assertLogRevnos(["-m", "committer2"], ["2"])
1045
self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1046
self.assertLogRevnos(["-m", "committer1", "-m", "committer2"],
1048
self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1049
self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1050
self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1051
self.assertLogRevnos(["--match-committer", "committer1",
1052
"--match-committer", "committer2"], ["2", "1"])
1054
def test_author(self):
1056
self.assertLogRevnos(["-m", "author1"], ["1"])
1057
self.assertLogRevnos(["-m", "author2"], ["2"])
1058
self.assertLogRevnos(["-m", "author"], ["2", "1"])
1059
self.assertLogRevnos(["-m", "author1", "-m", "author2"],
1061
self.assertLogRevnos(["--match-author", "author1"], ["1"])
1062
self.assertLogRevnos(["--match-author", "author2"], ["2"])
1063
self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1064
self.assertLogRevnos(["--match-author", "author1",
1065
"--match-author", "author2"], ["2", "1"])
1068
class TestSmartServerLog(tests.TestCaseWithTransport):
1070
def test_standard_log(self):
1071
self.setup_smart_server_with_call_log()
1072
t = self.make_branch_and_tree('branch')
1073
self.build_tree_contents([('branch/foo', 'thecontents')])
1076
self.reset_smart_call_log()
1077
out, err = self.run_bzr(['log', self.get_url('branch')])
1078
# This figure represent the amount of work to perform this use case. It
1079
# is entirely ok to reduce this number if a test fails due to rpc_count
1080
# being too low. If rpc_count increases, more network roundtrips have
1081
# become necessary for this use case. Please do not adjust this number
1082
# upwards without agreement from bzr's network support maintainers.
1083
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1084
self.assertLength(1, self.hpss_connections)
1085
self.assertLength(9, self.hpss_calls)
1087
def test_verbose_log(self):
1088
self.setup_smart_server_with_call_log()
1089
t = self.make_branch_and_tree('branch')
1090
self.build_tree_contents([('branch/foo', 'thecontents')])
1093
self.reset_smart_call_log()
1094
out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
1095
# This figure represent the amount of work to perform this use case. It
1096
# is entirely ok to reduce this number if a test fails due to rpc_count
1097
# being too low. If rpc_count increases, more network roundtrips have
1098
# become necessary for this use case. Please do not adjust this number
1099
# upwards without agreement from bzr's network support maintainers.
1100
self.assertLength(10, self.hpss_calls)
1101
self.assertLength(1, self.hpss_connections)
1102
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1104
def test_per_file(self):
1105
self.setup_smart_server_with_call_log()
1106
t = self.make_branch_and_tree('branch')
1107
self.build_tree_contents([('branch/foo', 'thecontents')])
1110
self.reset_smart_call_log()
1111
out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
1112
# This figure represent the amount of work to perform this use case. It
1113
# is entirely ok to reduce this number if a test fails due to rpc_count
1114
# being too low. If rpc_count increases, more network roundtrips have
1115
# become necessary for this use case. Please do not adjust this number
1116
# upwards without agreement from bzr's network support maintainers.
1117
self.assertLength(14, self.hpss_calls)
1118
self.assertLength(1, self.hpss_connections)
1119
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)