~bzr-pqm/bzr/bzr.dev

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