~bzr-pqm/bzr/bzr.dev

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