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'])
162
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
165
super(TestLogMergedLinearAncestry, self).setUp()
166
# FIXME: Using a MemoryTree would be even better here (but until we
167
# stop calling run_bzr, there is no point) --vila 100118.
168
builder = branchbuilder.BranchBuilder(self.get_transport())
169
builder.start_series()
171
builder.build_snapshot('1', None, [
172
('add', ('', 'root-id', 'directory', ''))])
173
builder.build_snapshot('2', ['1'], [])
175
builder.build_snapshot('1.1.1', ['1'], [])
176
# merge branch into mainline
177
builder.build_snapshot('3', ['2', '1.1.1'], [])
178
# new commits in branch
179
builder.build_snapshot('1.1.2', ['1.1.1'], [])
180
builder.build_snapshot('1.1.3', ['1.1.2'], [])
181
# merge branch into mainline
182
builder.build_snapshot('4', ['3', '1.1.3'], [])
183
# merge mainline into branch
184
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
185
# merge branch into mainline
186
builder.build_snapshot('5', ['4', '1.1.4'], [])
187
builder.finish_series()
190
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
191
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
192
def test_n0_forward(self):
193
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
194
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
197
# starting from 1.1.4 we follow the left-hand ancestry
198
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
199
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
201
def test_n1_forward(self):
202
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
203
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
206
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
209
super(Test_GenerateAllRevisions, self).setUp()
210
builder = self.make_branch_with_many_merges()
211
b = builder.get_branch()
213
self.addCleanup(b.unlock)
216
def make_branch_with_many_merges(self, path='.', format=None):
217
builder = branchbuilder.BranchBuilder(self.get_transport())
218
builder.start_series()
219
# The graph below may look a bit complicated (and it may be but I've
220
# banged my head enough on it) but the bug requires at least dotted
221
# revnos *and* merged revisions below that.
222
builder.build_snapshot('1', None, [
223
('add', ('', 'root-id', 'directory', ''))])
224
builder.build_snapshot('2', ['1'], [])
225
builder.build_snapshot('1.1.1', ['1'], [])
226
builder.build_snapshot('2.1.1', ['2'], [])
227
builder.build_snapshot('3', ['2', '1.1.1'], [])
228
builder.build_snapshot('2.1.2', ['2.1.1'], [])
229
builder.build_snapshot('2.2.1', ['2.1.1'], [])
230
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
231
builder.build_snapshot('4', ['3', '2.1.3'], [])
232
builder.build_snapshot('5', ['4', '2.1.2'], [])
233
builder.finish_series()
236
def test_not_an_ancestor(self):
237
self.assertRaises(errors.BzrCommandError,
238
log._generate_all_revisions,
239
self.branch, '1.1.1', '2.1.3', 'reverse',
240
delayed_graph_generation=True)
242
def test_wrong_order(self):
243
self.assertRaises(errors.BzrCommandError,
244
log._generate_all_revisions,
245
self.branch, '5', '2.1.3', 'reverse',
246
delayed_graph_generation=True)
248
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
249
revs = log._generate_all_revisions(
250
self.branch, None, '2.1.3',
251
'reverse', delayed_graph_generation=True)
254
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
256
def test_log_revno_n_path_wrong_namespace(self):
257
self.make_linear_branch('branch1')
258
self.make_linear_branch('branch2')
259
# There is no guarantee that a path exist between two arbitrary
261
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
263
def test_log_revno_n_path_correct_order(self):
264
self.make_linear_branch('branch2')
265
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
268
def test_log_revno_n_path(self):
269
self.make_linear_branch('branch2')
270
self.assertLogRevnos(['-rrevno:1:branch2'],
272
rev_props = self.log_catcher.revisions[0].rev.properties
273
self.assertEqual('branch2', rev_props['branch-nick'])
276
class TestLogErrors(TestLog):
278
def test_log_zero_revspec(self):
279
self.make_minimal_branch()
280
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
283
def test_log_zero_begin_revspec(self):
284
self.make_linear_branch()
285
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
288
def test_log_zero_end_revspec(self):
289
self.make_linear_branch()
290
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
293
def test_log_nonexistent_revno(self):
294
self.make_minimal_branch()
295
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
296
"does not exist in branch:"],
299
def test_log_nonexistent_dotted_revno(self):
300
self.make_minimal_branch()
301
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
302
"does not exist in branch:"],
303
['log', '-r123.123'])
305
def test_log_change_nonexistent_revno(self):
306
self.make_minimal_branch()
307
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
308
"does not exist in branch:"],
311
def test_log_change_nonexistent_dotted_revno(self):
312
self.make_minimal_branch()
313
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
314
"does not exist in branch:"],
315
['log', '-c123.123'])
317
def test_log_change_single_revno_only(self):
318
self.make_minimal_branch()
319
self.run_bzr_error(['bzr: ERROR: Option --change does not'
320
' accept revision ranges'],
321
['log', '--change', '2..3'])
323
def test_log_change_incompatible_with_revision(self):
324
self.run_bzr_error(['bzr: ERROR: --revision and --change'
325
' are mutually exclusive'],
326
['log', '--change', '2', '--revision', '3'])
328
def test_log_nonexistent_file(self):
329
self.make_minimal_branch()
330
# files that don't exist in either the basis tree or working tree
331
# should give an error
332
out, err = self.run_bzr('log does-not-exist', retcode=3)
333
self.assertContainsRe(err,
334
'Path unknown at end or start of revision range: '
337
def test_log_reversed_revspecs(self):
338
self.make_linear_branch()
339
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
340
'the end revision.\n',),
343
def test_log_reversed_dotted_revspecs(self):
344
self.make_merged_branch()
345
self.run_bzr_error(('bzr: ERROR: Start revision not found in '
346
'left-hand history of end revision.\n',),
349
def test_log_bad_message_re(self):
350
"""Bad --message argument gives a sensible message
352
See https://bugs.launchpad.net/bzr/+bug/251352
354
self.make_minimal_branch()
355
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
356
self.assertEqual("bzr: ERROR: Invalid regular expression"
357
" in log message filter"
359
": nothing to repeat\n", err)
360
self.assertEqual('', out)
362
def test_log_unsupported_timezone(self):
363
self.make_linear_branch()
364
self.run_bzr_error(['bzr: ERROR: Unsupported timezone format "foo", '
365
'options are "utc", "original", "local".'],
366
['log', '--timezone', 'foo'])
369
class TestLogTags(TestLog):
371
def test_log_with_tags(self):
372
tree = self.make_linear_branch(format='dirstate-tags')
374
branch.tags.set_tag('tag1', branch.get_rev_id(1))
375
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
376
branch.tags.set_tag('tag3', branch.last_revision())
378
log = self.run_bzr("log -r-1")[0]
379
self.assertTrue('tags: tag3' in log)
381
log = self.run_bzr("log -r1")[0]
382
# I guess that we can't know the order of tags in the output
383
# since dicts are unordered, need to check both possibilities
384
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
386
def test_merged_log_with_tags(self):
387
branch1_tree = self.make_linear_branch('branch1',
388
format='dirstate-tags')
389
branch1 = branch1_tree.branch
390
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
391
branch1_tree.commit(message='foobar', allow_pointless=True)
392
branch1.tags.set_tag('tag1', branch1.last_revision())
393
# tags don't propagate if we don't merge
394
self.run_bzr('merge ../branch1', working_dir='branch2')
395
branch2_tree.commit(message='merge branch 1')
396
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
397
self.assertContainsRe(log, r' tags: tag1')
398
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
399
self.assertContainsRe(log, r'tags: tag1')
402
class TestLogVerbose(TestLog):
405
super(TestLogVerbose, self).setUp()
406
self.make_minimal_branch()
408
def assertUseShortDeltaFormat(self, cmd):
409
log = self.run_bzr(cmd)[0]
410
# Check that we use the short status format
411
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
412
self.assertNotContainsRe(log, '(?m)^\s*added:$')
414
def assertUseLongDeltaFormat(self, cmd):
415
log = self.run_bzr(cmd)[0]
416
# Check that we use the long status format
417
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
418
self.assertContainsRe(log, '(?m)^\s*added:$')
420
def test_log_short_verbose(self):
421
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
423
def test_log_short_verbose_verbose(self):
424
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
426
def test_log_long_verbose(self):
427
# Check that we use the long status format, ignoring the verbosity
429
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
431
def test_log_long_verbose_verbose(self):
432
# Check that we use the long status format, ignoring the verbosity
434
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
437
class TestLogMerges(TestLogWithLogCatcher):
440
super(TestLogMerges, self).setUp()
441
self.make_branches_with_merges()
443
def make_branches_with_merges(self):
444
level0 = self.make_branch_and_tree('level0')
445
self.wt_commit(level0, 'in branch level0')
446
level1 = level0.bzrdir.sprout('level1').open_workingtree()
447
self.wt_commit(level1, 'in branch level1')
448
level2 = level1.bzrdir.sprout('level2').open_workingtree()
449
self.wt_commit(level2, 'in branch level2')
450
level1.merge_from_branch(level2.branch)
451
self.wt_commit(level1, 'merge branch level2')
452
level0.merge_from_branch(level1.branch)
453
self.wt_commit(level0, 'merge branch level1')
455
def test_merges_are_indented_by_level(self):
456
self.run_bzr(['log', '-n0'], working_dir='level0')
457
revnos_and_depth = [(r.revno, r.merge_depth)
458
for r in self.get_captured_revisions()]
459
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
461
[(r.revno, r.merge_depth)
462
for r in self.get_captured_revisions()])
464
def test_force_merge_revisions_off(self):
465
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
467
def test_force_merge_revisions_on(self):
468
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
469
working_dir='level0')
471
def test_include_merges(self):
472
# Confirm --include-merges gives the same output as -n0
473
self.assertLogRevnos(['--include-merges'],
474
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
475
working_dir='level0')
476
self.assertLogRevnos(['--include-merges'],
477
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
478
working_dir='level0')
479
out_im, err_im = self.run_bzr('log --include-merges',
480
working_dir='level0')
481
out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
482
self.assertEqual('', err_im)
483
self.assertEqual('', err_n0)
484
self.assertEqual(out_im, out_n0)
486
def test_force_merge_revisions_N(self):
487
self.assertLogRevnos(['-n2'],
488
['2', '1.1.2', '1.1.1', '1'],
489
working_dir='level0')
491
def test_merges_single_merge_rev(self):
492
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
493
[('1.1.2', 0), ('1.2.1', 1)],
494
working_dir='level0')
496
def test_merges_partial_range(self):
497
self.assertLogRevnosAndDepths(
498
['-n0', '-r1.1.1..1.1.2'],
499
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
500
working_dir='level0')
502
def test_merges_partial_range_ignore_before_lower_bound(self):
503
"""Dont show revisions before the lower bound's merged revs"""
504
self.assertLogRevnosAndDepths(
505
['-n0', '-r1.1.2..2'],
506
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
507
working_dir='level0')
510
class TestLogDiff(TestLogWithLogCatcher):
512
# FIXME: We need specific tests for each LogFormatter about how the diffs
513
# are displayed: --long indent them by depth, --short use a fixed
514
# indent and --line does't display them. -- vila 10019
517
super(TestLogDiff, self).setUp()
518
self.make_branch_with_diffs()
520
def make_branch_with_diffs(self):
521
level0 = self.make_branch_and_tree('level0')
522
self.build_tree(['level0/file1', 'level0/file2'])
525
self.wt_commit(level0, 'in branch level0')
527
level1 = level0.bzrdir.sprout('level1').open_workingtree()
528
self.build_tree_contents([('level1/file2', 'hello\n')])
529
self.wt_commit(level1, 'in branch level1')
530
level0.merge_from_branch(level1.branch)
531
self.wt_commit(level0, 'merge branch level1')
533
def _diff_file1_revno1(self):
534
return """=== added file 'file1'
535
--- file1\t1970-01-01 00:00:00 +0000
536
+++ file1\t2005-11-22 00:00:00 +0000
538
+contents of level0/file1
542
def _diff_file2_revno2(self):
543
return """=== modified file 'file2'
544
--- file2\t2005-11-22 00:00:00 +0000
545
+++ file2\t2005-11-22 00:00:01 +0000
547
-contents of level0/file2
552
def _diff_file2_revno1_1_1(self):
553
return """=== modified file 'file2'
554
--- file2\t2005-11-22 00:00:00 +0000
555
+++ file2\t2005-11-22 00:00:01 +0000
557
-contents of level0/file2
562
def _diff_file2_revno1(self):
563
return """=== added file 'file2'
564
--- file2\t1970-01-01 00:00:00 +0000
565
+++ file2\t2005-11-22 00:00:00 +0000
567
+contents of level0/file2
571
def assertLogRevnosAndDiff(self, args, expected,
573
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
574
expected_revnos_and_depths = [
575
(revno, depth) for revno, depth, diff in expected]
576
# Check the revnos and depths first to make debugging easier
577
self.assertEqual(expected_revnos_and_depths,
578
[(r.revno, r.merge_depth)
579
for r in self.get_captured_revisions()])
580
# Now check the diffs, adding the revno in case of failure
581
fmt = 'In revno %s\n%s'
582
for expected_rev, actual_rev in izip(expected,
583
self.get_captured_revisions()):
584
revno, depth, expected_diff = expected_rev
585
actual_diff = actual_rev.diff
586
self.assertEqualDiff(fmt % (revno, expected_diff),
587
fmt % (revno, actual_diff))
589
def test_log_diff_with_merges(self):
590
self.assertLogRevnosAndDiff(
592
[('2', 0, self._diff_file2_revno2()),
593
('1.1.1', 1, self._diff_file2_revno1_1_1()),
594
('1', 0, self._diff_file1_revno1()
595
+ self._diff_file2_revno1())],
596
working_dir='level0')
599
def test_log_diff_file1(self):
600
self.assertLogRevnosAndDiff(['-n0', 'file1'],
601
[('1', 0, self._diff_file1_revno1())],
602
working_dir='level0')
604
def test_log_diff_file2(self):
605
self.assertLogRevnosAndDiff(['-n1', 'file2'],
606
[('2', 0, self._diff_file2_revno2()),
607
('1', 0, self._diff_file2_revno1())],
608
working_dir='level0')
611
class TestLogUnicodeDiff(TestLog):
613
def test_log_show_diff_non_ascii(self):
614
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
615
message = u'Message with \xb5'
616
body = 'Body with \xb5\n'
617
wt = self.make_branch_and_tree('.')
618
self.build_tree_contents([('foo', body)])
620
wt.commit(message=message)
621
# check that command won't fail with unicode error
622
# don't care about exact output because we have other tests for this
623
out,err = self.run_bzr('log -p --long')
624
self.assertNotEqual('', out)
625
self.assertEqual('', err)
626
out,err = self.run_bzr('log -p --short')
627
self.assertNotEqual('', out)
628
self.assertEqual('', err)
629
out,err = self.run_bzr('log -p --line')
630
self.assertNotEqual('', out)
631
self.assertEqual('', err)
634
class TestLogEncodings(tests.TestCaseInTempDir):
637
_message = u'Message with \xb5'
639
# Encodings which can encode mu
644
'cp437', # Common windows encoding
645
'cp1251', # Russian windows encoding
646
'cp1258', # Common windows encoding
648
# Encodings which cannot encode mu
656
super(TestLogEncodings, self).setUp()
657
self.overrideAttr(osutils, '_cached_user_encoding')
659
def create_branch(self):
662
self.build_tree_contents([('a', 'some stuff\n')])
664
bzr(['commit', '-m', self._message])
666
def try_encoding(self, encoding, fail=False):
669
self.assertRaises(UnicodeEncodeError,
670
self._mu.encode, encoding)
671
encoded_msg = self._message.encode(encoding, 'replace')
673
encoded_msg = self._message.encode(encoding)
675
old_encoding = osutils._cached_user_encoding
676
# This test requires that 'run_bzr' uses the current
677
# bzrlib, because we override user_encoding, and expect
680
osutils._cached_user_encoding = 'ascii'
681
# We should be able to handle any encoding
682
out, err = bzr('log', encoding=encoding)
684
# Make sure we wrote mu as we expected it to exist
685
self.assertNotEqual(-1, out.find(encoded_msg))
686
out_unicode = out.decode(encoding)
687
self.assertNotEqual(-1, out_unicode.find(self._message))
689
self.assertNotEqual(-1, out.find('Message with ?'))
691
osutils._cached_user_encoding = old_encoding
693
def test_log_handles_encoding(self):
696
for encoding in self.good_encodings:
697
self.try_encoding(encoding)
699
def test_log_handles_bad_encoding(self):
702
for encoding in self.bad_encodings:
703
self.try_encoding(encoding, fail=True)
705
def test_stdout_encoding(self):
707
osutils._cached_user_encoding = "cp1251"
710
self.build_tree(['a'])
712
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
713
stdout, stderr = self.run_bzr('log', encoding='cp866')
715
message = stdout.splitlines()[-1]
717
# explanation of the check:
718
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
719
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
720
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
721
# This test should check that output of log command
722
# encoded to sys.stdout.encoding
723
test_in_cp866 = '\x92\xa5\xe1\xe2'
724
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
725
# Make sure the log string is encoded in cp866
726
self.assertEquals(test_in_cp866, message[2:])
727
# Make sure the cp1251 string is not found anywhere
728
self.assertEquals(-1, stdout.find(test_in_cp1251))
731
class TestLogFile(TestLogWithLogCatcher):
733
def test_log_local_branch_file(self):
734
"""We should be able to log files in local treeless branches"""
735
tree = self.make_branch_and_tree('tree')
736
self.build_tree(['tree/file'])
738
tree.commit('revision 1')
739
tree.bzrdir.destroy_workingtree()
740
self.run_bzr('log tree/file')
742
def prepare_tree(self, complex=False):
743
# The complex configuration includes deletes and renames
744
tree = self.make_branch_and_tree('parent')
745
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
747
tree.commit('add file1')
749
tree.commit('add file2')
751
tree.commit('add file3')
752
child_tree = tree.bzrdir.sprout('child').open_workingtree()
753
self.build_tree_contents([('child/file2', 'hello')])
754
child_tree.commit(message='branch 1')
755
tree.merge_from_branch(child_tree.branch)
756
tree.commit(message='merge child branch')
759
tree.commit('remove file2')
760
tree.rename_one('file3', 'file4')
761
tree.commit('file3 is now called file4')
763
tree.commit('remove file1')
766
# FIXME: It would be good to parametrize the following tests against all
767
# formatters. But the revisions selection is not *currently* part of the
768
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
769
def test_log_file1(self):
771
self.assertLogRevnos(['-n0', 'file1'], ['1'])
773
def test_log_file2(self):
776
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
777
# file2 in a merge revision
778
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
779
# file2 in a mainline revision
780
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
781
# file2 since a revision
782
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
783
# file2 up to a revision
784
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
786
def test_log_file3(self):
788
self.assertLogRevnos(['-n0', 'file3'], ['3'])
790
def test_log_file_historical_missing(self):
791
# Check logging a deleted file gives an error if the
792
# file isn't found at the end or start of the revision range
793
self.prepare_tree(complex=True)
794
err_msg = "Path unknown at end or start of revision range: file2"
795
err = self.run_bzr('log file2', retcode=3)[1]
796
self.assertContainsRe(err, err_msg)
798
def test_log_file_historical_end(self):
799
# Check logging a deleted file is ok if the file existed
800
# at the end the revision range
801
self.prepare_tree(complex=True)
802
self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
804
def test_log_file_historical_start(self):
805
# Check logging a deleted file is ok if the file existed
806
# at the start of the revision range
807
self.prepare_tree(complex=True)
808
self.assertLogRevnos(['file1'], ['1'])
810
def test_log_file_renamed(self):
811
"""File matched against revision range, not current tree."""
812
self.prepare_tree(complex=True)
814
# Check logging a renamed file gives an error by default
815
err_msg = "Path unknown at end or start of revision range: file3"
816
err = self.run_bzr('log file3', retcode=3)[1]
817
self.assertContainsRe(err, err_msg)
819
# Check we can see a renamed file if we give the right end revision
820
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
823
class TestLogMultiple(TestLogWithLogCatcher):
825
def prepare_tree(self):
826
tree = self.make_branch_and_tree('parent')
833
'parent/dir1/dir2/file3',
836
tree.commit('add file1')
838
tree.commit('add file2')
839
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
840
tree.commit('add file3')
842
tree.commit('add file4')
843
tree.add('dir1/file5')
844
tree.commit('add file5')
845
child_tree = tree.bzrdir.sprout('child').open_workingtree()
846
self.build_tree_contents([('child/file2', 'hello')])
847
child_tree.commit(message='branch 1')
848
tree.merge_from_branch(child_tree.branch)
849
tree.commit(message='merge child branch')
852
def test_log_files(self):
853
"""The log for multiple file should only list revs for those files"""
855
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
856
['6', '5.1.1', '3', '2', '1'])
858
def test_log_directory(self):
859
"""The log for a directory should show all nested files."""
861
self.assertLogRevnos(['dir1'], ['5', '3'])
863
def test_log_nested_directory(self):
864
"""The log for a directory should show all nested files."""
866
self.assertLogRevnos(['dir1/dir2'], ['3'])
868
def test_log_in_nested_directory(self):
869
"""The log for a directory should show all nested files."""
872
self.assertLogRevnos(['.'], ['5', '3'])
874
def test_log_files_and_directories(self):
875
"""Logging files and directories together should be fine."""
877
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
879
def test_log_files_and_dirs_in_nested_directory(self):
880
"""The log for a directory should show all nested files."""
883
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])