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>
402
def test_force_merge_revisions_on(self):
403
self._prepare_short()
404
out,err = self.run_bzr('log --short -n0')
405
self.assertEqual('', err)
406
log = normalize_log(out)
407
self.assertEqualDiff(log, """\
408
2 Joe Foo\t2005-11-22 [merge]
411
1.1.2 Joe Foo\t2005-11-22 [merge]
414
1.2.1 Joe Foo\t2005-11-22
417
1.1.1 Joe Foo\t2005-11-22
420
1 Joe Foo\t2005-11-22
425
def test_include_merges(self):
426
# Confirm --include-merges gives the same output as -n0
427
self._prepare_short()
428
out_im, err_im = self.run_bzr('log --include-merges')
429
out_n0, err_n0 = self.run_bzr('log -n0')
430
self.assertEqual(err_im, err_n0)
431
self.assertEqual(out_im, out_n0)
433
def test_force_merge_revisions_N(self):
434
self._prepare_short()
435
out,err = self.run_bzr('log --short -n2')
436
self.assertEqual('', err)
437
log = normalize_log(out)
438
self.assertEqualDiff(log, """\
439
2 Joe Foo\t2005-11-22 [merge]
442
1.1.2 Joe Foo\t2005-11-22 [merge]
445
1.1.1 Joe Foo\t2005-11-22
448
1 Joe Foo\t2005-11-22
453
def test_merges_single_merge_rev(self):
455
out,err = self.run_bzr('log -n0 -r1.1.2')
456
self.assertEqual('', err)
457
log = normalize_log(out)
458
self.assertEqualDiff(log, """\
459
------------------------------------------------------------
461
committer: Lorem Ipsum <test@example.com>
466
------------------------------------------------------------
468
committer: Lorem Ipsum <test@example.com>
469
branch nick: smallerchild
475
def test_merges_partial_range(self):
477
out, err = self.run_bzr('log -n0 -r1.1.1..1.1.2')
478
self.assertEqual('', err)
479
log = normalize_log(out)
480
self.assertEqualDiff(log, """\
481
------------------------------------------------------------
483
committer: Lorem Ipsum <test@example.com>
488
------------------------------------------------------------
490
committer: Lorem Ipsum <test@example.com>
491
branch nick: smallerchild
495
------------------------------------------------------------
497
committer: Lorem Ipsum <test@example.com>
505
def subst_dates(string):
506
"""Replace date strings with constant values."""
507
return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
508
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
511
class TestLogDiff(TestCaseWithoutPropsHandler):
514
parent_tree = self.make_branch_and_tree('parent')
515
self.build_tree(['parent/file1', 'parent/file2'])
516
parent_tree.add('file1')
517
parent_tree.add('file2')
518
parent_tree.commit(message='first post',
519
timestamp=1132586655, timezone=36000,
520
committer='Lorem Ipsum <test@example.com>')
521
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
522
self.build_tree_contents([('child/file2', 'hello\n')])
523
child_tree.commit(message='branch 1',
524
timestamp=1132586700, timezone=36000,
525
committer='Lorem Ipsum <test@example.com>')
526
parent_tree.merge_from_branch(child_tree.branch)
527
parent_tree.commit(message='merge branch 1',
528
timestamp=1132586800, timezone=36000,
529
committer='Lorem Ipsum <test@example.com>')
532
def test_log_show_diff_long_with_merges(self):
534
out,err = self.run_bzr('log -p -n0')
535
self.assertEqual('', err)
536
log = normalize_log(out)
537
self.assertEqualDiff(subst_dates(log), """\
538
------------------------------------------------------------
540
committer: Lorem Ipsum <test@example.com>
546
=== modified file 'file2'
547
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
548
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
550
-contents of parent/file2
552
------------------------------------------------------------
554
committer: Lorem Ipsum <test@example.com>
560
=== modified file 'file2'
561
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
562
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
564
-contents of parent/file2
566
------------------------------------------------------------
568
committer: Lorem Ipsum <test@example.com>
574
=== added file 'file1'
575
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
576
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
578
+contents of parent/file1
580
=== added file 'file2'
581
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
582
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
584
+contents of parent/file2
587
def test_log_show_diff_short(self):
589
out,err = self.run_bzr('log -p --short')
590
self.assertEqual('', err)
591
log = normalize_log(out)
592
self.assertEqualDiff(subst_dates(log), """\
593
2 Lorem Ipsum\t2005-11-22 [merge]
595
=== modified file 'file2'
596
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
597
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
599
-contents of parent/file2
602
1 Lorem Ipsum\t2005-11-22
604
=== added file 'file1'
605
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
606
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
608
+contents of parent/file1
609
\x20\x20\x20\x20\x20\x20
610
=== added file 'file2'
611
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
612
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
614
+contents of parent/file2
616
Use --include-merges or -n0 to see merged revisions.
619
def test_log_show_diff_line(self):
621
out,err = self.run_bzr('log -p --line')
622
self.assertEqual('', err)
623
log = normalize_log(out)
624
# Not supported by this formatter so expect plain output
625
self.assertEqualDiff(subst_dates(log), """\
626
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
627
1: Lorem Ipsum 2005-11-22 first post
630
def test_log_show_diff_file(self):
631
"""Only the diffs for the given file are to be shown"""
633
out,err = self.run_bzr('log -p --short file2')
634
self.assertEqual('', err)
635
log = normalize_log(out)
636
self.assertEqualDiff(subst_dates(log), """\
637
2 Lorem Ipsum\t2005-11-22 [merge]
639
=== modified file 'file2'
640
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
641
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
643
-contents of parent/file2
646
1 Lorem Ipsum\t2005-11-22
648
=== added file 'file2'
649
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
650
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
652
+contents of parent/file2
654
Use --include-merges or -n0 to see merged revisions.
656
out,err = self.run_bzr('log -p --short file1')
657
self.assertEqual('', err)
658
log = normalize_log(out)
659
self.assertEqualDiff(subst_dates(log), """\
660
1 Lorem Ipsum\t2005-11-22
662
=== added file 'file1'
663
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
664
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
666
+contents of parent/file1
670
def test_log_show_diff_non_ascii(self):
671
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
672
message = u'Message with \xb5'
673
body = 'Body with \xb5\n'
674
wt = self.make_branch_and_tree('.')
675
self.build_tree_contents([('foo', body)])
677
wt.commit(message=message)
678
# check that command won't fail with unicode error
679
# don't care about exact output because we have other tests for this
680
out,err = self.run_bzr('log -p --long')
681
self.assertNotEqual('', out)
682
self.assertEqual('', err)
683
out,err = self.run_bzr('log -p --short')
684
self.assertNotEqual('', out)
685
self.assertEqual('', err)
686
out,err = self.run_bzr('log -p --line')
687
self.assertNotEqual('', out)
688
self.assertEqual('', err)
691
class TestLogEncodings(TestCaseInTempDir):
694
_message = u'Message with \xb5'
696
# Encodings which can encode mu
701
'cp437', # Common windows encoding
702
'cp1251', # Russian windows encoding
703
'cp1258', # Common windows encoding
705
# Encodings which cannot encode mu
713
TestCaseInTempDir.setUp(self)
714
self.user_encoding = osutils._cached_user_encoding
717
osutils._cached_user_encoding = self.user_encoding
718
TestCaseInTempDir.tearDown(self)
720
def create_branch(self):
723
open('a', 'wb').write('some stuff\n')
725
bzr(['commit', '-m', self._message])
727
def try_encoding(self, encoding, fail=False):
730
self.assertRaises(UnicodeEncodeError,
731
self._mu.encode, encoding)
732
encoded_msg = self._message.encode(encoding, 'replace')
734
encoded_msg = self._message.encode(encoding)
736
old_encoding = osutils._cached_user_encoding
737
# This test requires that 'run_bzr' uses the current
738
# bzrlib, because we override user_encoding, and expect
741
osutils._cached_user_encoding = 'ascii'
742
# We should be able to handle any encoding
743
out, err = bzr('log', encoding=encoding)
745
# Make sure we wrote mu as we expected it to exist
746
self.assertNotEqual(-1, out.find(encoded_msg))
747
out_unicode = out.decode(encoding)
748
self.assertNotEqual(-1, out_unicode.find(self._message))
750
self.assertNotEqual(-1, out.find('Message with ?'))
752
osutils._cached_user_encoding = old_encoding
754
def test_log_handles_encoding(self):
757
for encoding in self.good_encodings:
758
self.try_encoding(encoding)
760
def test_log_handles_bad_encoding(self):
763
for encoding in self.bad_encodings:
764
self.try_encoding(encoding, fail=True)
766
def test_stdout_encoding(self):
768
osutils._cached_user_encoding = "cp1251"
771
self.build_tree(['a'])
773
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
774
stdout, stderr = self.run_bzr('log', encoding='cp866')
776
message = stdout.splitlines()[-1]
778
# explanation of the check:
779
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
780
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
781
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
782
# This test should check that output of log command
783
# encoded to sys.stdout.encoding
784
test_in_cp866 = '\x92\xa5\xe1\xe2'
785
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
786
# Make sure the log string is encoded in cp866
787
self.assertEquals(test_in_cp866, message[2:])
788
# Make sure the cp1251 string is not found anywhere
789
self.assertEquals(-1, stdout.find(test_in_cp1251))
792
class TestLogFile(TestCaseWithTransport):
794
def test_log_local_branch_file(self):
795
"""We should be able to log files in local treeless branches"""
796
tree = self.make_branch_and_tree('tree')
797
self.build_tree(['tree/file'])
799
tree.commit('revision 1')
800
tree.bzrdir.destroy_workingtree()
801
self.run_bzr('log tree/file')
803
def prepare_tree(self, complex=False):
804
# The complex configuration includes deletes and renames
805
tree = self.make_branch_and_tree('parent')
806
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
808
tree.commit('add file1')
810
tree.commit('add file2')
812
tree.commit('add file3')
813
child_tree = tree.bzrdir.sprout('child').open_workingtree()
814
self.build_tree_contents([('child/file2', 'hello')])
815
child_tree.commit(message='branch 1')
816
tree.merge_from_branch(child_tree.branch)
817
tree.commit(message='merge child branch')
820
tree.commit('remove file2')
821
tree.rename_one('file3', 'file4')
822
tree.commit('file3 is now called file4')
824
tree.commit('remove file1')
827
def test_log_file(self):
828
"""The log for a particular file should only list revs for that file"""
830
log = self.run_bzr('log -n0 file1')[0]
831
self.assertContainsRe(log, 'revno: 1\n')
832
self.assertNotContainsRe(log, 'revno: 2\n')
833
self.assertNotContainsRe(log, 'revno: 3\n')
834
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
835
self.assertNotContainsRe(log, 'revno: 4 ')
836
log = self.run_bzr('log -n0 file2')[0]
837
self.assertNotContainsRe(log, 'revno: 1\n')
838
self.assertContainsRe(log, 'revno: 2\n')
839
self.assertNotContainsRe(log, 'revno: 3\n')
840
self.assertContainsRe(log, 'revno: 3.1.1\n')
841
self.assertContainsRe(log, 'revno: 4 ')
842
log = self.run_bzr('log -n0 file3')[0]
843
self.assertNotContainsRe(log, 'revno: 1\n')
844
self.assertNotContainsRe(log, 'revno: 2\n')
845
self.assertContainsRe(log, 'revno: 3\n')
846
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
847
self.assertNotContainsRe(log, 'revno: 4 ')
848
log = self.run_bzr('log -n0 -r3.1.1 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.assertNotContainsRe(log, 'revno: 4 ')
854
log = self.run_bzr('log -n0 -r4 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 -r3.. file2')[0]
861
self.assertNotContainsRe(log, 'revno: 1\n')
862
self.assertNotContainsRe(log, 'revno: 2\n')
863
self.assertNotContainsRe(log, 'revno: 3\n')
864
self.assertContainsRe(log, 'revno: 3.1.1\n')
865
self.assertContainsRe(log, 'revno: 4 ')
866
log = self.run_bzr('log -n0 -r..3 file2')[0]
867
self.assertNotContainsRe(log, 'revno: 1\n')
868
self.assertContainsRe(log, 'revno: 2\n')
869
self.assertNotContainsRe(log, 'revno: 3\n')
870
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
871
self.assertNotContainsRe(log, 'revno: 4 ')
873
def test_log_file_historical_missing(self):
874
# Check logging a deleted file gives an error if the
875
# file isn't found at the end or start of the revision range
876
self.prepare_tree(complex=True)
877
err_msg = "Path unknown at end or start of revision range: file2"
878
err = self.run_bzr('log file2', retcode=3)[1]
879
self.assertContainsRe(err, err_msg)
881
def test_log_file_historical_end(self):
882
# Check logging a deleted file is ok if the file existed
883
# at the end the revision range
884
self.prepare_tree(complex=True)
885
log, err = self.run_bzr('log -n0 -r..4 file2')
886
self.assertEquals('', err)
887
self.assertNotContainsRe(log, 'revno: 1\n')
888
self.assertContainsRe(log, 'revno: 2\n')
889
self.assertNotContainsRe(log, 'revno: 3\n')
890
self.assertContainsRe(log, 'revno: 3.1.1\n')
891
self.assertContainsRe(log, 'revno: 4 ')
893
def test_log_file_historical_start(self):
894
# Check logging a deleted file is ok if the file existed
895
# at the start of the revision range
896
self.prepare_tree(complex=True)
897
log, err = self.run_bzr('log file1')
898
self.assertEquals('', err)
899
self.assertContainsRe(log, 'revno: 1\n')
900
self.assertNotContainsRe(log, 'revno: 2\n')
901
self.assertNotContainsRe(log, 'revno: 3\n')
902
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
903
self.assertNotContainsRe(log, 'revno: 4 ')
905
def test_log_file_renamed(self):
906
"""File matched against revision range, not current tree."""
907
self.prepare_tree(complex=True)
909
# Check logging a renamed file gives an error by default
910
err_msg = "Path unknown at end or start of revision range: file3"
911
err = self.run_bzr('log file3', retcode=3)[1]
912
self.assertContainsRe(err, err_msg)
914
# Check we can see a renamed file if we give the right end revision
915
log, err = self.run_bzr('log -r..4 file3')
916
self.assertEquals('', err)
917
self.assertNotContainsRe(log, 'revno: 1\n')
918
self.assertNotContainsRe(log, 'revno: 2\n')
919
self.assertContainsRe(log, 'revno: 3\n')
920
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
921
self.assertNotContainsRe(log, 'revno: 4 ')
923
def test_line_log_file(self):
924
"""The line log for a file should only list relevant mainline revs"""
925
# Note: this also implicitly covers the short logging case.
926
# We test using --line in preference to --short because matching
927
# revnos in the output of --line is more reliable.
930
# full history of file1
931
log = self.run_bzr('log --line file1')[0]
932
self.assertContainsRe(log, '^1:', re.MULTILINE)
933
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
934
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
935
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
936
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
938
# full history of file2
939
log = self.run_bzr('log --line file2')[0]
940
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
941
self.assertContainsRe(log, '^2:', re.MULTILINE)
942
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
943
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
944
self.assertContainsRe(log, '^4:', re.MULTILINE)
946
# full history of file3
947
log = self.run_bzr('log --line file3')[0]
948
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
949
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
950
self.assertContainsRe(log, '^3:', re.MULTILINE)
951
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
952
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
954
# file in a merge revision
955
log = self.run_bzr('log --line -r3.1.1 file2')[0]
956
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
957
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
958
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
959
self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
960
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
962
# file in a mainline revision
963
log = self.run_bzr('log --line -r4 file2')[0]
964
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
965
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
966
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
967
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
968
self.assertContainsRe(log, '^4:', re.MULTILINE)
970
# file since a revision
971
log = self.run_bzr('log --line -r3.. file2')[0]
972
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
973
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
974
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
975
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
976
self.assertContainsRe(log, '^4:', re.MULTILINE)
978
# file up to a revision
979
log = self.run_bzr('log --line -r..3 file2')[0]
980
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
981
self.assertContainsRe(log, '^2:', re.MULTILINE)
982
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
983
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
984
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
987
class TestLogMultiple(TestCaseWithTransport):
989
def prepare_tree(self):
990
tree = self.make_branch_and_tree('parent')
997
'parent/dir1/dir2/file3',
1000
tree.commit('add file1')
1002
tree.commit('add file2')
1003
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
1004
tree.commit('add file3')
1006
tree.commit('add file4')
1007
tree.add('dir1/file5')
1008
tree.commit('add file5')
1009
child_tree = tree.bzrdir.sprout('child').open_workingtree()
1010
self.build_tree_contents([('child/file2', 'hello')])
1011
child_tree.commit(message='branch 1')
1012
tree.merge_from_branch(child_tree.branch)
1013
tree.commit(message='merge child branch')
1016
def assertRevnos(self, paths_str, expected_revnos):
1017
# confirm the revision numbers in log --line output are those expected
1018
out, err = self.run_bzr('log --line -n0 %s' % (paths_str,))
1019
self.assertEqual('', err)
1020
revnos = [s.split(':', 1)[0].lstrip() for s in out.splitlines()]
1021
self.assertEqual(expected_revnos, revnos)
1023
def test_log_files(self):
1024
"""The log for multiple file should only list revs for those files"""
1026
self.assertRevnos('file1 file2 dir1/dir2/file3',
1027
['6', '5.1.1', '3', '2', '1'])
1029
def test_log_directory(self):
1030
"""The log for a directory should show all nested files."""
1032
self.assertRevnos('dir1', ['5', '3'])
1034
def test_log_nested_directory(self):
1035
"""The log for a directory should show all nested files."""
1037
self.assertRevnos('dir1/dir2', ['3'])
1039
def test_log_in_nested_directory(self):
1040
"""The log for a directory should show all nested files."""
1043
self.assertRevnos('.', ['5', '3'])
1045
def test_log_files_and_directories(self):
1046
"""Logging files and directories together should be fine."""
1048
self.assertRevnos('file4 dir1/dir2', ['4', '3'])
1050
def test_log_files_and_dirs_in_nested_directory(self):
1051
"""The log for a directory should show all nested files."""
1054
self.assertRevnos('dir2 file5', ['5', '3'])