1
# Copyright (C) 2005, 2006, 2007, 2009 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
30
from bzrlib.tests import (
36
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
38
def make_minimal_branch(self, path='.', format=None):
39
tree = self.make_branch_and_tree(path, format=format)
40
self.build_tree([path + '/hello.txt'])
42
tree.commit(message='message1')
45
def make_linear_branch(self, path='.', format=None):
46
tree = self.make_branch_and_tree(path, format=format)
48
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
50
tree.commit(message='message1')
51
tree.add('goodbye.txt')
52
tree.commit(message='message2')
54
tree.commit(message='message3')
57
def make_merged_branch(self, path='.', format=None):
58
tree = self.make_linear_branch(path, format)
59
tree2 = tree.bzrdir.sprout('tree2',
60
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
61
tree2.commit(message='tree2 message2')
62
tree2.commit(message='tree2 message3')
63
tree.merge_from_branch(tree2.branch)
64
tree.commit(message='merge')
68
class TestLogWithLogCatcher(TestLog):
71
super(TestLogWithLogCatcher, self).setUp()
72
# Capture log formatter creations
73
class MyLogFormatter(test_log.LogCatcher):
75
def __new__(klass, *args, **kwargs):
76
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
77
# Always return our own log formatter
78
return self.log_catcher
80
orig = log.log_formatter_registry.get_default
82
log.log_formatter_registry.get_default = orig
83
self.addCleanup(restore)
86
# Always return our own log formatter class hijacking the
87
# default behavior (which requires setting up a config
90
log.log_formatter_registry.get_default = getme
92
def get_captured_revisions(self):
93
return self.log_catcher.revisions
95
def assertLogRevnos(self, args, expected_revnos, working_dir='.'):
96
self.run_bzr(['log'] + args, working_dir=working_dir)
97
self.assertEqual(expected_revnos,
98
[r.revno for r in self.get_captured_revisions()])
100
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
102
self.run_bzr(['log'] + args, working_dir=working_dir)
103
self.assertEqual(expected_revnos_and_depths,
104
[(r.revno, r.merge_depth)
105
for r in self.get_captured_revisions()])
108
class TestLogRevSpecs(TestLogWithLogCatcher):
110
def test_log_no_revspec(self):
111
self.make_linear_branch()
112
self.assertLogRevnos([], ['3', '2', '1'])
114
def test_log_null_end_revspec(self):
115
self.make_linear_branch()
116
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
118
def test_log_null_begin_revspec(self):
119
self.make_linear_branch()
120
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
122
def test_log_null_both_revspecs(self):
123
self.make_linear_branch()
124
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
126
def test_log_negative_begin_revspec_full_log(self):
127
self.make_linear_branch()
128
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
130
def test_log_negative_both_revspec_full_log(self):
131
self.make_linear_branch()
132
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
134
def test_log_negative_both_revspec_partial(self):
135
self.make_linear_branch()
136
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
138
def test_log_negative_begin_revspec(self):
139
self.make_linear_branch()
140
self.assertLogRevnos(['-r-2..'], ['3', '2'])
142
def test_log_positive_revspecs(self):
143
self.make_linear_branch()
144
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
146
def test_log_dotted_revspecs(self):
147
self.make_merged_branch()
148
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
150
def test_log_limit(self):
151
tree = self.make_branch_and_tree('.')
152
# We want more commits than our batch size starts at
153
for pos in range(10):
154
tree.commit("%s" % pos)
155
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
157
def test_log_limit_short(self):
158
self.make_linear_branch()
159
self.assertLogRevnos(['-l', '2'], ['3', '2'])
161
def test_log_change_revno(self):
162
self.make_linear_branch()
163
self.assertLogRevnos(['-c1'], ['1'])
166
class TestBug474807(TestLogWithLogCatcher):
169
super(TestBug474807, self).setUp()
170
# FIXME: Using a MemoryTree would be even better here (but until we
171
# stop calling run_bzr, there is no point) --vila 100118.
172
builder = branchbuilder.BranchBuilder(self.get_transport())
173
builder.start_series()
175
builder.build_snapshot('1', None, [
176
('add', ('', 'root-id', 'directory', ''))])
177
builder.build_snapshot('2', ['1'], [])
179
builder.build_snapshot('1.1.1', ['1'], [])
180
# merge branch into mainline
181
builder.build_snapshot('3', ['2', '1.1.1'], [])
182
# new commits in branch
183
builder.build_snapshot('1.1.2', ['1.1.1'], [])
184
builder.build_snapshot('1.1.3', ['1.1.2'], [])
185
# merge branch into mainline
186
builder.build_snapshot('4', ['3', '1.1.3'], [])
187
# merge mainline into branch
188
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
189
# merge branch into mainline
190
builder.build_snapshot('5', ['4', '1.1.4'], [])
191
builder.finish_series()
194
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
195
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
196
def test_n0_forward(self):
197
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
198
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
201
# starting from 1.1.4 we follow the left-hand ancestry
202
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
203
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
205
def test_n1_forward(self):
206
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
207
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
210
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
212
def test_log_revno_n_path_wrong_namespace(self):
213
self.make_linear_branch('branch1')
214
self.make_linear_branch('branch2')
215
# There is no guarantee that a path exist between two arbitrary
217
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
218
# But may be it's worth trying though ? -- vila 100115
220
def test_log_revno_n_path_correct_order(self):
221
self.make_linear_branch('branch2')
222
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
225
def test_log_revno_n_path(self):
226
self.make_linear_branch('branch2')
227
self.assertLogRevnos(['-rrevno:1:branch2'],
229
rev_props = self.log_catcher.revisions[0].rev.properties
230
self.assertEqual('branch2', rev_props['branch-nick'])
233
class TestLogErrors(TestLog):
235
def test_log_zero_revspec(self):
236
self.make_minimal_branch()
237
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
240
def test_log_zero_begin_revspec(self):
241
self.make_linear_branch()
242
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
245
def test_log_zero_end_revspec(self):
246
self.make_linear_branch()
247
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
250
def test_log_nonexistent_revno(self):
251
self.make_minimal_branch()
252
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
253
"does not exist in branch:"],
256
def test_log_nonexistent_dotted_revno(self):
257
self.make_minimal_branch()
258
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
259
"does not exist in branch:"],
260
['log', '-r123.123'])
262
def test_log_change_nonexistent_revno(self):
263
self.make_minimal_branch()
264
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
265
"does not exist in branch:"],
268
def test_log_change_nonexistent_dotted_revno(self):
269
self.make_minimal_branch()
270
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
271
"does not exist in branch:"],
272
['log', '-c123.123'])
274
def test_log_change_single_revno_only(self):
275
self.make_minimal_branch()
276
self.run_bzr_error(['bzr: ERROR: Option --change does not'
277
' accept revision ranges'],
278
['log', '--change', '2..3'])
280
def test_log_change_incompatible_with_revision(self):
281
self.run_bzr_error(['bzr: ERROR: --revision and --change'
282
' are mutually exclusive'],
283
['log', '--change', '2', '--revision', '3'])
285
def test_log_nonexistent_file(self):
286
self.make_minimal_branch()
287
# files that don't exist in either the basis tree or working tree
288
# should give an error
289
out, err = self.run_bzr('log does-not-exist', retcode=3)
290
self.assertContainsRe(err,
291
'Path unknown at end or start of revision range: '
294
def test_log_reversed_revspecs(self):
295
self.make_linear_branch()
296
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
297
'the end revision.\n',),
300
def test_log_reversed_dotted_revspecs(self):
301
self.make_merged_branch()
302
self.run_bzr_error(('bzr: ERROR: Start revision not found in '
303
'left-hand history of end revision.\n',),
306
def test_log_bad_message_re(self):
307
"""Bad --message argument gives a sensible message
309
See https://bugs.launchpad.net/bzr/+bug/251352
311
self.make_minimal_branch()
312
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
313
self.assertEqual("bzr: ERROR: Invalid regular expression"
314
" in log message filter"
316
": nothing to repeat\n", err)
317
self.assertEqual('', out)
319
def test_log_unsupported_timezone(self):
320
self.make_linear_branch()
321
self.run_bzr_error(['bzr: ERROR: Unsupported timezone format "foo", '
322
'options are "utc", "original", "local".'],
323
['log', '--timezone', 'foo'])
326
class TestLogTags(TestLog):
328
def test_log_with_tags(self):
329
tree = self.make_linear_branch(format='dirstate-tags')
331
branch.tags.set_tag('tag1', branch.get_rev_id(1))
332
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
333
branch.tags.set_tag('tag3', branch.last_revision())
335
log = self.run_bzr("log -r-1")[0]
336
self.assertTrue('tags: tag3' in log)
338
log = self.run_bzr("log -r1")[0]
339
# I guess that we can't know the order of tags in the output
340
# since dicts are unordered, need to check both possibilities
341
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
343
def test_merged_log_with_tags(self):
344
branch1_tree = self.make_linear_branch('branch1',
345
format='dirstate-tags')
346
branch1 = branch1_tree.branch
347
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
348
branch1_tree.commit(message='foobar', allow_pointless=True)
349
branch1.tags.set_tag('tag1', branch1.last_revision())
350
# tags don't propagate if we don't merge
351
self.run_bzr('merge ../branch1', working_dir='branch2')
352
branch2_tree.commit(message='merge branch 1')
353
log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
354
self.assertContainsRe(log, r' tags: tag1')
355
log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
356
self.assertContainsRe(log, r'tags: tag1')
359
class TestLogVerbose(TestLog):
362
super(TestLogVerbose, self).setUp()
363
self.make_minimal_branch()
365
def assertUseShortDeltaFormat(self, cmd):
366
log = self.run_bzr(cmd)[0]
367
# Check that we use the short status format
368
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
369
self.assertNotContainsRe(log, '(?m)^\s*added:$')
371
def assertUseLongDeltaFormat(self, cmd):
372
log = self.run_bzr(cmd)[0]
373
# Check that we use the long status format
374
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
375
self.assertContainsRe(log, '(?m)^\s*added:$')
377
def test_log_short_verbose(self):
378
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
380
def test_log_short_verbose_verbose(self):
381
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
383
def test_log_long_verbose(self):
384
# Check that we use the long status format, ignoring the verbosity
386
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
388
def test_log_long_verbose_verbose(self):
389
# Check that we use the long status format, ignoring the verbosity
391
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
394
class TestLogMerges(TestLogWithLogCatcher):
397
super(TestLogMerges, self).setUp()
398
self.make_branches_with_merges()
400
def make_branches_with_merges(self):
401
level0 = self.make_branch_and_tree('level0')
402
self.wt_commit(level0, 'in branch level0')
403
level1 = level0.bzrdir.sprout('level1').open_workingtree()
404
self.wt_commit(level1, 'in branch level1')
405
level2 = level1.bzrdir.sprout('level2').open_workingtree()
406
self.wt_commit(level2, 'in branch level2')
407
level1.merge_from_branch(level2.branch)
408
self.wt_commit(level1, 'merge branch level2')
409
level0.merge_from_branch(level1.branch)
410
self.wt_commit(level0, 'merge branch level1')
412
def test_merges_are_indented_by_level(self):
413
self.run_bzr(['log', '-n0'], working_dir='level0')
414
revnos_and_depth = [(r.revno, r.merge_depth)
415
for r in self.get_captured_revisions()]
416
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
418
[(r.revno, r.merge_depth)
419
for r in self.get_captured_revisions()])
421
def test_force_merge_revisions_off(self):
422
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
424
def test_force_merge_revisions_on(self):
425
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
426
working_dir='level0')
428
def test_include_merges(self):
429
# Confirm --include-merges gives the same output as -n0
430
self.assertLogRevnos(['--include-merges'],
431
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
432
working_dir='level0')
433
self.assertLogRevnos(['--include-merges'],
434
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
435
working_dir='level0')
436
out_im, err_im = self.run_bzr('log --include-merges',
437
working_dir='level0')
438
out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
439
self.assertEqual('', err_im)
440
self.assertEqual('', err_n0)
441
self.assertEqual(out_im, out_n0)
443
def test_force_merge_revisions_N(self):
444
self.assertLogRevnos(['-n2'],
445
['2', '1.1.2', '1.1.1', '1'],
446
working_dir='level0')
448
def test_merges_single_merge_rev(self):
449
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
450
[('1.1.2', 0), ('1.2.1', 1)],
451
working_dir='level0')
453
def test_merges_partial_range(self):
454
self.assertLogRevnosAndDepths(
455
['-n0', '-r1.1.1..1.1.2'],
456
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
457
working_dir='level0')
459
def test_merges_partial_range_ignore_before_lower_bound(self):
460
"""Dont show revisions before the lower bound's merged revs"""
461
self.assertLogRevnosAndDepths(
462
['-n0', '-r1.1.2..2'],
463
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
464
working_dir='level0')
467
class TestLogDiff(TestLogWithLogCatcher):
469
# FIXME: We need specific tests for each LogFormatter about how the diffs
470
# are displayed: --long indent them by depth, --short use a fixed
471
# indent and --line does't display them. -- vila 10019
474
super(TestLogDiff, self).setUp()
475
self.make_branch_with_diffs()
477
def make_branch_with_diffs(self):
478
level0 = self.make_branch_and_tree('level0')
479
self.build_tree(['level0/file1', 'level0/file2'])
482
self.wt_commit(level0, 'in branch level0')
484
level1 = level0.bzrdir.sprout('level1').open_workingtree()
485
self.build_tree_contents([('level1/file2', 'hello\n')])
486
self.wt_commit(level1, 'in branch level1')
487
level0.merge_from_branch(level1.branch)
488
self.wt_commit(level0, 'merge branch level1')
490
def _diff_file1_revno1(self):
491
return """=== added file 'file1'
492
--- file1\t1970-01-01 00:00:00 +0000
493
+++ file1\t2005-11-22 00:00:00 +0000
495
+contents of level0/file1
499
def _diff_file2_revno2(self):
500
return """=== modified file 'file2'
501
--- file2\t2005-11-22 00:00:00 +0000
502
+++ file2\t2005-11-22 00:00:01 +0000
504
-contents of level0/file2
509
def _diff_file2_revno1_1_1(self):
510
return """=== modified file 'file2'
511
--- file2\t2005-11-22 00:00:00 +0000
512
+++ file2\t2005-11-22 00:00:01 +0000
514
-contents of level0/file2
519
def _diff_file2_revno1(self):
520
return """=== added file 'file2'
521
--- file2\t1970-01-01 00:00:00 +0000
522
+++ file2\t2005-11-22 00:00:00 +0000
524
+contents of level0/file2
528
def assertLogRevnosAndDiff(self, args, expected,
530
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
531
expected_revnos_and_depths = [
532
(revno, depth) for revno, depth, diff in expected]
533
# Check the revnos and depths first to make debugging easier
534
self.assertEqual(expected_revnos_and_depths,
535
[(r.revno, r.merge_depth)
536
for r in self.get_captured_revisions()])
537
# Now check the diffs, adding the revno in case of failure
538
fmt = 'In revno %s\n%s'
539
for expected_rev, actual_rev in izip(expected,
540
self.get_captured_revisions()):
541
revno, depth, expected_diff = expected_rev
542
actual_diff = actual_rev.diff
543
self.assertEqualDiff(fmt % (revno, expected_diff),
544
fmt % (revno, actual_diff))
546
def test_log_diff_with_merges(self):
547
self.assertLogRevnosAndDiff(
549
[('2', 0, self._diff_file2_revno2()),
550
('1.1.1', 1, self._diff_file2_revno1_1_1()),
551
('1', 0, self._diff_file1_revno1()
552
+ self._diff_file2_revno1())],
553
working_dir='level0')
556
def test_log_diff_file1(self):
557
self.assertLogRevnosAndDiff(['-n0', 'file1'],
558
[('1', 0, self._diff_file1_revno1())],
559
working_dir='level0')
561
def test_log_diff_file2(self):
562
self.assertLogRevnosAndDiff(['-n1', 'file2'],
563
[('2', 0, self._diff_file2_revno2()),
564
('1', 0, self._diff_file2_revno1())],
565
working_dir='level0')
568
class TestLogUnicodeDiff(TestLog):
570
def test_log_show_diff_non_ascii(self):
571
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
572
message = u'Message with \xb5'
573
body = 'Body with \xb5\n'
574
wt = self.make_branch_and_tree('.')
575
self.build_tree_contents([('foo', body)])
577
wt.commit(message=message)
578
# check that command won't fail with unicode error
579
# don't care about exact output because we have other tests for this
580
out,err = self.run_bzr('log -p --long')
581
self.assertNotEqual('', out)
582
self.assertEqual('', err)
583
out,err = self.run_bzr('log -p --short')
584
self.assertNotEqual('', out)
585
self.assertEqual('', err)
586
out,err = self.run_bzr('log -p --line')
587
self.assertNotEqual('', out)
588
self.assertEqual('', err)
591
class TestLogEncodings(tests.TestCaseInTempDir):
594
_message = u'Message with \xb5'
596
# Encodings which can encode mu
601
'cp437', # Common windows encoding
602
'cp1251', # Russian windows encoding
603
'cp1258', # Common windows encoding
605
# Encodings which cannot encode mu
613
super(TestLogEncodings, self).setUp()
614
self.user_encoding = osutils._cached_user_encoding
616
osutils._cached_user_encoding = self.user_encoding
617
self.addCleanup(restore)
619
def create_branch(self):
622
self.build_tree_contents([('a', 'some stuff\n')])
624
bzr(['commit', '-m', self._message])
626
def try_encoding(self, encoding, fail=False):
629
self.assertRaises(UnicodeEncodeError,
630
self._mu.encode, encoding)
631
encoded_msg = self._message.encode(encoding, 'replace')
633
encoded_msg = self._message.encode(encoding)
635
old_encoding = osutils._cached_user_encoding
636
# This test requires that 'run_bzr' uses the current
637
# bzrlib, because we override user_encoding, and expect
640
osutils._cached_user_encoding = 'ascii'
641
# We should be able to handle any encoding
642
out, err = bzr('log', encoding=encoding)
644
# Make sure we wrote mu as we expected it to exist
645
self.assertNotEqual(-1, out.find(encoded_msg))
646
out_unicode = out.decode(encoding)
647
self.assertNotEqual(-1, out_unicode.find(self._message))
649
self.assertNotEqual(-1, out.find('Message with ?'))
651
osutils._cached_user_encoding = old_encoding
653
def test_log_handles_encoding(self):
656
for encoding in self.good_encodings:
657
self.try_encoding(encoding)
659
def test_log_handles_bad_encoding(self):
662
for encoding in self.bad_encodings:
663
self.try_encoding(encoding, fail=True)
665
def test_stdout_encoding(self):
667
osutils._cached_user_encoding = "cp1251"
670
self.build_tree(['a'])
672
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
673
stdout, stderr = self.run_bzr('log', encoding='cp866')
675
message = stdout.splitlines()[-1]
677
# explanation of the check:
678
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
679
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
680
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
681
# This test should check that output of log command
682
# encoded to sys.stdout.encoding
683
test_in_cp866 = '\x92\xa5\xe1\xe2'
684
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
685
# Make sure the log string is encoded in cp866
686
self.assertEquals(test_in_cp866, message[2:])
687
# Make sure the cp1251 string is not found anywhere
688
self.assertEquals(-1, stdout.find(test_in_cp1251))
691
class TestLogFile(TestLogWithLogCatcher):
693
def test_log_local_branch_file(self):
694
"""We should be able to log files in local treeless branches"""
695
tree = self.make_branch_and_tree('tree')
696
self.build_tree(['tree/file'])
698
tree.commit('revision 1')
699
tree.bzrdir.destroy_workingtree()
700
self.run_bzr('log tree/file')
702
def prepare_tree(self, complex=False):
703
# The complex configuration includes deletes and renames
704
tree = self.make_branch_and_tree('parent')
705
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
707
tree.commit('add file1')
709
tree.commit('add file2')
711
tree.commit('add file3')
712
child_tree = tree.bzrdir.sprout('child').open_workingtree()
713
self.build_tree_contents([('child/file2', 'hello')])
714
child_tree.commit(message='branch 1')
715
tree.merge_from_branch(child_tree.branch)
716
tree.commit(message='merge child branch')
719
tree.commit('remove file2')
720
tree.rename_one('file3', 'file4')
721
tree.commit('file3 is now called file4')
723
tree.commit('remove file1')
726
# FIXME: It would be good to parametrize the following tests against all
727
# formatters. But the revisions selection is not *currently* part of the
728
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
729
def test_log_file1(self):
731
self.assertLogRevnos(['-n0', 'file1'], ['1'])
733
def test_log_file2(self):
736
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
737
# file2 in a merge revision
738
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
739
# file2 in a mainline revision
740
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
741
# file2 since a revision
742
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
743
# file2 up to a revision
744
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
746
def test_log_file3(self):
748
self.assertLogRevnos(['-n0', 'file3'], ['3'])
750
def test_log_file_historical_missing(self):
751
# Check logging a deleted file gives an error if the
752
# file isn't found at the end or start of the revision range
753
self.prepare_tree(complex=True)
754
err_msg = "Path unknown at end or start of revision range: file2"
755
err = self.run_bzr('log file2', retcode=3)[1]
756
self.assertContainsRe(err, err_msg)
758
def test_log_file_historical_end(self):
759
# Check logging a deleted file is ok if the file existed
760
# at the end the revision range
761
self.prepare_tree(complex=True)
762
self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
764
def test_log_file_historical_start(self):
765
# Check logging a deleted file is ok if the file existed
766
# at the start of the revision range
767
self.prepare_tree(complex=True)
768
self.assertLogRevnos(['file1'], ['1'])
770
def test_log_file_renamed(self):
771
"""File matched against revision range, not current tree."""
772
self.prepare_tree(complex=True)
774
# Check logging a renamed file gives an error by default
775
err_msg = "Path unknown at end or start of revision range: file3"
776
err = self.run_bzr('log file3', retcode=3)[1]
777
self.assertContainsRe(err, err_msg)
779
# Check we can see a renamed file if we give the right end revision
780
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
783
class TestLogMultiple(TestLogWithLogCatcher):
785
def prepare_tree(self):
786
tree = self.make_branch_and_tree('parent')
793
'parent/dir1/dir2/file3',
796
tree.commit('add file1')
798
tree.commit('add file2')
799
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
800
tree.commit('add file3')
802
tree.commit('add file4')
803
tree.add('dir1/file5')
804
tree.commit('add file5')
805
child_tree = tree.bzrdir.sprout('child').open_workingtree()
806
self.build_tree_contents([('child/file2', 'hello')])
807
child_tree.commit(message='branch 1')
808
tree.merge_from_branch(child_tree.branch)
809
tree.commit(message='merge child branch')
812
def test_log_files(self):
813
"""The log for multiple file should only list revs for those files"""
815
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
816
['6', '5.1.1', '3', '2', '1'])
818
def test_log_directory(self):
819
"""The log for a directory should show all nested files."""
821
self.assertLogRevnos(['dir1'], ['5', '3'])
823
def test_log_nested_directory(self):
824
"""The log for a directory should show all nested files."""
826
self.assertLogRevnos(['dir1/dir2'], ['3'])
828
def test_log_in_nested_directory(self):
829
"""The log for a directory should show all nested files."""
832
self.assertLogRevnos(['.'], ['5', '3'])
834
def test_log_files_and_directories(self):
835
"""Logging files and directories together should be fine."""
837
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
839
def test_log_files_and_dirs_in_nested_directory(self):
840
"""The log for a directory should show all nested files."""
843
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])