/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
3874.1.1 by Vincent Ladeuil
Fix #87179 by using the short status format when the short format is used for log.
222
    def test_log_short_verbose(self):
223
        self._prepare()
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
224
        log = self.run_bzr(['log', '--short', '-v', '-r', '1'])[0]
225
        # Check that we use the short status format and not the regular one
226
        self.assertContainsRe(log, '(?m)^A  hello.txt$')
227
        self.assertNotContainsRe(log, '(?m)^added:$')
228
229
    def test_log_short_verbose_verbose(self):
230
        self._prepare()
231
        log = self.run_bzr(['log', '--short', '-vv', '-r', '1'])[0]
232
        # Check that we use the long status format and not the short one
233
        self.assertNotContainsRe(log, '(?m)^A  hello.txt$')
234
        self.assertContainsRe(log, '(?m)^added:$')
235
236
    def test_log_long_verbose(self):
237
        self._prepare()
238
        log = self.run_bzr(['log', '--long', '-v', '-r', '1'])[0]
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
239
        # Check that we use the long status format, ignoring the verbosity
240
        # level
241
        self.assertNotContainsRe(log, '(?m)^A  hello.txt$')
242
        self.assertContainsRe(log, '(?m)^added:$')
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
243
244
    def test_log_long_verbose_verbose(self):
245
        self._prepare()
246
        log = self.run_bzr(['log', '--long', '-vv', '-r', '1'])[0]
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
247
        # Check that we use the long status format, ignoring the verbosity
248
        # level
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
249
        self.assertNotContainsRe(log, '(?m)^A  hello.txt$')
250
        self.assertContainsRe(log, '(?m)^added:$')
3874.1.1 by Vincent Ladeuil
Fix #87179 by using the short status format when the short format is used for log.
251
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
252
253
class TestLogMerges(TestCaseWithoutPropsHandler):
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
254
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
255
    def _prepare(self):
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
256
        parent_tree = self.make_branch_and_tree('parent')
257
        parent_tree.commit(message='first post', allow_pointless=True)
258
        child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
259
        child_tree.commit(message='branch 1', allow_pointless=True)
260
        smaller_tree = \
261
                child_tree.bzrdir.sprout('smallerchild').open_workingtree()
262
        smaller_tree.commit(message='branch 2', allow_pointless=True)
263
        child_tree.merge_from_branch(smaller_tree.branch)
264
        child_tree.commit(message='merge branch 2')
265
        parent_tree.merge_from_branch(child_tree.branch)
266
        parent_tree.commit(message='merge branch 1')
267
        os.chdir('parent')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
268
269
    def test_merges_are_indented_by_level(self):
270
        self._prepare()
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
271
        out,err = self.run_bzr('log')
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: 2
277
committer: Lorem Ipsum <test@example.com>
278
branch nick: parent
279
timestamp: Just now
280
message:
281
  merge branch 1
282
    ------------------------------------------------------------
283
    revno: 1.1.2
284
    committer: Lorem Ipsum <test@example.com>
285
    branch nick: child
286
    timestamp: Just now
287
    message:
288
      merge branch 2
289
        ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
290
        revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
291
        committer: Lorem Ipsum <test@example.com>
292
        branch nick: smallerchild
293
        timestamp: Just now
294
        message:
295
          branch 2
296
    ------------------------------------------------------------
297
    revno: 1.1.1
298
    committer: Lorem Ipsum <test@example.com>
299
    branch nick: child
300
    timestamp: Just now
301
    message:
302
      branch 1
303
------------------------------------------------------------
304
revno: 1
305
committer: Lorem Ipsum <test@example.com>
306
branch nick: parent
307
timestamp: Just now
308
message:
309
  first post
310
""")
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
311
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
312
    def test_merges_single_merge_rev(self):
313
        self._prepare()
2581.1.6 by Martin Pool
fix up more run_bzr callers
314
        out,err = self.run_bzr('log -r1.1.2')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
315
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
316
        log = normalize_log(out)
317
        self.assertEqualDiff(log, """\
318
------------------------------------------------------------
319
revno: 1.1.2
320
committer: Lorem Ipsum <test@example.com>
321
branch nick: child
322
timestamp: Just now
323
message:
324
  merge branch 2
325
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
326
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
327
    committer: Lorem Ipsum <test@example.com>
328
    branch nick: smallerchild
329
    timestamp: Just now
330
    message:
331
      branch 2
332
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
333
334
    def test_merges_partial_range(self):
335
        self._prepare()
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
336
        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.
337
        self.assertEqual('', err)
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
338
        log = normalize_log(out)
339
        self.assertEqualDiff(log, """\
340
------------------------------------------------------------
341
revno: 1.1.2
342
committer: Lorem Ipsum <test@example.com>
343
branch nick: child
344
timestamp: Just now
345
message:
346
  merge branch 2
347
    ------------------------------------------------------------
3170.3.4 by John Arbash Meinel
Update the tests for the new revision numbering.
348
    revno: 1.2.1
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
349
    committer: Lorem Ipsum <test@example.com>
350
    branch nick: smallerchild
351
    timestamp: Just now
352
    message:
353
      branch 2
354
------------------------------------------------------------
355
revno: 1.1.1
356
committer: Lorem Ipsum <test@example.com>
357
branch nick: child
358
timestamp: Just now
359
message:
360
  branch 1
361
""")
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
362
2978.3.1 by Kent Gibson
Return an error if the revisionspec contains merge revisions, but the log formatter doesn't support them.
363
    def test_merges_nonsupporting_formatter(self):
364
        self._prepare()
365
        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.
366
        # The single revision case is tested in the core tests
367
        # 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.
368
        out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
369
        self.assertContainsRe(err, err_msg)
370
        out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
371
        self.assertContainsRe(err, err_msg)
372
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
373
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
374
class TestLogEncodings(TestCaseInTempDir):
375
376
    _mu = u'\xb5'
377
    _message = u'Message with \xb5'
378
379
    # Encodings which can encode mu
380
    good_encodings = [
381
        'utf-8',
382
        'latin-1',
383
        'iso-8859-1',
384
        'cp437', # Common windows encoding
385
        'cp1251', # Alexander Belchenko's windows encoding
386
        'cp1258', # Common windows encoding
387
    ]
388
    # Encodings which cannot encode mu
389
    bad_encodings = [
390
        'ascii',
391
        'iso-8859-2',
392
        'koi8_r',
393
    ]
394
395
    def setUp(self):
396
        TestCaseInTempDir.setUp(self)
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
397
        self.user_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
398
399
    def tearDown(self):
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
400
        osutils._cached_user_encoding = self.user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
401
        TestCaseInTempDir.tearDown(self)
402
403
    def create_branch(self):
404
        bzr = self.run_bzr
405
        bzr('init')
406
        open('a', 'wb').write('some stuff\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
407
        bzr('add a')
408
        bzr(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
409
410
    def try_encoding(self, encoding, fail=False):
411
        bzr = self.run_bzr
412
        if fail:
413
            self.assertRaises(UnicodeEncodeError,
414
                self._mu.encode, encoding)
415
            encoded_msg = self._message.encode(encoding, 'replace')
416
        else:
417
            encoded_msg = self._message.encode(encoding)
418
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
419
        old_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
420
        # This test requires that 'run_bzr' uses the current
421
        # bzrlib, because we override user_encoding, and expect
422
        # it to be used
423
        try:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
424
            osutils._cached_user_encoding = 'ascii'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
425
            # We should be able to handle any encoding
426
            out, err = bzr('log', encoding=encoding)
427
            if not fail:
428
                # Make sure we wrote mu as we expected it to exist
429
                self.assertNotEqual(-1, out.find(encoded_msg))
430
                out_unicode = out.decode(encoding)
431
                self.assertNotEqual(-1, out_unicode.find(self._message))
432
            else:
433
                self.assertNotEqual(-1, out.find('Message with ?'))
434
        finally:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
435
            osutils._cached_user_encoding = old_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
436
437
    def test_log_handles_encoding(self):
438
        self.create_branch()
439
440
        for encoding in self.good_encodings:
441
            self.try_encoding(encoding)
442
443
    def test_log_handles_bad_encoding(self):
444
        self.create_branch()
445
446
        for encoding in self.bad_encodings:
447
            self.try_encoding(encoding, fail=True)
448
449
    def test_stdout_encoding(self):
450
        bzr = self.run_bzr
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
451
        osutils._cached_user_encoding = "cp1251"
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
452
453
        bzr('init')
454
        self.build_tree(['a'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
455
        bzr('add a')
456
        bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
457
        stdout, stderr = self.run_bzr('log', encoding='cp866')
458
459
        message = stdout.splitlines()[-1]
460
461
        # explanation of the check:
462
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
463
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
464
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
465
        # This test should check that output of log command
466
        # encoded to sys.stdout.encoding
467
        test_in_cp866 = '\x92\xa5\xe1\xe2'
468
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
469
        # Make sure the log string is encoded in cp866
470
        self.assertEquals(test_in_cp866, message[2:])
471
        # Make sure the cp1251 string is not found anywhere
472
        self.assertEquals(-1, stdout.find(test_in_cp1251))
473
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
474
475
class TestLogFile(TestCaseWithTransport):
476
477
    def test_log_local_branch_file(self):
478
        """We should be able to log files in local treeless branches"""
479
        tree = self.make_branch_and_tree('tree')
480
        self.build_tree(['tree/file'])
481
        tree.add('file')
482
        tree.commit('revision 1')
483
        tree.bzrdir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
484
        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.
485
486
    def test_log_file(self):
487
        """The log for a particular file should only list revs for that file"""
488
        tree = self.make_branch_and_tree('parent')
489
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
490
        tree.add('file1')
491
        tree.commit('add file1')
492
        tree.add('file2')
493
        tree.commit('add file2')
494
        tree.add('file3')
495
        tree.commit('add file3')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
496
        child_tree = tree.bzrdir.sprout('child').open_workingtree()
497
        self.build_tree_contents([('child/file2', 'hello')])
498
        child_tree.commit(message='branch 1')
499
        tree.merge_from_branch(child_tree.branch)
500
        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.
501
        os.chdir('parent')
2581.1.6 by Martin Pool
fix up more run_bzr callers
502
        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.
503
        self.assertContainsRe(log, 'revno: 1\n')
504
        self.assertNotContainsRe(log, 'revno: 2\n')
505
        self.assertNotContainsRe(log, 'revno: 3\n')
506
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
507
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
508
        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.
509
        self.assertNotContainsRe(log, 'revno: 1\n')
510
        self.assertContainsRe(log, 'revno: 2\n')
511
        self.assertNotContainsRe(log, 'revno: 3\n')
512
        self.assertContainsRe(log, 'revno: 3.1.1\n')
2359.1.2 by Kent Gibson
add logging of merge revisions
513
        self.assertContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
514
        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.
515
        self.assertNotContainsRe(log, 'revno: 1\n')
516
        self.assertNotContainsRe(log, 'revno: 2\n')
517
        self.assertContainsRe(log, 'revno: 3\n')
518
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
519
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
520
        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.
521
        self.assertNotContainsRe(log, 'revno: 1\n')
522
        self.assertNotContainsRe(log, 'revno: 2\n')
523
        self.assertNotContainsRe(log, 'revno: 3\n')
524
        self.assertContainsRe(log, 'revno: 3.1.1\n')
525
        self.assertNotContainsRe(log, 'revno: 4\n')
2581.1.6 by Martin Pool
fix up more run_bzr callers
526
        log = self.run_bzr('log -r4 file2')[0]
527
        self.assertNotContainsRe(log, 'revno: 1\n')
528
        self.assertNotContainsRe(log, 'revno: 2\n')
529
        self.assertNotContainsRe(log, 'revno: 3\n')
530
        self.assertContainsRe(log, 'revno: 3.1.1\n')
531
        self.assertContainsRe(log, 'revno: 4\n')
532
        log = self.run_bzr('log -r3.. file2')[0]
533
        self.assertNotContainsRe(log, 'revno: 1\n')
534
        self.assertNotContainsRe(log, 'revno: 2\n')
535
        self.assertNotContainsRe(log, 'revno: 3\n')
536
        self.assertContainsRe(log, 'revno: 3.1.1\n')
537
        self.assertContainsRe(log, 'revno: 4\n')
538
        log = self.run_bzr('log -r..3 file2')[0]
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
539
        self.assertNotContainsRe(log, 'revno: 1\n')
540
        self.assertContainsRe(log, 'revno: 2\n')
541
        self.assertNotContainsRe(log, 'revno: 3\n')
542
        self.assertNotContainsRe(log, 'revno: 3.1.1\n')
543
        self.assertNotContainsRe(log, 'revno: 4\n')