1
# Copyright (C) 2006-2010 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 bzr log."""
20
from itertools import izip
31
from bzrlib.tests import (
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.bzrdir.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
74
class MyLogFormatter(test_log.LogCatcher):
76
def __new__(klass, *args, **kwargs):
77
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
78
# Always return our own log formatter
79
return self.log_catcher
82
# Always return our own log formatter class hijacking the
83
# default behavior (which requires setting up a config
86
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
88
def get_captured_revisions(self):
89
return self.log_catcher.revisions
91
def assertLogRevnos(self, args, expected_revnos, working_dir='.'):
92
self.run_bzr(['log'] + args, working_dir=working_dir)
93
self.assertEqual(expected_revnos,
94
[r.revno for r in self.get_captured_revisions()])
96
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
98
self.run_bzr(['log'] + args, working_dir=working_dir)
99
self.assertEqual(expected_revnos_and_depths,
100
[(r.revno, r.merge_depth)
101
for r in self.get_captured_revisions()])
104
class TestLogRevSpecs(TestLogWithLogCatcher):
106
def test_log_no_revspec(self):
107
self.make_linear_branch()
108
self.assertLogRevnos([], ['3', '2', '1'])
110
def test_log_null_end_revspec(self):
111
self.make_linear_branch()
112
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
114
def test_log_null_begin_revspec(self):
115
self.make_linear_branch()
116
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
118
def test_log_null_both_revspecs(self):
119
self.make_linear_branch()
120
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
122
def test_log_negative_begin_revspec_full_log(self):
123
self.make_linear_branch()
124
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
126
def test_log_negative_both_revspec_full_log(self):
127
self.make_linear_branch()
128
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
130
def test_log_negative_both_revspec_partial(self):
131
self.make_linear_branch()
132
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
134
def test_log_negative_begin_revspec(self):
135
self.make_linear_branch()
136
self.assertLogRevnos(['-r-2..'], ['3', '2'])
138
def test_log_positive_revspecs(self):
139
self.make_linear_branch()
140
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
142
def test_log_dotted_revspecs(self):
143
self.make_merged_branch()
144
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
146
def test_log_limit(self):
147
tree = self.make_branch_and_tree('.')
148
# We want more commits than our batch size starts at
149
for pos in range(10):
150
tree.commit("%s" % pos)
151
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
153
def test_log_limit_short(self):
154
self.make_linear_branch()
155
self.assertLogRevnos(['-l', '2'], ['3', '2'])
157
def test_log_change_revno(self):
158
self.make_linear_branch()
159
self.assertLogRevnos(['-c1'], ['1'])
161
def test_branch_revspec(self):
162
foo = self.make_branch_and_tree('foo')
163
bar = self.make_branch_and_tree('bar')
164
self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
167
foo.commit(message='foo')
168
bar.commit(message='bar')
169
self.run_bzr('log -r branch:../bar', working_dir='foo')
170
self.assertEqual([bar.branch.get_rev_id(1)],
172
for r in self.get_captured_revisions()])
175
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
177
def test_exclude_common_ancestry_simple_revnos(self):
178
self.make_linear_branch()
179
self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
183
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
186
super(TestLogMergedLinearAncestry, self).setUp()
187
# FIXME: Using a MemoryTree would be even better here (but until we
188
# stop calling run_bzr, there is no point) --vila 100118.
189
builder = branchbuilder.BranchBuilder(self.get_transport())
190
builder.start_series()
204
builder.build_snapshot('1', None, [
205
('add', ('', 'root-id', 'directory', ''))])
206
builder.build_snapshot('2', ['1'], [])
208
builder.build_snapshot('1.1.1', ['1'], [])
209
# merge branch into mainline
210
builder.build_snapshot('3', ['2', '1.1.1'], [])
211
# new commits in branch
212
builder.build_snapshot('1.1.2', ['1.1.1'], [])
213
builder.build_snapshot('1.1.3', ['1.1.2'], [])
214
# merge branch into mainline
215
builder.build_snapshot('4', ['3', '1.1.3'], [])
216
# merge mainline into branch
217
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
218
# merge branch into mainline
219
builder.build_snapshot('5', ['4', '1.1.4'], [])
220
builder.finish_series()
223
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
224
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
225
def test_n0_forward(self):
226
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
227
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
230
# starting from 1.1.4 we follow the left-hand ancestry
231
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
232
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
234
def test_n1_forward(self):
235
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
236
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
239
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
242
super(Test_GenerateAllRevisions, self).setUp()
243
builder = self.make_branch_with_many_merges()
244
b = builder.get_branch()
246
self.addCleanup(b.unlock)
249
def make_branch_with_many_merges(self, path='.', format=None):
250
builder = branchbuilder.BranchBuilder(self.get_transport())
251
builder.start_series()
252
# The graph below may look a bit complicated (and it may be but I've
253
# banged my head enough on it) but the bug requires at least dotted
254
# revnos *and* merged revisions below that.
255
builder.build_snapshot('1', None, [
256
('add', ('', 'root-id', 'directory', ''))])
257
builder.build_snapshot('2', ['1'], [])
258
builder.build_snapshot('1.1.1', ['1'], [])
259
builder.build_snapshot('2.1.1', ['2'], [])
260
builder.build_snapshot('3', ['2', '1.1.1'], [])
261
builder.build_snapshot('2.1.2', ['2.1.1'], [])
262
builder.build_snapshot('2.2.1', ['2.1.1'], [])
263
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
264
builder.build_snapshot('4', ['3', '2.1.3'], [])
265
builder.build_snapshot('5', ['4', '2.1.2'], [])
266
builder.finish_series()
269
def test_not_an_ancestor(self):
270
self.assertRaises(errors.BzrCommandError,
271
log._generate_all_revisions,
272
self.branch, '1.1.1', '2.1.3', 'reverse',
273
delayed_graph_generation=True)
275
def test_wrong_order(self):
276
self.assertRaises(errors.BzrCommandError,
277
log._generate_all_revisions,
278
self.branch, '5', '2.1.3', 'reverse',
279
delayed_graph_generation=True)
281
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
282
revs = log._generate_all_revisions(
283
self.branch, None, '2.1.3',
284
'reverse', delayed_graph_generation=True)
287
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
289
def test_log_revno_n_path_wrong_namespace(self):
290
self.make_linear_branch('branch1')
291
self.make_linear_branch('branch2')
292
# There is no guarantee that a path exist between two arbitrary
294
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
296
def test_log_revno_n_path_correct_order(self):
297
self.make_linear_branch('branch2')
298
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
301
def test_log_revno_n_path(self):
302
self.make_linear_branch('branch2')
303
self.assertLogRevnos(['-rrevno:1:branch2'],
305
rev_props = self.log_catcher.revisions[0].rev.properties
306
self.assertEqual('branch2', rev_props['branch-nick'])
309
class TestLogErrors(TestLog):
311
def test_log_zero_revspec(self):
312
self.make_minimal_branch()
313
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
316
def test_log_zero_begin_revspec(self):
317
self.make_linear_branch()
318
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
321
def test_log_zero_end_revspec(self):
322
self.make_linear_branch()
323
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
326
def test_log_nonexistent_revno(self):
327
self.make_minimal_branch()
328
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
329
"does not exist in branch:"],
332
def test_log_nonexistent_dotted_revno(self):
333
self.make_minimal_branch()
334
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
335
"does not exist in branch:"],
336
['log', '-r123.123'])
338
def test_log_change_nonexistent_revno(self):
339
self.make_minimal_branch()
340
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
341
"does not exist in branch:"],
344
def test_log_change_nonexistent_dotted_revno(self):
345
self.make_minimal_branch()
346
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
347
"does not exist in branch:"],
348
['log', '-c123.123'])
350
def test_log_change_single_revno_only(self):
351
self.make_minimal_branch()
352
self.run_bzr_error(['bzr: ERROR: Option --change does not'
353
' accept revision ranges'],
354
['log', '--change', '2..3'])
356
def test_log_change_incompatible_with_revision(self):
357
self.run_bzr_error(['bzr: ERROR: --revision and --change'
358
' are mutually exclusive'],
359
['log', '--change', '2', '--revision', '3'])
361
def test_log_nonexistent_file(self):
362
self.make_minimal_branch()
363
# files that don't exist in either the basis tree or working tree
364
# should give an error
365
out, err = self.run_bzr('log does-not-exist', retcode=3)
366
self.assertContainsRe(err,
367
'Path unknown at end or start of revision range: '
370
def test_log_reversed_revspecs(self):
371
self.make_linear_branch()
372
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
373
'the end revision.\n',),
376
def test_log_reversed_dotted_revspecs(self):
377
self.make_merged_branch()
378
self.run_bzr_error(('bzr: ERROR: Start revision not found in '
379
'left-hand history of end revision.\n',),
382
def test_log_bad_message_re(self):
383
"""Bad --message argument gives a sensible message
385
See https://bugs.launchpad.net/bzr/+bug/251352
387
self.make_minimal_branch()
388
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
389
self.assertEqual("bzr: ERROR: Invalid regular expression"
390
" in log message filter"
392
": nothing to repeat\n", err)
393
self.assertEqual('', out)
395
def test_log_unsupported_timezone(self):
396
self.make_linear_branch()
397
self.run_bzr_error(['bzr: ERROR: Unsupported timezone format "foo", '
398
'options are "utc", "original", "local".'],
399
['log', '--timezone', 'foo'])
401
def test_log_exclude_ancestry_no_range(self):
402
self.make_linear_branch()
403
self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
404
' requires -r with two revisions'],
405
['log', '--exclude-common-ancestry'])
407
def test_log_exclude_ancestry_single_revision(self):
408
self.make_merged_branch()
409
self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
410
' requires two different revisions'],
411
['log', '--exclude-common-ancestry',
414
class TestLogTags(TestLog):
416
def test_log_with_tags(self):
417
tree = self.make_linear_branch(format='dirstate-tags')
419
branch.tags.set_tag('tag1', branch.get_rev_id(1))
420
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
421
branch.tags.set_tag('tag3', branch.last_revision())
423
log = self.run_bzr("log -r-1")[0]
424
self.assertTrue('tags: tag3' in log)
426
log = self.run_bzr("log -r1")[0]
427
# I guess that we can't know the order of tags in the output
428
# since dicts are unordered, need to check both possibilities
429
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
431
def test_merged_log_with_tags(self):
432
branch1_tree = self.make_linear_branch('branch1',
433
format='dirstate-tags')
434
branch1 = branch1_tree.branch
435
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
436
branch1_tree.commit(message='foobar', allow_pointless=True)
437
branch1.tags.set_tag('tag1', branch1.last_revision())
438
# tags don't propagate if we don't merge
439
self.run_bzr('merge ../branch1', working_dir='branch2')
440
branch2_tree.commit(message='merge branch 1')
441
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
442
self.assertContainsRe(log, r' tags: tag1')
443
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
444
self.assertContainsRe(log, r'tags: tag1')
447
class TestLogVerbose(TestLog):
450
super(TestLogVerbose, self).setUp()
451
self.make_minimal_branch()
453
def assertUseShortDeltaFormat(self, cmd):
454
log = self.run_bzr(cmd)[0]
455
# Check that we use the short status format
456
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
457
self.assertNotContainsRe(log, '(?m)^\s*added:$')
459
def assertUseLongDeltaFormat(self, cmd):
460
log = self.run_bzr(cmd)[0]
461
# Check that we use the long status format
462
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
463
self.assertContainsRe(log, '(?m)^\s*added:$')
465
def test_log_short_verbose(self):
466
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
468
def test_log_short_verbose_verbose(self):
469
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
471
def test_log_long_verbose(self):
472
# Check that we use the long status format, ignoring the verbosity
474
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
476
def test_log_long_verbose_verbose(self):
477
# Check that we use the long status format, ignoring the verbosity
479
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
482
class TestLogMerges(TestLogWithLogCatcher):
485
super(TestLogMerges, self).setUp()
486
self.make_branches_with_merges()
488
def make_branches_with_merges(self):
489
level0 = self.make_branch_and_tree('level0')
490
self.wt_commit(level0, 'in branch level0')
491
level1 = level0.bzrdir.sprout('level1').open_workingtree()
492
self.wt_commit(level1, 'in branch level1')
493
level2 = level1.bzrdir.sprout('level2').open_workingtree()
494
self.wt_commit(level2, 'in branch level2')
495
level1.merge_from_branch(level2.branch)
496
self.wt_commit(level1, 'merge branch level2')
497
level0.merge_from_branch(level1.branch)
498
self.wt_commit(level0, 'merge branch level1')
500
def test_merges_are_indented_by_level(self):
501
self.run_bzr(['log', '-n0'], working_dir='level0')
502
revnos_and_depth = [(r.revno, r.merge_depth)
503
for r in self.get_captured_revisions()]
504
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
506
[(r.revno, r.merge_depth)
507
for r in self.get_captured_revisions()])
509
def test_force_merge_revisions_off(self):
510
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
512
def test_force_merge_revisions_on(self):
513
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
514
working_dir='level0')
516
def test_include_merges(self):
517
# Confirm --include-merges gives the same output as -n0
518
self.assertLogRevnos(['--include-merges'],
519
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
520
working_dir='level0')
521
self.assertLogRevnos(['--include-merges'],
522
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
523
working_dir='level0')
524
out_im, err_im = self.run_bzr('log --include-merges',
525
working_dir='level0')
526
out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
527
self.assertEqual('', err_im)
528
self.assertEqual('', err_n0)
529
self.assertEqual(out_im, out_n0)
531
def test_force_merge_revisions_N(self):
532
self.assertLogRevnos(['-n2'],
533
['2', '1.1.2', '1.1.1', '1'],
534
working_dir='level0')
536
def test_merges_single_merge_rev(self):
537
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
538
[('1.1.2', 0), ('1.2.1', 1)],
539
working_dir='level0')
541
def test_merges_partial_range(self):
542
self.assertLogRevnosAndDepths(
543
['-n0', '-r1.1.1..1.1.2'],
544
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
545
working_dir='level0')
547
def test_merges_partial_range_ignore_before_lower_bound(self):
548
"""Dont show revisions before the lower bound's merged revs"""
549
self.assertLogRevnosAndDepths(
550
['-n0', '-r1.1.2..2'],
551
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
552
working_dir='level0')
555
class TestLogDiff(TestLogWithLogCatcher):
557
# FIXME: We need specific tests for each LogFormatter about how the diffs
558
# are displayed: --long indent them by depth, --short use a fixed
559
# indent and --line does't display them. -- vila 10019
562
super(TestLogDiff, self).setUp()
563
self.make_branch_with_diffs()
565
def make_branch_with_diffs(self):
566
level0 = self.make_branch_and_tree('level0')
567
self.build_tree(['level0/file1', 'level0/file2'])
570
self.wt_commit(level0, 'in branch level0')
572
level1 = level0.bzrdir.sprout('level1').open_workingtree()
573
self.build_tree_contents([('level1/file2', 'hello\n')])
574
self.wt_commit(level1, 'in branch level1')
575
level0.merge_from_branch(level1.branch)
576
self.wt_commit(level0, 'merge branch level1')
578
def _diff_file1_revno1(self):
579
return """=== added file 'file1'
580
--- file1\t1970-01-01 00:00:00 +0000
581
+++ file1\t2005-11-22 00:00:00 +0000
583
+contents of level0/file1
587
def _diff_file2_revno2(self):
588
return """=== modified file 'file2'
589
--- file2\t2005-11-22 00:00:00 +0000
590
+++ file2\t2005-11-22 00:00:01 +0000
592
-contents of level0/file2
597
def _diff_file2_revno1_1_1(self):
598
return """=== modified file 'file2'
599
--- file2\t2005-11-22 00:00:00 +0000
600
+++ file2\t2005-11-22 00:00:01 +0000
602
-contents of level0/file2
607
def _diff_file2_revno1(self):
608
return """=== added file 'file2'
609
--- file2\t1970-01-01 00:00:00 +0000
610
+++ file2\t2005-11-22 00:00:00 +0000
612
+contents of level0/file2
616
def assertLogRevnosAndDiff(self, args, expected,
618
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
619
expected_revnos_and_depths = [
620
(revno, depth) for revno, depth, diff in expected]
621
# Check the revnos and depths first to make debugging easier
622
self.assertEqual(expected_revnos_and_depths,
623
[(r.revno, r.merge_depth)
624
for r in self.get_captured_revisions()])
625
# Now check the diffs, adding the revno in case of failure
626
fmt = 'In revno %s\n%s'
627
for expected_rev, actual_rev in izip(expected,
628
self.get_captured_revisions()):
629
revno, depth, expected_diff = expected_rev
630
actual_diff = actual_rev.diff
631
self.assertEqualDiff(fmt % (revno, expected_diff),
632
fmt % (revno, actual_diff))
634
def test_log_diff_with_merges(self):
635
self.assertLogRevnosAndDiff(
637
[('2', 0, self._diff_file2_revno2()),
638
('1.1.1', 1, self._diff_file2_revno1_1_1()),
639
('1', 0, self._diff_file1_revno1()
640
+ self._diff_file2_revno1())],
641
working_dir='level0')
644
def test_log_diff_file1(self):
645
self.assertLogRevnosAndDiff(['-n0', 'file1'],
646
[('1', 0, self._diff_file1_revno1())],
647
working_dir='level0')
649
def test_log_diff_file2(self):
650
self.assertLogRevnosAndDiff(['-n1', 'file2'],
651
[('2', 0, self._diff_file2_revno2()),
652
('1', 0, self._diff_file2_revno1())],
653
working_dir='level0')
656
class TestLogUnicodeDiff(TestLog):
658
def test_log_show_diff_non_ascii(self):
659
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
660
message = u'Message with \xb5'
661
body = 'Body with \xb5\n'
662
wt = self.make_branch_and_tree('.')
663
self.build_tree_contents([('foo', body)])
665
wt.commit(message=message)
666
# check that command won't fail with unicode error
667
# don't care about exact output because we have other tests for this
668
out,err = self.run_bzr('log -p --long')
669
self.assertNotEqual('', out)
670
self.assertEqual('', err)
671
out,err = self.run_bzr('log -p --short')
672
self.assertNotEqual('', out)
673
self.assertEqual('', err)
674
out,err = self.run_bzr('log -p --line')
675
self.assertNotEqual('', out)
676
self.assertEqual('', err)
679
class TestLogEncodings(tests.TestCaseInTempDir):
682
_message = u'Message with \xb5'
684
# Encodings which can encode mu
689
'cp437', # Common windows encoding
690
'cp1251', # Russian windows encoding
691
'cp1258', # Common windows encoding
693
# Encodings which cannot encode mu
701
super(TestLogEncodings, self).setUp()
702
self.overrideAttr(osutils, '_cached_user_encoding')
704
def create_branch(self):
707
self.build_tree_contents([('a', 'some stuff\n')])
709
bzr(['commit', '-m', self._message])
711
def try_encoding(self, encoding, fail=False):
714
self.assertRaises(UnicodeEncodeError,
715
self._mu.encode, encoding)
716
encoded_msg = self._message.encode(encoding, 'replace')
718
encoded_msg = self._message.encode(encoding)
720
old_encoding = osutils._cached_user_encoding
721
# This test requires that 'run_bzr' uses the current
722
# bzrlib, because we override user_encoding, and expect
725
osutils._cached_user_encoding = 'ascii'
726
# We should be able to handle any encoding
727
out, err = bzr('log', encoding=encoding)
729
# Make sure we wrote mu as we expected it to exist
730
self.assertNotEqual(-1, out.find(encoded_msg))
731
out_unicode = out.decode(encoding)
732
self.assertNotEqual(-1, out_unicode.find(self._message))
734
self.assertNotEqual(-1, out.find('Message with ?'))
736
osutils._cached_user_encoding = old_encoding
738
def test_log_handles_encoding(self):
741
for encoding in self.good_encodings:
742
self.try_encoding(encoding)
744
def test_log_handles_bad_encoding(self):
747
for encoding in self.bad_encodings:
748
self.try_encoding(encoding, fail=True)
750
def test_stdout_encoding(self):
752
osutils._cached_user_encoding = "cp1251"
755
self.build_tree(['a'])
757
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
758
stdout, stderr = self.run_bzr('log', encoding='cp866')
760
message = stdout.splitlines()[-1]
762
# explanation of the check:
763
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
764
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
765
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
766
# This test should check that output of log command
767
# encoded to sys.stdout.encoding
768
test_in_cp866 = '\x92\xa5\xe1\xe2'
769
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
770
# Make sure the log string is encoded in cp866
771
self.assertEquals(test_in_cp866, message[2:])
772
# Make sure the cp1251 string is not found anywhere
773
self.assertEquals(-1, stdout.find(test_in_cp1251))
776
class TestLogFile(TestLogWithLogCatcher):
778
def test_log_local_branch_file(self):
779
"""We should be able to log files in local treeless branches"""
780
tree = self.make_branch_and_tree('tree')
781
self.build_tree(['tree/file'])
783
tree.commit('revision 1')
784
tree.bzrdir.destroy_workingtree()
785
self.run_bzr('log tree/file')
787
def prepare_tree(self, complex=False):
788
# The complex configuration includes deletes and renames
789
tree = self.make_branch_and_tree('parent')
790
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
792
tree.commit('add file1')
794
tree.commit('add file2')
796
tree.commit('add file3')
797
child_tree = tree.bzrdir.sprout('child').open_workingtree()
798
self.build_tree_contents([('child/file2', 'hello')])
799
child_tree.commit(message='branch 1')
800
tree.merge_from_branch(child_tree.branch)
801
tree.commit(message='merge child branch')
804
tree.commit('remove file2')
805
tree.rename_one('file3', 'file4')
806
tree.commit('file3 is now called file4')
808
tree.commit('remove file1')
811
# FIXME: It would be good to parametrize the following tests against all
812
# formatters. But the revisions selection is not *currently* part of the
813
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
814
def test_log_file1(self):
816
self.assertLogRevnos(['-n0', 'file1'], ['1'])
818
def test_log_file2(self):
821
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
822
# file2 in a merge revision
823
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
824
# file2 in a mainline revision
825
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
826
# file2 since a revision
827
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
828
# file2 up to a revision
829
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
831
def test_log_file3(self):
833
self.assertLogRevnos(['-n0', 'file3'], ['3'])
835
def test_log_file_historical_missing(self):
836
# Check logging a deleted file gives an error if the
837
# file isn't found at the end or start of the revision range
838
self.prepare_tree(complex=True)
839
err_msg = "Path unknown at end or start of revision range: file2"
840
err = self.run_bzr('log file2', retcode=3)[1]
841
self.assertContainsRe(err, err_msg)
843
def test_log_file_historical_end(self):
844
# Check logging a deleted file is ok if the file existed
845
# at the end the revision range
846
self.prepare_tree(complex=True)
847
self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
849
def test_log_file_historical_start(self):
850
# Check logging a deleted file is ok if the file existed
851
# at the start of the revision range
852
self.prepare_tree(complex=True)
853
self.assertLogRevnos(['file1'], ['1'])
855
def test_log_file_renamed(self):
856
"""File matched against revision range, not current tree."""
857
self.prepare_tree(complex=True)
859
# Check logging a renamed file gives an error by default
860
err_msg = "Path unknown at end or start of revision range: file3"
861
err = self.run_bzr('log file3', retcode=3)[1]
862
self.assertContainsRe(err, err_msg)
864
# Check we can see a renamed file if we give the right end revision
865
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
868
class TestLogMultiple(TestLogWithLogCatcher):
870
def prepare_tree(self):
871
tree = self.make_branch_and_tree('parent')
878
'parent/dir1/dir2/file3',
881
tree.commit('add file1')
883
tree.commit('add file2')
884
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
885
tree.commit('add file3')
887
tree.commit('add file4')
888
tree.add('dir1/file5')
889
tree.commit('add file5')
890
child_tree = tree.bzrdir.sprout('child').open_workingtree()
891
self.build_tree_contents([('child/file2', 'hello')])
892
child_tree.commit(message='branch 1')
893
tree.merge_from_branch(child_tree.branch)
894
tree.commit(message='merge child branch')
897
def test_log_files(self):
898
"""The log for multiple file should only list revs for those files"""
900
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
901
['6', '5.1.1', '3', '2', '1'])
903
def test_log_directory(self):
904
"""The log for a directory should show all nested files."""
906
self.assertLogRevnos(['dir1'], ['5', '3'])
908
def test_log_nested_directory(self):
909
"""The log for a directory should show all nested files."""
911
self.assertLogRevnos(['dir1/dir2'], ['3'])
913
def test_log_in_nested_directory(self):
914
"""The log for a directory should show all nested files."""
917
self.assertLogRevnos(['.'], ['5', '3'])
919
def test_log_files_and_directories(self):
920
"""Logging files and directories together should be fine."""
922
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
924
def test_log_files_and_dirs_in_nested_directory(self):
925
"""The log for a directory should show all nested files."""
928
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])