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."""
29
from breezy.tests import (
33
from breezy.tests.matchers import ContainsNoVfsCalls
36
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
38
def make_minimal_branch(self, path='.', format=None):
39
tree = self.make_branch_and_tree(path, format=format)
40
self.build_tree([path + '/hello.txt'])
42
tree.commit(message='message1')
45
def make_linear_branch(self, path='.', format=None):
46
tree = self.make_branch_and_tree(path, format=format)
48
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
50
tree.commit(message='message1')
51
tree.add('goodbye.txt')
52
tree.commit(message='message2')
54
tree.commit(message='message3')
57
def make_merged_branch(self, path='.', format=None):
58
tree = self.make_linear_branch(path, format)
59
tree2 = tree.bzrdir.sprout('tree2',
60
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
61
tree2.commit(message='tree2 message2')
62
tree2.commit(message='tree2 message3')
63
tree.merge_from_branch(tree2.branch)
64
tree.commit(message='merge')
68
class TestLogWithLogCatcher(TestLog):
71
super(TestLogWithLogCatcher, self).setUp()
72
# Capture log formatter creations
73
class MyLogFormatter(test_log.LogCatcher):
75
def __new__(klass, *args, **kwargs):
76
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
77
# Always return our own log formatter
78
return self.log_catcher
79
# Break cycle with closure over self on cleanup by removing method
80
self.addCleanup(setattr, MyLogFormatter, "__new__", None)
83
# Always return our own log formatter class hijacking the
84
# default behavior (which requires setting up a config
87
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
89
def get_captured_revisions(self):
90
return self.log_catcher.revisions
92
def assertLogRevnos(self, args, expected_revnos, working_dir='.',
94
actual_out, actual_err = self.run_bzr(['log'] + args,
95
working_dir=working_dir)
96
self.assertEqual(out, actual_out)
97
self.assertEqual(err, actual_err)
98
self.assertEqual(expected_revnos,
99
[r.revno for r in self.get_captured_revisions()])
101
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
103
self.run_bzr(['log'] + args, working_dir=working_dir)
104
self.assertEqual(expected_revnos_and_depths,
105
[(r.revno, r.merge_depth)
106
for r in self.get_captured_revisions()])
109
class TestLogRevSpecs(TestLogWithLogCatcher):
111
def test_log_no_revspec(self):
112
self.make_linear_branch()
113
self.assertLogRevnos([], ['3', '2', '1'])
115
def test_log_null_end_revspec(self):
116
self.make_linear_branch()
117
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
119
def test_log_null_begin_revspec(self):
120
self.make_linear_branch()
121
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
123
def test_log_null_both_revspecs(self):
124
self.make_linear_branch()
125
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
127
def test_log_negative_begin_revspec_full_log(self):
128
self.make_linear_branch()
129
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
131
def test_log_negative_both_revspec_full_log(self):
132
self.make_linear_branch()
133
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
135
def test_log_negative_both_revspec_partial(self):
136
self.make_linear_branch()
137
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
139
def test_log_negative_begin_revspec(self):
140
self.make_linear_branch()
141
self.assertLogRevnos(['-r-2..'], ['3', '2'])
143
def test_log_positive_revspecs(self):
144
self.make_linear_branch()
145
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
147
def test_log_dotted_revspecs(self):
148
self.make_merged_branch()
149
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
151
def test_log_limit(self):
152
tree = self.make_branch_and_tree('.')
153
# We want more commits than our batch size starts at
154
for pos in range(10):
155
tree.commit("%s" % pos)
156
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
158
def test_log_limit_short(self):
159
self.make_linear_branch()
160
self.assertLogRevnos(['-l', '2'], ['3', '2'])
162
def test_log_change_revno(self):
163
self.make_linear_branch()
164
self.assertLogRevnos(['-c1'], ['1'])
166
def test_branch_revspec(self):
167
foo = self.make_branch_and_tree('foo')
168
bar = self.make_branch_and_tree('bar')
169
self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
172
foo.commit(message='foo')
173
bar.commit(message='bar')
174
self.run_bzr('log -r branch:../bar', working_dir='foo')
175
self.assertEqual([bar.branch.get_rev_id(1)],
177
for r in self.get_captured_revisions()])
180
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
182
def test_exclude_common_ancestry_simple_revnos(self):
183
self.make_linear_branch()
184
self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
188
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
191
super(TestLogMergedLinearAncestry, self).setUp()
192
# FIXME: Using a MemoryTree would be even better here (but until we
193
# stop calling run_bzr, there is no point) --vila 100118.
194
builder = branchbuilder.BranchBuilder(self.get_transport())
195
builder.start_series()
213
builder.build_snapshot('1', None, [
214
('add', ('', 'root-id', 'directory', ''))])
215
builder.build_snapshot('2', ['1'], [])
217
builder.build_snapshot('1.1.1', ['1'], [])
218
# merge branch into mainline
219
builder.build_snapshot('3', ['2', '1.1.1'], [])
220
# new commits in branch
221
builder.build_snapshot('1.1.2', ['1.1.1'], [])
222
builder.build_snapshot('1.1.3', ['1.1.2'], [])
223
# merge branch into mainline
224
builder.build_snapshot('4', ['3', '1.1.3'], [])
225
# merge mainline into branch
226
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
227
# merge branch into mainline
228
builder.build_snapshot('5', ['4', '1.1.4'], [])
229
builder.build_snapshot('5.1.1', ['5'], [])
230
builder.build_snapshot('6', ['5', '5.1.1'], [])
231
builder.finish_series()
234
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
235
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
236
def test_n0_forward(self):
237
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
238
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
241
# starting from 1.1.4 we follow the left-hand ancestry
242
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
243
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
245
def test_n1_forward(self):
246
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
247
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
249
def test_fallback_when_end_rev_is_not_on_mainline(self):
250
self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
251
# We don't get 1.1.1 because we say -n1
252
['5.1.1', '5', '4', '3'])
255
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
258
super(Test_GenerateAllRevisions, self).setUp()
259
builder = self.make_branch_with_many_merges()
260
b = builder.get_branch()
262
self.addCleanup(b.unlock)
265
def make_branch_with_many_merges(self, path='.', format=None):
266
builder = branchbuilder.BranchBuilder(self.get_transport())
267
builder.start_series()
268
# The graph below may look a bit complicated (and it may be but I've
269
# banged my head enough on it) but the bug requires at least dotted
270
# revnos *and* merged revisions below that.
284
builder.build_snapshot('1', None, [
285
('add', ('', 'root-id', 'directory', ''))])
286
builder.build_snapshot('2', ['1'], [])
287
builder.build_snapshot('1.1.1', ['1'], [])
288
builder.build_snapshot('2.1.1', ['2'], [])
289
builder.build_snapshot('3', ['2', '1.1.1'], [])
290
builder.build_snapshot('2.1.2', ['2.1.1'], [])
291
builder.build_snapshot('2.2.1', ['2.1.1'], [])
292
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
293
builder.build_snapshot('4', ['3', '2.1.3'], [])
294
builder.build_snapshot('5', ['4', '2.1.2'], [])
295
builder.finish_series()
298
def test_not_an_ancestor(self):
299
self.assertRaises(errors.BzrCommandError,
300
log._generate_all_revisions,
301
self.branch, '1.1.1', '2.1.3', 'reverse',
302
delayed_graph_generation=True)
304
def test_wrong_order(self):
305
self.assertRaises(errors.BzrCommandError,
306
log._generate_all_revisions,
307
self.branch, '5', '2.1.3', 'reverse',
308
delayed_graph_generation=True)
310
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
311
revs = log._generate_all_revisions(
312
self.branch, None, '2.1.3',
313
'reverse', delayed_graph_generation=True)
316
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
318
def test_log_revno_n_path_wrong_namespace(self):
319
self.make_linear_branch('branch1')
320
self.make_linear_branch('branch2')
321
# There is no guarantee that a path exist between two arbitrary
323
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
325
def test_log_revno_n_path_correct_order(self):
326
self.make_linear_branch('branch2')
327
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
330
def test_log_revno_n_path(self):
331
self.make_linear_branch('branch2')
332
self.assertLogRevnos(['-rrevno:1:branch2'],
334
rev_props = self.log_catcher.revisions[0].rev.properties
335
self.assertEqual('branch2', rev_props['branch-nick'])
338
class TestLogErrors(TestLog):
340
def test_log_zero_revspec(self):
341
self.make_minimal_branch()
342
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
345
def test_log_zero_begin_revspec(self):
346
self.make_linear_branch()
347
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
350
def test_log_zero_end_revspec(self):
351
self.make_linear_branch()
352
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
355
def test_log_nonexistent_revno(self):
356
self.make_minimal_branch()
357
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
358
"does not exist in branch:"],
361
def test_log_nonexistent_dotted_revno(self):
362
self.make_minimal_branch()
363
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
364
"does not exist in branch:"],
365
['log', '-r123.123'])
367
def test_log_change_nonexistent_revno(self):
368
self.make_minimal_branch()
369
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
370
"does not exist in branch:"],
373
def test_log_change_nonexistent_dotted_revno(self):
374
self.make_minimal_branch()
375
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
376
"does not exist in branch:"],
377
['log', '-c123.123'])
379
def test_log_change_single_revno_only(self):
380
self.make_minimal_branch()
381
self.run_bzr_error(['brz: ERROR: Option --change does not'
382
' accept revision ranges'],
383
['log', '--change', '2..3'])
385
def test_log_change_incompatible_with_revision(self):
386
self.run_bzr_error(['brz: ERROR: --revision and --change'
387
' are mutually exclusive'],
388
['log', '--change', '2', '--revision', '3'])
390
def test_log_nonexistent_file(self):
391
self.make_minimal_branch()
392
# files that don't exist in either the basis tree or working tree
393
# should give an error
394
out, err = self.run_bzr('log does-not-exist', retcode=3)
395
self.assertContainsRe(err,
396
'Path unknown at end or start of revision range: '
399
def test_log_reversed_revspecs(self):
400
self.make_linear_branch()
401
self.run_bzr_error(('brz: ERROR: Start revision must be older than '
402
'the end revision.\n',),
405
def test_log_reversed_dotted_revspecs(self):
406
self.make_merged_branch()
407
self.run_bzr_error(('brz: ERROR: Start revision not found in '
408
'history of end revision.\n',),
411
def test_log_bad_message_re(self):
412
"""Bad --message argument gives a sensible message
414
See https://bugs.launchpad.net/bzr/+bug/251352
416
self.make_minimal_branch()
417
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
418
self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
419
self.assertNotContainsRe(err, "Unprintable exception")
420
self.assertEqual(out, '')
422
def test_log_unsupported_timezone(self):
423
self.make_linear_branch()
424
self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
425
'options are "utc", "original", "local".'],
426
['log', '--timezone', 'foo'])
428
def test_log_exclude_ancestry_no_range(self):
429
self.make_linear_branch()
430
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
431
' requires -r with two revisions'],
432
['log', '--exclude-common-ancestry'])
434
def test_log_exclude_ancestry_single_revision(self):
435
self.make_merged_branch()
436
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
437
' requires two different revisions'],
438
['log', '--exclude-common-ancestry',
441
class TestLogTags(TestLog):
443
def test_log_with_tags(self):
444
tree = self.make_linear_branch(format='dirstate-tags')
446
branch.tags.set_tag('tag1', branch.get_rev_id(1))
447
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
448
branch.tags.set_tag('tag3', branch.last_revision())
450
log = self.run_bzr("log -r-1")[0]
451
self.assertTrue('tags: tag3' in log)
453
log = self.run_bzr("log -r1")[0]
454
# I guess that we can't know the order of tags in the output
455
# since dicts are unordered, need to check both possibilities
456
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
458
def test_merged_log_with_tags(self):
459
branch1_tree = self.make_linear_branch('branch1',
460
format='dirstate-tags')
461
branch1 = branch1_tree.branch
462
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
463
branch1_tree.commit(message='foobar', allow_pointless=True)
464
branch1.tags.set_tag('tag1', branch1.last_revision())
465
# tags don't propagate if we don't merge
466
self.run_bzr('merge ../branch1', working_dir='branch2')
467
branch2_tree.commit(message='merge branch 1')
468
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
469
self.assertContainsRe(log, r' tags: tag1')
470
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
471
self.assertContainsRe(log, r'tags: tag1')
474
class TestLogSignatures(TestLog):
476
def test_log_with_signatures(self):
477
self.requireFeature(features.gpgme)
479
tree = self.make_linear_branch(format='dirstate-tags')
481
log = self.run_bzr("log --signatures")[0]
482
self.assertTrue('signature: no signature' in log)
484
def test_log_without_signatures(self):
485
self.requireFeature(features.gpgme)
487
tree = self.make_linear_branch(format='dirstate-tags')
489
log = self.run_bzr("log")[0]
490
self.assertFalse('signature: no signature' in log)
493
class TestLogVerbose(TestLog):
496
super(TestLogVerbose, self).setUp()
497
self.make_minimal_branch()
499
def assertUseShortDeltaFormat(self, cmd):
500
log = self.run_bzr(cmd)[0]
501
# Check that we use the short status format
502
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
503
self.assertNotContainsRe(log, '(?m)^\s*added:$')
505
def assertUseLongDeltaFormat(self, cmd):
506
log = self.run_bzr(cmd)[0]
507
# Check that we use the long status format
508
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
509
self.assertContainsRe(log, '(?m)^\s*added:$')
511
def test_log_short_verbose(self):
512
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
514
def test_log_s_verbose(self):
515
self.assertUseShortDeltaFormat(['log', '-S', '-v'])
517
def test_log_short_verbose_verbose(self):
518
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
520
def test_log_long_verbose(self):
521
# Check that we use the long status format, ignoring the verbosity
523
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
525
def test_log_long_verbose_verbose(self):
526
# Check that we use the long status format, ignoring the verbosity
528
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
531
class TestLogMerges(TestLogWithLogCatcher):
534
super(TestLogMerges, self).setUp()
535
self.make_branches_with_merges()
537
def make_branches_with_merges(self):
538
level0 = self.make_branch_and_tree('level0')
539
self.wt_commit(level0, 'in branch level0')
540
level1 = level0.bzrdir.sprout('level1').open_workingtree()
541
self.wt_commit(level1, 'in branch level1')
542
level2 = level1.bzrdir.sprout('level2').open_workingtree()
543
self.wt_commit(level2, 'in branch level2')
544
level1.merge_from_branch(level2.branch)
545
self.wt_commit(level1, 'merge branch level2')
546
level0.merge_from_branch(level1.branch)
547
self.wt_commit(level0, 'merge branch level1')
549
def test_merges_are_indented_by_level(self):
550
self.run_bzr(['log', '-n0'], working_dir='level0')
551
revnos_and_depth = [(r.revno, r.merge_depth)
552
for r in self.get_captured_revisions()]
553
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
555
[(r.revno, r.merge_depth)
556
for r in self.get_captured_revisions()])
558
def test_force_merge_revisions_off(self):
559
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
561
def test_force_merge_revisions_on(self):
562
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
563
working_dir='level0')
565
def test_include_merged(self):
566
# Confirm --include-merged gives the same output as -n0
567
expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
568
self.assertLogRevnos(['--include-merged'],
569
expected, working_dir='level0')
570
self.assertLogRevnos(['--include-merged'],
571
expected, working_dir='level0')
573
def test_force_merge_revisions_N(self):
574
self.assertLogRevnos(['-n2'],
575
['2', '1.1.2', '1.1.1', '1'],
576
working_dir='level0')
578
def test_merges_single_merge_rev(self):
579
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
580
[('1.1.2', 0), ('1.2.1', 1)],
581
working_dir='level0')
583
def test_merges_partial_range(self):
584
self.assertLogRevnosAndDepths(
585
['-n0', '-r1.1.1..1.1.2'],
586
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
587
working_dir='level0')
589
def test_merges_partial_range_ignore_before_lower_bound(self):
590
"""Dont show revisions before the lower bound's merged revs"""
591
self.assertLogRevnosAndDepths(
592
['-n0', '-r1.1.2..2'],
593
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
594
working_dir='level0')
596
def test_omit_merges_with_sidelines(self):
597
self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
598
working_dir='level0')
600
def test_omit_merges_without_sidelines(self):
601
self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
602
working_dir='level0')
605
class TestLogDiff(TestLogWithLogCatcher):
607
# FIXME: We need specific tests for each LogFormatter about how the diffs
608
# are displayed: --long indent them by depth, --short use a fixed
609
# indent and --line does't display them. -- vila 10019
612
super(TestLogDiff, self).setUp()
613
self.make_branch_with_diffs()
615
def make_branch_with_diffs(self):
616
level0 = self.make_branch_and_tree('level0')
617
self.build_tree(['level0/file1', 'level0/file2'])
620
self.wt_commit(level0, 'in branch level0')
622
level1 = level0.bzrdir.sprout('level1').open_workingtree()
623
self.build_tree_contents([('level1/file2', 'hello\n')])
624
self.wt_commit(level1, 'in branch level1')
625
level0.merge_from_branch(level1.branch)
626
self.wt_commit(level0, 'merge branch level1')
628
def _diff_file1_revno1(self):
629
return """=== added file 'file1'
630
--- file1\t1970-01-01 00:00:00 +0000
631
+++ file1\t2005-11-22 00:00:00 +0000
633
+contents of level0/file1
637
def _diff_file2_revno2(self):
638
return """=== modified file 'file2'
639
--- file2\t2005-11-22 00:00:00 +0000
640
+++ file2\t2005-11-22 00:00:01 +0000
642
-contents of level0/file2
647
def _diff_file2_revno1_1_1(self):
648
return """=== modified file 'file2'
649
--- file2\t2005-11-22 00:00:00 +0000
650
+++ file2\t2005-11-22 00:00:01 +0000
652
-contents of level0/file2
657
def _diff_file2_revno1(self):
658
return """=== added file 'file2'
659
--- file2\t1970-01-01 00:00:00 +0000
660
+++ file2\t2005-11-22 00:00:00 +0000
662
+contents of level0/file2
666
def assertLogRevnosAndDiff(self, args, expected,
668
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
669
expected_revnos_and_depths = [
670
(revno, depth) for revno, depth, diff in expected]
671
# Check the revnos and depths first to make debugging easier
672
self.assertEqual(expected_revnos_and_depths,
673
[(r.revno, r.merge_depth)
674
for r in self.get_captured_revisions()])
675
# Now check the diffs, adding the revno in case of failure
676
fmt = 'In revno %s\n%s'
677
for expected_rev, actual_rev in zip(expected,
678
self.get_captured_revisions()):
679
revno, depth, expected_diff = expected_rev
680
actual_diff = actual_rev.diff
681
self.assertEqualDiff(fmt % (revno, expected_diff),
682
fmt % (revno, actual_diff))
684
def test_log_diff_with_merges(self):
685
self.assertLogRevnosAndDiff(
687
[('2', 0, self._diff_file2_revno2()),
688
('1.1.1', 1, self._diff_file2_revno1_1_1()),
689
('1', 0, self._diff_file1_revno1()
690
+ self._diff_file2_revno1())],
691
working_dir='level0')
694
def test_log_diff_file1(self):
695
self.assertLogRevnosAndDiff(['-n0', 'file1'],
696
[('1', 0, self._diff_file1_revno1())],
697
working_dir='level0')
699
def test_log_diff_file2(self):
700
self.assertLogRevnosAndDiff(['-n1', 'file2'],
701
[('2', 0, self._diff_file2_revno2()),
702
('1', 0, self._diff_file2_revno1())],
703
working_dir='level0')
706
class TestLogUnicodeDiff(TestLog):
708
def test_log_show_diff_non_ascii(self):
709
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
710
message = u'Message with \xb5'
711
body = 'Body with \xb5\n'
712
wt = self.make_branch_and_tree('.')
713
self.build_tree_contents([('foo', body)])
715
wt.commit(message=message)
716
# check that command won't fail with unicode error
717
# don't care about exact output because we have other tests for this
718
out,err = self.run_bzr('log -p --long')
719
self.assertNotEqual('', out)
720
self.assertEqual('', err)
721
out,err = self.run_bzr('log -p --short')
722
self.assertNotEqual('', out)
723
self.assertEqual('', err)
724
out,err = self.run_bzr('log -p --line')
725
self.assertNotEqual('', out)
726
self.assertEqual('', err)
729
class TestLogEncodings(tests.TestCaseInTempDir):
732
_message = u'Message with \xb5'
734
# Encodings which can encode mu
739
'cp437', # Common windows encoding
740
'cp1251', # Russian windows encoding
741
'cp1258', # Common windows encoding
743
# Encodings which cannot encode mu
751
super(TestLogEncodings, self).setUp()
752
self.overrideAttr(osutils, '_cached_user_encoding')
754
def create_branch(self):
757
self.build_tree_contents([('a', 'some stuff\n')])
759
brz(['commit', '-m', self._message])
761
def try_encoding(self, encoding, fail=False):
764
self.assertRaises(UnicodeEncodeError,
765
self._mu.encode, encoding)
766
encoded_msg = self._message.encode(encoding, 'replace')
768
encoded_msg = self._message.encode(encoding)
770
old_encoding = osutils._cached_user_encoding
771
# This test requires that 'run_bzr' uses the current
772
# breezy, because we override user_encoding, and expect
775
osutils._cached_user_encoding = 'ascii'
776
# We should be able to handle any encoding
777
out, err = brz('log', encoding=encoding)
779
# Make sure we wrote mu as we expected it to exist
780
self.assertNotEqual(-1, out.find(encoded_msg))
781
out_unicode = out.decode(encoding)
782
self.assertNotEqual(-1, out_unicode.find(self._message))
784
self.assertNotEqual(-1, out.find('Message with ?'))
786
osutils._cached_user_encoding = old_encoding
788
def test_log_handles_encoding(self):
791
for encoding in self.good_encodings:
792
self.try_encoding(encoding)
794
def test_log_handles_bad_encoding(self):
797
for encoding in self.bad_encodings:
798
self.try_encoding(encoding, fail=True)
800
def test_stdout_encoding(self):
802
osutils._cached_user_encoding = "cp1251"
805
self.build_tree(['a'])
807
brz(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
808
stdout, stderr = self.run_bzr('log', encoding='cp866')
810
message = stdout.splitlines()[-1]
812
# explanation of the check:
813
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
814
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
815
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
816
# This test should check that output of log command
817
# encoded to sys.stdout.encoding
818
test_in_cp866 = '\x92\xa5\xe1\xe2'
819
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
820
# Make sure the log string is encoded in cp866
821
self.assertEqual(test_in_cp866, message[2:])
822
# Make sure the cp1251 string is not found anywhere
823
self.assertEqual(-1, stdout.find(test_in_cp1251))
826
class TestLogFile(TestLogWithLogCatcher):
828
def test_log_local_branch_file(self):
829
"""We should be able to log files in local treeless branches"""
830
tree = self.make_branch_and_tree('tree')
831
self.build_tree(['tree/file'])
833
tree.commit('revision 1')
834
tree.bzrdir.destroy_workingtree()
835
self.run_bzr('log tree/file')
837
def prepare_tree(self, complex=False):
838
# The complex configuration includes deletes and renames
839
tree = self.make_branch_and_tree('parent')
840
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
842
tree.commit('add file1')
844
tree.commit('add file2')
846
tree.commit('add file3')
847
child_tree = tree.bzrdir.sprout('child').open_workingtree()
848
self.build_tree_contents([('child/file2', 'hello')])
849
child_tree.commit(message='branch 1')
850
tree.merge_from_branch(child_tree.branch)
851
tree.commit(message='merge child branch')
854
tree.commit('remove file2')
855
tree.rename_one('file3', 'file4')
856
tree.commit('file3 is now called file4')
858
tree.commit('remove file1')
861
# FIXME: It would be good to parametrize the following tests against all
862
# formatters. But the revisions selection is not *currently* part of the
863
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
864
def test_log_file1(self):
866
self.assertLogRevnos(['-n0', 'file1'], ['1'])
868
def test_log_file2(self):
871
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
872
# file2 in a merge revision
873
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
874
# file2 in a mainline revision
875
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
876
# file2 since a revision
877
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
878
# file2 up to a revision
879
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
881
def test_log_file3(self):
883
self.assertLogRevnos(['-n0', 'file3'], ['3'])
885
def test_log_file_historical_missing(self):
886
# Check logging a deleted file gives an error if the
887
# file isn't found at the end or start of the revision range
888
self.prepare_tree(complex=True)
889
err_msg = "Path unknown at end or start of revision range: file2"
890
err = self.run_bzr('log file2', retcode=3)[1]
891
self.assertContainsRe(err, err_msg)
893
def test_log_file_historical_end(self):
894
# Check logging a deleted file is ok if the file existed
895
# at the end the revision range
896
self.prepare_tree(complex=True)
897
self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
899
def test_log_file_historical_start(self):
900
# Check logging a deleted file is ok if the file existed
901
# at the start of the revision range
902
self.prepare_tree(complex=True)
903
self.assertLogRevnos(['file1'], ['1'])
905
def test_log_file_renamed(self):
906
"""File matched against revision range, not current tree."""
907
self.prepare_tree(complex=True)
909
# Check logging a renamed file gives an error by default
910
err_msg = "Path unknown at end or start of revision range: file3"
911
err = self.run_bzr('log file3', retcode=3)[1]
912
self.assertContainsRe(err, err_msg)
914
# Check we can see a renamed file if we give the right end revision
915
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
918
class TestLogMultiple(TestLogWithLogCatcher):
920
def prepare_tree(self):
921
tree = self.make_branch_and_tree('parent')
928
'parent/dir1/dir2/file3',
931
tree.commit('add file1')
933
tree.commit('add file2')
934
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
935
tree.commit('add file3')
937
tree.commit('add file4')
938
tree.add('dir1/file5')
939
tree.commit('add file5')
940
child_tree = tree.bzrdir.sprout('child').open_workingtree()
941
self.build_tree_contents([('child/file2', 'hello')])
942
child_tree.commit(message='branch 1')
943
tree.merge_from_branch(child_tree.branch)
944
tree.commit(message='merge child branch')
947
def test_log_files(self):
948
"""The log for multiple file should only list revs for those files"""
950
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
951
['6', '5.1.1', '3', '2', '1'])
953
def test_log_directory(self):
954
"""The log for a directory should show all nested files."""
956
self.assertLogRevnos(['dir1'], ['5', '3'])
958
def test_log_nested_directory(self):
959
"""The log for a directory should show all nested files."""
961
self.assertLogRevnos(['dir1/dir2'], ['3'])
963
def test_log_in_nested_directory(self):
964
"""The log for a directory should show all nested files."""
967
self.assertLogRevnos(['.'], ['5', '3'])
969
def test_log_files_and_directories(self):
970
"""Logging files and directories together should be fine."""
972
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
974
def test_log_files_and_dirs_in_nested_directory(self):
975
"""The log for a directory should show all nested files."""
978
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
981
class MainlineGhostTests(TestLogWithLogCatcher):
984
super(MainlineGhostTests, self).setUp()
985
tree = self.make_branch_and_tree('')
986
tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
988
tree.commit('msg1', rev_id='rev1')
989
tree.commit('msg2', rev_id='rev2')
991
def test_log_range(self):
992
self.assertLogRevnos(["-r1..2"], ["2", "1"])
994
def test_log_norange(self):
995
self.assertLogRevnos([], ["2", "1"])
997
def test_log_range_open_begin(self):
998
self.knownFailure("log with ghosts fails. bug #726466")
999
(stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
1000
self.assertEqual(["2", "1"],
1001
[r.revno for r in self.get_captured_revisions()])
1002
self.assertEqual("brz: ERROR: Further revision history missing.", stderr)
1004
def test_log_range_open_end(self):
1005
self.assertLogRevnos(["-r1.."], ["2", "1"])
1007
class TestLogMatch(TestLogWithLogCatcher):
1008
def prepare_tree(self):
1009
tree = self.make_branch_and_tree('')
1011
['/hello.txt', '/goodbye.txt'])
1012
tree.add('hello.txt')
1013
tree.commit(message='message1', committer='committer1', authors=['author1'])
1014
tree.add('goodbye.txt')
1015
tree.commit(message='message2', committer='committer2', authors=['author2'])
1017
def test_message(self):
1019
self.assertLogRevnos(["-m", "message1"], ["1"])
1020
self.assertLogRevnos(["-m", "message2"], ["2"])
1021
self.assertLogRevnos(["-m", "message"], ["2", "1"])
1022
self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
1023
self.assertLogRevnos(["--match-message", "message1"], ["1"])
1024
self.assertLogRevnos(["--match-message", "message2"], ["2"])
1025
self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
1026
self.assertLogRevnos(["--match-message", "message1",
1027
"--match-message", "message2"], ["2", "1"])
1028
self.assertLogRevnos(["--message", "message1"], ["1"])
1029
self.assertLogRevnos(["--message", "message2"], ["2"])
1030
self.assertLogRevnos(["--message", "message"], ["2", "1"])
1031
self.assertLogRevnos(["--match-message", "message1",
1032
"--message", "message2"], ["2", "1"])
1033
self.assertLogRevnos(["--message", "message1",
1034
"--match-message", "message2"], ["2", "1"])
1036
def test_committer(self):
1038
self.assertLogRevnos(["-m", "committer1"], ["1"])
1039
self.assertLogRevnos(["-m", "committer2"], ["2"])
1040
self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1041
self.assertLogRevnos(["-m", "committer1", "-m", "committer2"],
1043
self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1044
self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1045
self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1046
self.assertLogRevnos(["--match-committer", "committer1",
1047
"--match-committer", "committer2"], ["2", "1"])
1049
def test_author(self):
1051
self.assertLogRevnos(["-m", "author1"], ["1"])
1052
self.assertLogRevnos(["-m", "author2"], ["2"])
1053
self.assertLogRevnos(["-m", "author"], ["2", "1"])
1054
self.assertLogRevnos(["-m", "author1", "-m", "author2"],
1056
self.assertLogRevnos(["--match-author", "author1"], ["1"])
1057
self.assertLogRevnos(["--match-author", "author2"], ["2"])
1058
self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1059
self.assertLogRevnos(["--match-author", "author1",
1060
"--match-author", "author2"], ["2", "1"])
1063
class TestSmartServerLog(tests.TestCaseWithTransport):
1065
def test_standard_log(self):
1066
self.setup_smart_server_with_call_log()
1067
t = self.make_branch_and_tree('branch')
1068
self.build_tree_contents([('branch/foo', 'thecontents')])
1071
self.reset_smart_call_log()
1072
out, err = self.run_bzr(['log', self.get_url('branch')])
1073
# This figure represent the amount of work to perform this use case. It
1074
# is entirely ok to reduce this number if a test fails due to rpc_count
1075
# being too low. If rpc_count increases, more network roundtrips have
1076
# become necessary for this use case. Please do not adjust this number
1077
# upwards without agreement from bzr's network support maintainers.
1078
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1079
self.assertLength(1, self.hpss_connections)
1080
self.assertLength(9, self.hpss_calls)
1082
def test_verbose_log(self):
1083
self.setup_smart_server_with_call_log()
1084
t = self.make_branch_and_tree('branch')
1085
self.build_tree_contents([('branch/foo', 'thecontents')])
1088
self.reset_smart_call_log()
1089
out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
1090
# This figure represent the amount of work to perform this use case. It
1091
# is entirely ok to reduce this number if a test fails due to rpc_count
1092
# being too low. If rpc_count increases, more network roundtrips have
1093
# become necessary for this use case. Please do not adjust this number
1094
# upwards without agreement from bzr's network support maintainers.
1095
self.assertLength(10, self.hpss_calls)
1096
self.assertLength(1, self.hpss_connections)
1097
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1099
def test_per_file(self):
1100
self.setup_smart_server_with_call_log()
1101
t = self.make_branch_and_tree('branch')
1102
self.build_tree_contents([('branch/foo', 'thecontents')])
1105
self.reset_smart_call_log()
1106
out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
1107
# This figure represent the amount of work to perform this use case. It
1108
# is entirely ok to reduce this number if a test fails due to rpc_count
1109
# being too low. If rpc_count increases, more network roundtrips have
1110
# become necessary for this use case. Please do not adjust this number
1111
# upwards without agreement from bzr's network support maintainers.
1112
self.assertLength(14, self.hpss_calls)
1113
self.assertLength(1, self.hpss_connections)
1114
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)