/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
19
"""Black-box tests for bzr log."""
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
20
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
21
import os
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
22
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
23
from bzrlib import osutils
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
24
from bzrlib.tests.blackbox import ExternalBase
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
25
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
26
from bzrlib.tests.test_log import (
27
    normalize_log,
28
    )
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
29
from bzrlib.tests import test_log
30
31
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
32
class TestCaseWithoutPropsHandler(ExternalBase,
33
                                  test_log.TestCaseWithoutPropsHandler):
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
34
    pass
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
35
36
37
class TestLog(ExternalBase):
38
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
39
    def _prepare(self, path='.', format=None):
2809.1.2 by Daniel Watkins
Removed unnecessary check as per abentley's on-list comments.
40
        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.
41
        self.build_tree(
42
            [path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
43
        tree.add('hello.txt')
44
        tree.commit(message='message1')
45
        tree.add('goodbye.txt')
46
        tree.commit(message='message2')
47
        tree.add('meep.txt')
48
        tree.commit(message='message3')
49
        self.full_log = self.run_bzr(["log", path])[0]
50
        return tree
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
51
52
    def test_log_null_end_revspec(self):
53
        self._prepare()
54
        self.assertTrue('revno: 1\n' in self.full_log)
55
        self.assertTrue('revno: 2\n' in self.full_log)
56
        self.assertTrue('revno: 3\n' in self.full_log)
57
        self.assertTrue('message:\n  message1\n' in self.full_log)
58
        self.assertTrue('message:\n  message2\n' in self.full_log)
59
        self.assertTrue('message:\n  message3\n' in self.full_log)
60
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
61
        log = self.run_bzr("log -r 1..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
62
        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
63
64
    def test_log_null_begin_revspec(self):
65
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
66
        log = self.run_bzr("log -r ..3")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
67
        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
68
69
    def test_log_null_both_revspecs(self):
70
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
71
        log = self.run_bzr("log -r ..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
72
        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
73
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
74
    def test_log_zero_revspec(self):
75
        self._prepare()
76
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
77
                           ['log', '-r0'])
78
79
    def test_log_zero_begin_revspec(self):
80
        self._prepare()
81
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
82
                           ['log', '-r0..2'])
83
84
    def test_log_zero_end_revspec(self):
85
        self._prepare()
86
        self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
87
                           ['log', '-r-2..0'])
88
3144.1.1 by Lukáš Lalinský
Fixed error reporting of unsupported timezone format.
89
    def test_log_unsupported_timezone(self):
90
        self._prepare()
91
        self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
92
                           'options are "utc", "original", "local".',
93
                           ['log', '--timezone', 'foo'])
94
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
95
    def test_log_negative_begin_revspec_full_log(self):
96
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
97
        log = self.run_bzr("log -r -3..")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
98
        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
99
100
    def test_log_negative_both_revspec_full_log(self):
101
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
102
        log = self.run_bzr("log -r -3..-1")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
103
        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
104
105
    def test_log_negative_both_revspec_partial(self):
106
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
107
        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
108
        self.assertTrue('revno: 1\n' in log)
109
        self.assertTrue('revno: 2\n' in log)
110
        self.assertTrue('revno: 3\n' not in log)
111
112
    def test_log_negative_begin_revspec(self):
113
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
114
        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
115
        self.assertTrue('revno: 1\n' not in log)
116
        self.assertTrue('revno: 2\n' in log)
117
        self.assertTrue('revno: 3\n' in log)
118
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
119
    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
120
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
121
        log = self.run_bzr("log -r 1..3")[0]
2466.11.2 by Kent Gibson
Add tests for deltas in merge revisions
122
        self.assertEqualDiff(self.full_log, log)
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
123
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
124
    def test_log_reversed_revspecs(self):
125
        self._prepare()
126
        self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
127
                            'the end revision.\n',),
2581.1.6 by Martin Pool
fix up more run_bzr callers
128
                           ['log', '-r3..1'])
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
129
1907.4.2 by Matthieu Moy
Make log work nicely with revno:N:path too.
130
    def test_log_revno_n_path(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
131
        self._prepare(path='branch1')
132
        self._prepare(path='branch2')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
133
        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.
134
                          retcode=3)[0]
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
135
        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
136
        self.assertEqualDiff(self.full_log, log)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
137
        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.
138
        self.assertTrue('revno: 1\n' in log)
139
        self.assertTrue('revno: 2\n' not in log)
140
        self.assertTrue('branch nick: branch2\n' in log)
141
        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.
142
143
    def test_log_change_revno(self):
144
        self._prepare()
145
        expected_log = self.run_bzr("log -r 1")[0]
146
        log = self.run_bzr("log -c 1")[0]
147
        self.assertEqualDiff(expected_log, log)
148
149
    def test_log_change_single_revno(self):
150
        self._prepare()
151
        self.run_bzr_error('bzr: ERROR: Option --change does not'
152
                           ' accept revision ranges',
153
                           ['log', '--change', '2..3'])
154
155
    def test_log_change_incompatible_with_revision(self):
156
        self._prepare()
157
        self.run_bzr_error('bzr: ERROR: --revision and --change'
158
                           ' are mutually exclusive',
159
                           ['log', '--change', '2', '--revision', '3'])
160
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
161
    def test_log_nonexistent_file(self):
162
        # files that don't exist in either the basis tree or working tree
163
        # should give an error
164
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
165
        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
166
        self.assertContainsRe(
167
            err, 'Path does not have any revision history: does-not-exist')
2388.1.11 by Alexander Belchenko
changes after John's review
168
2388.1.3 by Erik Bagfors
tests for tags in log output
169
    def test_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
170
        tree = self._prepare(format='dirstate-tags')
171
        branch = tree.branch
172
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
173
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
174
        branch.tags.set_tag('tag3', branch.last_revision())
175
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
176
        log = self.run_bzr("log -r-1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
177
        self.assertTrue('tags: tag3' in log)
178
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
179
        log = self.run_bzr("log -r1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
180
        # I guess that we can't know the order of tags in the output
181
        # since dicts are unordered, need to check both possibilities
2388.1.11 by Alexander Belchenko
changes after John's review
182
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
183
2388.1.9 by Erik Bagfors
test for merges with tags in log
184
    def test_merged_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
185
        branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
186
        branch1 = branch1_tree.branch
187
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
188
        branch1_tree.commit(message='foobar', allow_pointless=True)
189
        branch1.tags.set_tag('tag1', branch1.last_revision())
190
        os.chdir('branch2')
191
        self.run_bzr('merge ../branch1') # tags don't propagate otherwise
192
        branch2_tree.commit(message='merge branch 1')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
193
        log = self.run_bzr("log -r-1")[0]
2388.1.11 by Alexander Belchenko
changes after John's review
194
        self.assertContainsRe(log, r'    tags: tag1')
2578.2.1 by Andrew Bennetts
Merge Kent Gibson's fix for bug #4663, resolving conflicts.
195
        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
196
        self.assertContainsRe(log, r'tags: tag1')
2388.1.3 by Erik Bagfors
tests for tags in log output
197
2466.9.1 by Kent Gibson
add bzr log --limit
198
    def test_log_limit(self):
3660.1.1 by Robert Collins
Fix log --limit (broken by log filtering patch).
199
        tree = self.make_branch_and_tree('.')
200
        # We want more commits than our batch size starts at
201
        for pos in range(10):
202
            tree.commit("%s" % pos)
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
203
        log = self.run_bzr("log --limit 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
204
        self.assertNotContainsRe(log, r'revno: 1\n')
3660.1.1 by Robert Collins
Fix log --limit (broken by log filtering patch).
205
        self.assertNotContainsRe(log, r'revno: 2\n')
206
        self.assertNotContainsRe(log, r'revno: 3\n')
207
        self.assertNotContainsRe(log, r'revno: 4\n')
208
        self.assertNotContainsRe(log, r'revno: 5\n')
209
        self.assertNotContainsRe(log, r'revno: 6\n')
210
        self.assertNotContainsRe(log, r'revno: 7\n')
211
        self.assertNotContainsRe(log, r'revno: 8\n')
212
        self.assertContainsRe(log, r'revno: 9\n')
213
        self.assertContainsRe(log, r'revno: 10\n')
2466.9.1 by Kent Gibson
add bzr log --limit
214
3108.1.2 by Matt Nordhoff
Simple copied unit test.
215
    def test_log_limit_short(self):
216
        self._prepare()
217
        log = self.run_bzr("log -l 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
218
        self.assertNotContainsRe(log, r'revno: 1\n')
219
        self.assertContainsRe(log, r'revno: 2\n')
220
        self.assertContainsRe(log, r'revno: 3\n')
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
221
222
223
class TestLogMerges(TestCaseWithoutPropsHandler):
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
224
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
225
    def _prepare(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
226
        parent_tree = self.make_branch_and_tree('parent')
227
        parent_tree.commit(message='first post', allow_pointless=True)
228
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
229
        child_tree.commit(message='branch 1', allow_pointless=True)
230
        smaller_tree = \
231
                child_tree.bzrdir.sprout('smallerchild').open_workingtree()
232
        smaller_tree.commit(message='branch 2', allow_pointless=True)
233
        child_tree.merge_from_branch(smaller_tree.branch)
234
        child_tree.commit(message='merge branch 2')
235
        parent_tree.merge_from_branch(child_tree.branch)
236
        parent_tree.commit(message='merge branch 1')
237
        os.chdir('parent')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
238
239
    def test_merges_are_indented_by_level(self):
240
        self._prepare()
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
241
        out,err = self.run_bzr('log')
242
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
243
        log = normalize_log(out)
244
        self.assertEqualDiff(log, """\
245
------------------------------------------------------------
246
revno: 2
247
committer: Lorem Ipsum <test@example.com>
248
branch nick: parent
249
timestamp: Just now
250
message:
251
  merge branch 1
252
    ------------------------------------------------------------
253
    revno: 1.1.2
254
    committer: Lorem Ipsum <test@example.com>
255
    branch nick: child
256
    timestamp: Just now
257
    message:
258
      merge branch 2
259
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
260
        revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
261
        committer: Lorem Ipsum <test@example.com>
262
        branch nick: smallerchild
263
        timestamp: Just now
264
        message:
265
          branch 2
266
    ------------------------------------------------------------
267
    revno: 1.1.1
268
    committer: Lorem Ipsum <test@example.com>
269
    branch nick: child
270
    timestamp: Just now
271
    message:
272
      branch 1
273
------------------------------------------------------------
274
revno: 1
275
committer: Lorem Ipsum <test@example.com>
276
branch nick: parent
277
timestamp: Just now
278
message:
279
  first post
280
""")
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
281
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
282
    def test_merges_single_merge_rev(self):
283
        self._prepare()
2581.1.6 by Martin Pool
fix up more run_bzr callers
284
        out,err = self.run_bzr('log -r1.1.2')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
285
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
286
        log = normalize_log(out)
287
        self.assertEqualDiff(log, """\
288
------------------------------------------------------------
289
revno: 1.1.2
290
committer: Lorem Ipsum <test@example.com>
291
branch nick: child
292
timestamp: Just now
293
message:
294
  merge branch 2
295
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
296
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
297
    committer: Lorem Ipsum <test@example.com>
298
    branch nick: smallerchild
299
    timestamp: Just now
300
    message:
301
      branch 2
302
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
303
304
    def test_merges_partial_range(self):
305
        self._prepare()
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
306
        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.
307
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
308
        log = normalize_log(out)
309
        self.assertEqualDiff(log, """\
310
------------------------------------------------------------
311
revno: 1.1.2
312
committer: Lorem Ipsum <test@example.com>
313
branch nick: child
314
timestamp: Just now
315
message:
316
  merge branch 2
317
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
318
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
319
    committer: Lorem Ipsum <test@example.com>
320
    branch nick: smallerchild
321
    timestamp: Just now
322
    message:
323
      branch 2
324
------------------------------------------------------------
325
revno: 1.1.1
326
committer: Lorem Ipsum <test@example.com>
327
branch nick: child
328
timestamp: Just now
329
message:
330
  branch 1
331
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
332
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
333
    def test_merges_nonsupporting_formatter(self):
334
        self._prepare()
335
        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.
336
        # The single revision case is tested in the core tests
337
        # since all standard formatters support single merge revisions.
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
338
        out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
339
        self.assertContainsRe(err, err_msg)
340
        out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
341
        self.assertContainsRe(err, err_msg)
342
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
343
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
344
class TestLogEncodings(TestCaseInTempDir):
345
346
    _mu = u'\xb5'
347
    _message = u'Message with \xb5'
348
349
    # Encodings which can encode mu
350
    good_encodings = [
351
        'utf-8',
352
        'latin-1',
353
        'iso-8859-1',
354
        'cp437', # Common windows encoding
355
        'cp1251', # Alexander Belchenko's windows encoding
356
        'cp1258', # Common windows encoding
357
    ]
358
    # Encodings which cannot encode mu
359
    bad_encodings = [
360
        'ascii',
361
        'iso-8859-2',
362
        'koi8_r',
363
    ]
364
365
    def setUp(self):
366
        TestCaseInTempDir.setUp(self)
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
367
        self.user_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
368
369
    def tearDown(self):
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
370
        osutils._cached_user_encoding = self.user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
371
        TestCaseInTempDir.tearDown(self)
372
373
    def create_branch(self):
374
        bzr = self.run_bzr
375
        bzr('init')
376
        open('a', 'wb').write('some stuff\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
377
        bzr('add a')
378
        bzr(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
379
380
    def try_encoding(self, encoding, fail=False):
381
        bzr = self.run_bzr
382
        if fail:
383
            self.assertRaises(UnicodeEncodeError,
384
                self._mu.encode, encoding)
385
            encoded_msg = self._message.encode(encoding, 'replace')
386
        else:
387
            encoded_msg = self._message.encode(encoding)
388
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
389
        old_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
390
        # This test requires that 'run_bzr' uses the current
391
        # bzrlib, because we override user_encoding, and expect
392
        # it to be used
393
        try:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
394
            osutils._cached_user_encoding = 'ascii'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
395
            # We should be able to handle any encoding
396
            out, err = bzr('log', encoding=encoding)
397
            if not fail:
398
                # Make sure we wrote mu as we expected it to exist
399
                self.assertNotEqual(-1, out.find(encoded_msg))
400
                out_unicode = out.decode(encoding)
401
                self.assertNotEqual(-1, out_unicode.find(self._message))
402
            else:
403
                self.assertNotEqual(-1, out.find('Message with ?'))
404
        finally:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
405
            osutils._cached_user_encoding = old_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
406
407
    def test_log_handles_encoding(self):
408
        self.create_branch()
409
410
        for encoding in self.good_encodings:
411
            self.try_encoding(encoding)
412
413
    def test_log_handles_bad_encoding(self):
414
        self.create_branch()
415
416
        for encoding in self.bad_encodings:
417
            self.try_encoding(encoding, fail=True)
418
419
    def test_stdout_encoding(self):
420
        bzr = self.run_bzr
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
421
        osutils._cached_user_encoding = "cp1251"
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
422
423
        bzr('init')
424
        self.build_tree(['a'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
425
        bzr('add a')
426
        bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
427
        stdout, stderr = self.run_bzr('log', encoding='cp866')
428
429
        message = stdout.splitlines()[-1]
430
431
        # explanation of the check:
432
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
433
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
434
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
435
        # This test should check that output of log command
436
        # encoded to sys.stdout.encoding
437
        test_in_cp866 = '\x92\xa5\xe1\xe2'
438
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
439
        # Make sure the log string is encoded in cp866
440
        self.assertEquals(test_in_cp866, message[2:])
441
        # Make sure the cp1251 string is not found anywhere
442
        self.assertEquals(-1, stdout.find(test_in_cp1251))
443
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
444
445
class TestLogFile(TestCaseWithTransport):
446
447
    def test_log_local_branch_file(self):
448
        """We should be able to log files in local treeless branches"""
449
        tree = self.make_branch_and_tree('tree')
450
        self.build_tree(['tree/file'])
451
        tree.add('file')
452
        tree.commit('revision 1')
453
        tree.bzrdir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
454
        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.
455
456
    def test_log_file(self):
457
        """The log for a particular file should only list revs for that file"""
458
        tree = self.make_branch_and_tree('parent')
459
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
460
        tree.add('file1')
461
        tree.commit('add file1')
462
        tree.add('file2')
463
        tree.commit('add file2')
464
        tree.add('file3')
465
        tree.commit('add file3')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
466
        child_tree = tree.bzrdir.sprout('child').open_workingtree()
467
        self.build_tree_contents([('child/file2', 'hello')])
468
        child_tree.commit(message='branch 1')
469
        tree.merge_from_branch(child_tree.branch)
470
        tree.commit(message='merge child branch')
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
471
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
472
        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.
473
        self.assertContainsRe(log, 'revno: 1\n')
474
        self.assertNotContainsRe(log, 'revno: 2\n')
475
        self.assertNotContainsRe(log, 'revno: 3\n')
476
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
477
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
478
        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.
479
        self.assertNotContainsRe(log, 'revno: 1\n')
480
        self.assertContainsRe(log, 'revno: 2\n')
481
        self.assertNotContainsRe(log, 'revno: 3\n')
482
        self.assertContainsRe(log, 'revno: 3.1.1\n')
2359.1.2 by Kent Gibson
add logging of merge revisions
483
        self.assertContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
484
        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.
485
        self.assertNotContainsRe(log, 'revno: 1\n')
486
        self.assertNotContainsRe(log, 'revno: 2\n')
487
        self.assertContainsRe(log, 'revno: 3\n')
488
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
489
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
490
        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.
491
        self.assertNotContainsRe(log, 'revno: 1\n')
492
        self.assertNotContainsRe(log, 'revno: 2\n')
493
        self.assertNotContainsRe(log, 'revno: 3\n')
494
        self.assertContainsRe(log, 'revno: 3.1.1\n')
495
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
496
        log = self.run_bzr('log -r4 file2')[0]
497
        self.assertNotContainsRe(log, 'revno: 1\n')
498
        self.assertNotContainsRe(log, 'revno: 2\n')
499
        self.assertNotContainsRe(log, 'revno: 3\n')
500
        self.assertContainsRe(log, 'revno: 3.1.1\n')
501
        self.assertContainsRe(log, 'revno: 4\n')
502
        log = self.run_bzr('log -r3.. file2')[0]
503
        self.assertNotContainsRe(log, 'revno: 1\n')
504
        self.assertNotContainsRe(log, 'revno: 2\n')
505
        self.assertNotContainsRe(log, 'revno: 3\n')
506
        self.assertContainsRe(log, 'revno: 3.1.1\n')
507
        self.assertContainsRe(log, 'revno: 4\n')
508
        log = self.run_bzr('log -r..3 file2')[0]
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
509
        self.assertNotContainsRe(log, 'revno: 1\n')
510
        self.assertContainsRe(log, 'revno: 2\n')
511
        self.assertNotContainsRe(log, 'revno: 3\n')
512
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
513
        self.assertNotContainsRe(log, 'revno: 4\n')