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."""
22
from bzrlib import osutils
23
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.tests import KnownFailure, TestCaseInTempDir, TestCaseWithTransport
25
from bzrlib.tests.test_log import (
28
from bzrlib.tests import test_log
31
class TestCaseWithoutPropsHandler(ExternalBase,
32
test_log.TestCaseWithoutPropsHandler):
36
class TestLog(ExternalBase):
38
def _prepare(self, path='.', format=None):
39
tree = self.make_branch_and_tree(path, format=format)
41
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
43
tree.commit(message='message1')
44
tree.add('goodbye.txt')
45
tree.commit(message='message2')
47
tree.commit(message='message3')
48
self.full_log = self.run_bzr(["log", path])[0]
51
def test_log_null_end_revspec(self):
53
self.assertTrue('revno: 1\n' in self.full_log)
54
self.assertTrue('revno: 2\n' in self.full_log)
55
self.assertTrue('revno: 3\n' in self.full_log)
56
self.assertTrue('message:\n message1\n' in self.full_log)
57
self.assertTrue('message:\n message2\n' in self.full_log)
58
self.assertTrue('message:\n message3\n' in self.full_log)
60
log = self.run_bzr("log -r 1..")[0]
61
self.assertEqualDiff(log, self.full_log)
63
def test_log_null_begin_revspec(self):
65
log = self.run_bzr("log -r ..3")[0]
66
self.assertEqualDiff(self.full_log, log)
68
def test_log_null_both_revspecs(self):
70
log = self.run_bzr("log -r ..")[0]
71
self.assertEqualDiff(self.full_log, log)
73
def test_log_zero_revspec(self):
75
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
78
def test_log_zero_begin_revspec(self):
80
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
83
def test_log_zero_end_revspec(self):
85
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
88
def test_log_unsupported_timezone(self):
90
self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
91
'options are "utc", "original", "local".',
92
['log', '--timezone', 'foo'])
94
def test_log_negative_begin_revspec_full_log(self):
96
log = self.run_bzr("log -r -3..")[0]
97
self.assertEqualDiff(self.full_log, log)
99
def test_log_negative_both_revspec_full_log(self):
101
log = self.run_bzr("log -r -3..-1")[0]
102
self.assertEqualDiff(self.full_log, log)
104
def test_log_negative_both_revspec_partial(self):
106
log = self.run_bzr("log -r -3..-2")[0]
107
self.assertTrue('revno: 1\n' in log)
108
self.assertTrue('revno: 2\n' in log)
109
self.assertTrue('revno: 3\n' not in log)
111
def test_log_negative_begin_revspec(self):
113
log = self.run_bzr("log -r -2..")[0]
114
self.assertTrue('revno: 1\n' not in log)
115
self.assertTrue('revno: 2\n' in log)
116
self.assertTrue('revno: 3\n' in log)
118
def test_log_positive_revspecs(self):
120
log = self.run_bzr("log -r 1..3")[0]
121
self.assertEqualDiff(self.full_log, log)
123
def test_log_reversed_revspecs(self):
125
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
126
'the end revision.\n',),
129
def test_log_revno_n_path(self):
130
self._prepare(path='branch1')
131
self._prepare(path='branch2')
132
log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
134
log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
135
self.assertEqualDiff(self.full_log, log)
136
log = self.run_bzr("log -r revno:1:branch2")[0]
137
self.assertTrue('revno: 1\n' in log)
138
self.assertTrue('revno: 2\n' not in log)
139
self.assertTrue('branch nick: branch2\n' in log)
140
self.assertTrue('branch nick: branch1\n' not in log)
142
def test_log_nonexistent_revno(self):
144
(out, err) = self.run_bzr_error(args="log -r 1234",
145
error_regexes=["bzr: ERROR: Requested revision: '1234' "
146
"does not exist in branch:"])
148
def test_log_nonexistent_dotted_revno(self):
150
(out, err) = self.run_bzr_error(args="log -r 123.123",
151
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
152
"does not exist in branch:"])
154
def test_log_change_revno(self):
156
expected_log = self.run_bzr("log -r 1")[0]
157
log = self.run_bzr("log -c 1")[0]
158
self.assertEqualDiff(expected_log, log)
160
def test_log_change_nonexistent_revno(self):
162
(out, err) = self.run_bzr_error(args="log -c 1234",
163
error_regexes=["bzr: ERROR: Requested revision: '1234' "
164
"does not exist in branch:"])
166
def test_log_change_nonexistent_dotted_revno(self):
168
(out, err) = self.run_bzr_error(args="log -c 123.123",
169
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
170
"does not exist in branch:"])
172
def test_log_change_single_revno(self):
174
self.run_bzr_error('bzr: ERROR: Option --change does not'
175
' accept revision ranges',
176
['log', '--change', '2..3'])
178
def test_log_change_incompatible_with_revision(self):
180
self.run_bzr_error('bzr: ERROR: --revision and --change'
181
' are mutually exclusive',
182
['log', '--change', '2', '--revision', '3'])
184
def test_log_nonexistent_file(self):
185
# files that don't exist in either the basis tree or working tree
186
# should give an error
187
wt = self.make_branch_and_tree('.')
188
out, err = self.run_bzr('log does-not-exist', retcode=3)
189
self.assertContainsRe(
190
err, 'Path unknown at end or start of revision range: does-not-exist')
192
def test_log_with_tags(self):
193
tree = self._prepare(format='dirstate-tags')
195
branch.tags.set_tag('tag1', branch.get_rev_id(1))
196
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
197
branch.tags.set_tag('tag3', branch.last_revision())
199
log = self.run_bzr("log -r-1")[0]
200
self.assertTrue('tags: tag3' in log)
202
log = self.run_bzr("log -r1")[0]
203
# I guess that we can't know the order of tags in the output
204
# since dicts are unordered, need to check both possibilities
205
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
207
def test_merged_log_with_tags(self):
208
branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
209
branch1 = branch1_tree.branch
210
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
211
branch1_tree.commit(message='foobar', allow_pointless=True)
212
branch1.tags.set_tag('tag1', branch1.last_revision())
214
self.run_bzr('merge ../branch1') # tags don't propagate otherwise
215
branch2_tree.commit(message='merge branch 1')
216
log = self.run_bzr("log -n0 -r-1")[0]
217
self.assertContainsRe(log, r' tags: tag1')
218
log = self.run_bzr("log -n0 -r3.1.1")[0]
219
self.assertContainsRe(log, r'tags: tag1')
221
def test_log_limit(self):
222
tree = self.make_branch_and_tree('.')
223
# We want more commits than our batch size starts at
224
for pos in range(10):
225
tree.commit("%s" % pos)
226
log = self.run_bzr("log --limit 2")[0]
227
self.assertNotContainsRe(log, r'revno: 1\n')
228
self.assertNotContainsRe(log, r'revno: 2\n')
229
self.assertNotContainsRe(log, r'revno: 3\n')
230
self.assertNotContainsRe(log, r'revno: 4\n')
231
self.assertNotContainsRe(log, r'revno: 5\n')
232
self.assertNotContainsRe(log, r'revno: 6\n')
233
self.assertNotContainsRe(log, r'revno: 7\n')
234
self.assertNotContainsRe(log, r'revno: 8\n')
235
self.assertContainsRe(log, r'revno: 9\n')
236
self.assertContainsRe(log, r'revno: 10\n')
238
def test_log_limit_short(self):
240
log = self.run_bzr("log -l 2")[0]
241
self.assertNotContainsRe(log, r'revno: 1\n')
242
self.assertContainsRe(log, r'revno: 2\n')
243
self.assertContainsRe(log, r'revno: 3\n')
245
def test_log_bad_message_re(self):
246
"""Bad --message argument gives a sensible message
248
See https://bugs.launchpad.net/bzr/+bug/251352
251
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
252
self.assertEqual("bzr: ERROR: Invalid regular expression"
253
" in log message filter"
255
": nothing to repeat\n", err)
256
self.assertEqual('', out)
259
class TestLogVerbose(TestCaseWithTransport):
262
super(TestLogVerbose, self).setUp()
263
tree = self.make_branch_and_tree('.')
264
self.build_tree(['hello.txt'])
265
tree.add('hello.txt')
266
tree.commit(message='message1')
268
def assertUseShortDeltaFormat(self, cmd):
269
log = self.run_bzr(cmd)[0]
270
# Check that we use the short status format
271
self.assertContainsRe(log, '(?m)^\s*A hello.txt$')
272
self.assertNotContainsRe(log, '(?m)^\s*added:$')
274
def assertUseLongDeltaFormat(self, cmd):
275
log = self.run_bzr(cmd)[0]
276
# Check that we use the long status format
277
self.assertNotContainsRe(log, '(?m)^\s*A hello.txt$')
278
self.assertContainsRe(log, '(?m)^\s*added:$')
280
def test_log_short_verbose(self):
281
self.assertUseShortDeltaFormat(['log', '--short', '-v'])
283
def test_log_short_verbose_verbose(self):
284
self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
286
def test_log_long_verbose(self):
287
# Check that we use the long status format, ignoring the verbosity
289
self.assertUseLongDeltaFormat(['log', '--long', '-v'])
291
def test_log_long_verbose_verbose(self):
292
# Check that we use the long status format, ignoring the verbosity
294
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
297
class TestLogMerges(TestCaseWithoutPropsHandler):
300
parent_tree = self.make_branch_and_tree('parent')
301
parent_tree.commit(message='first post', allow_pointless=True)
302
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
303
child_tree.commit(message='branch 1', allow_pointless=True)
305
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
306
smaller_tree.commit(message='branch 2', allow_pointless=True)
307
child_tree.merge_from_branch(smaller_tree.branch)
308
child_tree.commit(message='merge branch 2')
309
parent_tree.merge_from_branch(child_tree.branch)
310
parent_tree.commit(message='merge branch 1')
313
def _prepare_short(self):
314
parent_tree = self.make_branch_and_tree('parent')
315
parent_tree.commit(message='first post',
316
timestamp=1132586700, timezone=36000,
317
committer='Joe Foo <joe@foo.com>')
318
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
319
child_tree.commit(message='branch 1',
320
timestamp=1132586800, timezone=36000,
321
committer='Joe Foo <joe@foo.com>')
323
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
324
smaller_tree.commit(message='branch 2',
325
timestamp=1132586900, timezone=36000,
326
committer='Joe Foo <joe@foo.com>')
327
child_tree.merge_from_branch(smaller_tree.branch)
328
child_tree.commit(message='merge branch 2',
329
timestamp=1132587000, timezone=36000,
330
committer='Joe Foo <joe@foo.com>')
331
parent_tree.merge_from_branch(child_tree.branch)
332
parent_tree.commit(message='merge branch 1',
333
timestamp=1132587100, timezone=36000,
334
committer='Joe Foo <joe@foo.com>')
337
def test_merges_are_indented_by_level(self):
339
out,err = self.run_bzr('log -n0')
340
self.assertEqual('', err)
341
log = normalize_log(out)
342
self.assertEqualDiff(log, """\
343
------------------------------------------------------------
345
committer: Lorem Ipsum <test@example.com>
350
------------------------------------------------------------
352
committer: Lorem Ipsum <test@example.com>
357
------------------------------------------------------------
359
committer: Lorem Ipsum <test@example.com>
360
branch nick: smallerchild
364
------------------------------------------------------------
366
committer: Lorem Ipsum <test@example.com>
371
------------------------------------------------------------
373
committer: Lorem Ipsum <test@example.com>
380
def test_force_merge_revisions_off(self):
382
out,err = self.run_bzr('log --long -n1')
383
self.assertEqual('', err)
384
log = normalize_log(out)
385
self.assertEqualDiff(log, """\
386
------------------------------------------------------------
388
committer: Lorem Ipsum <test@example.com>
393
------------------------------------------------------------
395
committer: Lorem Ipsum <test@example.com>
400
------------------------------------------------------------
401
Use --levels 0 (or -n0) to see merged revisions.
404
def test_force_merge_revisions_on(self):
405
self._prepare_short()
406
out,err = self.run_bzr('log --short -n0')
407
self.assertEqual('', err)
408
log = normalize_log(out)
409
self.assertEqualDiff(log, """\
410
2 Joe Foo\t2005-11-22 [merge]
413
1.1.2 Joe Foo\t2005-11-22 [merge]
416
1.2.1 Joe Foo\t2005-11-22
419
1.1.1 Joe Foo\t2005-11-22
422
1 Joe Foo\t2005-11-22
427
def test_force_merge_revisions_N(self):
428
self._prepare_short()
429
out,err = self.run_bzr('log --short -n2')
430
self.assertEqual('', err)
431
log = normalize_log(out)
432
self.assertEqualDiff(log, """\
433
2 Joe Foo\t2005-11-22 [merge]
436
1.1.2 Joe Foo\t2005-11-22 [merge]
439
1.1.1 Joe Foo\t2005-11-22
442
1 Joe Foo\t2005-11-22
447
def test_merges_single_merge_rev(self):
449
out,err = self.run_bzr('log -n0 -r1.1.2')
450
self.assertEqual('', err)
451
log = normalize_log(out)
452
self.assertEqualDiff(log, """\
453
------------------------------------------------------------
455
committer: Lorem Ipsum <test@example.com>
460
------------------------------------------------------------
462
committer: Lorem Ipsum <test@example.com>
463
branch nick: smallerchild
469
def test_merges_partial_range(self):
471
out, err = self.run_bzr('log -n0 -r1.1.1..1.1.2')
472
self.assertEqual('', err)
473
log = normalize_log(out)
474
self.assertEqualDiff(log, """\
475
------------------------------------------------------------
477
committer: Lorem Ipsum <test@example.com>
482
------------------------------------------------------------
484
committer: Lorem Ipsum <test@example.com>
485
branch nick: smallerchild
489
------------------------------------------------------------
491
committer: Lorem Ipsum <test@example.com>
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_with_merges(self):
528
out,err = self.run_bzr('log -p -n0')
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
603
\x20\x20\x20\x20\x20\x20
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
610
Use --levels 0 (or -n0) to see merged revisions.
613
def test_log_show_diff_line(self):
615
out,err = self.run_bzr('log -p --line')
616
self.assertEqual('', err)
617
log = normalize_log(out)
618
# Not supported by this formatter so expect plain output
619
self.assertEqualDiff(subst_dates(log), """\
620
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
621
1: Lorem Ipsum 2005-11-22 first post
624
def test_log_show_diff_file(self):
625
"""Only the diffs for the given file are to be shown"""
627
out,err = self.run_bzr('log -p --short file2')
628
self.assertEqual('', err)
629
log = normalize_log(out)
630
self.assertEqualDiff(subst_dates(log), """\
631
2 Lorem Ipsum\t2005-11-22 [merge]
633
=== modified file 'file2'
634
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
635
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
637
-contents of parent/file2
640
1 Lorem Ipsum\t2005-11-22
642
=== added file 'file2'
643
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
644
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
646
+contents of parent/file2
648
Use --levels 0 (or -n0) to see merged revisions.
650
out,err = self.run_bzr('log -p --short file1')
651
self.assertEqual('', err)
652
log = normalize_log(out)
653
self.assertEqualDiff(subst_dates(log), """\
654
1 Lorem Ipsum\t2005-11-22
656
=== added file 'file1'
657
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
658
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
660
+contents of parent/file1
664
def test_log_show_diff_non_ascii(self):
665
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
666
message = u'Message with \xb5'
667
body = 'Body with \xb5\n'
668
wt = self.make_branch_and_tree('.')
669
self.build_tree_contents([('foo', body)])
671
wt.commit(message=message)
672
# check that command won't fail with unicode error
673
# don't care about exact output because we have other tests for this
674
out,err = self.run_bzr('log -p --long')
675
self.assertNotEqual('', out)
676
self.assertEqual('', err)
677
out,err = self.run_bzr('log -p --short')
678
self.assertNotEqual('', out)
679
self.assertEqual('', err)
680
out,err = self.run_bzr('log -p --line')
681
self.assertNotEqual('', out)
682
self.assertEqual('', err)
685
class TestLogEncodings(TestCaseInTempDir):
688
_message = u'Message with \xb5'
690
# Encodings which can encode mu
695
'cp437', # Common windows encoding
696
'cp1251', # Russian windows encoding
697
'cp1258', # Common windows encoding
699
# Encodings which cannot encode mu
707
TestCaseInTempDir.setUp(self)
708
self.user_encoding = osutils._cached_user_encoding
711
osutils._cached_user_encoding = self.user_encoding
712
TestCaseInTempDir.tearDown(self)
714
def create_branch(self):
717
open('a', 'wb').write('some stuff\n')
719
bzr(['commit', '-m', self._message])
721
def try_encoding(self, encoding, fail=False):
724
self.assertRaises(UnicodeEncodeError,
725
self._mu.encode, encoding)
726
encoded_msg = self._message.encode(encoding, 'replace')
728
encoded_msg = self._message.encode(encoding)
730
old_encoding = osutils._cached_user_encoding
731
# This test requires that 'run_bzr' uses the current
732
# bzrlib, because we override user_encoding, and expect
735
osutils._cached_user_encoding = 'ascii'
736
# We should be able to handle any encoding
737
out, err = bzr('log', encoding=encoding)
739
# Make sure we wrote mu as we expected it to exist
740
self.assertNotEqual(-1, out.find(encoded_msg))
741
out_unicode = out.decode(encoding)
742
self.assertNotEqual(-1, out_unicode.find(self._message))
744
self.assertNotEqual(-1, out.find('Message with ?'))
746
osutils._cached_user_encoding = old_encoding
748
def test_log_handles_encoding(self):
751
for encoding in self.good_encodings:
752
self.try_encoding(encoding)
754
def test_log_handles_bad_encoding(self):
757
for encoding in self.bad_encodings:
758
self.try_encoding(encoding, fail=True)
760
def test_stdout_encoding(self):
762
osutils._cached_user_encoding = "cp1251"
765
self.build_tree(['a'])
767
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
768
stdout, stderr = self.run_bzr('log', encoding='cp866')
770
message = stdout.splitlines()[-1]
772
# explanation of the check:
773
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
774
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
775
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
776
# This test should check that output of log command
777
# encoded to sys.stdout.encoding
778
test_in_cp866 = '\x92\xa5\xe1\xe2'
779
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
780
# Make sure the log string is encoded in cp866
781
self.assertEquals(test_in_cp866, message[2:])
782
# Make sure the cp1251 string is not found anywhere
783
self.assertEquals(-1, stdout.find(test_in_cp1251))
786
class TestLogFile(TestCaseWithTransport):
788
def test_log_local_branch_file(self):
789
"""We should be able to log files in local treeless branches"""
790
tree = self.make_branch_and_tree('tree')
791
self.build_tree(['tree/file'])
793
tree.commit('revision 1')
794
tree.bzrdir.destroy_workingtree()
795
self.run_bzr('log tree/file')
797
def prepare_tree(self, complex=False):
798
# The complex configuration includes deletes and renames
799
tree = self.make_branch_and_tree('parent')
800
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
802
tree.commit('add file1')
804
tree.commit('add file2')
806
tree.commit('add file3')
807
child_tree = tree.bzrdir.sprout('child').open_workingtree()
808
self.build_tree_contents([('child/file2', 'hello')])
809
child_tree.commit(message='branch 1')
810
tree.merge_from_branch(child_tree.branch)
811
tree.commit(message='merge child branch')
814
tree.commit('remove file2')
815
tree.rename_one('file3', 'file4')
816
tree.commit('file3 is now called file4')
818
tree.commit('remove file1')
821
def test_log_file(self):
822
"""The log for a particular file should only list revs for that file"""
824
log = self.run_bzr('log -n0 file1')[0]
825
self.assertContainsRe(log, 'revno: 1\n')
826
self.assertNotContainsRe(log, 'revno: 2\n')
827
self.assertNotContainsRe(log, 'revno: 3\n')
828
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
829
self.assertNotContainsRe(log, 'revno: 4 ')
830
log = self.run_bzr('log -n0 file2')[0]
831
self.assertNotContainsRe(log, 'revno: 1\n')
832
self.assertContainsRe(log, 'revno: 2\n')
833
self.assertNotContainsRe(log, 'revno: 3\n')
834
self.assertContainsRe(log, 'revno: 3.1.1\n')
835
self.assertContainsRe(log, 'revno: 4 ')
836
log = self.run_bzr('log -n0 file3')[0]
837
self.assertNotContainsRe(log, 'revno: 1\n')
838
self.assertNotContainsRe(log, 'revno: 2\n')
839
self.assertContainsRe(log, 'revno: 3\n')
840
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
841
self.assertNotContainsRe(log, 'revno: 4 ')
842
log = self.run_bzr('log -n0 -r3.1.1 file2')[0]
843
self.assertNotContainsRe(log, 'revno: 1\n')
844
self.assertNotContainsRe(log, 'revno: 2\n')
845
self.assertNotContainsRe(log, 'revno: 3\n')
846
self.assertContainsRe(log, 'revno: 3.1.1\n')
847
self.assertNotContainsRe(log, 'revno: 4 ')
848
log = self.run_bzr('log -n0 -r4 file2')[0]
849
self.assertNotContainsRe(log, 'revno: 1\n')
850
self.assertNotContainsRe(log, 'revno: 2\n')
851
self.assertNotContainsRe(log, 'revno: 3\n')
852
self.assertContainsRe(log, 'revno: 3.1.1\n')
853
self.assertContainsRe(log, 'revno: 4 ')
854
log = self.run_bzr('log -n0 -r3.. file2')[0]
855
self.assertNotContainsRe(log, 'revno: 1\n')
856
self.assertNotContainsRe(log, 'revno: 2\n')
857
self.assertNotContainsRe(log, 'revno: 3\n')
858
self.assertContainsRe(log, 'revno: 3.1.1\n')
859
self.assertContainsRe(log, 'revno: 4 ')
860
log = self.run_bzr('log -n0 -r..3 file2')[0]
861
self.assertNotContainsRe(log, 'revno: 1\n')
862
self.assertContainsRe(log, 'revno: 2\n')
863
self.assertNotContainsRe(log, 'revno: 3\n')
864
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
865
self.assertNotContainsRe(log, 'revno: 4 ')
867
def test_log_file_historical_missing(self):
868
# Check logging a deleted file gives an error if the
869
# file isn't found at the end or start of the revision range
870
self.prepare_tree(complex=True)
871
err_msg = "Path unknown at end or start of revision range: file2"
872
err = self.run_bzr('log file2', retcode=3)[1]
873
self.assertContainsRe(err, err_msg)
875
def test_log_file_historical_end(self):
876
# Check logging a deleted file is ok if the file existed
877
# at the end the revision range
878
self.prepare_tree(complex=True)
879
log, err = self.run_bzr('log -n0 -r..4 file2')
880
self.assertEquals('', err)
881
self.assertNotContainsRe(log, 'revno: 1\n')
882
self.assertContainsRe(log, 'revno: 2\n')
883
self.assertNotContainsRe(log, 'revno: 3\n')
884
self.assertContainsRe(log, 'revno: 3.1.1\n')
885
self.assertContainsRe(log, 'revno: 4 ')
887
def test_log_file_historical_start(self):
888
# Check logging a deleted file is ok if the file existed
889
# at the start of the revision range
890
self.prepare_tree(complex=True)
891
log, err = self.run_bzr('log file1')
892
self.assertEquals('', err)
893
self.assertContainsRe(log, 'revno: 1\n')
894
self.assertNotContainsRe(log, 'revno: 2\n')
895
self.assertNotContainsRe(log, 'revno: 3\n')
896
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
897
self.assertNotContainsRe(log, 'revno: 4 ')
899
def test_log_file_renamed(self):
900
"""File matched against revision range, not current tree."""
901
self.prepare_tree(complex=True)
903
# Check logging a renamed file gives an error by default
904
err_msg = "Path unknown at end or start of revision range: file3"
905
err = self.run_bzr('log file3', retcode=3)[1]
906
self.assertContainsRe(err, err_msg)
908
# Check we can see a renamed file if we give the right end revision
909
log, err = self.run_bzr('log -r..4 file3')
910
self.assertEquals('', err)
911
self.assertNotContainsRe(log, 'revno: 1\n')
912
self.assertNotContainsRe(log, 'revno: 2\n')
913
self.assertContainsRe(log, 'revno: 3\n')
914
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
915
self.assertNotContainsRe(log, 'revno: 4 ')
917
def test_line_log_file(self):
918
"""The line log for a file should only list relevant mainline revs"""
919
# Note: this also implicitly covers the short logging case.
920
# We test using --line in preference to --short because matching
921
# revnos in the output of --line is more reliable.
924
# full history of file1
925
log = self.run_bzr('log --line file1')[0]
926
self.assertContainsRe(log, '^1:', re.MULTILINE)
927
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
928
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
929
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
930
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
932
# full history of file2
933
log = self.run_bzr('log --line file2')[0]
934
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
935
self.assertContainsRe(log, '^2:', re.MULTILINE)
936
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
937
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
938
self.assertContainsRe(log, '^4:', re.MULTILINE)
940
# full history of file3
941
log = self.run_bzr('log --line file3')[0]
942
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
943
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
944
self.assertContainsRe(log, '^3:', re.MULTILINE)
945
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
946
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
948
# file in a merge revision
949
log = self.run_bzr('log --line -r3.1.1 file2')[0]
950
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
951
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
952
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
953
self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
954
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
956
# file in a mainline revision
957
log = self.run_bzr('log --line -r4 file2')[0]
958
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
959
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
960
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
961
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
962
self.assertContainsRe(log, '^4:', re.MULTILINE)
964
# file since a revision
965
log = self.run_bzr('log --line -r3.. file2')[0]
966
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
967
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
968
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
969
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
970
self.assertContainsRe(log, '^4:', re.MULTILINE)
972
# file up to a revision
973
log = self.run_bzr('log --line -r..3 file2')[0]
974
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
975
self.assertContainsRe(log, '^2:', re.MULTILINE)
976
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
977
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
978
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
981
class TestLogMultiple(TestCaseWithTransport):
983
def prepare_tree(self):
984
tree = self.make_branch_and_tree('parent')
991
'parent/dir1/dir2/file3',
994
tree.commit('add file1')
996
tree.commit('add file2')
997
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
998
tree.commit('add file3')
1000
tree.commit('add file4')
1001
tree.add('dir1/file5')
1002
tree.commit('add file5')
1003
child_tree = tree.bzrdir.sprout('child').open_workingtree()
1004
self.build_tree_contents([('child/file2', 'hello')])
1005
child_tree.commit(message='branch 1')
1006
tree.merge_from_branch(child_tree.branch)
1007
tree.commit(message='merge child branch')
1010
def assertRevnos(self, paths_str, expected_revnos):
1011
# confirm the revision numbers in log --line output are those expected
1012
out, err = self.run_bzr('log --line -n0 %s' % (paths_str,))
1013
self.assertEqual('', err)
1014
revnos = [s.split(':', 1)[0].lstrip() for s in out.splitlines()]
1015
self.assertEqual(expected_revnos, revnos)
1017
def test_log_files(self):
1018
"""The log for multiple file should only list revs for those files"""
1020
self.assertRevnos('file1 file2 dir1/dir2/file3',
1021
['6', '5.1.1', '3', '2', '1'])
1023
def test_log_directory(self):
1024
"""The log for a directory should show all nested files."""
1026
self.assertRevnos('dir1', ['5', '3'])
1028
def test_log_nested_directory(self):
1029
"""The log for a directory should show all nested files."""
1031
self.assertRevnos('dir1/dir2', ['3'])
1033
def test_log_in_nested_directory(self):
1034
"""The log for a directory should show all nested files."""
1037
self.assertRevnos('.', ['5', '3'])
1039
def test_log_files_and_directories(self):
1040
"""Logging files and directories together should be fine."""
1042
self.assertRevnos('file4 dir1/dir2', ['4', '3'])
1044
def test_log_files_and_dirs_in_nested_directory(self):
1045
"""The log for a directory should show all nested files."""
1048
self.assertRevnos('dir2 file5', ['5', '3'])