/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
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
23
import bzrlib
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
32
class TestCaseWithoutPropsHandler(ExternalBase, test_log.TestCaseWithoutPropsHandler):
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)
141
        
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
142
    def test_log_nonexistent_file(self):
143
        # files that don't exist in either the basis tree or working tree
144
        # should give an error
145
        wt = self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
146
        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
147
        self.assertContainsRe(
148
            err, 'Path does not have any revision history: does-not-exist')
2388.1.11 by Alexander Belchenko
changes after John's review
149
2388.1.3 by Erik Bagfors
tests for tags in log output
150
    def test_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
151
        tree = self._prepare(format='dirstate-tags')
152
        branch = tree.branch
153
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
154
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
155
        branch.tags.set_tag('tag3', branch.last_revision()) 
2388.1.3 by Erik Bagfors
tests for tags in log output
156
        
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
157
        log = self.run_bzr("log -r-1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
158
        self.assertTrue('tags: tag3' in log)
159
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
160
        log = self.run_bzr("log -r1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
161
        # I guess that we can't know the order of tags in the output
162
        # since dicts are unordered, need to check both possibilities
2388.1.11 by Alexander Belchenko
changes after John's review
163
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
164
2388.1.9 by Erik Bagfors
test for merges with tags in log
165
    def test_merged_log_with_tags(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
166
        branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
167
        branch1 = branch1_tree.branch
168
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
169
        branch1_tree.commit(message='foobar', allow_pointless=True)
170
        branch1.tags.set_tag('tag1', branch1.last_revision())
171
        os.chdir('branch2')
172
        self.run_bzr('merge ../branch1') # tags don't propagate otherwise
173
        branch2_tree.commit(message='merge branch 1')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
174
        log = self.run_bzr("log -r-1")[0]
2388.1.11 by Alexander Belchenko
changes after John's review
175
        self.assertContainsRe(log, r'    tags: tag1')
2578.2.1 by Andrew Bennetts
Merge Kent Gibson's fix for bug #4663, resolving conflicts.
176
        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
177
        self.assertContainsRe(log, r'tags: tag1')
2388.1.3 by Erik Bagfors
tests for tags in log output
178
2466.9.1 by Kent Gibson
add bzr log --limit
179
    def test_log_limit(self):
180
        self._prepare()
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
181
        log = self.run_bzr("log --limit 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
182
        self.assertNotContainsRe(log, r'revno: 1\n')
183
        self.assertContainsRe(log, r'revno: 2\n')
184
        self.assertContainsRe(log, r'revno: 3\n')
2466.9.1 by Kent Gibson
add bzr log --limit
185
3108.1.2 by Matt Nordhoff
Simple copied unit test.
186
    def test_log_limit_short(self):
187
        self._prepare()
188
        log = self.run_bzr("log -l 2")[0]
3108.1.3 by Matt Nordhoff
Use assertContainsRe/assertNotContainsRe in tests.
189
        self.assertNotContainsRe(log, r'revno: 1\n')
190
        self.assertContainsRe(log, r'revno: 2\n')
191
        self.assertContainsRe(log, r'revno: 3\n')
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
192
193
194
class TestLogMerges(TestCaseWithoutPropsHandler):
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
195
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
196
    def _prepare(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
197
        parent_tree = self.make_branch_and_tree('parent')
198
        parent_tree.commit(message='first post', allow_pointless=True)
199
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
200
        child_tree.commit(message='branch 1', allow_pointless=True)
201
        smaller_tree = \
202
                child_tree.bzrdir.sprout('smallerchild').open_workingtree()
203
        smaller_tree.commit(message='branch 2', allow_pointless=True)
204
        child_tree.merge_from_branch(smaller_tree.branch)
205
        child_tree.commit(message='merge branch 2')
206
        parent_tree.merge_from_branch(child_tree.branch)
207
        parent_tree.commit(message='merge branch 1')
208
        os.chdir('parent')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
209
210
    def test_merges_are_indented_by_level(self):
211
        self._prepare()
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
212
        out,err = self.run_bzr('log')
213
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
214
        log = normalize_log(out)
215
        self.assertEqualDiff(log, """\
216
------------------------------------------------------------
217
revno: 2
218
committer: Lorem Ipsum <test@example.com>
219
branch nick: parent
220
timestamp: Just now
221
message:
222
  merge branch 1
223
    ------------------------------------------------------------
224
    revno: 1.1.2
225
    committer: Lorem Ipsum <test@example.com>
226
    branch nick: child
227
    timestamp: Just now
228
    message:
229
      merge branch 2
230
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
231
        revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
232
        committer: Lorem Ipsum <test@example.com>
233
        branch nick: smallerchild
234
        timestamp: Just now
235
        message:
236
          branch 2
237
    ------------------------------------------------------------
238
    revno: 1.1.1
239
    committer: Lorem Ipsum <test@example.com>
240
    branch nick: child
241
    timestamp: Just now
242
    message:
243
      branch 1
244
------------------------------------------------------------
245
revno: 1
246
committer: Lorem Ipsum <test@example.com>
247
branch nick: parent
248
timestamp: Just now
249
message:
250
  first post
251
""")
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
252
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
253
    def test_merges_single_merge_rev(self):
254
        self._prepare()
2581.1.6 by Martin Pool
fix up more run_bzr callers
255
        out,err = self.run_bzr('log -r1.1.2')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
256
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
257
        log = normalize_log(out)
258
        self.assertEqualDiff(log, """\
259
------------------------------------------------------------
260
revno: 1.1.2
261
committer: Lorem Ipsum <test@example.com>
262
branch nick: child
263
timestamp: Just now
264
message:
265
  merge branch 2
266
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
267
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
268
    committer: Lorem Ipsum <test@example.com>
269
    branch nick: smallerchild
270
    timestamp: Just now
271
    message:
272
      branch 2
273
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
274
275
    def test_merges_partial_range(self):
276
        self._prepare()
2581.1.6 by Martin Pool
fix up more run_bzr callers
277
        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.
278
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
279
        log = normalize_log(out)
280
        self.assertEqualDiff(log, """\
281
------------------------------------------------------------
282
revno: 1.1.2
283
committer: Lorem Ipsum <test@example.com>
284
branch nick: child
285
timestamp: Just now
286
message:
287
  merge branch 2
288
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
289
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
290
    committer: Lorem Ipsum <test@example.com>
291
    branch nick: smallerchild
292
    timestamp: Just now
293
    message:
294
      branch 2
295
------------------------------------------------------------
296
revno: 1.1.1
297
committer: Lorem Ipsum <test@example.com>
298
branch nick: child
299
timestamp: Just now
300
message:
301
  branch 1
302
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
303
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
304
    def test_merges_nonsupporting_formatter(self):
305
        self._prepare()
306
        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.
307
        # The single revision case is tested in the core tests
308
        # 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.
309
        out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
310
        self.assertContainsRe(err, err_msg)
311
        out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
312
        self.assertContainsRe(err, err_msg)
313
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
314
 
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
315
class TestLogEncodings(TestCaseInTempDir):
316
317
    _mu = u'\xb5'
318
    _message = u'Message with \xb5'
319
320
    # Encodings which can encode mu
321
    good_encodings = [
322
        'utf-8',
323
        'latin-1',
324
        'iso-8859-1',
325
        'cp437', # Common windows encoding
326
        'cp1251', # Alexander Belchenko's windows encoding
327
        'cp1258', # Common windows encoding
328
    ]
329
    # Encodings which cannot encode mu
330
    bad_encodings = [
331
        'ascii',
332
        'iso-8859-2',
333
        'koi8_r',
334
    ]
335
336
    def setUp(self):
337
        TestCaseInTempDir.setUp(self)
338
        self.user_encoding = bzrlib.user_encoding
339
340
    def tearDown(self):
341
        bzrlib.user_encoding = self.user_encoding
342
        TestCaseInTempDir.tearDown(self)
343
344
    def create_branch(self):
345
        bzr = self.run_bzr
346
        bzr('init')
347
        open('a', 'wb').write('some stuff\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
348
        bzr('add a')
349
        bzr(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
350
351
    def try_encoding(self, encoding, fail=False):
352
        bzr = self.run_bzr
353
        if fail:
354
            self.assertRaises(UnicodeEncodeError,
355
                self._mu.encode, encoding)
356
            encoded_msg = self._message.encode(encoding, 'replace')
357
        else:
358
            encoded_msg = self._message.encode(encoding)
359
360
        old_encoding = bzrlib.user_encoding
361
        # This test requires that 'run_bzr' uses the current
362
        # bzrlib, because we override user_encoding, and expect
363
        # it to be used
364
        try:
365
            bzrlib.user_encoding = 'ascii'
366
            # We should be able to handle any encoding
367
            out, err = bzr('log', encoding=encoding)
368
            if not fail:
369
                # Make sure we wrote mu as we expected it to exist
370
                self.assertNotEqual(-1, out.find(encoded_msg))
371
                out_unicode = out.decode(encoding)
372
                self.assertNotEqual(-1, out_unicode.find(self._message))
373
            else:
374
                self.assertNotEqual(-1, out.find('Message with ?'))
375
        finally:
376
            bzrlib.user_encoding = old_encoding
377
378
    def test_log_handles_encoding(self):
379
        self.create_branch()
380
381
        for encoding in self.good_encodings:
382
            self.try_encoding(encoding)
383
384
    def test_log_handles_bad_encoding(self):
385
        self.create_branch()
386
387
        for encoding in self.bad_encodings:
388
            self.try_encoding(encoding, fail=True)
389
390
    def test_stdout_encoding(self):
391
        bzr = self.run_bzr
392
        bzrlib.user_encoding = "cp1251"
393
394
        bzr('init')
395
        self.build_tree(['a'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
396
        bzr('add a')
397
        bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
398
        stdout, stderr = self.run_bzr('log', encoding='cp866')
399
400
        message = stdout.splitlines()[-1]
401
402
        # explanation of the check:
403
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
404
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
405
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
406
        # This test should check that output of log command
407
        # encoded to sys.stdout.encoding
408
        test_in_cp866 = '\x92\xa5\xe1\xe2'
409
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
410
        # Make sure the log string is encoded in cp866
411
        self.assertEquals(test_in_cp866, message[2:])
412
        # Make sure the cp1251 string is not found anywhere
413
        self.assertEquals(-1, stdout.find(test_in_cp1251))
414
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
415
416
class TestLogFile(TestCaseWithTransport):
417
418
    def test_log_local_branch_file(self):
419
        """We should be able to log files in local treeless branches"""
420
        tree = self.make_branch_and_tree('tree')
421
        self.build_tree(['tree/file'])
422
        tree.add('file')
423
        tree.commit('revision 1')
424
        tree.bzrdir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
425
        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.
426
427
    def test_log_file(self):
428
        """The log for a particular file should only list revs for that file"""
429
        tree = self.make_branch_and_tree('parent')
430
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
431
        tree.add('file1')
432
        tree.commit('add file1')
433
        tree.add('file2')
434
        tree.commit('add file2')
435
        tree.add('file3')
436
        tree.commit('add file3')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
437
        child_tree = tree.bzrdir.sprout('child').open_workingtree()
438
        self.build_tree_contents([('child/file2', 'hello')])
439
        child_tree.commit(message='branch 1')
440
        tree.merge_from_branch(child_tree.branch)
441
        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.
442
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
443
        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.
444
        self.assertContainsRe(log, 'revno: 1\n')
445
        self.assertNotContainsRe(log, 'revno: 2\n')
446
        self.assertNotContainsRe(log, 'revno: 3\n')
447
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
448
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
449
        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.
450
        self.assertNotContainsRe(log, 'revno: 1\n')
451
        self.assertContainsRe(log, 'revno: 2\n')
452
        self.assertNotContainsRe(log, 'revno: 3\n')
453
        self.assertContainsRe(log, 'revno: 3.1.1\n')
2359.1.2 by Kent Gibson
add logging of merge revisions
454
        self.assertContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
455
        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.
456
        self.assertNotContainsRe(log, 'revno: 1\n')
457
        self.assertNotContainsRe(log, 'revno: 2\n')
458
        self.assertContainsRe(log, 'revno: 3\n')
459
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
460
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
461
        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.
462
        self.assertNotContainsRe(log, 'revno: 1\n')
463
        self.assertNotContainsRe(log, 'revno: 2\n')
464
        self.assertNotContainsRe(log, 'revno: 3\n')
465
        self.assertContainsRe(log, 'revno: 3.1.1\n')
466
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
467
        log = self.run_bzr('log -r4 file2')[0]
468
        self.assertNotContainsRe(log, 'revno: 1\n')
469
        self.assertNotContainsRe(log, 'revno: 2\n')
470
        self.assertNotContainsRe(log, 'revno: 3\n')
471
        self.assertContainsRe(log, 'revno: 3.1.1\n')
472
        self.assertContainsRe(log, 'revno: 4\n')
473
        log = self.run_bzr('log -r3.. file2')[0]
474
        self.assertNotContainsRe(log, 'revno: 1\n')
475
        self.assertNotContainsRe(log, 'revno: 2\n')
476
        self.assertNotContainsRe(log, 'revno: 3\n')
477
        self.assertContainsRe(log, 'revno: 3.1.1\n')
478
        self.assertContainsRe(log, 'revno: 4\n')
479
        log = self.run_bzr('log -r..3 file2')[0]
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
480
        self.assertNotContainsRe(log, 'revno: 1\n')
481
        self.assertContainsRe(log, 'revno: 2\n')
482
        self.assertNotContainsRe(log, 'revno: 3\n')
483
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
484
        self.assertNotContainsRe(log, 'revno: 4\n')