/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4183.6.2 by Martin Pool
Add better message and test for 251352
1
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
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
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
16
17
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
18
"""Black-box tests for bzr log."""
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
19
3940.1.2 by Ian Clatworthy
add test
20
import os, re
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
21
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
22
from bzrlib import osutils
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
23
from bzrlib.tests.blackbox import ExternalBase
3936.3.12 by Ian Clatworthy
more single revision & sequence tuning
24
from bzrlib.tests import KnownFailure, TestCaseInTempDir, TestCaseWithTransport
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
25
from bzrlib.tests.test_log import (
26
    normalize_log,
27
    )
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
28
from bzrlib.tests import test_log
29
30
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
31
class TestCaseWithoutPropsHandler(ExternalBase,
32
                                  test_log.TestCaseWithoutPropsHandler):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
33
    pass
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
34
35
36
class TestLog(ExternalBase):
37
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
38
    def _prepare(self, path='.', format=None):
2809.1.2 by Daniel Watkins
Removed unnecessary check as per abentley's on-list comments.
39
        tree = self.make_branch_and_tree(path, format=format)
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
40
        self.build_tree(
41
            [path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
42
        tree.add('hello.txt')
43
        tree.commit(message='message1')
44
        tree.add('goodbye.txt')
45
        tree.commit(message='message2')
46
        tree.add('meep.txt')
47
        tree.commit(message='message3')
48
        self.full_log = self.run_bzr(["log", path])[0]
49
        return tree
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
50
51
    def test_log_null_end_revspec(self):
52
        self._prepare()
53
        self.assertTrue('revno: 1\n' in self.full_log)
54
        self.assertTrue('revno: 2\n' in self.full_log)
55
        self.assertTrue('revno: 3\n' in self.full_log)
56
        self.assertTrue('message:\n  message1\n' in self.full_log)
57
        self.assertTrue('message:\n  message2\n' in self.full_log)
58
        self.assertTrue('message:\n  message3\n' in self.full_log)
59
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
60
        log = self.run_bzr("log -r 1..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
61
        self.assertEqualDiff(log, self.full_log)
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
62
63
    def test_log_null_begin_revspec(self):
64
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
65
        log = self.run_bzr("log -r ..3")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
66
        self.assertEqualDiff(self.full_log, log)
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
67
68
    def test_log_null_both_revspecs(self):
69
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
70
        log = self.run_bzr("log -r ..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
71
        self.assertEqualDiff(self.full_log, log)
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
72
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
73
    def test_log_zero_revspec(self):
74
        self._prepare()
75
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
76
                           ['log', '-r0'])
77
78
    def test_log_zero_begin_revspec(self):
79
        self._prepare()
80
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
81
                           ['log', '-r0..2'])
82
83
    def test_log_zero_end_revspec(self):
84
        self._prepare()
85
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
86
                           ['log', '-r-2..0'])
87
3144.1.1 by Lukáš Lalinský
Fixed error reporting of unsupported timezone format.
88
    def test_log_unsupported_timezone(self):
89
        self._prepare()
90
        self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
91
                           'options are "utc", "original", "local".',
92
                           ['log', '--timezone', 'foo'])
93
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
94
    def test_log_negative_begin_revspec_full_log(self):
95
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
96
        log = self.run_bzr("log -r -3..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
97
        self.assertEqualDiff(self.full_log, log)
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
98
99
    def test_log_negative_both_revspec_full_log(self):
100
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
101
        log = self.run_bzr("log -r -3..-1")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
102
        self.assertEqualDiff(self.full_log, log)
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
103
104
    def test_log_negative_both_revspec_partial(self):
105
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
106
        log = self.run_bzr("log -r -3..-2")[0]
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
107
        self.assertTrue('revno: 1\n' in log)
108
        self.assertTrue('revno: 2\n' in log)
109
        self.assertTrue('revno: 3\n' not in log)
110
111
    def test_log_negative_begin_revspec(self):
112
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
113
        log = self.run_bzr("log -r -2..")[0]
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
114
        self.assertTrue('revno: 1\n' not in log)
115
        self.assertTrue('revno: 2\n' in log)
116
        self.assertTrue('revno: 3\n' in log)
117
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
118
    def test_log_positive_revspecs(self):
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
119
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
120
        log = self.run_bzr("log -r 1..3")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
121
        self.assertEqualDiff(self.full_log, log)
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
122
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
123
    def test_log_reversed_revspecs(self):
124
        self._prepare()
125
        self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
126
                            'the end revision.\n',),
2581.1.6 by Martin Pool
fix up more run_bzr callers
127
                           ['log', '-r3..1'])
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
128
1907.4.2 by Matthieu Moy
Make log work nicely with revno:N:path too.
129
    def test_log_revno_n_path(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
130
        self._prepare(path='branch1')
131
        self._prepare(path='branch2')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
132
        log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
1907.4.2 by Matthieu Moy
Make log work nicely with revno:N:path too.
133
                          retcode=3)[0]
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
134
        log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
135
        self.assertEqualDiff(self.full_log, log)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
136
        log = self.run_bzr("log -r revno:1:branch2")[0]
1907.4.2 by Matthieu Moy
Make log work nicely with revno:N:path too.
137
        self.assertTrue('revno: 1\n' in log)
138
        self.assertTrue('revno: 2\n' not in log)
139
        self.assertTrue('branch nick: branch2\n' in log)
140
        self.assertTrue('branch nick: branch1\n' not in log)
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
141
3878.3.3 by Marius Kruger
Add tests for log -r with non-exising revno's
142
    def test_log_nonexistent_revno(self):
143
        self._prepare()
144
        (out, err) = self.run_bzr_error(args="log -r 1234",
145
            error_regexes=["bzr: ERROR: Requested revision: '1234' "
146
                "does not exist in branch:"])
147
148
    def test_log_nonexistent_dotted_revno(self):
149
        self._prepare()
150
        (out, err) = self.run_bzr_error(args="log -r 123.123",
151
            error_regexes=["bzr: ERROR: Requested revision: '123.123' "
152
                "does not exist in branch:"])
153
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
154
    def test_log_change_revno(self):
155
        self._prepare()
156
        expected_log = self.run_bzr("log -r 1")[0]
157
        log = self.run_bzr("log -c 1")[0]
158
        self.assertEqualDiff(expected_log, log)
159
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
160
    def test_log_change_nonexistent_revno(self):
161
        self._prepare()
162
        (out, err) = self.run_bzr_error(args="log -c 1234",
163
            error_regexes=["bzr: ERROR: Requested revision: '1234' "
164
                "does not exist in branch:"])
165
166
    def test_log_change_nonexistent_dotted_revno(self):
167
        self._prepare()
168
        (out, err) = self.run_bzr_error(args="log -c 123.123",
169
            error_regexes=["bzr: ERROR: Requested revision: '123.123' "
170
                "does not exist in branch:"])
171
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
172
    def test_log_change_single_revno(self):
173
        self._prepare()
174
        self.run_bzr_error('bzr: ERROR: Option --change does not'
175
                           ' accept revision ranges',
176
                           ['log', '--change', '2..3'])
177
178
    def test_log_change_incompatible_with_revision(self):
179
        self._prepare()
180
        self.run_bzr_error('bzr: ERROR: --revision and --change'
181
                           ' are mutually exclusive',
182
                           ['log', '--change', '2', '--revision', '3'])
183
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
184
    def test_log_nonexistent_file(self):
185
        # files that don't exist in either the basis tree or working tree
186
        # should give an error
187
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
188
        out, err = self.run_bzr('log does-not-exist', retcode=3)
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
189
        self.assertContainsRe(
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
190
            err, 'Path unknown at end or start of revision range: does-not-exist')
2388.1.11 by Alexander Belchenko
changes after John's review
191
2388.1.3 by Erik Bagfors
tests for tags in log output
192
    def test_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
193
        tree = self._prepare(format='dirstate-tags')
194
        branch = tree.branch
195
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
196
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
197
        branch.tags.set_tag('tag3', branch.last_revision())
198
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
199
        log = self.run_bzr("log -r-1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
200
        self.assertTrue('tags: tag3' in log)
201
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
202
        log = self.run_bzr("log -r1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
203
        # I guess that we can't know the order of tags in the output
204
        # since dicts are unordered, need to check both possibilities
2388.1.11 by Alexander Belchenko
changes after John's review
205
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
206
2388.1.9 by Erik Bagfors
test for merges with tags in log
207
    def test_merged_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
208
        branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
209
        branch1 = branch1_tree.branch
210
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
211
        branch1_tree.commit(message='foobar', allow_pointless=True)
212
        branch1.tags.set_tag('tag1', branch1.last_revision())
213
        os.chdir('branch2')
214
        self.run_bzr('merge ../branch1') # tags don't propagate otherwise
215
        branch2_tree.commit(message='merge branch 1')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
216
        log = self.run_bzr("log -r-1")[0]
2388.1.11 by Alexander Belchenko
changes after John's review
217
        self.assertContainsRe(log, r'    tags: tag1')
2578.2.1 by Andrew Bennetts
Merge Kent Gibson's fix for bug #4663, resolving conflicts.
218
        log = self.run_bzr("log -r3.1.1")[0]
2466.12.2 by Kent Gibson
shift log output with only merge revisions to the left margin
219
        self.assertContainsRe(log, r'tags: tag1')
2388.1.3 by Erik Bagfors
tests for tags in log output
220
2466.9.1 by Kent Gibson
add bzr log --limit
221
    def test_log_limit(self):
3660.1.1 by Robert Collins
Fix log --limit (broken by log filtering patch).
222
        tree = self.make_branch_and_tree('.')
223
        # We want more commits than our batch size starts at
224
        for pos in range(10):
225
            tree.commit("%s" % pos)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
226
        log = self.run_bzr("log --limit 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
227
        self.assertNotContainsRe(log, r'revno: 1\n')
3660.1.1 by Robert Collins
Fix log --limit (broken by log filtering patch).
228
        self.assertNotContainsRe(log, r'revno: 2\n')
229
        self.assertNotContainsRe(log, r'revno: 3\n')
230
        self.assertNotContainsRe(log, r'revno: 4\n')
231
        self.assertNotContainsRe(log, r'revno: 5\n')
232
        self.assertNotContainsRe(log, r'revno: 6\n')
233
        self.assertNotContainsRe(log, r'revno: 7\n')
234
        self.assertNotContainsRe(log, r'revno: 8\n')
235
        self.assertContainsRe(log, r'revno: 9\n')
236
        self.assertContainsRe(log, r'revno: 10\n')
2466.9.1 by Kent Gibson
add bzr log --limit
237
3108.1.2 by Matt Nordhoff
Simple copied unit test.
238
    def test_log_limit_short(self):
239
        self._prepare()
240
        log = self.run_bzr("log -l 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
241
        self.assertNotContainsRe(log, r'revno: 1\n')
242
        self.assertContainsRe(log, r'revno: 2\n')
243
        self.assertContainsRe(log, r'revno: 3\n')
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
244
4183.6.2 by Martin Pool
Add better message and test for 251352
245
    def test_log_bad_message_re(self):
246
        """Bad --message argument gives a sensible message
247
        
248
        See https://bugs.launchpad.net/bzr/+bug/251352
249
        """
250
        self._prepare()
251
        out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
4183.6.4 by Martin Pool
Separate out re_compile_checked
252
        self.assertEqual("bzr: ERROR: Invalid regular expression"
253
            " in log message filter"
254
            ": '*'"
255
            ": nothing to repeat\n", err)
4183.6.2 by Martin Pool
Add better message and test for 251352
256
        self.assertEqual('', out)
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
257
258
class TestLogVerbose(TestCaseWithTransport):
259
260
    def setUp(self):
261
        super(TestLogVerbose, self).setUp()
262
        tree = self.make_branch_and_tree('.')
263
        self.build_tree(['hello.txt'])
264
        tree.add('hello.txt')
265
        tree.commit(message='message1')
266
267
    def assertUseShortDeltaFormat(self, cmd):
268
        log = self.run_bzr(cmd)[0]
269
        # Check that we use the short status format
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
270
        self.assertContainsRe(log, '(?m)^\s*A  hello.txt$')
271
        self.assertNotContainsRe(log, '(?m)^\s*added:$')
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
272
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
273
    def assertUseLongDeltaFormat(self, cmd):
274
        log = self.run_bzr(cmd)[0]
275
        # Check that we use the long status format
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
276
        self.assertNotContainsRe(log, '(?m)^\s*A  hello.txt$')
277
        self.assertContainsRe(log, '(?m)^\s*added:$')
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
278
279
    def test_log_short_verbose(self):
280
        self.assertUseShortDeltaFormat(['log', '--short', '-v'])
281
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
282
    def test_log_short_verbose_verbose(self):
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
283
        self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
284
285
    def test_log_long_verbose(self):
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
286
        # Check that we use the long status format, ignoring the verbosity
287
        # level
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
288
        self.assertUseLongDeltaFormat(['log', '--long', '-v'])
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
289
290
    def test_log_long_verbose_verbose(self):
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
291
        # Check that we use the long status format, ignoring the verbosity
292
        # level
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
293
        self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
3874.1.1 by Vincent Ladeuil
Fix #87179 by using the short status format when the short format is used for log.
294
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
295
296
class TestLogMerges(TestCaseWithoutPropsHandler):
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
297
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
298
    def _prepare(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
299
        parent_tree = self.make_branch_and_tree('parent')
300
        parent_tree.commit(message='first post', allow_pointless=True)
301
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
302
        child_tree.commit(message='branch 1', allow_pointless=True)
303
        smaller_tree = \
304
                child_tree.bzrdir.sprout('smallerchild').open_workingtree()
305
        smaller_tree.commit(message='branch 2', allow_pointless=True)
306
        child_tree.merge_from_branch(smaller_tree.branch)
307
        child_tree.commit(message='merge branch 2')
308
        parent_tree.merge_from_branch(child_tree.branch)
309
        parent_tree.commit(message='merge branch 1')
310
        os.chdir('parent')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
311
3947.1.3 by Ian Clatworthy
blackbox tests
312
    def _prepare_short(self):
313
        parent_tree = self.make_branch_and_tree('parent')
314
        parent_tree.commit(message='first post',
315
            timestamp=1132586700, timezone=36000,
316
            committer='Joe Foo <joe@foo.com>')
317
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
318
        child_tree.commit(message='branch 1',
319
            timestamp=1132586800, timezone=36000,
320
            committer='Joe Foo <joe@foo.com>')
321
        smaller_tree = \
322
                child_tree.bzrdir.sprout('smallerchild').open_workingtree()
323
        smaller_tree.commit(message='branch 2',
324
            timestamp=1132586900, timezone=36000,
325
            committer='Joe Foo <joe@foo.com>')
326
        child_tree.merge_from_branch(smaller_tree.branch)
327
        child_tree.commit(message='merge branch 2',
328
            timestamp=1132587000, timezone=36000,
329
            committer='Joe Foo <joe@foo.com>')
330
        parent_tree.merge_from_branch(child_tree.branch)
331
        parent_tree.commit(message='merge branch 1',
332
            timestamp=1132587100, timezone=36000,
333
            committer='Joe Foo <joe@foo.com>')
334
        os.chdir('parent')
335
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
336
    def test_merges_are_indented_by_level(self):
337
        self._prepare()
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
338
        out,err = self.run_bzr('log')
339
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
340
        log = normalize_log(out)
341
        self.assertEqualDiff(log, """\
342
------------------------------------------------------------
343
revno: 2
344
committer: Lorem Ipsum <test@example.com>
345
branch nick: parent
346
timestamp: Just now
347
message:
348
  merge branch 1
349
    ------------------------------------------------------------
350
    revno: 1.1.2
351
    committer: Lorem Ipsum <test@example.com>
352
    branch nick: child
353
    timestamp: Just now
354
    message:
355
      merge branch 2
356
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
357
        revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
358
        committer: Lorem Ipsum <test@example.com>
359
        branch nick: smallerchild
360
        timestamp: Just now
361
        message:
362
          branch 2
363
    ------------------------------------------------------------
364
    revno: 1.1.1
365
    committer: Lorem Ipsum <test@example.com>
366
    branch nick: child
367
    timestamp: Just now
368
    message:
369
      branch 1
370
------------------------------------------------------------
371
revno: 1
372
committer: Lorem Ipsum <test@example.com>
373
branch nick: parent
374
timestamp: Just now
375
message:
376
  first post
377
""")
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
378
3947.1.3 by Ian Clatworthy
blackbox tests
379
    def test_force_merge_revisions_off(self):
380
        self._prepare()
3947.1.6 by Ian Clatworthy
log -n/--level-count N option
381
        out,err = self.run_bzr('log --long -n1')
3947.1.3 by Ian Clatworthy
blackbox tests
382
        self.assertEqual('', err)
383
        log = normalize_log(out)
384
        self.assertEqualDiff(log, """\
385
------------------------------------------------------------
386
revno: 2
387
committer: Lorem Ipsum <test@example.com>
388
branch nick: parent
389
timestamp: Just now
390
message:
391
  merge branch 1
392
------------------------------------------------------------
393
revno: 1
394
committer: Lorem Ipsum <test@example.com>
395
branch nick: parent
396
timestamp: Just now
397
message:
398
  first post
399
""")
400
401
    def test_force_merge_revisions_on(self):
402
        self._prepare_short()
3947.1.6 by Ian Clatworthy
log -n/--level-count N option
403
        out,err = self.run_bzr('log --short -n0')
3947.1.3 by Ian Clatworthy
blackbox tests
404
        self.assertEqual('', err)
405
        log = normalize_log(out)
406
        self.assertEqualDiff(log, """\
407
    2 Joe Foo\t2005-11-22 [merge]
408
      merge branch 1
409
3947.1.10 by Ian Clatworthy
review feedback from vila
410
          1.1.2 Joe Foo\t2005-11-22 [merge]
411
                merge branch 2
412
413
              1.2.1 Joe Foo\t2005-11-22
414
                    branch 2
415
416
          1.1.1 Joe Foo\t2005-11-22
417
                branch 1
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
418
419
    1 Joe Foo\t2005-11-22
420
      first post
421
422
""")
423
424
    def test_force_merge_revisions_N(self):
425
        self._prepare_short()
426
        out,err = self.run_bzr('log --short -n2')
427
        self.assertEqual('', err)
428
        log = normalize_log(out)
429
        self.assertEqualDiff(log, """\
430
    2 Joe Foo\t2005-11-22 [merge]
431
      merge branch 1
432
3947.1.10 by Ian Clatworthy
review feedback from vila
433
          1.1.2 Joe Foo\t2005-11-22 [merge]
434
                merge branch 2
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
435
3947.1.10 by Ian Clatworthy
review feedback from vila
436
          1.1.1 Joe Foo\t2005-11-22
437
                branch 1
3947.1.3 by Ian Clatworthy
blackbox tests
438
439
    1 Joe Foo\t2005-11-22
440
      first post
441
442
""")
443
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
444
    def test_merges_single_merge_rev(self):
445
        self._prepare()
2581.1.6 by Martin Pool
fix up more run_bzr callers
446
        out,err = self.run_bzr('log -r1.1.2')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
447
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
448
        log = normalize_log(out)
449
        self.assertEqualDiff(log, """\
450
------------------------------------------------------------
451
revno: 1.1.2
452
committer: Lorem Ipsum <test@example.com>
453
branch nick: child
454
timestamp: Just now
455
message:
456
  merge branch 2
457
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
458
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
459
    committer: Lorem Ipsum <test@example.com>
460
    branch nick: smallerchild
461
    timestamp: Just now
462
    message:
463
      branch 2
464
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
465
466
    def test_merges_partial_range(self):
467
        self._prepare()
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
468
        out, err = self.run_bzr('log -r1.1.1..1.1.2')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
469
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
470
        log = normalize_log(out)
471
        self.assertEqualDiff(log, """\
472
------------------------------------------------------------
473
revno: 1.1.2
474
committer: Lorem Ipsum <test@example.com>
475
branch nick: child
476
timestamp: Just now
477
message:
478
  merge branch 2
479
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
480
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
481
    committer: Lorem Ipsum <test@example.com>
482
    branch nick: smallerchild
483
    timestamp: Just now
484
    message:
485
      branch 2
486
------------------------------------------------------------
487
revno: 1.1.1
488
committer: Lorem Ipsum <test@example.com>
489
branch nick: child
490
timestamp: Just now
491
message:
492
  branch 1
493
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
494
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
495
    def test_merges_nonsupporting_formatter(self):
3936.3.12 by Ian Clatworthy
more single revision & sequence tuning
496
        # This "feature" of log formatters is madness. If a log
497
        # formatter cannot display a dotted-revno, it ought to ignore it.
498
        # Otherwise, a linear sequence is always expected to be handled now.
499
        raise KnownFailure('log formatters must support linear sequences now')
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
500
        self._prepare()
501
        err_msg = 'Selected log formatter only supports mainline revisions.'
2997.1.1 by Kent Gibson
Support logging single merge revisions with short and line log formatters.
502
        # The single revision case is tested in the core tests
503
        # since all standard formatters support single merge revisions.
3936.3.8 by Ian Clatworthy
back-out --strict
504
        out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
505
        self.assertContainsRe(err, err_msg)
3936.3.8 by Ian Clatworthy
back-out --strict
506
        out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
507
        self.assertContainsRe(err, err_msg)
508
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
509
3943.5.3 by Ian Clatworthy
add tests
510
def subst_dates(string):
511
    """Replace date strings with constant values."""
512
    return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
513
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
514
515
516
class TestLogDiff(TestCaseWithoutPropsHandler):
517
518
    def _prepare(self):
519
        parent_tree = self.make_branch_and_tree('parent')
520
        self.build_tree(['parent/file1', 'parent/file2'])
521
        parent_tree.add('file1')
522
        parent_tree.add('file2')
523
        parent_tree.commit(message='first post',
524
            timestamp=1132586655, timezone=36000,
525
            committer='Lorem Ipsum <test@example.com>')
526
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
527
        self.build_tree_contents([('child/file2', 'hello\n')])
528
        child_tree.commit(message='branch 1',
529
            timestamp=1132586700, timezone=36000,
530
            committer='Lorem Ipsum <test@example.com>')
531
        parent_tree.merge_from_branch(child_tree.branch)
532
        parent_tree.commit(message='merge branch 1',
533
            timestamp=1132586800, timezone=36000,
534
            committer='Lorem Ipsum <test@example.com>')
535
        os.chdir('parent')
536
537
    def test_log_show_diff_long(self):
538
        self._prepare()
3943.5.5 by Ian Clatworthy
tweak option name as requested in bug report
539
        out,err = self.run_bzr('log -p')
3943.5.3 by Ian Clatworthy
add tests
540
        self.assertEqual('', err)
541
        log = normalize_log(out)
542
        self.assertEqualDiff(subst_dates(log), """\
543
------------------------------------------------------------
544
revno: 2
545
committer: Lorem Ipsum <test@example.com>
546
branch nick: parent
547
timestamp: Just now
548
message:
549
  merge branch 1
550
diff:
3943.5.6 by Ian Clatworthy
feedback from jam's review
551
=== modified file 'file2'
552
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
553
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
554
@@ -1,1 +1,1 @@
555
-contents of parent/file2
556
+hello
3943.5.3 by Ian Clatworthy
add tests
557
    ------------------------------------------------------------
558
    revno: 1.1.1
559
    committer: Lorem Ipsum <test@example.com>
560
    branch nick: child
561
    timestamp: Just now
562
    message:
563
      branch 1
564
    diff:
3943.5.6 by Ian Clatworthy
feedback from jam's review
565
    === modified file 'file2'
566
    --- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
567
    +++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
568
    @@ -1,1 +1,1 @@
569
    -contents of parent/file2
570
    +hello
3943.5.3 by Ian Clatworthy
add tests
571
------------------------------------------------------------
572
revno: 1
573
committer: Lorem Ipsum <test@example.com>
574
branch nick: parent
575
timestamp: Just now
576
message:
577
  first post
578
diff:
3943.5.6 by Ian Clatworthy
feedback from jam's review
579
=== added file 'file1'
580
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
581
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
582
@@ -0,0 +1,1 @@
583
+contents of parent/file1
584
585
=== added file 'file2'
586
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
587
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
588
@@ -0,0 +1,1 @@
589
+contents of parent/file2
3943.5.3 by Ian Clatworthy
add tests
590
""")
591
592
    def test_log_show_diff_short(self):
593
        self._prepare()
3943.5.5 by Ian Clatworthy
tweak option name as requested in bug report
594
        out,err = self.run_bzr('log -p --short')
3943.5.3 by Ian Clatworthy
add tests
595
        self.assertEqual('', err)
596
        log = normalize_log(out)
597
        self.assertEqualDiff(subst_dates(log), """\
598
    2 Lorem Ipsum\t2005-11-22 [merge]
599
      merge branch 1
600
      === modified file 'file2'
601
      --- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
602
      +++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
603
      @@ -1,1 +1,1 @@
604
      -contents of parent/file2
605
      +hello
606
607
    1 Lorem Ipsum\t2005-11-22
608
      first post
609
      === added file 'file1'
610
      --- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
611
      +++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
612
      @@ -0,0 +1,1 @@
613
      +contents of parent/file1
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
614
\x20\x20\x20\x20\x20\x20
3943.5.3 by Ian Clatworthy
add tests
615
      === added file 'file2'
616
      --- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
617
      +++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
618
      @@ -0,0 +1,1 @@
619
      +contents of parent/file2
620
621
""")
622
623
    def test_log_show_diff_line(self):
624
        self._prepare()
3943.5.5 by Ian Clatworthy
tweak option name as requested in bug report
625
        out,err = self.run_bzr('log -p --line')
3943.5.3 by Ian Clatworthy
add tests
626
        self.assertEqual('', err)
627
        log = normalize_log(out)
628
        # Not supported by this formatter so expect plain output
629
        self.assertEqualDiff(subst_dates(log), """\
3983.2.1 by Neil Martinsen-Burrell
add merge indication to the line format
630
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
3943.5.3 by Ian Clatworthy
add tests
631
1: Lorem Ipsum 2005-11-22 first post
632
""")
633
3943.5.4 by Ian Clatworthy
filter diff by file
634
    def test_log_show_diff_file(self):
635
        """Only the diffs for the given file are to be shown"""
636
        self._prepare()
3943.5.5 by Ian Clatworthy
tweak option name as requested in bug report
637
        out,err = self.run_bzr('log -p --short file2')
3943.5.4 by Ian Clatworthy
filter diff by file
638
        self.assertEqual('', err)
639
        log = normalize_log(out)
640
        self.assertEqualDiff(subst_dates(log), """\
641
    2 Lorem Ipsum\t2005-11-22 [merge]
642
      merge branch 1
643
      === modified file 'file2'
644
      --- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
645
      +++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
646
      @@ -1,1 +1,1 @@
647
      -contents of parent/file2
648
      +hello
649
650
    1 Lorem Ipsum\t2005-11-22
651
      first post
652
      === added file 'file2'
653
      --- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
654
      +++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
655
      @@ -0,0 +1,1 @@
656
      +contents of parent/file2
657
658
""")
3943.5.5 by Ian Clatworthy
tweak option name as requested in bug report
659
        out,err = self.run_bzr('log -p --short file1')
3943.5.4 by Ian Clatworthy
filter diff by file
660
        self.assertEqual('', err)
661
        log = normalize_log(out)
662
        self.assertEqualDiff(subst_dates(log), """\
663
    1 Lorem Ipsum\t2005-11-22
664
      first post
665
      === added file 'file1'
666
      --- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
667
      +++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
668
      @@ -0,0 +1,1 @@
669
      +contents of parent/file1
670
671
""")
672
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
673
    def test_log_show_diff_non_ascii(self):
674
        # Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
675
        message = u'Message with \xb5'
676
        body = 'Body with \xb5\n'
677
        wt = self.make_branch_and_tree('.')
678
        self.build_tree_contents([('foo', body)])
679
        wt.add('foo')
680
        wt.commit(message=message)
681
        # check that command won't fail with unicode error
682
        # don't care about exact output because we have other tests for this
683
        out,err = self.run_bzr('log -p --long')
684
        self.assertNotEqual('', out)
685
        self.assertEqual('', err)
686
        out,err = self.run_bzr('log -p --short')
687
        self.assertNotEqual('', out)
688
        self.assertEqual('', err)
689
        out,err = self.run_bzr('log -p --line')
690
        self.assertNotEqual('', out)
691
        self.assertEqual('', err)
692
3943.5.3 by Ian Clatworthy
add tests
693
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
694
class TestLogEncodings(TestCaseInTempDir):
695
696
    _mu = u'\xb5'
697
    _message = u'Message with \xb5'
698
699
    # Encodings which can encode mu
700
    good_encodings = [
701
        'utf-8',
702
        'latin-1',
703
        'iso-8859-1',
704
        'cp437', # Common windows encoding
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
705
        'cp1251', # Russian windows encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
706
        'cp1258', # Common windows encoding
707
    ]
708
    # Encodings which cannot encode mu
709
    bad_encodings = [
710
        'ascii',
711
        'iso-8859-2',
712
        'koi8_r',
713
    ]
714
715
    def setUp(self):
716
        TestCaseInTempDir.setUp(self)
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
717
        self.user_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
718
719
    def tearDown(self):
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
720
        osutils._cached_user_encoding = self.user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
721
        TestCaseInTempDir.tearDown(self)
722
723
    def create_branch(self):
724
        bzr = self.run_bzr
725
        bzr('init')
726
        open('a', 'wb').write('some stuff\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
727
        bzr('add a')
728
        bzr(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
729
730
    def try_encoding(self, encoding, fail=False):
731
        bzr = self.run_bzr
732
        if fail:
733
            self.assertRaises(UnicodeEncodeError,
734
                self._mu.encode, encoding)
735
            encoded_msg = self._message.encode(encoding, 'replace')
736
        else:
737
            encoded_msg = self._message.encode(encoding)
738
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
739
        old_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
740
        # This test requires that 'run_bzr' uses the current
741
        # bzrlib, because we override user_encoding, and expect
742
        # it to be used
743
        try:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
744
            osutils._cached_user_encoding = 'ascii'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
745
            # We should be able to handle any encoding
746
            out, err = bzr('log', encoding=encoding)
747
            if not fail:
748
                # Make sure we wrote mu as we expected it to exist
749
                self.assertNotEqual(-1, out.find(encoded_msg))
750
                out_unicode = out.decode(encoding)
751
                self.assertNotEqual(-1, out_unicode.find(self._message))
752
            else:
753
                self.assertNotEqual(-1, out.find('Message with ?'))
754
        finally:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
755
            osutils._cached_user_encoding = old_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
756
757
    def test_log_handles_encoding(self):
758
        self.create_branch()
759
760
        for encoding in self.good_encodings:
761
            self.try_encoding(encoding)
762
763
    def test_log_handles_bad_encoding(self):
764
        self.create_branch()
765
766
        for encoding in self.bad_encodings:
767
            self.try_encoding(encoding, fail=True)
768
769
    def test_stdout_encoding(self):
770
        bzr = self.run_bzr
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
771
        osutils._cached_user_encoding = "cp1251"
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
772
773
        bzr('init')
774
        self.build_tree(['a'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
775
        bzr('add a')
776
        bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
777
        stdout, stderr = self.run_bzr('log', encoding='cp866')
778
779
        message = stdout.splitlines()[-1]
780
781
        # explanation of the check:
782
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
783
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
784
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
785
        # This test should check that output of log command
786
        # encoded to sys.stdout.encoding
787
        test_in_cp866 = '\x92\xa5\xe1\xe2'
788
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
789
        # Make sure the log string is encoded in cp866
790
        self.assertEquals(test_in_cp866, message[2:])
791
        # Make sure the cp1251 string is not found anywhere
792
        self.assertEquals(-1, stdout.find(test_in_cp1251))
793
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
794
795
class TestLogFile(TestCaseWithTransport):
796
797
    def test_log_local_branch_file(self):
798
        """We should be able to log files in local treeless branches"""
799
        tree = self.make_branch_and_tree('tree')
800
        self.build_tree(['tree/file'])
801
        tree.add('file')
802
        tree.commit('revision 1')
803
        tree.bzrdir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
804
        self.run_bzr('log tree/file')
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
805
3943.6.1 by Ian Clatworthy
find file using the end revision
806
    def prepare_tree(self, complex=False):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
807
        # The complex configuration includes deletes and renames
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
808
        tree = self.make_branch_and_tree('parent')
809
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
810
        tree.add('file1')
811
        tree.commit('add file1')
812
        tree.add('file2')
813
        tree.commit('add file2')
814
        tree.add('file3')
815
        tree.commit('add file3')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
816
        child_tree = tree.bzrdir.sprout('child').open_workingtree()
817
        self.build_tree_contents([('child/file2', 'hello')])
818
        child_tree.commit(message='branch 1')
819
        tree.merge_from_branch(child_tree.branch)
820
        tree.commit(message='merge child branch')
3943.6.1 by Ian Clatworthy
find file using the end revision
821
        if complex:
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
822
            tree.remove('file2')
823
            tree.commit('remove file2')
824
            tree.rename_one('file3', 'file4')
825
            tree.commit('file3 is now called file4')
3943.6.1 by Ian Clatworthy
find file using the end revision
826
            tree.remove('file1')
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
827
            tree.commit('remove file1')
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
828
        os.chdir('parent')
3940.1.2 by Ian Clatworthy
add test
829
830
    def test_log_file(self):
831
        """The log for a particular file should only list revs for that file"""
832
        self.prepare_tree()
2581.1.6 by Martin Pool
fix up more run_bzr callers
833
        log = self.run_bzr('log file1')[0]
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
834
        self.assertContainsRe(log, 'revno: 1\n')
835
        self.assertNotContainsRe(log, 'revno: 2\n')
836
        self.assertNotContainsRe(log, 'revno: 3\n')
837
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
838
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
839
        log = self.run_bzr('log file2')[0]
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
840
        self.assertNotContainsRe(log, 'revno: 1\n')
841
        self.assertContainsRe(log, 'revno: 2\n')
842
        self.assertNotContainsRe(log, 'revno: 3\n')
843
        self.assertContainsRe(log, 'revno: 3.1.1\n')
2359.1.2 by Kent Gibson
add logging of merge revisions
844
        self.assertContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
845
        log = self.run_bzr('log file3')[0]
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
846
        self.assertNotContainsRe(log, 'revno: 1\n')
847
        self.assertNotContainsRe(log, 'revno: 2\n')
848
        self.assertContainsRe(log, 'revno: 3\n')
849
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
850
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
851
        log = self.run_bzr('log -r3.1.1 file2')[0]
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
852
        self.assertNotContainsRe(log, 'revno: 1\n')
853
        self.assertNotContainsRe(log, 'revno: 2\n')
854
        self.assertNotContainsRe(log, 'revno: 3\n')
855
        self.assertContainsRe(log, 'revno: 3.1.1\n')
856
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
857
        log = self.run_bzr('log -r4 file2')[0]
858
        self.assertNotContainsRe(log, 'revno: 1\n')
859
        self.assertNotContainsRe(log, 'revno: 2\n')
860
        self.assertNotContainsRe(log, 'revno: 3\n')
861
        self.assertContainsRe(log, 'revno: 3.1.1\n')
862
        self.assertContainsRe(log, 'revno: 4\n')
863
        log = self.run_bzr('log -r3.. file2')[0]
864
        self.assertNotContainsRe(log, 'revno: 1\n')
865
        self.assertNotContainsRe(log, 'revno: 2\n')
866
        self.assertNotContainsRe(log, 'revno: 3\n')
867
        self.assertContainsRe(log, 'revno: 3.1.1\n')
868
        self.assertContainsRe(log, 'revno: 4\n')
869
        log = self.run_bzr('log -r..3 file2')[0]
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
870
        self.assertNotContainsRe(log, 'revno: 1\n')
871
        self.assertContainsRe(log, 'revno: 2\n')
872
        self.assertNotContainsRe(log, 'revno: 3\n')
873
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
874
        self.assertNotContainsRe(log, 'revno: 4\n')
3940.1.2 by Ian Clatworthy
add test
875
3943.6.4 by Ian Clatworthy
review feedback from vila
876
    def test_log_file_historical_missing(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
877
        # Check logging a deleted file gives an error if the
878
        # file isn't found at the end or start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
879
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
880
        err_msg = "Path unknown at end or start of revision range: file2"
881
        err = self.run_bzr('log file2', retcode=3)[1]
3943.6.1 by Ian Clatworthy
find file using the end revision
882
        self.assertContainsRe(err, err_msg)
883
3943.6.4 by Ian Clatworthy
review feedback from vila
884
    def test_log_file_historical_end(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
885
        # Check logging a deleted file is ok if the file existed
886
        # at the end the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
887
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
888
        log, err = self.run_bzr('log -r..4 file2')
889
        self.assertEquals('', err)
890
        self.assertNotContainsRe(log, 'revno: 1\n')
891
        self.assertContainsRe(log, 'revno: 2\n')
892
        self.assertNotContainsRe(log, 'revno: 3\n')
893
        self.assertContainsRe(log, 'revno: 3.1.1\n')
894
        self.assertContainsRe(log, 'revno: 4\n')
895
3943.6.4 by Ian Clatworthy
review feedback from vila
896
    def test_log_file_historical_start(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
897
        # Check logging a deleted file is ok if the file existed
898
        # at the start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
899
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
900
        log, err = self.run_bzr('log file1')
901
        self.assertEquals('', err)
3943.6.1 by Ian Clatworthy
find file using the end revision
902
        self.assertContainsRe(log, 'revno: 1\n')
903
        self.assertNotContainsRe(log, 'revno: 2\n')
904
        self.assertNotContainsRe(log, 'revno: 3\n')
905
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
906
        self.assertNotContainsRe(log, 'revno: 4\n')
907
908
    def test_log_file_renamed(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
909
        """File matched against revision range, not current tree."""
3943.6.1 by Ian Clatworthy
find file using the end revision
910
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
911
3943.6.1 by Ian Clatworthy
find file using the end revision
912
        # Check logging a renamed file gives an error by default
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
913
        err_msg = "Path unknown at end or start of revision range: file3"
3943.6.1 by Ian Clatworthy
find file using the end revision
914
        err = self.run_bzr('log file3', retcode=3)[1]
915
        self.assertContainsRe(err, err_msg)
916
917
        # Check we can see a renamed file if we give the right end revision
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
918
        log, err = self.run_bzr('log -r..4 file3')
919
        self.assertEquals('', err)
3943.6.1 by Ian Clatworthy
find file using the end revision
920
        self.assertNotContainsRe(log, 'revno: 1\n')
921
        self.assertNotContainsRe(log, 'revno: 2\n')
922
        self.assertContainsRe(log, 'revno: 3\n')
923
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
924
        self.assertNotContainsRe(log, 'revno: 4\n')
925
3940.1.2 by Ian Clatworthy
add test
926
    def test_line_log_file(self):
927
        """The line log for a file should only list relevant mainline revs"""
928
        # Note: this also implicitly  covers the short logging case.
929
        # We test using --line in preference to --short because matching
930
        # revnos in the output of --line is more reliable.
931
        self.prepare_tree()
3940.1.5 by Ian Clatworthy
feedback from vila
932
933
        # full history of file1
3940.1.2 by Ian Clatworthy
add test
934
        log = self.run_bzr('log --line file1')[0]
935
        self.assertContainsRe(log, '^1:', re.MULTILINE)
936
        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
937
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
938
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
939
        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
940
941
        # full history of file2
3940.1.2 by Ian Clatworthy
add test
942
        log = self.run_bzr('log --line file2')[0]
943
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
944
        self.assertContainsRe(log, '^2:', re.MULTILINE)
945
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
946
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
947
        self.assertContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
948
949
        # full history of file3
3940.1.2 by Ian Clatworthy
add test
950
        log = self.run_bzr('log --line file3')[0]
951
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
952
        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
953
        self.assertContainsRe(log, '^3:', re.MULTILINE)
954
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
955
        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
956
957
        # file in a merge revision
3940.1.2 by Ian Clatworthy
add test
958
        log = self.run_bzr('log --line -r3.1.1 file2')[0]
959
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
960
        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
961
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
962
        self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
963
        self.assertNotContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
964
965
        # file in a mainline revision
3940.1.2 by Ian Clatworthy
add test
966
        log = self.run_bzr('log --line -r4 file2')[0]
967
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
968
        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
969
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
970
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
971
        self.assertContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
972
973
        # file since a revision
3940.1.2 by Ian Clatworthy
add test
974
        log = self.run_bzr('log --line -r3.. file2')[0]
975
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
976
        self.assertNotContainsRe(log, '^2:', re.MULTILINE)
977
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
978
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
979
        self.assertContainsRe(log, '^4:', re.MULTILINE)
3940.1.5 by Ian Clatworthy
feedback from vila
980
981
        # file up to a revision
3940.1.2 by Ian Clatworthy
add test
982
        log = self.run_bzr('log --line -r..3 file2')[0]
983
        self.assertNotContainsRe(log, '^1:', re.MULTILINE)
984
        self.assertContainsRe(log, '^2:', re.MULTILINE)
985
        self.assertNotContainsRe(log, '^3:', re.MULTILINE)
986
        self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
987
        self.assertNotContainsRe(log, '^4:', re.MULTILINE)