1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr log."""
23
from bzrlib import osutils
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.tests import KnownFailure, TestCaseInTempDir, TestCaseWithTransport
26
from bzrlib.tests.test_log import (
29
from bzrlib.tests import test_log
32
class TestCaseWithoutPropsHandler(ExternalBase,
33
test_log.TestCaseWithoutPropsHandler):
37
class TestLog(ExternalBase):
39
def _prepare(self, path='.', format=None):
40
tree = self.make_branch_and_tree(path, format=format)
42
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
44
tree.commit(message='message1')
45
tree.add('goodbye.txt')
46
tree.commit(message='message2')
48
tree.commit(message='message3')
49
self.full_log = self.run_bzr(["log", path])[0]
52
def test_log_null_end_revspec(self):
54
self.assertTrue('revno: 1\n' in self.full_log)
55
self.assertTrue('revno: 2\n' in self.full_log)
56
self.assertTrue('revno: 3\n' in self.full_log)
57
self.assertTrue('message:\n message1\n' in self.full_log)
58
self.assertTrue('message:\n message2\n' in self.full_log)
59
self.assertTrue('message:\n message3\n' in self.full_log)
61
log = self.run_bzr("log -r 1..")[0]
62
self.assertEqualDiff(log, self.full_log)
64
def test_log_null_begin_revspec(self):
66
log = self.run_bzr("log -r ..3")[0]
67
self.assertEqualDiff(self.full_log, log)
69
def test_log_null_both_revspecs(self):
71
log = self.run_bzr("log -r ..")[0]
72
self.assertEqualDiff(self.full_log, log)
74
def test_log_zero_revspec(self):
76
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
79
def test_log_zero_begin_revspec(self):
81
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
84
def test_log_zero_end_revspec(self):
86
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
89
def test_log_unsupported_timezone(self):
91
self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
92
'options are "utc", "original", "local".',
93
['log', '--timezone', 'foo'])
95
def test_log_negative_begin_revspec_full_log(self):
97
log = self.run_bzr("log -r -3..")[0]
98
self.assertEqualDiff(self.full_log, log)
100
def test_log_negative_both_revspec_full_log(self):
102
log = self.run_bzr("log -r -3..-1")[0]
103
self.assertEqualDiff(self.full_log, log)
105
def test_log_negative_both_revspec_partial(self):
107
log = self.run_bzr("log -r -3..-2")[0]
108
self.assertTrue('revno: 1\n' in log)
109
self.assertTrue('revno: 2\n' in log)
110
self.assertTrue('revno: 3\n' not in log)
112
def test_log_negative_begin_revspec(self):
114
log = self.run_bzr("log -r -2..")[0]
115
self.assertTrue('revno: 1\n' not in log)
116
self.assertTrue('revno: 2\n' in log)
117
self.assertTrue('revno: 3\n' in log)
119
def test_log_positive_revspecs(self):
121
log = self.run_bzr("log -r 1..3")[0]
122
self.assertEqualDiff(self.full_log, log)
124
def test_log_reversed_revspecs(self):
126
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
127
'the end revision.\n',),
130
def test_log_revno_n_path(self):
131
self._prepare(path='branch1')
132
self._prepare(path='branch2')
133
log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
135
log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
136
self.assertEqualDiff(self.full_log, log)
137
log = self.run_bzr("log -r revno:1:branch2")[0]
138
self.assertTrue('revno: 1\n' in log)
139
self.assertTrue('revno: 2\n' not in log)
140
self.assertTrue('branch nick: branch2\n' in log)
141
self.assertTrue('branch nick: branch1\n' not in log)
143
def test_log_nonexistent_revno(self):
145
(out, err) = self.run_bzr_error(args="log -r 1234",
146
error_regexes=["bzr: ERROR: Requested revision: '1234' "
147
"does not exist in branch:"])
149
def test_log_nonexistent_dotted_revno(self):
151
(out, err) = self.run_bzr_error(args="log -r 123.123",
152
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
153
"does not exist in branch:"])
155
def test_log_change_revno(self):
157
expected_log = self.run_bzr("log -r 1")[0]
158
log = self.run_bzr("log -c 1")[0]
159
self.assertEqualDiff(expected_log, log)
161
def test_log_change_nonexistent_revno(self):
163
(out, err) = self.run_bzr_error(args="log -c 1234",
164
error_regexes=["bzr: ERROR: Requested revision: '1234' "
165
"does not exist in branch:"])
167
def test_log_change_nonexistent_dotted_revno(self):
169
(out, err) = self.run_bzr_error(args="log -c 123.123",
170
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
171
"does not exist in branch:"])
173
def test_log_change_single_revno(self):
175
self.run_bzr_error('bzr: ERROR: Option --change does not'
176
' accept revision ranges',
177
['log', '--change', '2..3'])
179
def test_log_change_incompatible_with_revision(self):
181
self.run_bzr_error('bzr: ERROR: --revision and --change'
182
' are mutually exclusive',
183
['log', '--change', '2', '--revision', '3'])
185
def test_log_nonexistent_file(self):
186
# files that don't exist in either the basis tree or working tree
187
# should give an error
188
wt = self.make_branch_and_tree('.')
189
out, err = self.run_bzr('log does-not-exist', retcode=3)
190
self.assertContainsRe(
191
err, 'Path unknown at end or start of revision range: does-not-exist')
193
def test_log_with_tags(self):
194
tree = self._prepare(format='dirstate-tags')
196
branch.tags.set_tag('tag1', branch.get_rev_id(1))
197
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
198
branch.tags.set_tag('tag3', branch.last_revision())
200
log = self.run_bzr("log -r-1")[0]
201
self.assertTrue('tags: tag3' in log)
203
log = self.run_bzr("log -r1")[0]
204
# I guess that we can't know the order of tags in the output
205
# since dicts are unordered, need to check both possibilities
206
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
208
def test_merged_log_with_tags(self):
209
branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
210
branch1 = branch1_tree.branch
211
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
212
branch1_tree.commit(message='foobar', allow_pointless=True)
213
branch1.tags.set_tag('tag1', branch1.last_revision())
215
self.run_bzr('merge ../branch1') # tags don't propagate otherwise
216
branch2_tree.commit(message='merge branch 1')
217
log = self.run_bzr("log -r-1")[0]
218
self.assertContainsRe(log, r' tags: tag1')
219
log = self.run_bzr("log -r3.1.1")[0]
220
self.assertContainsRe(log, r'tags: tag1')
222
def test_log_limit(self):
223
tree = self.make_branch_and_tree('.')
224
# We want more commits than our batch size starts at
225
for pos in range(10):
226
tree.commit("%s" % pos)
227
log = self.run_bzr("log --limit 2")[0]
228
self.assertNotContainsRe(log, r'revno: 1\n')
229
self.assertNotContainsRe(log, r'revno: 2\n')
230
self.assertNotContainsRe(log, r'revno: 3\n')
231
self.assertNotContainsRe(log, r'revno: 4\n')
232
self.assertNotContainsRe(log, r'revno: 5\n')
233
self.assertNotContainsRe(log, r'revno: 6\n')
234
self.assertNotContainsRe(log, r'revno: 7\n')
235
self.assertNotContainsRe(log, r'revno: 8\n')
236
self.assertContainsRe(log, r'revno: 9\n')
237
self.assertContainsRe(log, r'revno: 10\n')
239
def test_log_limit_short(self):
241
log = self.run_bzr("log -l 2")[0]
242
self.assertNotContainsRe(log, r'revno: 1\n')
243
self.assertContainsRe(log, r'revno: 2\n')
244
self.assertContainsRe(log, r'revno: 3\n')
247
class TestLogVerbose(TestCaseWithTransport):
250
super(TestLogVerbose, self).setUp()
251
tree = self.make_branch_and_tree('.')
252
self.build_tree(['hello.txt'])
253
tree.add('hello.txt')
254
tree.commit(message='message1')
256
def assertUseShortDeltaFormat(self, cmd):
257
log = self.run_bzr(cmd)[0]
258
# Check that we use the short status format
259
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
260
self.assertNotContainsRe(log, '(?m)^\s*added:$')
262
def assertUseLongDeltaFormat(self, cmd):
263
log = self.run_bzr(cmd)[0]
264
# Check that we use the long status format
265
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
266
self.assertContainsRe(log, '(?m)^\s*added:$')
268
def test_log_short_verbose(self):
269
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
271
def test_log_short_verbose_verbose(self):
272
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
274
def test_log_long_verbose(self):
275
# Check that we use the long status format, ignoring the verbosity
277
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
279
def test_log_long_verbose_verbose(self):
280
# Check that we use the long status format, ignoring the verbosity
282
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
285
class TestLogMerges(TestCaseWithoutPropsHandler):
288
parent_tree = self.make_branch_and_tree('parent')
289
parent_tree.commit(message='first post', allow_pointless=True)
290
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
291
child_tree.commit(message='branch 1', allow_pointless=True)
293
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
294
smaller_tree.commit(message='branch 2', allow_pointless=True)
295
child_tree.merge_from_branch(smaller_tree.branch)
296
child_tree.commit(message='merge branch 2')
297
parent_tree.merge_from_branch(child_tree.branch)
298
parent_tree.commit(message='merge branch 1')
301
def _prepare_short(self):
302
parent_tree = self.make_branch_and_tree('parent')
303
parent_tree.commit(message='first post',
304
timestamp=1132586700, timezone=36000,
305
committer='Joe Foo <joe@foo.com>')
306
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
307
child_tree.commit(message='branch 1',
308
timestamp=1132586800, timezone=36000,
309
committer='Joe Foo <joe@foo.com>')
311
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
312
smaller_tree.commit(message='branch 2',
313
timestamp=1132586900, timezone=36000,
314
committer='Joe Foo <joe@foo.com>')
315
child_tree.merge_from_branch(smaller_tree.branch)
316
child_tree.commit(message='merge branch 2',
317
timestamp=1132587000, timezone=36000,
318
committer='Joe Foo <joe@foo.com>')
319
parent_tree.merge_from_branch(child_tree.branch)
320
parent_tree.commit(message='merge branch 1',
321
timestamp=1132587100, timezone=36000,
322
committer='Joe Foo <joe@foo.com>')
325
def test_merges_are_indented_by_level(self):
327
out,err = self.run_bzr('log')
328
self.assertEqual('', err)
329
log = normalize_log(out)
330
self.assertEqualDiff(log, """\
331
------------------------------------------------------------
333
committer: Lorem Ipsum <test@example.com>
338
------------------------------------------------------------
340
committer: Lorem Ipsum <test@example.com>
345
------------------------------------------------------------
347
committer: Lorem Ipsum <test@example.com>
348
branch nick: smallerchild
352
------------------------------------------------------------
354
committer: Lorem Ipsum <test@example.com>
359
------------------------------------------------------------
361
committer: Lorem Ipsum <test@example.com>
368
def test_force_merge_revisions_off(self):
370
out,err = self.run_bzr('log --long -n1')
371
self.assertEqual('', err)
372
log = normalize_log(out)
373
self.assertEqualDiff(log, """\
374
------------------------------------------------------------
376
committer: Lorem Ipsum <test@example.com>
381
------------------------------------------------------------
383
committer: Lorem Ipsum <test@example.com>
390
def test_force_merge_revisions_on(self):
391
self._prepare_short()
392
out,err = self.run_bzr('log --short -n0')
393
self.assertEqual('', err)
394
log = normalize_log(out)
395
self.assertEqualDiff(log, """\
396
2 Joe Foo\t2005-11-22 [merge]
399
1.1.2 Joe Foo\t2005-11-22 [merge]
402
1.2.1 Joe Foo\t2005-11-22
405
1.1.1 Joe Foo\t2005-11-22
408
1 Joe Foo\t2005-11-22
413
def test_force_merge_revisions_N(self):
414
self._prepare_short()
415
out,err = self.run_bzr('log --short -n2')
416
self.assertEqual('', err)
417
log = normalize_log(out)
418
self.assertEqualDiff(log, """\
419
2 Joe Foo\t2005-11-22 [merge]
422
1.1.2 Joe Foo\t2005-11-22 [merge]
425
1.1.1 Joe Foo\t2005-11-22
428
1 Joe Foo\t2005-11-22
433
def test_merges_single_merge_rev(self):
435
out,err = self.run_bzr('log -r1.1.2')
436
self.assertEqual('', err)
437
log = normalize_log(out)
438
self.assertEqualDiff(log, """\
439
------------------------------------------------------------
441
committer: Lorem Ipsum <test@example.com>
446
------------------------------------------------------------
448
committer: Lorem Ipsum <test@example.com>
449
branch nick: smallerchild
455
def test_merges_partial_range(self):
457
out, err = self.run_bzr('log -r1.1.1..1.1.2')
458
self.assertEqual('', err)
459
log = normalize_log(out)
460
self.assertEqualDiff(log, """\
461
------------------------------------------------------------
463
committer: Lorem Ipsum <test@example.com>
468
------------------------------------------------------------
470
committer: Lorem Ipsum <test@example.com>
471
branch nick: smallerchild
475
------------------------------------------------------------
477
committer: Lorem Ipsum <test@example.com>
484
def test_merges_nonsupporting_formatter(self):
485
# This "feature" of log formatters is madness. If a log
486
# formatter cannot display a dotted-revno, it ought to ignore it.
487
# Otherwise, a linear sequence is always expected to be handled now.
488
raise KnownFailure('log formatters must support linear sequences now')
490
err_msg = 'Selected log formatter only supports mainline revisions.'
491
# The single revision case is tested in the core tests
492
# since all standard formatters support single merge revisions.
493
out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
494
self.assertContainsRe(err, err_msg)
495
out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
496
self.assertContainsRe(err, err_msg)
499
def subst_dates(string):
500
"""Replace date strings with constant values."""
501
return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
502
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
505
class TestLogDiff(TestCaseWithoutPropsHandler):
508
parent_tree = self.make_branch_and_tree('parent')
509
self.build_tree(['parent/file1', 'parent/file2'])
510
parent_tree.add('file1')
511
parent_tree.add('file2')
512
parent_tree.commit(message='first post',
513
timestamp=1132586655, timezone=36000,
514
committer='Lorem Ipsum <test@example.com>')
515
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
516
self.build_tree_contents([('child/file2', 'hello\n')])
517
child_tree.commit(message='branch 1',
518
timestamp=1132586700, timezone=36000,
519
committer='Lorem Ipsum <test@example.com>')
520
parent_tree.merge_from_branch(child_tree.branch)
521
parent_tree.commit(message='merge branch 1',
522
timestamp=1132586800, timezone=36000,
523
committer='Lorem Ipsum <test@example.com>')
526
def test_log_show_diff_long(self):
528
out,err = self.run_bzr('log -p')
529
self.assertEqual('', err)
530
log = normalize_log(out)
531
self.assertEqualDiff(subst_dates(log), """\
532
------------------------------------------------------------
534
committer: Lorem Ipsum <test@example.com>
540
=== modified file 'file2'
541
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
542
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
544
-contents of parent/file2
546
------------------------------------------------------------
548
committer: Lorem Ipsum <test@example.com>
554
=== modified file 'file2'
555
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
556
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
558
-contents of parent/file2
560
------------------------------------------------------------
562
committer: Lorem Ipsum <test@example.com>
568
=== added file 'file1'
569
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
570
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
572
+contents of parent/file1
574
=== added file 'file2'
575
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
576
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
578
+contents of parent/file2
581
def test_log_show_diff_short(self):
583
out,err = self.run_bzr('log -p --short')
584
self.assertEqual('', err)
585
log = normalize_log(out)
586
self.assertEqualDiff(subst_dates(log), """\
587
2 Lorem Ipsum\t2005-11-22 [merge]
589
=== modified file 'file2'
590
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
591
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
593
-contents of parent/file2
596
1 Lorem Ipsum\t2005-11-22
598
=== added file 'file1'
599
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
600
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
602
+contents of parent/file1
604
=== added file 'file2'
605
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
606
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
608
+contents of parent/file2
612
def test_log_show_diff_line(self):
614
out,err = self.run_bzr('log -p --line')
615
self.assertEqual('', err)
616
log = normalize_log(out)
617
# Not supported by this formatter so expect plain output
618
self.assertEqualDiff(subst_dates(log), """\
619
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
620
1: Lorem Ipsum 2005-11-22 first post
623
def test_log_show_diff_file(self):
624
"""Only the diffs for the given file are to be shown"""
626
out,err = self.run_bzr('log -p --short file2')
627
self.assertEqual('', err)
628
log = normalize_log(out)
629
self.assertEqualDiff(subst_dates(log), """\
630
2 Lorem Ipsum\t2005-11-22 [merge]
632
=== modified file 'file2'
633
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
634
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
636
-contents of parent/file2
639
1 Lorem Ipsum\t2005-11-22
641
=== added file 'file2'
642
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
643
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
645
+contents of parent/file2
648
out,err = self.run_bzr('log -p --short file1')
649
self.assertEqual('', err)
650
log = normalize_log(out)
651
self.assertEqualDiff(subst_dates(log), """\
652
1 Lorem Ipsum\t2005-11-22
654
=== added file 'file1'
655
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
656
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
658
+contents of parent/file1
663
class TestLogEncodings(TestCaseInTempDir):
666
_message = u'Message with \xb5'
668
# Encodings which can encode mu
673
'cp437', # Common windows encoding
674
'cp1251', # Alexander Belchenko's windows encoding
675
'cp1258', # Common windows encoding
677
# Encodings which cannot encode mu
685
TestCaseInTempDir.setUp(self)
686
self.user_encoding = osutils._cached_user_encoding
689
osutils._cached_user_encoding = self.user_encoding
690
TestCaseInTempDir.tearDown(self)
692
def create_branch(self):
695
open('a', 'wb').write('some stuff\n')
697
bzr(['commit', '-m', self._message])
699
def try_encoding(self, encoding, fail=False):
702
self.assertRaises(UnicodeEncodeError,
703
self._mu.encode, encoding)
704
encoded_msg = self._message.encode(encoding, 'replace')
706
encoded_msg = self._message.encode(encoding)
708
old_encoding = osutils._cached_user_encoding
709
# This test requires that 'run_bzr' uses the current
710
# bzrlib, because we override user_encoding, and expect
713
osutils._cached_user_encoding = 'ascii'
714
# We should be able to handle any encoding
715
out, err = bzr('log', encoding=encoding)
717
# Make sure we wrote mu as we expected it to exist
718
self.assertNotEqual(-1, out.find(encoded_msg))
719
out_unicode = out.decode(encoding)
720
self.assertNotEqual(-1, out_unicode.find(self._message))
722
self.assertNotEqual(-1, out.find('Message with ?'))
724
osutils._cached_user_encoding = old_encoding
726
def test_log_handles_encoding(self):
729
for encoding in self.good_encodings:
730
self.try_encoding(encoding)
732
def test_log_handles_bad_encoding(self):
735
for encoding in self.bad_encodings:
736
self.try_encoding(encoding, fail=True)
738
def test_stdout_encoding(self):
740
osutils._cached_user_encoding = "cp1251"
743
self.build_tree(['a'])
745
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
746
stdout, stderr = self.run_bzr('log', encoding='cp866')
748
message = stdout.splitlines()[-1]
750
# explanation of the check:
751
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
752
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
753
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
754
# This test should check that output of log command
755
# encoded to sys.stdout.encoding
756
test_in_cp866 = '\x92\xa5\xe1\xe2'
757
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
758
# Make sure the log string is encoded in cp866
759
self.assertEquals(test_in_cp866, message[2:])
760
# Make sure the cp1251 string is not found anywhere
761
self.assertEquals(-1, stdout.find(test_in_cp1251))
764
class TestLogFile(TestCaseWithTransport):
766
def test_log_local_branch_file(self):
767
"""We should be able to log files in local treeless branches"""
768
tree = self.make_branch_and_tree('tree')
769
self.build_tree(['tree/file'])
771
tree.commit('revision 1')
772
tree.bzrdir.destroy_workingtree()
773
self.run_bzr('log tree/file')
775
def prepare_tree(self, complex=False):
776
# The complex configuration includes deletes and renames
777
tree = self.make_branch_and_tree('parent')
778
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
780
tree.commit('add file1')
782
tree.commit('add file2')
784
tree.commit('add file3')
785
child_tree = tree.bzrdir.sprout('child').open_workingtree()
786
self.build_tree_contents([('child/file2', 'hello')])
787
child_tree.commit(message='branch 1')
788
tree.merge_from_branch(child_tree.branch)
789
tree.commit(message='merge child branch')
792
tree.commit('remove file2')
793
tree.rename_one('file3', 'file4')
794
tree.commit('file3 is now called file4')
796
tree.commit('remove file1')
799
def test_log_file(self):
800
"""The log for a particular file should only list revs for that file"""
802
log = self.run_bzr('log file1')[0]
803
self.assertContainsRe(log, 'revno: 1\n')
804
self.assertNotContainsRe(log, 'revno: 2\n')
805
self.assertNotContainsRe(log, 'revno: 3\n')
806
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
807
self.assertNotContainsRe(log, 'revno: 4\n')
808
log = self.run_bzr('log file2')[0]
809
self.assertNotContainsRe(log, 'revno: 1\n')
810
self.assertContainsRe(log, 'revno: 2\n')
811
self.assertNotContainsRe(log, 'revno: 3\n')
812
self.assertContainsRe(log, 'revno: 3.1.1\n')
813
self.assertContainsRe(log, 'revno: 4\n')
814
log = self.run_bzr('log file3')[0]
815
self.assertNotContainsRe(log, 'revno: 1\n')
816
self.assertNotContainsRe(log, 'revno: 2\n')
817
self.assertContainsRe(log, 'revno: 3\n')
818
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
819
self.assertNotContainsRe(log, 'revno: 4\n')
820
log = self.run_bzr('log -r3.1.1 file2')[0]
821
self.assertNotContainsRe(log, 'revno: 1\n')
822
self.assertNotContainsRe(log, 'revno: 2\n')
823
self.assertNotContainsRe(log, 'revno: 3\n')
824
self.assertContainsRe(log, 'revno: 3.1.1\n')
825
self.assertNotContainsRe(log, 'revno: 4\n')
826
log = self.run_bzr('log -r4 file2')[0]
827
self.assertNotContainsRe(log, 'revno: 1\n')
828
self.assertNotContainsRe(log, 'revno: 2\n')
829
self.assertNotContainsRe(log, 'revno: 3\n')
830
self.assertContainsRe(log, 'revno: 3.1.1\n')
831
self.assertContainsRe(log, 'revno: 4\n')
832
log = self.run_bzr('log -r3.. file2')[0]
833
self.assertNotContainsRe(log, 'revno: 1\n')
834
self.assertNotContainsRe(log, 'revno: 2\n')
835
self.assertNotContainsRe(log, 'revno: 3\n')
836
self.assertContainsRe(log, 'revno: 3.1.1\n')
837
self.assertContainsRe(log, 'revno: 4\n')
838
log = self.run_bzr('log -r..3 file2')[0]
839
self.assertNotContainsRe(log, 'revno: 1\n')
840
self.assertContainsRe(log, 'revno: 2\n')
841
self.assertNotContainsRe(log, 'revno: 3\n')
842
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
843
self.assertNotContainsRe(log, 'revno: 4\n')
845
def test_log_file_historical_missing(self):
846
# Check logging a deleted file gives an error if the
847
# file isn't found at the end or start of the revision range
848
self.prepare_tree(complex=True)
849
err_msg = "Path unknown at end or start of revision range: file2"
850
err = self.run_bzr('log file2', retcode=3)[1]
851
self.assertContainsRe(err, err_msg)
853
def test_log_file_historical_end(self):
854
# Check logging a deleted file is ok if the file existed
855
# at the end the revision range
856
self.prepare_tree(complex=True)
857
log, err = self.run_bzr('log -r..4 file2')
858
self.assertEquals('', err)
859
self.assertNotContainsRe(log, 'revno: 1\n')
860
self.assertContainsRe(log, 'revno: 2\n')
861
self.assertNotContainsRe(log, 'revno: 3\n')
862
self.assertContainsRe(log, 'revno: 3.1.1\n')
863
self.assertContainsRe(log, 'revno: 4\n')
865
def test_log_file_historical_start(self):
866
# Check logging a deleted file is ok if the file existed
867
# at the start of the revision range
868
self.prepare_tree(complex=True)
869
log, err = self.run_bzr('log file1')
870
self.assertEquals('', err)
871
self.assertContainsRe(log, 'revno: 1\n')
872
self.assertNotContainsRe(log, 'revno: 2\n')
873
self.assertNotContainsRe(log, 'revno: 3\n')
874
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
875
self.assertNotContainsRe(log, 'revno: 4\n')
877
def test_log_file_renamed(self):
878
"""File matched against revision range, not current tree."""
879
self.prepare_tree(complex=True)
881
# Check logging a renamed file gives an error by default
882
err_msg = "Path unknown at end or start of revision range: file3"
883
err = self.run_bzr('log file3', retcode=3)[1]
884
self.assertContainsRe(err, err_msg)
886
# Check we can see a renamed file if we give the right end revision
887
log, err = self.run_bzr('log -r..4 file3')
888
self.assertEquals('', err)
889
self.assertNotContainsRe(log, 'revno: 1\n')
890
self.assertNotContainsRe(log, 'revno: 2\n')
891
self.assertContainsRe(log, 'revno: 3\n')
892
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
893
self.assertNotContainsRe(log, 'revno: 4\n')
895
def test_line_log_file(self):
896
"""The line log for a file should only list relevant mainline revs"""
897
# Note: this also implicitly covers the short logging case.
898
# We test using --line in preference to --short because matching
899
# revnos in the output of --line is more reliable.
902
# full history of file1
903
log = self.run_bzr('log --line file1')[0]
904
self.assertContainsRe(log, '^1:', re.MULTILINE)
905
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
906
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
907
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
908
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
910
# full history of file2
911
log = self.run_bzr('log --line file2')[0]
912
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
913
self.assertContainsRe(log, '^2:', re.MULTILINE)
914
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
915
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
916
self.assertContainsRe(log, '^4:', re.MULTILINE)
918
# full history of file3
919
log = self.run_bzr('log --line file3')[0]
920
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
921
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
922
self.assertContainsRe(log, '^3:', re.MULTILINE)
923
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
924
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
926
# file in a merge revision
927
log = self.run_bzr('log --line -r3.1.1 file2')[0]
928
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
929
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
930
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
931
self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
932
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
934
# file in a mainline revision
935
log = self.run_bzr('log --line -r4 file2')[0]
936
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
937
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
938
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
939
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
940
self.assertContainsRe(log, '^4:', re.MULTILINE)
942
# file since a revision
943
log = self.run_bzr('log --line -r3.. file2')[0]
944
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
945
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
946
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
947
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
948
self.assertContainsRe(log, '^4:', re.MULTILINE)
950
# file up to a revision
951
log = self.run_bzr('log --line -r..3 file2')[0]
952
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
953
self.assertContainsRe(log, '^2:', re.MULTILINE)
954
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
955
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
956
self.assertNotContainsRe(log, '^4:', re.MULTILINE)