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."""
30
from breezy.tests import (
34
from breezy.tests.matchers import ContainsNoVfsCalls
37
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
39
def make_minimal_branch(self, path='.', format=None):
40
tree = self.make_branch_and_tree(path, format=format)
41
self.build_tree([path + '/hello.txt'])
43
tree.commit(message='message1')
46
def make_linear_branch(self, path='.', format=None):
47
tree = self.make_branch_and_tree(path, format=format)
49
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
51
tree.commit(message='message1')
52
tree.add('goodbye.txt')
53
tree.commit(message='message2')
55
tree.commit(message='message3')
58
def make_merged_branch(self, path='.', format=None):
59
tree = self.make_linear_branch(path, format)
60
tree2 = tree.controldir.sprout('tree2',
61
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
62
tree2.commit(message='tree2 message2')
63
tree2.commit(message='tree2 message3')
64
tree.merge_from_branch(tree2.branch)
65
tree.commit(message='merge')
69
class TestLogWithLogCatcher(TestLog):
72
super(TestLogWithLogCatcher, self).setUp()
73
# Capture log formatter creations
75
class MyLogFormatter(test_log.LogCatcher):
77
def __new__(klass, *args, **kwargs):
78
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
79
# Always return our own log formatter
80
return self.log_catcher
81
# Break cycle with closure over self on cleanup by removing method
82
self.addCleanup(setattr, MyLogFormatter, "__new__", None)
85
# Always return our own log formatter class hijacking the
86
# default behavior (which requires setting up a config
89
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
91
def get_captured_revisions(self):
92
return self.log_catcher.revisions
94
def assertLogRevnos(self, args, expected_revnos, working_dir='.',
96
actual_out, actual_err = self.run_bzr(['log'] + args,
97
working_dir=working_dir)
98
self.assertEqual(out, actual_out)
99
self.assertEqual(err, actual_err)
100
self.assertEqual(expected_revnos,
101
[r.revno for r in self.get_captured_revisions()])
103
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
105
self.run_bzr(['log'] + args, working_dir=working_dir)
106
self.assertEqual(expected_revnos_and_depths,
107
[(r.revno, r.merge_depth)
108
for r in self.get_captured_revisions()])
111
class TestLogRevSpecs(TestLogWithLogCatcher):
113
def test_log_no_revspec(self):
114
self.make_linear_branch()
115
self.assertLogRevnos([], ['3', '2', '1'])
117
def test_log_null_end_revspec(self):
118
self.make_linear_branch()
119
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
121
def test_log_null_begin_revspec(self):
122
self.make_linear_branch()
123
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
125
def test_log_null_both_revspecs(self):
126
self.make_linear_branch()
127
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
129
def test_log_negative_begin_revspec_full_log(self):
130
self.make_linear_branch()
131
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
133
def test_log_negative_both_revspec_full_log(self):
134
self.make_linear_branch()
135
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
137
def test_log_negative_both_revspec_partial(self):
138
self.make_linear_branch()
139
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
141
def test_log_negative_begin_revspec(self):
142
self.make_linear_branch()
143
self.assertLogRevnos(['-r-2..'], ['3', '2'])
145
def test_log_positive_revspecs(self):
146
self.make_linear_branch()
147
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
149
def test_log_dotted_revspecs(self):
150
self.make_merged_branch()
151
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
153
def test_log_limit(self):
154
tree = self.make_branch_and_tree('.')
155
# We want more commits than our batch size starts at
156
for pos in range(10):
157
tree.commit("%s" % pos)
158
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
160
def test_log_limit_short(self):
161
self.make_linear_branch()
162
self.assertLogRevnos(['-l', '2'], ['3', '2'])
164
def test_log_change_revno(self):
165
self.make_linear_branch()
166
self.assertLogRevnos(['-c1'], ['1'])
168
def test_branch_revspec(self):
169
foo = self.make_branch_and_tree('foo')
170
bar = self.make_branch_and_tree('bar')
171
self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
174
foo.commit(message='foo')
175
bar.commit(message='bar')
176
self.run_bzr('log -r branch:../bar', working_dir='foo')
177
self.assertEqual([bar.branch.get_rev_id(1)],
179
for r in self.get_captured_revisions()])
182
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
184
def test_exclude_common_ancestry_simple_revnos(self):
185
self.make_linear_branch()
186
self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
190
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
193
super(TestLogMergedLinearAncestry, self).setUp()
194
# FIXME: Using a MemoryTree would be even better here (but until we
195
# stop calling run_bzr, there is no point) --vila 100118.
196
builder = branchbuilder.BranchBuilder(self.get_transport())
197
builder.start_series()
215
builder.build_snapshot(None, [
216
('add', ('', b'root-id', 'directory', ''))],
218
builder.build_snapshot([b'1'], [], revision_id=b'2')
220
builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
221
# merge branch into mainline
222
builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
223
# new commits in branch
224
builder.build_snapshot([b'1.1.1'], [], revision_id=b'1.1.2')
225
builder.build_snapshot([b'1.1.2'], [], revision_id=b'1.1.3')
226
# merge branch into mainline
227
builder.build_snapshot([b'3', b'1.1.3'], [], revision_id=b'4')
228
# merge mainline into branch
229
builder.build_snapshot([b'1.1.3', b'4'], [], revision_id=b'1.1.4')
230
# merge branch into mainline
231
builder.build_snapshot([b'4', b'1.1.4'], [], revision_id=b'5')
232
builder.build_snapshot([b'5'], [], revision_id=b'5.1.1')
233
builder.build_snapshot([b'5', b'5.1.1'], [], revision_id=b'6')
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'])
240
def test_n0_forward(self):
241
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
242
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
245
# starting from 1.1.4 we follow the left-hand ancestry
246
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
247
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
249
def test_n1_forward(self):
250
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
251
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
253
def test_fallback_when_end_rev_is_not_on_mainline(self):
254
self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
255
# We don't get 1.1.1 because we say -n1
256
['5.1.1', '5', '4', '3'])
259
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
262
super(Test_GenerateAllRevisions, self).setUp()
263
builder = self.make_branch_with_many_merges()
264
b = builder.get_branch()
266
self.addCleanup(b.unlock)
269
def make_branch_with_many_merges(self, path='.', format=None):
270
builder = branchbuilder.BranchBuilder(self.get_transport())
271
builder.start_series()
272
# The graph below may look a bit complicated (and it may be but I've
273
# banged my head enough on it) but the bug requires at least dotted
274
# revnos *and* merged revisions below that.
288
builder.build_snapshot(None, [
289
('add', ('', b'root-id', 'directory', ''))], revision_id=b'1')
290
builder.build_snapshot([b'1'], [], revision_id=b'2')
291
builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
292
builder.build_snapshot([b'2'], [], revision_id=b'2.1.1')
293
builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
294
builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.1.2')
295
builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.2.1')
296
builder.build_snapshot([b'2.1.2', b'2.2.1'], [], revision_id=b'2.1.3')
297
builder.build_snapshot([b'3', b'2.1.3'], [], revision_id=b'4')
298
builder.build_snapshot([b'4', b'2.1.2'], [], revision_id=b'5')
299
builder.finish_series()
302
def test_not_an_ancestor(self):
303
self.assertRaises(errors.BzrCommandError,
304
log._generate_all_revisions,
305
self.branch, '1.1.1', '2.1.3', 'reverse',
306
delayed_graph_generation=True)
308
def test_wrong_order(self):
309
self.assertRaises(errors.BzrCommandError,
310
log._generate_all_revisions,
311
self.branch, '5', '2.1.3', 'reverse',
312
delayed_graph_generation=True)
314
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
315
revs = log._generate_all_revisions(
316
self.branch, None, '2.1.3',
317
'reverse', delayed_graph_generation=True)
320
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
322
def test_log_revno_n_path_wrong_namespace(self):
323
self.make_linear_branch('branch1')
324
self.make_linear_branch('branch2')
325
# There is no guarantee that a path exist between two arbitrary
327
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
329
def test_log_revno_n_path_correct_order(self):
330
self.make_linear_branch('branch2')
331
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
334
def test_log_revno_n_path(self):
335
self.make_linear_branch('branch2')
336
self.assertLogRevnos(['-rrevno:1:branch2'],
338
rev_props = self.log_catcher.revisions[0].rev.properties
339
self.assertEqual('branch2', rev_props[u'branch-nick'])
342
class TestLogErrors(TestLog):
344
def test_log_zero_revspec(self):
345
self.make_minimal_branch()
346
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
349
def test_log_zero_begin_revspec(self):
350
self.make_linear_branch()
351
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
354
def test_log_zero_end_revspec(self):
355
self.make_linear_branch()
356
self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
359
def test_log_nonexistent_revno(self):
360
self.make_minimal_branch()
361
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
362
"does not exist in branch:"],
365
def test_log_nonexistent_dotted_revno(self):
366
self.make_minimal_branch()
367
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
368
"does not exist in branch:"],
369
['log', '-r123.123'])
371
def test_log_change_nonexistent_revno(self):
372
self.make_minimal_branch()
373
self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
374
"does not exist in branch:"],
377
def test_log_change_nonexistent_dotted_revno(self):
378
self.make_minimal_branch()
379
self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
380
"does not exist in branch:"],
381
['log', '-c123.123'])
383
def test_log_change_single_revno_only(self):
384
self.make_minimal_branch()
385
self.run_bzr_error(['brz: ERROR: Option --change does not'
386
' accept revision ranges'],
387
['log', '--change', '2..3'])
389
def test_log_change_incompatible_with_revision(self):
390
self.run_bzr_error(['brz: ERROR: --revision and --change'
391
' are mutually exclusive'],
392
['log', '--change', '2', '--revision', '3'])
394
def test_log_nonexistent_file(self):
395
self.make_minimal_branch()
396
# files that don't exist in either the basis tree or working tree
397
# should give an error
398
out, err = self.run_bzr('log does-not-exist', retcode=3)
399
self.assertContainsRe(err,
400
'Path unknown at end or start of revision range: '
403
def test_log_reversed_revspecs(self):
404
self.make_linear_branch()
405
self.run_bzr_error(('brz: ERROR: Start revision must be older than '
406
'the end revision.\n',),
409
def test_log_reversed_dotted_revspecs(self):
410
self.make_merged_branch()
411
self.run_bzr_error(('brz: ERROR: Start revision not found in '
412
'history of end revision.\n',),
415
def test_log_bad_message_re(self):
416
"""Bad --message argument gives a sensible message
418
See https://bugs.launchpad.net/bzr/+bug/251352
420
self.make_minimal_branch()
421
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
422
self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
423
self.assertNotContainsRe(err, "Unprintable exception")
424
self.assertEqual(out, '')
426
def test_log_unsupported_timezone(self):
427
self.make_linear_branch()
428
self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
429
'options are "utc", "original", "local".'],
430
['log', '--timezone', 'foo'])
432
def test_log_exclude_ancestry_no_range(self):
433
self.make_linear_branch()
434
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
435
' requires -r with two revisions'],
436
['log', '--exclude-common-ancestry'])
438
def test_log_exclude_ancestry_single_revision(self):
439
self.make_merged_branch()
440
self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
441
' requires two different revisions'],
442
['log', '--exclude-common-ancestry',
446
class TestLogTags(TestLog):
448
def test_log_with_tags(self):
449
tree = self.make_linear_branch(format='dirstate-tags')
451
branch.tags.set_tag('tag1', branch.get_rev_id(1))
452
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
453
branch.tags.set_tag('tag3', branch.last_revision())
455
log = self.run_bzr("log -r-1")[0]
456
self.assertTrue('tags: tag3' in log)
458
log = self.run_bzr("log -r1")[0]
459
# I guess that we can't know the order of tags in the output
460
# since dicts are unordered, need to check both possibilities
461
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
463
def test_merged_log_with_tags(self):
464
branch1_tree = self.make_linear_branch('branch1',
465
format='dirstate-tags')
466
branch1 = branch1_tree.branch
467
branch2_tree = branch1_tree.controldir.sprout(
468
'branch2').open_workingtree()
469
branch1_tree.commit(message='foobar', allow_pointless=True)
470
branch1.tags.set_tag('tag1', branch1.last_revision())
471
# tags don't propagate if we don't merge
472
self.run_bzr('merge ../branch1', working_dir='branch2')
473
branch2_tree.commit(message='merge branch 1')
474
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
475
self.assertContainsRe(log, r' tags: tag1')
476
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
477
self.assertContainsRe(log, r'tags: tag1')
480
class TestLogSignatures(TestLog):
482
def test_log_with_signatures(self):
483
self.requireFeature(features.gpg)
485
tree = self.make_linear_branch(format='dirstate-tags')
487
log = self.run_bzr("log --signatures")[0]
488
self.assertTrue('signature: no signature' in log)
490
def test_log_without_signatures(self):
491
self.requireFeature(features.gpg)
493
tree = self.make_linear_branch(format='dirstate-tags')
495
log = self.run_bzr("log")[0]
496
self.assertFalse('signature: no signature' in log)
499
class TestLogVerbose(TestLog):
502
super(TestLogVerbose, self).setUp()
503
self.make_minimal_branch()
505
def assertUseShortDeltaFormat(self, cmd):
506
log = self.run_bzr(cmd)[0]
507
# Check that we use the short status format
508
self.assertContainsRe(log, '(?m)^\\s*A hello.txt$')
509
self.assertNotContainsRe(log, '(?m)^\\s*added:$')
511
def assertUseLongDeltaFormat(self, cmd):
512
log = self.run_bzr(cmd)[0]
513
# Check that we use the long status format
514
self.assertNotContainsRe(log, '(?m)^\\s*A hello.txt$')
515
self.assertContainsRe(log, '(?m)^\\s*added:$')
517
def test_log_short_verbose(self):
518
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
520
def test_log_s_verbose(self):
521
self.assertUseShortDeltaFormat(['log', '-S', '-v'])
523
def test_log_short_verbose_verbose(self):
524
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
526
def test_log_long_verbose(self):
527
# Check that we use the long status format, ignoring the verbosity
529
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
531
def test_log_long_verbose_verbose(self):
532
# Check that we use the long status format, ignoring the verbosity
534
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
537
class TestLogMerges(TestLogWithLogCatcher):
540
super(TestLogMerges, self).setUp()
541
self.make_branches_with_merges()
543
def make_branches_with_merges(self):
544
level0 = self.make_branch_and_tree('level0')
545
self.wt_commit(level0, 'in branch level0')
546
level1 = level0.controldir.sprout('level1').open_workingtree()
547
self.wt_commit(level1, 'in branch level1')
548
level2 = level1.controldir.sprout('level2').open_workingtree()
549
self.wt_commit(level2, 'in branch level2')
550
level1.merge_from_branch(level2.branch)
551
self.wt_commit(level1, 'merge branch level2')
552
level0.merge_from_branch(level1.branch)
553
self.wt_commit(level0, 'merge branch level1')
555
def test_merges_are_indented_by_level(self):
556
self.run_bzr(['log', '-n0'], working_dir='level0')
557
revnos_and_depth = [(r.revno, r.merge_depth)
558
for r in self.get_captured_revisions()]
559
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
561
[(r.revno, r.merge_depth)
562
for r in self.get_captured_revisions()])
564
def test_force_merge_revisions_off(self):
565
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
567
def test_force_merge_revisions_on(self):
568
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
569
working_dir='level0')
571
def test_include_merged(self):
572
# Confirm --include-merged gives the same output as -n0
573
expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
574
self.assertLogRevnos(['--include-merged'],
575
expected, working_dir='level0')
576
self.assertLogRevnos(['--include-merged'],
577
expected, working_dir='level0')
579
def test_force_merge_revisions_N(self):
580
self.assertLogRevnos(['-n2'],
581
['2', '1.1.2', '1.1.1', '1'],
582
working_dir='level0')
584
def test_merges_single_merge_rev(self):
585
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
586
[('1.1.2', 0), ('1.2.1', 1)],
587
working_dir='level0')
589
def test_merges_partial_range(self):
590
self.assertLogRevnosAndDepths(
591
['-n0', '-r1.1.1..1.1.2'],
592
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
593
working_dir='level0')
595
def test_merges_partial_range_ignore_before_lower_bound(self):
596
"""Dont show revisions before the lower bound's merged revs"""
597
self.assertLogRevnosAndDepths(
598
['-n0', '-r1.1.2..2'],
599
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
600
working_dir='level0')
602
def test_omit_merges_with_sidelines(self):
603
self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
604
working_dir='level0')
606
def test_omit_merges_without_sidelines(self):
607
self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
608
working_dir='level0')
611
class TestLogDiff(TestLogWithLogCatcher):
613
# FIXME: We need specific tests for each LogFormatter about how the diffs
614
# are displayed: --long indent them by depth, --short use a fixed
615
# indent and --line does't display them. -- vila 10019
618
super(TestLogDiff, self).setUp()
619
self.make_branch_with_diffs()
621
def make_branch_with_diffs(self):
622
level0 = self.make_branch_and_tree('level0')
623
self.build_tree(['level0/file1', 'level0/file2'])
626
self.wt_commit(level0, 'in branch level0')
628
level1 = level0.controldir.sprout('level1').open_workingtree()
629
self.build_tree_contents([('level1/file2', b'hello\n')])
630
self.wt_commit(level1, 'in branch level1')
631
level0.merge_from_branch(level1.branch)
632
self.wt_commit(level0, 'merge branch level1')
634
def _diff_file1_revno1(self):
635
return b"""=== added file 'file1'
636
--- file1\t1970-01-01 00:00:00 +0000
637
+++ file1\t2005-11-22 00:00:00 +0000
639
+contents of level0/file1
643
def _diff_file2_revno2(self):
644
return b"""=== modified file 'file2'
645
--- file2\t2005-11-22 00:00:00 +0000
646
+++ file2\t2005-11-22 00:00:01 +0000
648
-contents of level0/file2
653
def _diff_file2_revno1_1_1(self):
654
return b"""=== modified file 'file2'
655
--- file2\t2005-11-22 00:00:00 +0000
656
+++ file2\t2005-11-22 00:00:01 +0000
658
-contents of level0/file2
663
def _diff_file2_revno1(self):
664
return b"""=== added file 'file2'
665
--- file2\t1970-01-01 00:00:00 +0000
666
+++ file2\t2005-11-22 00:00:00 +0000
668
+contents of level0/file2
672
def assertLogRevnosAndDiff(self, args, expected,
674
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
675
expected_revnos_and_depths = [
676
(revno, depth) for revno, depth, diff in expected]
677
# Check the revnos and depths first to make debugging easier
678
self.assertEqual(expected_revnos_and_depths,
679
[(r.revno, r.merge_depth)
680
for r in self.get_captured_revisions()])
681
# Now check the diffs, adding the revno in case of failure
682
fmt = 'In revno %s\n%s'
683
for expected_rev, actual_rev in zip(expected,
684
self.get_captured_revisions()):
685
revno, depth, expected_diff = expected_rev
686
actual_diff = actual_rev.diff
687
self.assertEqualDiff(fmt % (revno, expected_diff),
688
fmt % (revno, actual_diff))
690
def test_log_diff_with_merges(self):
691
self.assertLogRevnosAndDiff(
693
[('2', 0, self._diff_file2_revno2()),
694
('1.1.1', 1, self._diff_file2_revno1_1_1()),
695
('1', 0, self._diff_file1_revno1() +
696
self._diff_file2_revno1())],
697
working_dir='level0')
699
def test_log_diff_file1(self):
700
self.assertLogRevnosAndDiff(['-n0', 'file1'],
701
[('1', 0, self._diff_file1_revno1())],
702
working_dir='level0')
704
def test_log_diff_file2(self):
705
self.assertLogRevnosAndDiff(['-n1', 'file2'],
706
[('2', 0, self._diff_file2_revno2()),
707
('1', 0, self._diff_file2_revno1())],
708
working_dir='level0')
711
class TestLogUnicodeDiff(TestLog):
713
def test_log_show_diff_non_ascii(self):
714
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
715
message = u'Message with \xb5'
716
body = b'Body with \xb5\n'
717
wt = self.make_branch_and_tree('.')
718
self.build_tree_contents([('foo', body)])
720
wt.commit(message=message)
721
# check that command won't fail with unicode error
722
# don't care about exact output because we have other tests for this
723
out, err = self.run_bzr('log -p --long')
724
self.assertNotEqual('', out)
725
self.assertEqual('', err)
726
out, err = self.run_bzr('log -p --short')
727
self.assertNotEqual('', out)
728
self.assertEqual('', err)
729
out, err = self.run_bzr('log -p --line')
730
self.assertNotEqual('', out)
731
self.assertEqual('', err)
734
class TestLogEncodings(tests.TestCaseInTempDir):
737
_message = u'Message with \xb5'
739
# Encodings which can encode mu
744
'cp437', # Common windows encoding
745
'cp1251', # Russian windows encoding
746
'cp1258', # Common windows encoding
748
# Encodings which cannot encode mu
756
super(TestLogEncodings, self).setUp()
757
self.overrideAttr(osutils, '_cached_user_encoding')
759
def create_branch(self):
762
self.build_tree_contents([('a', b'some stuff\n')])
764
brz(['commit', '-m', self._message])
766
def try_encoding(self, encoding, fail=False):
769
self.assertRaises(UnicodeEncodeError,
770
self._mu.encode, encoding)
771
encoded_msg = self._message.encode(encoding, 'replace')
773
encoded_msg = self._message.encode(encoding)
775
old_encoding = osutils._cached_user_encoding
776
# This test requires that 'run_bzr' uses the current
777
# breezy, because we override user_encoding, and expect
780
osutils._cached_user_encoding = 'ascii'
781
# We should be able to handle any encoding
782
out, err = brz('log', encoding=encoding)
784
# Make sure we wrote mu as we expected it to exist
785
self.assertNotEqual(-1, out.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_raw('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 = b'\x92\xa5\xe1\xe2'
822
test_in_cp1251 = b'\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', b'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', b'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([b"spooky"], allow_leftmost_as_ghost=True)
991
tree.commit('msg1', rev_id=b'rev1')
992
tree.commit('msg2', rev_id=b'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',
1019
authors=['author1'])
1020
tree.add('goodbye.txt')
1021
tree.commit(message='message2', committer='committer2',
1022
authors=['author2'])
1024
def test_message(self):
1026
self.assertLogRevnos(["-m", "message1"], ["1"])
1027
self.assertLogRevnos(["-m", "message2"], ["2"])
1028
self.assertLogRevnos(["-m", "message"], ["2", "1"])
1029
self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
1030
self.assertLogRevnos(["--match-message", "message1"], ["1"])
1031
self.assertLogRevnos(["--match-message", "message2"], ["2"])
1032
self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
1033
self.assertLogRevnos(["--match-message", "message1",
1034
"--match-message", "message2"], ["2", "1"])
1035
self.assertLogRevnos(["--message", "message1"], ["1"])
1036
self.assertLogRevnos(["--message", "message2"], ["2"])
1037
self.assertLogRevnos(["--message", "message"], ["2", "1"])
1038
self.assertLogRevnos(["--match-message", "message1",
1039
"--message", "message2"], ["2", "1"])
1040
self.assertLogRevnos(["--message", "message1",
1041
"--match-message", "message2"], ["2", "1"])
1043
def test_committer(self):
1045
self.assertLogRevnos(["-m", "committer1"], ["1"])
1046
self.assertLogRevnos(["-m", "committer2"], ["2"])
1047
self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1048
self.assertLogRevnos(["-m", "committer1", "-m", "committer2"],
1050
self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1051
self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1052
self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1053
self.assertLogRevnos(["--match-committer", "committer1",
1054
"--match-committer", "committer2"], ["2", "1"])
1056
def test_author(self):
1058
self.assertLogRevnos(["-m", "author1"], ["1"])
1059
self.assertLogRevnos(["-m", "author2"], ["2"])
1060
self.assertLogRevnos(["-m", "author"], ["2", "1"])
1061
self.assertLogRevnos(["-m", "author1", "-m", "author2"],
1063
self.assertLogRevnos(["--match-author", "author1"], ["1"])
1064
self.assertLogRevnos(["--match-author", "author2"], ["2"])
1065
self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1066
self.assertLogRevnos(["--match-author", "author1",
1067
"--match-author", "author2"], ["2", "1"])
1070
class TestSmartServerLog(tests.TestCaseWithTransport):
1072
def test_standard_log(self):
1073
self.setup_smart_server_with_call_log()
1074
t = self.make_branch_and_tree('branch')
1075
self.build_tree_contents([('branch/foo', b'thecontents')])
1078
self.reset_smart_call_log()
1079
out, err = self.run_bzr(['log', self.get_url('branch')])
1080
# This figure represent the amount of work to perform this use case. It
1081
# is entirely ok to reduce this number if a test fails due to rpc_count
1082
# being too low. If rpc_count increases, more network roundtrips have
1083
# become necessary for this use case. Please do not adjust this number
1084
# upwards without agreement from bzr's network support maintainers.
1085
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1086
self.assertLength(1, self.hpss_connections)
1087
self.assertLength(9, self.hpss_calls)
1089
def test_verbose_log(self):
1090
self.setup_smart_server_with_call_log()
1091
t = self.make_branch_and_tree('branch')
1092
self.build_tree_contents([('branch/foo', b'thecontents')])
1095
self.reset_smart_call_log()
1096
out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
1097
# This figure represent the amount of work to perform this use case. It
1098
# is entirely ok to reduce this number if a test fails due to rpc_count
1099
# being too low. If rpc_count increases, more network roundtrips have
1100
# become necessary for this use case. Please do not adjust this number
1101
# upwards without agreement from bzr's network support maintainers.
1102
self.assertLength(10, self.hpss_calls)
1103
self.assertLength(1, self.hpss_connections)
1104
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
1106
def test_per_file(self):
1107
self.setup_smart_server_with_call_log()
1108
t = self.make_branch_and_tree('branch')
1109
self.build_tree_contents([('branch/foo', b'thecontents')])
1112
self.reset_smart_call_log()
1113
out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
1114
# This figure represent the amount of work to perform this use case. It
1115
# is entirely ok to reduce this number if a test fails due to rpc_count
1116
# being too low. If rpc_count increases, more network roundtrips have
1117
# become necessary for this use case. Please do not adjust this number
1118
# upwards without agreement from bzr's network support maintainers.
1119
self.assertLength(14, self.hpss_calls)
1120
self.assertLength(1, self.hpss_connections)
1121
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)