/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2013, 2016 Canonical Ltd
1685.1.80 by Wouter van Heyst
more code cleanup
2
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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.
1685.1.80 by Wouter van Heyst
more code cleanup
7
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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.
1685.1.80 by Wouter van Heyst
more code cleanup
12
#
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
16
17
import os
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
20
    branchbuilder,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
21
    errors,
22
    log,
23
    registry,
24
    revision,
25
    revisionspec,
26
    tests,
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
27
    gpg,
28
    trace,
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
31
    BytesIO,
32
    )
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
33
34
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
35
class TestLogMixin(object):
36
37
    def wt_commit(self, wt, message, **kwargs):
38
        """Use some mostly fixed values for commits to simplify tests.
39
40
        Tests can use this function to get some commit attributes. The time
41
        stamp is incremented at each commit.
42
        """
43
        if getattr(self, 'timestamp', None) is None:
44
            self.timestamp = 1132617600 # Mon 2005-11-22 00:00:00 +0000
45
        else:
46
            self.timestamp += 1 # 1 second between each commit
47
        kwargs.setdefault('timestamp', self.timestamp)
48
        kwargs.setdefault('timezone', 0) # UTC
49
        kwargs.setdefault('committer', 'Joe Foo <joe@foo.com>')
50
51
        return wt.commit(message, **kwargs)
52
53
54
class TestCaseForLogFormatter(tests.TestCaseWithTransport, TestLogMixin):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
55
56
    def setUp(self):
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
57
        super(TestCaseForLogFormatter, self).setUp()
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
58
        # keep a reference to the "current" custom prop. handler registry
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
59
        self.properties_handler_registry = log.properties_handler_registry
4325.4.3 by Vincent Ladeuil
More cleanups.
60
        # Use a clean registry for log
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
61
        log.properties_handler_registry = registry.Registry()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
62
4325.4.3 by Vincent Ladeuil
More cleanups.
63
        def restore():
64
            log.properties_handler_registry = self.properties_handler_registry
65
        self.addCleanup(restore)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
66
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
67
    def assertFormatterResult(self, result, branch, formatter_class,
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
68
                              formatter_kwargs=None, show_log_kwargs=None):
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
69
        logfile = self.make_utf8_encoded_stringio()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
70
        if formatter_kwargs is None:
71
            formatter_kwargs = {}
72
        formatter = formatter_class(to_file=logfile, **formatter_kwargs)
73
        if show_log_kwargs is None:
74
            show_log_kwargs = {}
75
        log.show_log(branch, formatter, **show_log_kwargs)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
76
        self.assertEqualDiff(result, logfile.getvalue())
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
77
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
78
    def make_standard_commit(self, branch_nick, **kwargs):
79
        wt = self.make_branch_and_tree('.')
80
        wt.lock_write()
81
        self.addCleanup(wt.unlock)
82
        self.build_tree(['a'])
83
        wt.add(['a'])
84
        wt.branch.nick = branch_nick
85
        kwargs.setdefault('committer', 'Lorem Ipsum <test@example.com>')
86
        kwargs.setdefault('authors', ['John Doe <jdoe@example.com>'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
87
        self.wt_commit(wt, 'add a', **kwargs)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
88
        return wt
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
89
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
90
    def make_commits_with_trailing_newlines(self, wt):
91
        """Helper method for LogFormatter tests"""
92
        b = wt.branch
93
        b.nick = 'test'
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
94
        self.build_tree_contents([('a', 'hello moto\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
95
        self.wt_commit(wt, 'simple log message', rev_id='a1')
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
96
        self.build_tree_contents([('b', 'goodbye\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
97
        wt.add('b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
98
        self.wt_commit(wt, 'multiline\nlog\nmessage\n', rev_id='a2')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
99
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
100
        self.build_tree_contents([('c', 'just another manic monday\n')])
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
101
        wt.add('c')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
102
        self.wt_commit(wt, 'single line with trailing newline\n', rev_id='a3')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
103
        return b
104
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
105
    def _prepare_tree_with_merges(self, with_tags=False):
106
        wt = self.make_branch_and_memory_tree('.')
107
        wt.lock_write()
108
        self.addCleanup(wt.unlock)
109
        wt.add('')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
110
        self.wt_commit(wt, 'rev-1', rev_id='rev-1')
111
        self.wt_commit(wt, 'rev-merged', rev_id='rev-2a')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
112
        wt.set_parent_ids(['rev-1', 'rev-2a'])
113
        wt.branch.set_last_revision_info(1, 'rev-1')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
114
        self.wt_commit(wt, 'rev-2', rev_id='rev-2b')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
115
        if with_tags:
116
            branch = wt.branch
117
            branch.tags.set_tag('v0.2', 'rev-2b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
118
            self.wt_commit(wt, 'rev-3', rev_id='rev-3')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
119
            branch.tags.set_tag('v1.0rc1', 'rev-3')
120
            branch.tags.set_tag('v1.0', 'rev-3')
121
        return wt
122
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
123
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
124
class LogCatcher(log.LogFormatter):
4325.4.3 by Vincent Ladeuil
More cleanups.
125
    """Pull log messages into a list rather than displaying them.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
126
4325.4.3 by Vincent Ladeuil
More cleanups.
127
    To simplify testing we save logged revisions here rather than actually
4325.4.1 by Vincent Ladeuil
Some cleanups.
128
    formatting anything, so that we can precisely check the result without
4325.4.3 by Vincent Ladeuil
More cleanups.
129
    being dependent on the formatting.
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
130
    """
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
131
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
132
    supports_merge_revisions = True
2490.1.2 by John Arbash Meinel
Cleanup according to PEP8 and some other small whitespace fixes
133
    supports_delta = True
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
134
    supports_diff = True
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
135
    preferred_levels = 0
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
136
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
137
    def __init__(self, *args, **kwargs):
138
        kwargs.update(dict(to_file=None))
139
        super(LogCatcher, self).__init__(*args, **kwargs)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
140
        self.revisions = []
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
141
2466.8.1 by Kent Gibson
Reworked LogFormatter API to simplify extending the attributes of the revision being logged. Added support for begin_log() and end_log() hooks in LogFormatters.
142
    def log_revision(self, revision):
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
143
        self.revisions.append(revision)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
144
145
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
146
class TestShowLog(tests.TestCaseWithTransport):
1102 by Martin Pool
- merge test refactoring from robertc
147
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
148
    def checkDelta(self, delta, **kw):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
149
        """Check the filenames touched by a delta are as expected.
150
151
        Caller only have to pass in the list of files for each part, all
152
        unspecified parts are considered empty (and checked as such).
153
        """
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
154
        for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
155
            # By default we expect an empty list
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
156
            expected = kw.get(n, [])
157
            # strip out only the path components
158
            got = [x[0] for x in getattr(delta, n)]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
159
            self.assertEqual(expected, got)
160
161
    def assertInvalidRevisonNumber(self, br, start, end):
162
        lf = LogCatcher()
163
        self.assertRaises(errors.InvalidRevisionNumber,
164
                          log.show_log, br, lf,
165
                          start_revision=start, end_revision=end)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
166
974.1.54 by aaron.bentley at utoronto
Fixed the revno bug in log
167
    def test_cur_revno(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
168
        wt = self.make_branch_and_tree('.')
169
        b = wt.branch
1092.3.4 by Robert Collins
update symlink branch to integration
170
171
        lf = LogCatcher()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
172
        wt.commit('empty commit')
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
173
        log.show_log(b, lf, verbose=True, start_revision=1, end_revision=1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
174
175
        # Since there is a single revision in the branch all the combinations
176
        # below should fail.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
177
        self.assertInvalidRevisonNumber(b, 2, 1)
178
        self.assertInvalidRevisonNumber(b, 1, 2)
179
        self.assertInvalidRevisonNumber(b, 0, 2)
180
        self.assertInvalidRevisonNumber(b, 1, 0)
181
        self.assertInvalidRevisonNumber(b, -1, 1)
182
        self.assertInvalidRevisonNumber(b, 1, -1)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
183
184
    def test_empty_branch(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
185
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
186
187
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
188
        log.show_log(wt.branch, lf)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
189
        # no entries yet
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
190
        self.assertEqual([], lf.revisions)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
191
192
    def test_empty_commit(self):
193
        wt = self.make_branch_and_tree('.')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
194
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
195
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
196
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
197
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
198
        revs = lf.revisions
199
        self.assertEqual(1, len(revs))
200
        self.assertEqual('1', revs[0].revno)
201
        self.assertEqual('empty commit', revs[0].rev.message)
202
        self.checkDelta(revs[0].delta)
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
203
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
204
    def test_simple_commit(self):
205
        wt = self.make_branch_and_tree('.')
206
        wt.commit('empty commit')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
207
        self.build_tree(['hello'])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
208
        wt.add('hello')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
209
        wt.commit('add one file',
210
                  committer=u'\u013d\xf3r\xe9m \xcdp\u0161\xfam '
211
                            u'<test@example.com>')
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
212
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
213
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
214
        self.assertEqual(2, len(lf.revisions))
974.1.26 by aaron.bentley at utoronto
merged mbp@sourcefrog.net-20050817233101-0939da1cf91f2472
215
        # first one is most recent
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
216
        log_entry = lf.revisions[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
217
        self.assertEqual('2', log_entry.revno)
218
        self.assertEqual('add one file', log_entry.rev.message)
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
219
        self.checkDelta(log_entry.delta, added=['hello'])
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
220
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
221
    def test_commit_message_with_control_chars(self):
222
        wt = self.make_branch_and_tree('.')
3831.1.6 by John Arbash Meinel
For the simple-log tests, avoid using '\r' in the test.
223
        msg = u"All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)])
224
        msg = msg.replace(u'\r', u'\n')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
225
        wt.commit(msg)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
226
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
227
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
228
        committed_msg = lf.revisions[0].rev.message
4627.1.1 by Robert Collins
Review feedback per IanC.
229
        if wt.branch.repository._serializer.squashes_xml_invalid_characters:
230
            self.assertNotEqual(msg, committed_msg)
231
            self.assertTrue(len(committed_msg) > len(msg))
232
        else:
233
            self.assertEqual(msg, committed_msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
234
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
235
    def test_commit_message_without_control_chars(self):
236
        wt = self.make_branch_and_tree('.')
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
237
        # escaped.  As ElementTree apparently does some kind of
238
        # newline conversion, neither LF (\x0A) nor CR (\x0D) are
239
        # included in the test commit message, even though they are
240
        # valid XML 1.0 characters.
241
        msg = "\x09" + ''.join([unichr(x) for x in range(0x20, 256)])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
242
        wt.commit(msg)
1393.4.2 by Harald Meland
Cleanup + better test of commit-msg control character escape code.
243
        lf = LogCatcher()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
244
        log.show_log(wt.branch, lf, verbose=True)
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
245
        committed_msg = lf.revisions[0].rev.message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
246
        self.assertEqual(msg, committed_msg)
1185.31.22 by John Arbash Meinel
[merge] bzr.dev
247
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
248
    def test_deltas_in_merge_revisions(self):
249
        """Check deltas created for both mainline and merge revisions"""
250
        wt = self.make_branch_and_tree('parent')
251
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
252
        wt.add('file1')
253
        wt.add('file2')
254
        wt.commit(message='add file1 and file2')
2581.1.6 by Martin Pool
fix up more run_bzr callers
255
        self.run_bzr('branch parent child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
256
        os.unlink('child/file1')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
257
        with file('child/file2', 'wb') as f: f.write('hello\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
258
        self.run_bzr(['commit', '-m', 'remove file1 and modify file2',
259
            'child'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
260
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
261
        self.run_bzr('merge ../child')
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
262
        wt.commit('merge child branch')
263
        os.chdir('..')
264
        b = wt.branch
265
        lf = LogCatcher()
266
        lf.supports_merge_revisions = True
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
267
        log.show_log(b, lf, verbose=True)
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
268
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
269
        revs = lf.revisions
270
        self.assertEqual(3, len(revs))
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
271
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
272
        logentry = revs[0]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
273
        self.assertEqual('2', logentry.revno)
274
        self.assertEqual('merge child branch', logentry.rev.message)
275
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
276
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
277
        logentry = revs[1]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
278
        self.assertEqual('1.1.1', logentry.revno)
279
        self.assertEqual('remove file1 and modify file2', logentry.rev.message)
280
        self.checkDelta(logentry.delta, removed=['file1'], modified=['file2'])
281
4325.4.4 by Vincent Ladeuil
Clarify LogCatcher purpose.
282
        logentry = revs[2]
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
283
        self.assertEqual('1', logentry.revno)
284
        self.assertEqual('add file1 and file2', logentry.rev.message)
285
        self.checkDelta(logentry.delta, added=['file1', 'file2'])
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
286
287
6583.4.5 by Reagan Sanders
Added a test case covering the possibility of UTF-8 characters within the name portion of a GPG key. This can happen during a 'bzr log --signatures' command.
288
class TestFormatSignatureValidity(tests.TestCaseWithTransport):
289
    class UTFLoopbackGPGStrategy(gpg.LoopbackGPGStrategy):
290
        def verify(self, content, testament):
291
            return (gpg.SIGNATURE_VALID,
292
                u'UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>')
293
294
    def has_signature_for_revision_id(self, revision_id):
295
        return True
296
297
    def get_signature_text(self, revision_id):
298
        return ''
299
300
    def test_format_signature_validity_utf(self):
301
        """Check that GPG signatures containing UTF-8 names are formatted
302
        correctly."""
303
        # Monkey patch to use our UTF-8 generating GPGStrategy
304
        self.overrideAttr(gpg, 'GPGStrategy', self.UTFLoopbackGPGStrategy)
305
        wt = self.make_branch_and_tree('.')
306
        revid = wt.commit('empty commit')
307
        repo = wt.branch.repository
308
        # Monkey patch out checking if this rev is actually signed, since we
309
        # can't sign it without a heavier TestCase and LoopbackGPGStrategy
310
        # doesn't care anyways.
311
        self.overrideAttr(repo, 'has_signature_for_revision_id',
312
                self.has_signature_for_revision_id)
313
        self.overrideAttr(repo, 'get_signature_text', self.get_signature_text)
314
        out = log.format_signature_validity(revid, repo)
315
        self.assertEqual(
316
u'valid signature from UTF8 Test \xa1\xb1\xc1\xd1\xe1\xf1 <jrandom@example.com>',
317
                out)
318
319
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
320
class TestShortLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
321
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
322
    def test_trailing_newlines(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
323
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
324
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
325
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
326
    3 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
327
      single line with trailing newline
328
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
329
    2 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
330
      multiline
331
      log
332
      message
333
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
334
    1 Joe Foo\t2005-11-22
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
335
      simple log message
336
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
337
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
338
            b, log.ShortLogFormatter)
1185.31.21 by John Arbash Meinel
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.
339
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
340
    def test_short_log_with_merges(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
341
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
342
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
343
    2 Joe Foo\t2005-11-22 [merge]
344
      rev-2
345
346
    1 Joe Foo\t2005-11-22
347
      rev-1
348
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
349
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
350
            wt.branch, log.ShortLogFormatter)
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
351
352
    def test_short_log_with_merges_and_advice(self):
353
        wt = self._prepare_tree_with_merges()
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
354
        self.assertFormatterResult("""\
4221.2.3 by Ian Clatworthy
jam feedback: don't show advice if --levels explicitly given
355
    2 Joe Foo\t2005-11-22 [merge]
356
      rev-2
357
358
    1 Joe Foo\t2005-11-22
359
      rev-1
360
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
361
Use --include-merged or -n0 to see merged revisions.
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
362
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
363
            wt.branch, log.ShortLogFormatter,
364
            formatter_kwargs=dict(show_advice=True))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
365
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
366
    def test_short_log_with_merges_and_range(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
367
        wt = self._prepare_tree_with_merges()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
368
        self.wt_commit(wt, 'rev-3a', rev_id='rev-3a')
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
369
        wt.branch.set_last_revision_info(2, 'rev-2b')
370
        wt.set_parent_ids(['rev-2b', 'rev-3a'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
371
        self.wt_commit(wt, 'rev-3b', rev_id='rev-3b')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
372
        self.assertFormatterResult("""\
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
373
    3 Joe Foo\t2005-11-22 [merge]
374
      rev-3b
375
376
    2 Joe Foo\t2005-11-22 [merge]
4955.4.19 by Vincent Ladeuil
Less code duplication.
377
      rev-2
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
378
379
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
380
            wt.branch, log.ShortLogFormatter,
381
            show_log_kwargs=dict(start_revision=2, end_revision=3))
3943.4.2 by John Arbash Meinel
Add a test case which exercises this code path.
382
3946.3.2 by Ian Clatworthy
add tests & NEWS item
383
    def test_short_log_with_tags(self):
384
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
385
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
386
    3 Joe Foo\t2005-11-22 {v1.0, v1.0rc1}
3946.3.2 by Ian Clatworthy
add tests & NEWS item
387
      rev-3
388
389
    2 Joe Foo\t2005-11-22 {v0.2} [merge]
390
      rev-2
391
392
    1 Joe Foo\t2005-11-22
393
      rev-1
394
395
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
396
            wt.branch, log.ShortLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
397
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
398
    def test_short_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
399
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
400
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
401
        rev = revspec.in_history(wt.branch)
402
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
403
      1.1.1 Joe Foo\t2005-11-22
404
            rev-merged
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
405
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
406
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
407
            wt.branch, log.ShortLogFormatter,
408
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
409
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
410
    def test_show_ids(self):
411
        wt = self.make_branch_and_tree('parent')
412
        self.build_tree(['parent/f1', 'parent/f2'])
413
        wt.add(['f1','f2'])
414
        self.wt_commit(wt, 'first post', rev_id='a')
415
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
416
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
417
        wt.merge_from_branch(child_wt.branch)
418
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
419
        self.assertFormatterResult("""\
420
    2 Joe Foo\t2005-11-22 [merge]
421
      revision-id:c
422
      merge branch 1
423
424
          1.1.1 Joe Foo\t2005-11-22
425
                revision-id:b
426
                branch 1 changes
427
428
    1 Joe Foo\t2005-11-22
429
      revision-id:a
430
      first post
431
432
""",
433
            wt.branch, log.ShortLogFormatter,
434
            formatter_kwargs=dict(levels=0,show_ids=True))
435
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
436
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
437
class TestShortLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
438
439
    def test_short_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
440
        wt = self._prepare_tree_with_merges()
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
441
        # Note that the 1.1.1 indenting is in fact correct given that
442
        # the revision numbers are right justified within 5 characters
443
        # for mainline revnos and 9 characters for dotted revnos.
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
444
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
445
    2 Joe Foo\t2005-11-22 [merge]
446
      rev-2
447
3947.1.10 by Ian Clatworthy
review feedback from vila
448
          1.1.1 Joe Foo\t2005-11-22
449
                rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
450
451
    1 Joe Foo\t2005-11-22
452
      rev-1
453
454
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
455
            wt.branch, log.ShortLogFormatter,
456
            formatter_kwargs=dict(levels=0))
3947.1.2 by Ian Clatworthy
formatter tests
457
458
    def test_short_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
459
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
460
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
461
        rev = revspec.in_history(wt.branch)
462
        self.assertFormatterResult("""\
3947.1.10 by Ian Clatworthy
review feedback from vila
463
      1.1.1 Joe Foo\t2005-11-22
464
            rev-merged
3947.1.2 by Ian Clatworthy
formatter tests
465
466
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
467
            wt.branch, log.ShortLogFormatter,
468
            formatter_kwargs=dict(levels=0),
469
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
470
471
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
472
class TestLongLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
473
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
474
    def test_verbose_log(self):
475
        """Verbose log includes changed files
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
476
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
477
        bug #4676
478
        """
4857.4.4 by John Arbash Meinel
One more standard-commit
479
        wt = self.make_standard_commit('test_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
480
        self.assertFormatterResult('''\
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
481
------------------------------------------------------------
482
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
483
committer: Lorem Ipsum <test@example.com>
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
484
branch nick: test_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
485
timestamp: Tue 2005-11-22 00:00:00 +0000
1185.33.41 by Martin Pool
Fix regression of 'bzr log -v' - it wasn't showing changed files at all. (#4676)
486
message:
487
  add a
488
added:
489
  a
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
490
''',
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
491
            wt.branch, log.LongLogFormatter,
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
492
            show_log_kwargs=dict(verbose=True))
1185.85.4 by John Arbash Meinel
currently broken, trying to fix things up.
493
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
494
    def test_merges_are_indented_by_level(self):
495
        wt = self.make_branch_and_tree('parent')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
496
        self.wt_commit(wt, 'first post')
497
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
498
        self.wt_commit(child_wt, 'branch 1')
499
        smallerchild_wt = wt.bzrdir.sprout('smallerchild').open_workingtree()
500
        self.wt_commit(smallerchild_wt, 'branch 2')
501
        child_wt.merge_from_branch(smallerchild_wt.branch)
502
        self.wt_commit(child_wt, 'merge branch 2')
503
        wt.merge_from_branch(child_wt.branch)
504
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
505
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
506
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
507
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
508
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
509
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
510
timestamp: Tue 2005-11-22 00:00:04 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
511
message:
512
  merge branch 1
513
    ------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
514
    revno: 1.1.2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
515
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
516
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
517
    timestamp: Tue 2005-11-22 00:00:03 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
518
    message:
519
      merge branch 2
520
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
521
        revno: 1.2.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
522
        committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
523
        branch nick: smallerchild
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
524
        timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
525
        message:
526
          branch 2
527
    ------------------------------------------------------------
528
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
529
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
530
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
531
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
532
    message:
533
      branch 1
534
------------------------------------------------------------
535
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
536
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
537
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
538
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
539
message:
540
  first post
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
541
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
542
            wt.branch, log.LongLogFormatter,
543
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
544
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
545
546
    def test_verbose_merge_revisions_contain_deltas(self):
547
        wt = self.make_branch_and_tree('parent')
548
        self.build_tree(['parent/f1', 'parent/f2'])
549
        wt.add(['f1','f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
550
        self.wt_commit(wt, 'first post')
551
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
552
        os.unlink('child/f1')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
553
        self.build_tree_contents([('child/f2', 'hello\n')])
554
        self.wt_commit(child_wt, 'removed f1 and modified f2')
555
        wt.merge_from_branch(child_wt.branch)
556
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
557
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
558
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
559
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
560
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
561
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
562
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
563
message:
564
  merge branch 1
565
removed:
566
  f1
567
modified:
568
  f2
569
    ------------------------------------------------------------
570
    revno: 1.1.1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
571
    committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
572
    branch nick: child
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
573
    timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
574
    message:
575
      removed f1 and modified f2
576
    removed:
577
      f1
578
    modified:
579
      f2
580
------------------------------------------------------------
581
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
582
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
583
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
584
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
585
message:
586
  first post
587
added:
588
  f1
589
  f2
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
590
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
591
            wt.branch, log.LongLogFormatter,
592
            formatter_kwargs=dict(levels=0),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
593
            show_log_kwargs=dict(verbose=True))
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
594
595
    def test_trailing_newlines(self):
596
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
597
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
598
        self.assertFormatterResult("""\
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
599
------------------------------------------------------------
600
revno: 3
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
601
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
602
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
603
timestamp: Tue 2005-11-22 00:00:02 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
604
message:
605
  single line with trailing newline
606
------------------------------------------------------------
607
revno: 2
608
committer: Joe Foo <joe@foo.com>
609
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
610
timestamp: Tue 2005-11-22 00:00:01 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
611
message:
612
  multiline
613
  log
614
  message
615
------------------------------------------------------------
616
revno: 1
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
617
committer: Joe Foo <joe@foo.com>
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
618
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
619
timestamp: Tue 2005-11-22 00:00:00 +0000
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
620
message:
621
  simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
622
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
623
        b, log.LongLogFormatter)
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
624
2671.5.7 by Lukáš Lalinsky
Rename get_author to get_apparent_author, revert the long log back to displaying the committer.
625
    def test_author_in_log(self):
626
        """Log includes the author name if it's set in
627
        the revision properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
628
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
629
        wt = self.make_standard_commit('test_author_log',
630
            authors=['John Doe <jdoe@example.com>',
631
                     'Jane Rey <jrey@example.com>'])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
632
        self.assertFormatterResult("""\
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
633
------------------------------------------------------------
634
revno: 1
4056.2.3 by James Westby
Use a new "authors" revision property to allow multiple authors
635
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
2671.5.4 by Lukáš Lalinsky
Replace the committer with the author in log, the committer is displayed only in the long format and only if it's different from the author.
636
committer: Lorem Ipsum <test@example.com>
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
637
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
638
timestamp: Tue 2005-11-22 00:00:00 +0000
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
639
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
640
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
641
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
642
        wt.branch, log.LongLogFormatter)
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
643
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
644
    def test_properties_in_log(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
645
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
646
        handlers.
647
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
648
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
649
        def trivial_custom_prop_handler(revision):
650
            return {'test_prop':'test_value'}
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
651
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
652
        # Cleaned up in setUp()
653
        log.properties_handler_registry.register(
654
            'trivial_custom_prop_handler',
655
            trivial_custom_prop_handler)
656
        self.assertFormatterResult("""\
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
657
------------------------------------------------------------
658
revno: 1
659
test_prop: test_value
660
author: John Doe <jdoe@example.com>
661
committer: Lorem Ipsum <test@example.com>
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
662
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
663
timestamp: Tue 2005-11-22 00:00:00 +0000
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
664
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
665
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
666
""",
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
667
            wt.branch, log.LongLogFormatter)
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
668
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
669
    def test_properties_in_short_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
670
        """Log includes the custom properties returned by the registered
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
671
        handlers.
672
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
673
        wt = self.make_standard_commit('test_properties_in_short_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
674
        def trivial_custom_prop_handler(revision):
675
            return {'test_prop':'test_value'}
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
676
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
677
        log.properties_handler_registry.register(
678
            'trivial_custom_prop_handler',
679
            trivial_custom_prop_handler)
680
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
681
    1 John Doe\t2005-11-22
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
682
      test_prop: test_value
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
683
      add a
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
684
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
685
""",
686
            wt.branch, log.ShortLogFormatter)
3976.3.1 by Neil Martinsen-Burrell
Add custom properties handling to short log format
687
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
688
    def test_error_in_properties_handler(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
689
        """Log includes the custom properties returned by the registered
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
690
        handlers.
691
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
692
        wt = self.make_standard_commit('error_in_properties_handler',
693
            revprops={'first_prop':'first_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
694
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
695
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
696
        def trivial_custom_prop_handler(revision):
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
697
            raise Exception("a test error")
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
698
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
699
        log.properties_handler_registry.register(
700
            'trivial_custom_prop_handler',
701
            trivial_custom_prop_handler)
6619.3.9 by Jelmer Vernooij
Run 2to3 standarderror fixer.
702
        self.assertRaises(Exception, log.show_log, wt.branch, formatter,)
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
703
3144.7.13 by Guillermo Gonzalez
* fixed typo LogFormatter.show_properties in docstring
704
    def test_properties_handler_bad_argument(self):
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
705
        wt = self.make_standard_commit('bad_argument',
706
              revprops={'a_prop':'test_value'})
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
707
        sio = self.make_utf8_encoded_stringio()
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
708
        formatter = log.LongLogFormatter(to_file=sio)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
709
        def bad_argument_prop_handler(revision):
710
            return {'custom_prop_name':revision.properties['a_prop']}
711
712
        log.properties_handler_registry.register(
713
            'bad_argument_prop_handler',
714
            bad_argument_prop_handler)
715
716
        self.assertRaises(AttributeError, formatter.show_properties,
717
                          'a revision', '')
718
719
        revision = wt.branch.repository.get_revision(wt.branch.last_revision())
720
        formatter.show_properties(revision, '')
721
        self.assertEqualDiff('''custom_prop_name: test_value\n''',
722
                             sio.getvalue())
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
723
5728.1.1 by Matt Giuca
test_log: Added test cases for the --show-ids switch on 'long' and 'short' log
724
    def test_show_ids(self):
725
        wt = self.make_branch_and_tree('parent')
726
        self.build_tree(['parent/f1', 'parent/f2'])
727
        wt.add(['f1','f2'])
728
        self.wt_commit(wt, 'first post', rev_id='a')
729
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
730
        self.wt_commit(child_wt, 'branch 1 changes', rev_id='b')
731
        wt.merge_from_branch(child_wt.branch)
732
        self.wt_commit(wt, 'merge branch 1', rev_id='c')
733
        self.assertFormatterResult("""\
734
------------------------------------------------------------
735
revno: 2 [merge]
736
revision-id: c
737
parent: a
738
parent: b
739
committer: Joe Foo <joe@foo.com>
740
branch nick: parent
741
timestamp: Tue 2005-11-22 00:00:02 +0000
742
message:
743
  merge branch 1
744
    ------------------------------------------------------------
745
    revno: 1.1.1
746
    revision-id: b
747
    parent: a
748
    committer: Joe Foo <joe@foo.com>
749
    branch nick: child
750
    timestamp: Tue 2005-11-22 00:00:01 +0000
751
    message:
752
      branch 1 changes
753
------------------------------------------------------------
754
revno: 1
755
revision-id: a
756
committer: Joe Foo <joe@foo.com>
757
branch nick: parent
758
timestamp: Tue 2005-11-22 00:00:00 +0000
759
message:
760
  first post
761
""",
762
            wt.branch, log.LongLogFormatter,
763
            formatter_kwargs=dict(levels=0,show_ids=True))
764
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
765
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
766
class TestLongLogFormatterWithoutMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
767
768
    def test_long_verbose_log(self):
769
        """Verbose log includes changed files
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
770
3947.1.2 by Ian Clatworthy
formatter tests
771
        bug #4676
772
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
773
        wt = self.make_standard_commit('test_long_verbose_log', authors=[])
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
774
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
775
------------------------------------------------------------
776
revno: 1
777
committer: Lorem Ipsum <test@example.com>
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
778
branch nick: test_long_verbose_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
779
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
780
message:
781
  add a
782
added:
783
  a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
784
""",
785
            wt.branch, log.LongLogFormatter,
786
            formatter_kwargs=dict(levels=1),
4857.4.5 by John Arbash Meinel
We don't need the utf8 option, no test actually wanted to run without it,
787
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
788
789
    def test_long_verbose_contain_deltas(self):
790
        wt = self.make_branch_and_tree('parent')
791
        self.build_tree(['parent/f1', 'parent/f2'])
792
        wt.add(['f1','f2'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
793
        self.wt_commit(wt, 'first post')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
794
        child_wt = wt.bzrdir.sprout('child').open_workingtree()
3947.1.2 by Ian Clatworthy
formatter tests
795
        os.unlink('child/f1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
796
        self.build_tree_contents([('child/f2', 'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
797
        self.wt_commit(child_wt, 'removed f1 and modified f2')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
798
        wt.merge_from_branch(child_wt.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
799
        self.wt_commit(wt, 'merge branch 1')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
800
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
801
------------------------------------------------------------
4208.2.1 by Ian Clatworthy
merge indicators in log --long
802
revno: 2 [merge]
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
803
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
804
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
805
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
806
message:
807
  merge branch 1
808
removed:
809
  f1
810
modified:
811
  f2
812
------------------------------------------------------------
813
revno: 1
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
814
committer: Joe Foo <joe@foo.com>
3947.1.2 by Ian Clatworthy
formatter tests
815
branch nick: parent
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
816
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
817
message:
818
  first post
819
added:
820
  f1
821
  f2
822
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
823
            wt.branch, log.LongLogFormatter,
824
            formatter_kwargs=dict(levels=1),
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
825
            show_log_kwargs=dict(verbose=True))
3947.1.2 by Ian Clatworthy
formatter tests
826
827
    def test_long_trailing_newlines(self):
828
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
829
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
830
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
831
------------------------------------------------------------
832
revno: 3
833
committer: Joe Foo <joe@foo.com>
834
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
835
timestamp: Tue 2005-11-22 00:00:02 +0000
3947.1.2 by Ian Clatworthy
formatter tests
836
message:
837
  single line with trailing newline
838
------------------------------------------------------------
839
revno: 2
840
committer: Joe Foo <joe@foo.com>
841
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
842
timestamp: Tue 2005-11-22 00:00:01 +0000
3947.1.2 by Ian Clatworthy
formatter tests
843
message:
844
  multiline
845
  log
846
  message
847
------------------------------------------------------------
848
revno: 1
849
committer: Joe Foo <joe@foo.com>
850
branch nick: test
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
851
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
852
message:
853
  simple log message
854
""",
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
855
        b, log.LongLogFormatter,
856
        formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
857
858
    def test_long_author_in_log(self):
859
        """Log includes the author name if it's set in
860
        the revision properties
861
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
862
        wt = self.make_standard_commit('test_author_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
863
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
864
------------------------------------------------------------
865
revno: 1
866
author: John Doe <jdoe@example.com>
867
committer: Lorem Ipsum <test@example.com>
868
branch nick: test_author_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
869
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
870
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
871
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
872
""",
873
            wt.branch, log.LongLogFormatter,
874
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
875
876
    def test_long_properties_in_log(self):
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
877
        """Log includes the custom properties returned by the registered
3947.1.2 by Ian Clatworthy
formatter tests
878
        handlers.
879
        """
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
880
        wt = self.make_standard_commit('test_properties_in_log')
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
881
        def trivial_custom_prop_handler(revision):
882
            return {'test_prop':'test_value'}
3947.1.2 by Ian Clatworthy
formatter tests
883
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
884
        log.properties_handler_registry.register(
885
            'trivial_custom_prop_handler',
886
            trivial_custom_prop_handler)
887
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
888
------------------------------------------------------------
889
revno: 1
890
test_prop: test_value
891
author: John Doe <jdoe@example.com>
892
committer: Lorem Ipsum <test@example.com>
893
branch nick: test_properties_in_log
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
894
timestamp: Tue 2005-11-22 00:00:00 +0000
3947.1.2 by Ian Clatworthy
formatter tests
895
message:
4857.4.2 by John Arbash Meinel
Add a 'make_standard_commit' helper, to remove more code duplication.
896
  add a
4857.4.1 by John Arbash Meinel
Start cleaning up test_log.
897
""",
898
            wt.branch, log.LongLogFormatter,
899
            formatter_kwargs=dict(levels=1))
3947.1.2 by Ian Clatworthy
formatter tests
900
901
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
902
class TestLineLogFormatter(TestCaseForLogFormatter):
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
903
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
904
    def test_line_log(self):
905
        """Line log should show revno
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
906
1704.2.20 by Martin Pool
log --line shows revision numbers (Alexander)
907
        bug #5162
908
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
909
        wt = self.make_standard_commit('test-line-log',
910
                committer='Line-Log-Formatter Tester <test@line.log>',
911
                authors=[])
912
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
913
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
914
""",
915
            wt.branch, log.LineLogFormatter)
1756.2.20 by Aaron Bentley
Optimize log formats that don't show merges
916
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
917
    def test_trailing_newlines(self):
918
        wt = self.make_branch_and_tree('.')
4955.4.1 by Vincent Ladeuil
Refactor the function into an helper.
919
        b = self.make_commits_with_trailing_newlines(wt)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
920
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
921
3: Joe Foo 2005-11-22 single line with trailing newline
922
2: Joe Foo 2005-11-22 multiline
923
1: Joe Foo 2005-11-22 simple log message
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
924
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
925
            b, log.LineLogFormatter)
3946.3.2 by Ian Clatworthy
add tests & NEWS item
926
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
927
    def test_line_log_single_merge_revision(self):
3946.3.2 by Ian Clatworthy
add tests & NEWS item
928
        wt = self._prepare_tree_with_merges()
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
929
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
930
        rev = revspec.in_history(wt.branch)
931
        self.assertFormatterResult("""\
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
932
1.1.1: Joe Foo 2005-11-22 rev-merged
3842.2.7 by Vincent Ladeuil
Fixed as per Jonh's review.
933
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
934
            wt.branch, log.LineLogFormatter,
935
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
936
3946.3.2 by Ian Clatworthy
add tests & NEWS item
937
    def test_line_log_with_tags(self):
938
        wt = self._prepare_tree_with_merges(with_tags=True)
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
939
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
940
3: Joe Foo 2005-11-22 {v1.0, v1.0rc1} rev-3
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
941
2: Joe Foo 2005-11-22 [merge] {v0.2} rev-2
3946.3.2 by Ian Clatworthy
add tests & NEWS item
942
1: Joe Foo 2005-11-22 rev-1
943
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
944
            wt.branch, log.LineLogFormatter)
945
946
947
class TestLineLogFormatterWithMergeRevisions(TestCaseForLogFormatter):
3947.1.2 by Ian Clatworthy
formatter tests
948
949
    def test_line_merge_revs_log(self):
950
        """Line log should show revno
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
951
3947.1.2 by Ian Clatworthy
formatter tests
952
        bug #5162
953
        """
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
954
        wt = self.make_standard_commit('test-line-log',
955
                committer='Line-Log-Formatter Tester <test@line.log>',
956
                authors=[])
957
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
958
1: Line-Log-Formatte... 2005-11-22 add a
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
959
""",
960
            wt.branch, log.LineLogFormatter)
3947.1.2 by Ian Clatworthy
formatter tests
961
962
    def test_line_merge_revs_log_single_merge_revision(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
963
        wt = self._prepare_tree_with_merges()
3947.1.2 by Ian Clatworthy
formatter tests
964
        revspec = revisionspec.RevisionSpec.from_string('1.1.1')
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
965
        rev = revspec.in_history(wt.branch)
966
        self.assertFormatterResult("""\
3947.1.2 by Ian Clatworthy
formatter tests
967
1.1.1: Joe Foo 2005-11-22 rev-merged
968
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
969
            wt.branch, log.LineLogFormatter,
970
            formatter_kwargs=dict(levels=0),
971
            show_log_kwargs=dict(start_revision=rev, end_revision=rev))
3947.1.2 by Ian Clatworthy
formatter tests
972
973
    def test_line_merge_revs_log_with_merges(self):
4955.4.19 by Vincent Ladeuil
Less code duplication.
974
        wt = self._prepare_tree_with_merges()
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
975
        self.assertFormatterResult("""\
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
976
2: Joe Foo 2005-11-22 [merge] rev-2
3947.1.2 by Ian Clatworthy
formatter tests
977
  1.1.1: Joe Foo 2005-11-22 rev-merged
978
1: Joe Foo 2005-11-22 rev-1
979
""",
4857.4.3 by John Arbash Meinel
Handle LineLogFormatter
980
            wt.branch, log.LineLogFormatter,
981
            formatter_kwargs=dict(levels=0))
982
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
983
4081.2.4 by Martin von Gagern
Added basic test cases for GNU Changelog format.
984
class TestGnuChangelogFormatter(TestCaseForLogFormatter):
985
986
    def test_gnu_changelog(self):
987
        wt = self.make_standard_commit('nicky', authors=[])
988
        self.assertFormatterResult('''\
989
2005-11-22  Lorem Ipsum  <test@example.com>
990
991
\tadd a
992
993
''',
994
            wt.branch, log.GnuChangelogLogFormatter)
995
996
    def test_with_authors(self):
997
        wt = self.make_standard_commit('nicky',
998
            authors=['Fooa Fooz <foo@example.com>',
999
                     'Bari Baro <bar@example.com>'])
1000
        self.assertFormatterResult('''\
1001
2005-11-22  Fooa Fooz  <foo@example.com>
1002
1003
\tadd a
1004
1005
''',
1006
            wt.branch, log.GnuChangelogLogFormatter)
1007
1008
    def test_verbose(self):
1009
        wt = self.make_standard_commit('nicky')
1010
        self.assertFormatterResult('''\
1011
2005-11-22  John Doe  <jdoe@example.com>
1012
1013
\t* a:
1014
1015
\tadd a
1016
1017
''',
1018
            wt.branch, log.GnuChangelogLogFormatter,
1019
            show_log_kwargs=dict(verbose=True))
1020
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1021
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1022
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1023
1024
    def test_show_changed_revisions_verbose(self):
1025
        tree = self.make_branch_and_tree('tree_a')
1026
        self.build_tree(['tree_a/foo'])
1027
        tree.add('foo')
1028
        tree.commit('bar', rev_id='bar-id')
2717.1.1 by Lukáš Lalinsky
Use UTF-8 encoded StringIO for log tests to avoid failures on non-ASCII committer names.
1029
        s = self.make_utf8_encoded_stringio()
1551.17.2 by Aaron Bentley
Stop showing deltas in pull -v output
1030
        log.show_changed_revisions(tree.branch, [], ['bar-id'], s)
1031
        self.assertContainsRe(s.getvalue(), 'bar')
1032
        self.assertNotContainsRe(s.getvalue(), 'foo')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1033
1034
3842.2.1 by Vincent Ladeuil
Cosmetic changes.
1035
class TestLogFormatter(tests.TestCase):
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1036
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1037
    def setUp(self):
1038
        super(TestLogFormatter, self).setUp()
1039
        self.rev = revision.Revision('a-id')
1040
        self.lf = log.LogFormatter(None)
1041
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1042
    def test_short_committer(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1043
        def assertCommitter(expected, committer):
1044
            self.rev.committer = committer
1045
            self.assertEqual(expected, self.lf.short_committer(self.rev))
1046
1047
        assertCommitter('John Doe', 'John Doe <jdoe@example.com>')
1048
        assertCommitter('John Smith', 'John Smith <jsmith@example.com>')
1049
        assertCommitter('John Smith', 'John Smith')
1050
        assertCommitter('jsmith@example.com', 'jsmith@example.com')
1051
        assertCommitter('jsmith@example.com', '<jsmith@example.com>')
1052
        assertCommitter('John Smith', 'John Smith jsmith@example.com')
2671.5.8 by Lukáš Lalinsky
Add tests for LogFormatter.short_committer and LogFormatter.short_author.
1053
1054
    def test_short_author(self):
4955.4.15 by Vincent Ladeuil
Remove duplicated code.
1055
        def assertAuthor(expected, author):
1056
            self.rev.properties['author'] = author
1057
            self.assertEqual(expected, self.lf.short_author(self.rev))
1058
1059
        assertAuthor('John Smith', 'John Smith <jsmith@example.com>')
1060
        assertAuthor('John Smith', 'John Smith')
1061
        assertAuthor('jsmith@example.com', 'jsmith@example.com')
1062
        assertAuthor('jsmith@example.com', '<jsmith@example.com>')
1063
        assertAuthor('John Smith', 'John Smith jsmith@example.com')
1064
1065
    def test_short_author_from_committer(self):
1066
        self.rev.committer = 'John Doe <jdoe@example.com>'
1067
        self.assertEqual('John Doe', self.lf.short_author(self.rev))
1068
1069
    def test_short_author_from_authors(self):
1070
        self.rev.properties['authors'] = ('John Smith <jsmith@example.com>\n'
1071
                                          'Jane Rey <jrey@example.com>')
1072
        self.assertEqual('John Smith', self.lf.short_author(self.rev))
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1073
1074
1075
class TestReverseByDepth(tests.TestCase):
1076
    """Test reverse_by_depth behavior.
1077
1078
    This is used to present revisions in forward (oldest first) order in a nice
1079
    layout.
1080
1081
    The tests use lighter revision description to ease reading.
1082
    """
1083
1084
    def assertReversed(self, forward, backward):
1085
        # Transform the descriptions to suit the API: tests use (revno, depth),
1086
        # while the API expects (revid, revno, depth)
1087
        def complete_revisions(l):
1088
            """Transform the description to suit the API.
1089
1090
            Tests use (revno, depth) whil the API expects (revid, revno, depth).
1091
            Since the revid is arbitrary, we just duplicate revno
1092
            """
1093
            return [ (r, r, d) for r, d in l]
1094
        forward = complete_revisions(forward)
1095
        backward= complete_revisions(backward)
1096
        self.assertEqual(forward, log.reverse_by_depth(backward))
1097
1098
1099
    def test_mainline_revisions(self):
1100
        self.assertReversed([( '1', 0), ('2', 0)],
1101
                            [('2', 0), ('1', 0)])
1102
1103
    def test_merged_revisions(self):
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1104
        self.assertReversed([('1', 0), ('2', 0), ('2.2', 1), ('2.1', 1),],
1105
                            [('2', 0), ('2.1', 1), ('2.2', 1), ('1', 0),])
3842.2.2 by Vincent Ladeuil
Reproduce bug #300055.
1106
    def test_shifted_merged_revisions(self):
1107
        """Test irregular layout.
1108
1109
        Requesting revisions touching a file can produce "holes" in the depths.
1110
        """
1111
        self.assertReversed([('1', 0), ('2', 0), ('1.1', 2), ('1.2', 2),],
1112
                            [('2', 0), ('1.2', 2), ('1.1', 2), ('1', 0),])
3842.2.3 by Vincent Ladeuil
Yet more cleanup and fix test_file_id_f3 bogus test.
1113
1114
    def test_merged_without_child_revisions(self):
1115
        """Test irregular layout.
1116
1117
        Revision ranges can produce "holes" in the depths.
1118
        """
1119
        # When a revision of higher depth doesn't follow one of lower depth, we
1120
        # assume a lower depth one is virtually there
1121
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1122
                            [('4', 4), ('3', 3), ('2', 2), ('1', 2),])
1123
        # So we get the same order after reversing below even if the original
1124
        # revisions are not in the same order.
1125
        self.assertReversed([('1', 2), ('2', 2), ('3', 3), ('4', 4)],
1126
                            [('3', 3), ('4', 4), ('2', 2), ('1', 2),])
3848.1.6 by Aaron Bentley
Implement get_history_change
1127
1128
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1129
class TestHistoryChange(tests.TestCaseWithTransport):
3848.1.6 by Aaron Bentley
Implement get_history_change
1130
1131
    def setup_a_tree(self):
1132
        tree = self.make_branch_and_tree('tree')
1133
        tree.lock_write()
1134
        self.addCleanup(tree.unlock)
1135
        tree.commit('1a', rev_id='1a')
1136
        tree.commit('2a', rev_id='2a')
1137
        tree.commit('3a', rev_id='3a')
1138
        return tree
1139
1140
    def setup_ab_tree(self):
1141
        tree = self.setup_a_tree()
1142
        tree.set_last_revision('1a')
1143
        tree.branch.set_last_revision_info(1, '1a')
1144
        tree.commit('2b', rev_id='2b')
1145
        tree.commit('3b', rev_id='3b')
1146
        return tree
1147
1148
    def setup_ac_tree(self):
1149
        tree = self.setup_a_tree()
1150
        tree.set_last_revision(revision.NULL_REVISION)
1151
        tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1152
        tree.commit('1c', rev_id='1c')
1153
        tree.commit('2c', rev_id='2c')
1154
        tree.commit('3c', rev_id='3c')
1155
        return tree
1156
1157
    def test_all_new(self):
1158
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1159
        old, new = log.get_history_change('1a', '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1160
        self.assertEqual([], old)
1161
        self.assertEqual(['2a', '3a'], new)
1162
1163
    def test_all_old(self):
1164
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1165
        old, new = log.get_history_change('3a', '1a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1166
        self.assertEqual([], new)
1167
        self.assertEqual(['2a', '3a'], old)
1168
1169
    def test_null_old(self):
1170
        tree = self.setup_ab_tree()
1171
        old, new = log.get_history_change(revision.NULL_REVISION,
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1172
                                          '3a', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1173
        self.assertEqual([], old)
1174
        self.assertEqual(['1a', '2a', '3a'], new)
1175
1176
    def test_null_new(self):
1177
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1178
        old, new = log.get_history_change('3a', revision.NULL_REVISION,
1179
                                          tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1180
        self.assertEqual([], new)
1181
        self.assertEqual(['1a', '2a', '3a'], old)
1182
1183
    def test_diverged(self):
1184
        tree = self.setup_ab_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1185
        old, new = log.get_history_change('3a', '3b', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1186
        self.assertEqual(old, ['2a', '3a'])
1187
        self.assertEqual(new, ['2b', '3b'])
1188
1189
    def test_unrelated(self):
1190
        tree = self.setup_ac_tree()
3848.1.7 by Aaron Bentley
Use repository in get_history_change
1191
        old, new = log.get_history_change('3a', '3c', tree.branch.repository)
3848.1.6 by Aaron Bentley
Implement get_history_change
1192
        self.assertEqual(old, ['1a', '2a', '3a'])
1193
        self.assertEqual(new, ['1c', '2c', '3c'])
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1194
1195
    def test_show_branch_change(self):
1196
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1197
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1198
        log.show_branch_change(tree.branch, s, 3, '3a')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1199
        self.assertContainsRe(s.getvalue(),
1200
            '[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1201
            '[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1202
1203
    def test_show_branch_change_no_change(self):
1204
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1205
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1206
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.8 by Aaron Bentley
Implement basic show_branch_change
1207
        self.assertEqual(s.getvalue(),
1208
            'Nothing seems to have changed\n')
1209
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1210
    def test_show_branch_change_no_old(self):
1211
        tree = self.setup_ab_tree()
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1212
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1213
        log.show_branch_change(tree.branch, s, 2, '2b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1214
        self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1215
        self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1216
1217
    def test_show_branch_change_no_new(self):
1218
        tree = self.setup_ab_tree()
1219
        tree.branch.set_last_revision_info(2, '2b')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
1220
        s = BytesIO()
3848.1.12 by Aaron Bentley
Fix test parameter order
1221
        log.show_branch_change(tree.branch, s, 3, '3b')
3848.1.9 by Aaron Bentley
new/old sections are omitted as appropriate.
1222
        self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1223
        self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1224
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1225
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1226
class TestRevisionNotInBranch(TestCaseForLogFormatter):
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1227
1228
    def setup_a_tree(self):
1229
        tree = self.make_branch_and_tree('tree')
1230
        tree.lock_write()
1231
        self.addCleanup(tree.unlock)
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1232
        kwargs = {
1233
            'committer': 'Joe Foo <joe@foo.com>',
1234
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1235
            'timezone': 0, # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1236
        }
1237
        tree.commit('commit 1a', rev_id='1a', **kwargs)
1238
        tree.commit('commit 2a', rev_id='2a', **kwargs)
1239
        tree.commit('commit 3a', rev_id='3a', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1240
        return tree
1241
1242
    def setup_ab_tree(self):
1243
        tree = self.setup_a_tree()
1244
        tree.set_last_revision('1a')
1245
        tree.branch.set_last_revision_info(1, '1a')
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1246
        kwargs = {
1247
            'committer': 'Joe Foo <joe@foo.com>',
1248
            'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1249
            'timezone': 0, # UTC
5728.5.3 by Matt Giuca
test_log: TestRevisionNotInBranch commits now have more metadata.
1250
        }
1251
        tree.commit('commit 2b', rev_id='2b', **kwargs)
1252
        tree.commit('commit 3b', rev_id='3b', **kwargs)
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1253
        return tree
1254
1255
    def test_one_revision(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1256
        tree = self.setup_ab_tree()
1257
        lf = LogCatcher()
1258
        rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1259
        log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1260
                     end_revision=rev)
1261
        self.assertEqual(1, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1262
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1263
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1264
5728.5.2 by Matt Giuca
test_log: Split new test cases for this branch out into a separate class,
1265
    def test_many_revisions(self):
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1266
        tree = self.setup_ab_tree()
1267
        lf = LogCatcher()
1268
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1269
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1270
        log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1271
                     end_revision=end_rev)
1272
        self.assertEqual(3, len(lf.revisions))
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1273
        self.assertEqual(None, lf.revisions[0].revno)   # Out-of-branch
1274
        self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1275
        self.assertEqual(None, lf.revisions[1].revno)   # Out-of-branch
1276
        self.assertEqual('2a', lf.revisions[1].rev.revision_id)
5728.5.1 by Matt Giuca
log no longer raises NoSuchRevision against revisions in the
1277
        self.assertEqual('1', lf.revisions[2].revno)    # In-branch
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1278
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1279
    def test_long_format(self):
1280
        tree = self.setup_ab_tree()
1281
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1282
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1283
        self.assertFormatterResult("""\
1284
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1285
revision-id: 3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1286
committer: Joe Foo <joe@foo.com>
1287
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1288
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1289
message:
1290
  commit 3a
1291
------------------------------------------------------------
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1292
revision-id: 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1293
committer: Joe Foo <joe@foo.com>
1294
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1295
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1296
message:
1297
  commit 2a
1298
------------------------------------------------------------
1299
revno: 1
1300
committer: Joe Foo <joe@foo.com>
1301
branch nick: tree
5728.5.10 by Andrew Bennetts
Use UTC, not system time zone, for the new log tests to get predictable output.
1302
timestamp: Tue 2005-11-22 00:00:00 +0000
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1303
message:
1304
  commit 1a
1305
""",
1306
            tree.branch, log.LongLogFormatter, show_log_kwargs={
1307
                'start_revision': start_rev, 'end_revision': end_rev
1308
            })
1309
1310
    def test_short_format(self):
1311
        tree = self.setup_ab_tree()
1312
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1313
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1314
        self.assertFormatterResult("""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1315
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1316
      revision-id:3a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1317
      commit 3a
1318
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1319
      Joe Foo\t2005-11-22
5728.5.6 by Matt Giuca
log: 'long' and 'short' log formats now always show the revision-id for any
1320
      revision-id:2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1321
      commit 2a
1322
1323
    1 Joe Foo\t2005-11-22
1324
      commit 1a
1325
1326
""",
1327
            tree.branch, log.ShortLogFormatter, show_log_kwargs={
1328
                'start_revision': start_rev, 'end_revision': end_rev
1329
            })
1330
1331
    def test_line_format(self):
1332
        tree = self.setup_ab_tree()
1333
        start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1334
        end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1335
        self.assertFormatterResult("""\
5728.5.5 by Matt Giuca
log: If a revision is not in the branch, it now sets its revno to None
1336
Joe Foo 2005-11-22 commit 3a
1337
Joe Foo 2005-11-22 commit 2a
5728.5.4 by Matt Giuca
test_log: TestRevisionNotInBranch: Added three new test cases, testing the
1338
1: Joe Foo 2005-11-22 commit 1a
1339
""",
1340
            tree.branch, log.LineLogFormatter, show_log_kwargs={
1341
                'start_revision': start_rev, 'end_revision': end_rev
1342
            })
1343
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1344
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1345
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1346
1347
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1348
        super(TestLogWithBugs, self).setUp()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1349
        log.properties_handler_registry.register(
1350
            'bugs_properties_handler',
1351
            log._bugs_properties_handler)
1352
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1353
    def make_commits_with_bugs(self):
1354
        """Helper method for LogFormatter tests"""
1355
        tree = self.make_branch_and_tree(u'.')
1356
        self.build_tree(['a', 'b'])
1357
        tree.add('a')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1358
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1359
                       revprops={'bugs': 'test://bug/id fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1360
        tree.add('b')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1361
        self.wt_commit(tree, 'multiline\nlog\nmessage\n', rev_id='a2',
1362
                       authors=['Joe Bar <joe@bar.com>'],
1363
                       revprops={'bugs': 'test://bug/id fixed\n'
1364
                                 'test://bug/2 fixed'})
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1365
        return tree
1366
1367
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1368
    def test_long_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1369
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1370
        self.assertFormatterResult("""\
1371
------------------------------------------------------------
1372
revno: 2
6143.1.8 by Jonathan Riddell
fix log formatting of bug line
1373
fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1374
author: Joe Bar <joe@bar.com>
1375
committer: Joe Foo <joe@foo.com>
1376
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1377
timestamp: Tue 2005-11-22 00:00:01 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1378
message:
1379
  multiline
1380
  log
1381
  message
1382
------------------------------------------------------------
1383
revno: 1
6143.1.4 by Jonathan Riddell
update tests
1384
fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1385
committer: Joe Foo <joe@foo.com>
1386
branch nick: work
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1387
timestamp: Tue 2005-11-22 00:00:00 +0000
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1388
message:
1389
  simple log message
1390
""",
1391
            tree.branch, log.LongLogFormatter)
1392
1393
    def test_short_bugs(self):
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1394
        tree = self.make_commits_with_bugs()
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1395
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1396
    2 Joe Bar\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1397
      fixes bugs: test://bug/id test://bug/2
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1398
      multiline
1399
      log
1400
      message
1401
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1402
    1 Joe Foo\t2005-11-22
6143.1.4 by Jonathan Riddell
update tests
1403
      fixes bug: test://bug/id
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1404
      simple log message
1405
1406
""",
1407
            tree.branch, log.ShortLogFormatter)
1408
1409
    def test_wrong_bugs_property(self):
1410
        tree = self.make_branch_and_tree(u'.')
1411
        self.build_tree(['foo'])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1412
        self.wt_commit(tree, 'simple log message', rev_id='a1',
1413
                       revprops={'bugs': 'test://bug/id invalid_value'})
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1414
        self.assertFormatterResult("""\
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
1415
    1 Joe Foo\t2005-11-22
4921.2.1 by Neil Martinsen-Burrell
include bug fixes in log output
1416
      simple log message
1417
1418
""",
1419
            tree.branch, log.ShortLogFormatter)
4921.2.2 by Neil Martinsen-Burrell
from review comments: improve splitting, add test that handler is present, use build_tree in tests
1420
1421
    def test_bugs_handler_present(self):
1422
        self.properties_handler_registry.get('bugs_properties_handler')
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1423
1424
1425
class TestLogForAuthors(TestCaseForLogFormatter):
1426
1427
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
1428
        super(TestLogForAuthors, self).setUp()
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1429
        self.wt = self.make_standard_commit('nicky',
1430
            authors=['John Doe <jdoe@example.com>',
1431
                     'Jane Rey <jrey@example.com>'])
1432
1433
    def assertFormatterResult(self, formatter, who, result):
1434
        formatter_kwargs = dict()
1435
        if who is not None:
4081.3.10 by Martin von Gagern
Renamed "authors" to "author_list_handler" in several places.
1436
            author_list_handler = log.author_list_registry.get(who)
1437
            formatter_kwargs['author_list_handler'] = author_list_handler
4081.3.5 by Martin von Gagern
NEWS and test cases for bzr log --authors.
1438
        TestCaseForLogFormatter.assertFormatterResult(self, result,
1439
            self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
1440
1441
    def test_line_default(self):
1442
        self.assertFormatterResult(log.LineLogFormatter, None, """\
1443
1: John Doe 2005-11-22 add a
1444
""")
1445
1446
    def test_line_committer(self):
1447
        self.assertFormatterResult(log.LineLogFormatter, 'committer', """\
1448
1: Lorem Ipsum 2005-11-22 add a
1449
""")
1450
1451
    def test_line_first(self):
1452
        self.assertFormatterResult(log.LineLogFormatter, 'first', """\
1453
1: John Doe 2005-11-22 add a
1454
""")
1455
1456
    def test_line_all(self):
1457
        self.assertFormatterResult(log.LineLogFormatter, 'all', """\
1458
1: John Doe, Jane Rey 2005-11-22 add a
1459
""")
1460
1461
1462
    def test_short_default(self):
1463
        self.assertFormatterResult(log.ShortLogFormatter, None, """\
1464
    1 John Doe\t2005-11-22
1465
      add a
1466
1467
""")
1468
1469
    def test_short_committer(self):
1470
        self.assertFormatterResult(log.ShortLogFormatter, 'committer', """\
1471
    1 Lorem Ipsum\t2005-11-22
1472
      add a
1473
1474
""")
1475
1476
    def test_short_first(self):
1477
        self.assertFormatterResult(log.ShortLogFormatter, 'first', """\
1478
    1 John Doe\t2005-11-22
1479
      add a
1480
1481
""")
1482
1483
    def test_short_all(self):
1484
        self.assertFormatterResult(log.ShortLogFormatter, 'all', """\
1485
    1 John Doe, Jane Rey\t2005-11-22
1486
      add a
1487
1488
""")
1489
1490
    def test_long_default(self):
1491
        self.assertFormatterResult(log.LongLogFormatter, None, """\
1492
------------------------------------------------------------
1493
revno: 1
1494
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1495
committer: Lorem Ipsum <test@example.com>
1496
branch nick: nicky
1497
timestamp: Tue 2005-11-22 00:00:00 +0000
1498
message:
1499
  add a
1500
""")
1501
1502
    def test_long_committer(self):
1503
        self.assertFormatterResult(log.LongLogFormatter, 'committer', """\
1504
------------------------------------------------------------
1505
revno: 1
1506
committer: Lorem Ipsum <test@example.com>
1507
branch nick: nicky
1508
timestamp: Tue 2005-11-22 00:00:00 +0000
1509
message:
1510
  add a
1511
""")
1512
1513
    def test_long_first(self):
1514
        self.assertFormatterResult(log.LongLogFormatter, 'first', """\
1515
------------------------------------------------------------
1516
revno: 1
1517
author: John Doe <jdoe@example.com>
1518
committer: Lorem Ipsum <test@example.com>
1519
branch nick: nicky
1520
timestamp: Tue 2005-11-22 00:00:00 +0000
1521
message:
1522
  add a
1523
""")
1524
1525
    def test_long_all(self):
1526
        self.assertFormatterResult(log.LongLogFormatter, 'all', """\
1527
------------------------------------------------------------
1528
revno: 1
1529
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1530
committer: Lorem Ipsum <test@example.com>
1531
branch nick: nicky
1532
timestamp: Tue 2005-11-22 00:00:00 +0000
1533
message:
1534
  add a
1535
""")
1536
1537
    def test_gnu_changelog_default(self):
1538
        self.assertFormatterResult(log.GnuChangelogLogFormatter, None, """\
1539
2005-11-22  John Doe  <jdoe@example.com>
1540
1541
\tadd a
1542
1543
""")
1544
1545
    def test_gnu_changelog_committer(self):
1546
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', """\
1547
2005-11-22  Lorem Ipsum  <test@example.com>
1548
1549
\tadd a
1550
1551
""")
1552
1553
    def test_gnu_changelog_first(self):
1554
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', """\
1555
2005-11-22  John Doe  <jdoe@example.com>
1556
1557
\tadd a
1558
1559
""")
1560
1561
    def test_gnu_changelog_all(self):
1562
        self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', """\
1563
2005-11-22  John Doe  <jdoe@example.com>, Jane Rey  <jrey@example.com>
1564
1565
\tadd a
1566
1567
""")
4081.3.15 by Gary van der Merwe
Merge bzr.dev.
1568
5691.1.3 by Jelmer Vernooij
Fix whitespace.
1569
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1570
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1571
1572
    def make_branch_with_alternate_ancestries(self, relpath='.'):
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1573
        # See test_merge_sorted_exclude_ancestry below for the difference with
1574
        # bt.per_branch.test_iter_merge_sorted_revision.
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1575
        # TestIterMergeSortedRevisionsBushyGraph.
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1576
        # make_branch_with_alternate_ancestries
1577
        # and test_merge_sorted_exclude_ancestry
1578
        # See the FIXME in assertLogRevnos too.
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1579
        builder = branchbuilder.BranchBuilder(self.get_transport(relpath))
1580
        # 1
1581
        # |\
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1582
        # 2 \
1583
        # |  |
1584
        # |  1.1.1
1585
        # |  | \
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1586
        # |  |  1.2.1
1587
        # |  | /
1588
        # |  1.1.2
1589
        # | /
1590
        # 3
1591
        builder.start_series()
1592
        builder.build_snapshot('1', None, [
1593
            ('add', ('', 'TREE_ROOT', 'directory', '')),])
1594
        builder.build_snapshot('1.1.1', ['1'], [])
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1595
        builder.build_snapshot('2', ['1'], [])
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1596
        builder.build_snapshot('1.2.1', ['1.1.1'], [])
1597
        builder.build_snapshot('1.1.2', ['1.1.1', '1.2.1'], [])
1598
        builder.build_snapshot('3', ['2', '1.1.2'], [])
1599
        builder.finish_series()
1600
        br = builder.get_branch()
1601
        br.lock_read()
1602
        self.addCleanup(br.unlock)
1603
        return br
1604
1605
    def assertLogRevnos(self, expected_revnos, b, start, end,
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1606
                        exclude_common_ancestry, generate_merge_revisions=True):
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1607
        # FIXME: the layering in log makes it hard to test intermediate levels,
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
1608
        # I wish adding filters with their parameters was easier...
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1609
        # -- vila 20100413
1610
        iter_revs = log._calc_view_revisions(
1611
            b, start, end, direction='reverse',
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1612
            generate_merge_revisions=generate_merge_revisions,
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1613
            exclude_common_ancestry=exclude_common_ancestry)
1614
        self.assertEqual(expected_revnos,
1615
                         [revid for revid, revno, depth in iter_revs])
1616
1617
    def test_merge_sorted_exclude_ancestry(self):
1618
        b = self.make_branch_with_alternate_ancestries()
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1619
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1620
                             b, '1', '3', exclude_common_ancestry=False)
5155.1.5 by Vincent Ladeuil
Fixed as per Andrew's review.
1621
        # '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1622
        # it should be mentioned even if merge_sort order will make it appear
1623
        # after 1.1.1
5155.1.3 by Vincent Ladeuil
Fix the performance by finding the relevant subgraph once.
1624
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1625
                             b, '1.1.1', '3', exclude_common_ancestry=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1626
5268.4.2 by Vincent Ladeuil
Failing whitebox test for bug #575631.
1627
    def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1628
        b = self.make_branch_with_alternate_ancestries()
1629
        self.assertLogRevnos(['3', '2'],
1630
                             b, '1', '3', exclude_common_ancestry=True,
1631
                             generate_merge_revisions=False)
5268.4.3 by Vincent Ladeuil
Respect --exclude-common-ancestry for linear ancestries.
1632
        self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2'],
1633
                             b, '1', '3', exclude_common_ancestry=True,
1634
                             generate_merge_revisions=True)
5097.1.12 by Vincent Ladeuil
Implement the --exclude-common-ancestry log option.
1635
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1636
1637
class TestLogDefaults(TestCaseForLogFormatter):
1638
    def test_default_log_level(self):
6042.1.2 by Thomi Richards
Minor changes as a result of feedback from merge proposal.
1639
        """
1640
        Test to ensure that specifying 'levels=1' to make_log_request_dict
1641
        doesn't get overwritten when using a LogFormatter that supports more
1642
        detail.
1643
        Fixes bug #747958.
1644
        """
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1645
        wt = self._prepare_tree_with_merges()
1646
        b = wt.branch
1647
1648
        class CustomLogFormatter(log.LogFormatter):
1649
            def __init__(self, *args, **kwargs):
1650
                super(CustomLogFormatter, self).__init__(*args, **kwargs)
1651
                self.revisions = []
1652
            def get_levels(self):
1653
                # log formatter supports all levels:
1654
                return 0
1655
            def log_revision(self, revision):
1656
                self.revisions.append(revision)
1657
1658
        log_formatter = LogCatcher()
1659
        # First request we don't specify number of levels, we should get a
1660
        # sensible default (whatever the LogFormatter handles - which in this
1661
        # case is 0/everything):
1662
        request = log.make_log_request_dict(limit=10)
1663
        log.Logger(b, request).show(log_formatter)
1664
        # should have all three revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1665
        self.assertEqual(len(log_formatter.revisions), 3)
6042.1.1 by Thomi Richards
Fix bug #747958 - 'levels' value is no longer overridden in Logger if the user explicitly asked for less details than the logger is capable of providing.
1666
1667
        del log_formatter
1668
        log_formatter = LogCatcher()
1669
        # now explicitly request mainline revisions only:
1670
        request = log.make_log_request_dict(limit=10, levels=1)
1671
        log.Logger(b, request).show(log_formatter)
1672
        # should now only have 2 revisions:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1673
        self.assertEqual(len(log_formatter.revisions), 2)
6283.1.13 by Jelmer Vernooij
ADd hpss call count tests for 'bzr log'.
1674