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