/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz log."""
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
19
6728.1.2 by Jelmer Vernooij
Sign using python-gpg rather than command-line gpg.
20
from __future__ import absolute_import
21
22
4325.4.3 by Vincent Ladeuil
More cleanups.
23
import os
1540.2.6 by Robey Pointer
make 'log' and 'status' treat '-r N..' as implicitly '-r N..-1'
24
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy import (
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
26
    branchbuilder,
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
27
    errors,
4955.5.2 by Vincent Ladeuil
Simplify tests.
28
    log,
4325.4.3 by Vincent Ladeuil
More cleanups.
29
    osutils,
30
    tests,
2978.6.1 by Kent Gibson
Use normalize_log to more accurately test blackbox log output.
31
    )
7027.4.11 by Jelmer Vernooij
Fix some tests that fail with -Werror.
32
from breezy.sixish import PY3
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
33
from breezy.tests import (
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
34
    test_log,
5971.1.49 by Jonathan Riddell
import features in test
35
    features,
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
36
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
37
from breezy.tests.matchers import ContainsNoVfsCalls
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
38
39
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
40
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
41
42
    def make_minimal_branch(self, path='.', format=None):
43
        tree = self.make_branch_and_tree(path, format=format)
44
        self.build_tree([path + '/hello.txt'])
45
        tree.add('hello.txt')
46
        tree.commit(message='message1')
47
        return tree
48
49
    def make_linear_branch(self, path='.', format=None):
2809.1.2 by Daniel Watkins
Removed unnecessary check as per abentley's on-list comments.
50
        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.
51
        self.build_tree(
52
            [path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
53
        tree.add('hello.txt')
54
        tree.commit(message='message1')
55
        tree.add('goodbye.txt')
56
        tree.commit(message='message2')
57
        tree.add('meep.txt')
58
        tree.commit(message='message3')
59
        return tree
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
60
4369.2.1 by Marius Kruger
add some leftover log tests
61
    def make_merged_branch(self, path='.', format=None):
4369.2.2 by Marius Kruger
use make_linear_branch in make_merged_branch
62
        tree = self.make_linear_branch(path, format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
63
        tree2 = tree.controldir.sprout('tree2',
4369.2.2 by Marius Kruger
use make_linear_branch in make_merged_branch
64
            revision_id=tree.branch.get_rev_id(1)).open_workingtree()
4369.2.1 by Marius Kruger
add some leftover log tests
65
        tree2.commit(message='tree2 message2')
66
        tree2.commit(message='tree2 message3')
67
        tree.merge_from_branch(tree2.branch)
68
        tree.commit(message='merge')
69
        return tree
70
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
71
4955.5.2 by Vincent Ladeuil
Simplify tests.
72
class TestLogWithLogCatcher(TestLog):
73
74
    def setUp(self):
75
        super(TestLogWithLogCatcher, self).setUp()
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
76
        # Capture log formatter creations
4955.5.2 by Vincent Ladeuil
Simplify tests.
77
        class MyLogFormatter(test_log.LogCatcher):
78
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
79
            def __new__(klass, *args, **kwargs):
80
                self.log_catcher = test_log.LogCatcher(*args, **kwargs)
81
                # Always return our own log formatter
82
                return self.log_catcher
5340.15.1 by John Arbash Meinel
supersede exc-info branch
83
        # Break cycle with closure over self on cleanup by removing method
84
        self.addCleanup(setattr, MyLogFormatter, "__new__", None)
4955.5.2 by Vincent Ladeuil
Simplify tests.
85
86
        def getme(branch):
87
                # Always return our own log formatter class hijacking the
88
                # default behavior (which requires setting up a config
89
                # variable)
90
            return MyLogFormatter
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
91
        self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
4955.5.2 by Vincent Ladeuil
Simplify tests.
92
4955.4.8 by Vincent Ladeuil
Simplify more tests.
93
    def get_captured_revisions(self):
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
94
        return self.log_catcher.revisions
4955.4.8 by Vincent Ladeuil
Simplify more tests.
95
6123.11.10 by Martin von Gagern
Print deprecation warnings for all uses of include_merges.
96
    def assertLogRevnos(self, args, expected_revnos, working_dir='.',
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
97
                        out='', err=''):
6123.11.10 by Martin von Gagern
Print deprecation warnings for all uses of include_merges.
98
        actual_out, actual_err = self.run_bzr(['log'] + args,
99
                                              working_dir=working_dir)
100
        self.assertEqual(out, actual_out)
101
        self.assertEqual(err, actual_err)
4955.4.8 by Vincent Ladeuil
Simplify more tests.
102
        self.assertEqual(expected_revnos,
103
                         [r.revno for r in self.get_captured_revisions()])
104
105
    def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
106
                                working_dir='.'):
107
        self.run_bzr(['log'] + args, working_dir=working_dir)
108
        self.assertEqual(expected_revnos_and_depths,
109
                         [(r.revno, r.merge_depth)
110
                           for r in self.get_captured_revisions()])
4955.5.2 by Vincent Ladeuil
Simplify tests.
111
112
113
class TestLogRevSpecs(TestLogWithLogCatcher):
114
115
    def test_log_no_revspec(self):
116
        self.make_linear_branch()
117
        self.assertLogRevnos([], ['3', '2', '1'])
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
118
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
119
    def test_log_null_end_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
120
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
121
        self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
122
123
    def test_log_null_begin_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
124
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
125
        self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
126
127
    def test_log_null_both_revspecs(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
128
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
129
        self.assertLogRevnos(['-r..'], ['3', '2', '1'])
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
130
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
131
    def test_log_negative_begin_revspec_full_log(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
132
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
133
        self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
134
135
    def test_log_negative_both_revspec_full_log(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
136
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
137
        self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
138
139
    def test_log_negative_both_revspec_partial(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
140
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
141
        self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
142
143
    def test_log_negative_begin_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
144
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
145
        self.assertLogRevnos(['-r-2..'], ['3', '2'])
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
146
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
147
    def test_log_positive_revspecs(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
148
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
149
        self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
150
4369.2.1 by Marius Kruger
add some leftover log tests
151
    def test_log_dotted_revspecs(self):
152
        self.make_merged_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
153
        self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
154
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
155
    def test_log_limit(self):
156
        tree = self.make_branch_and_tree('.')
157
        # We want more commits than our batch size starts at
158
        for pos in range(10):
159
            tree.commit("%s" % pos)
4955.5.2 by Vincent Ladeuil
Simplify tests.
160
        self.assertLogRevnos(['--limit', '2'], ['10', '9'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
161
162
    def test_log_limit_short(self):
163
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
164
        self.assertLogRevnos(['-l', '2'], ['3', '2'])
165
4955.4.7 by Vincent Ladeuil
Some more cleanup.
166
    def test_log_change_revno(self):
167
        self.make_linear_branch()
168
        self.assertLogRevnos(['-c1'], ['1'])
169
5318.1.2 by Martin von Gagern
Add blackbox test for "bzr log -r branch:../bar".
170
    def test_branch_revspec(self):
171
        foo = self.make_branch_and_tree('foo')
172
        bar = self.make_branch_and_tree('bar')
173
        self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
174
        foo.add('foo.txt')
175
        bar.add('bar.txt')
176
        foo.commit(message='foo')
177
        bar.commit(message='bar')
178
        self.run_bzr('log -r branch:../bar', working_dir='foo')
179
        self.assertEqual([bar.branch.get_rev_id(1)],
180
                         [r.rev.revision_id
181
                          for r in self.get_captured_revisions()])
182
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
183
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
184
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
185
186
    def test_exclude_common_ancestry_simple_revnos(self):
187
        self.make_linear_branch()
188
        self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
189
                             ['3', '2'])
190
191
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
192
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
193
194
    def setUp(self):
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
195
        super(TestLogMergedLinearAncestry, self).setUp()
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
196
        # FIXME: Using a MemoryTree would be even better here (but until we
197
        # stop calling run_bzr, there is no point) --vila 100118.
198
        builder = branchbuilder.BranchBuilder(self.get_transport())
199
        builder.start_series()
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
200
        # 1
201
        # | \
202
        # 2  1.1.1
203
        # | / |
204
        # 3  1.1.2
205
        # |   |
206
        # |  1.1.3
207
        # | / |
208
        # 4  1.1.4
209
        # | /
210
        # 5
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
211
        # | \
212
        # | 5.1.1
213
        # | /
214
        # 6
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
215
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
216
        # mainline
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
217
        builder.build_snapshot(None, [
6973.13.2 by Jelmer Vernooij
Fix some more tests.
218
            ('add', ('', b'root-id', 'directory', ''))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
219
            revision_id=b'1')
220
        builder.build_snapshot([b'1'], [], revision_id=b'2')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
221
        # branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
222
        builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
223
        # merge branch into mainline
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
224
        builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
225
        # new commits in branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
226
        builder.build_snapshot([b'1.1.1'], [], revision_id=b'1.1.2')
227
        builder.build_snapshot([b'1.1.2'], [], revision_id=b'1.1.3')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
228
        # merge branch into mainline
6855.4.1 by Jelmer Vernooij
Yet more bees.
229
        builder.build_snapshot([b'3', b'1.1.3'], [], revision_id=b'4')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
230
        # merge mainline into branch
6855.4.1 by Jelmer Vernooij
Yet more bees.
231
        builder.build_snapshot([b'1.1.3', b'4'], [], revision_id=b'1.1.4')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
232
        # merge branch into mainline
6855.4.1 by Jelmer Vernooij
Yet more bees.
233
        builder.build_snapshot([b'4', b'1.1.4'], [], revision_id=b'5')
234
        builder.build_snapshot([b'5'], [], revision_id=b'5.1.1')
235
        builder.build_snapshot([b'5', b'5.1.1'], [], revision_id=b'6')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
236
        builder.finish_series()
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
237
238
    def test_n0(self):
239
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
240
                             ['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
241
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
242
    def test_n0_forward(self):
243
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
244
                             ['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
245
246
    def test_n1(self):
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
247
        # starting from 1.1.4 we follow the left-hand ancestry
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
248
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
249
                             ['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
250
251
    def test_n1_forward(self):
252
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
253
                             ['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
254
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
255
    def test_fallback_when_end_rev_is_not_on_mainline(self):
256
        self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
257
                             # We don't get 1.1.1 because we say -n1
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
258
                             ['5.1.1', '5', '4', '3'])
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
259
4955.5.2 by Vincent Ladeuil
Simplify tests.
260
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
261
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
262
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
263
    def setUp(self):
264
        super(Test_GenerateAllRevisions, self).setUp()
265
        builder = self.make_branch_with_many_merges()
266
        b = builder.get_branch()
267
        b.lock_read()
268
        self.addCleanup(b.unlock)
269
        self.branch = b
270
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
271
    def make_branch_with_many_merges(self, path='.', format=None):
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
272
        builder = branchbuilder.BranchBuilder(self.get_transport())
273
        builder.start_series()
274
        # The graph below may look a bit complicated (and it may be but I've
275
        # banged my head enough on it) but the bug requires at least dotted
276
        # revnos *and* merged revisions below that.
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
277
        # 1
278
        # | \
279
        # 2  1.1.1
280
        # | X
281
        # 3  2.1.1
282
        # |   |    \
283
        # |  2.1.2  2.2.1
284
        # |   |    X
285
        # |  2.1.3  \
286
        # | /       /
287
        # 4        /
288
        # |       /
289
        # 5 -----/
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
290
        builder.build_snapshot(None, [
6855.4.1 by Jelmer Vernooij
Yet more bees.
291
            ('add', ('', b'root-id', 'directory', ''))], revision_id=b'1')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
292
        builder.build_snapshot([b'1'], [], revision_id=b'2')
293
        builder.build_snapshot([b'1'], [], revision_id=b'1.1.1')
294
        builder.build_snapshot([b'2'], [], revision_id=b'2.1.1')
295
        builder.build_snapshot([b'2', b'1.1.1'], [], revision_id=b'3')
296
        builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.1.2')
297
        builder.build_snapshot([b'2.1.1'], [], revision_id=b'2.2.1')
298
        builder.build_snapshot([b'2.1.2', b'2.2.1'], [], revision_id=b'2.1.3')
299
        builder.build_snapshot([b'3', b'2.1.3'], [], revision_id=b'4')
300
        builder.build_snapshot([b'4', b'2.1.2'], [], revision_id=b'5')
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
301
        builder.finish_series()
302
        return builder
303
304
    def test_not_an_ancestor(self):
305
        self.assertRaises(errors.BzrCommandError,
306
                          log._generate_all_revisions,
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
307
                          self.branch, '1.1.1', '2.1.3', 'reverse',
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
308
                          delayed_graph_generation=True)
309
310
    def test_wrong_order(self):
311
        self.assertRaises(errors.BzrCommandError,
312
                          log._generate_all_revisions,
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
313
                          self.branch, '5', '2.1.3', 'reverse',
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
314
                          delayed_graph_generation=True)
315
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
316
    def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
317
        revs = log._generate_all_revisions(
318
            self.branch, None, '2.1.3',
319
            'reverse', delayed_graph_generation=True)
320
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
321
4955.5.2 by Vincent Ladeuil
Simplify tests.
322
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
323
324
    def test_log_revno_n_path_wrong_namespace(self):
325
        self.make_linear_branch('branch1')
326
        self.make_linear_branch('branch2')
327
        # There is no guarantee that a path exist between two arbitrary
328
        # revisions.
329
        self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
330
331
    def test_log_revno_n_path_correct_order(self):
332
        self.make_linear_branch('branch2')
333
        self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
334
                             ['3', '2', '1'])
4955.5.2 by Vincent Ladeuil
Simplify tests.
335
336
    def test_log_revno_n_path(self):
337
        self.make_linear_branch('branch2')
338
        self.assertLogRevnos(['-rrevno:1:branch2'],
339
                             ['1'])
340
        rev_props = self.log_catcher.revisions[0].rev.properties
6973.13.2 by Jelmer Vernooij
Fix some more tests.
341
        self.assertEqual('branch2', rev_props[u'branch-nick'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
342
343
344
class TestLogErrors(TestLog):
345
4955.5.2 by Vincent Ladeuil
Simplify tests.
346
    def test_log_zero_revspec(self):
347
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
348
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
349
                           ['log', '-r0'])
350
351
    def test_log_zero_begin_revspec(self):
352
        self.make_linear_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
353
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
354
                           ['log', '-r0..2'])
355
356
    def test_log_zero_end_revspec(self):
357
        self.make_linear_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
358
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
359
                           ['log', '-r-2..0'])
360
3878.3.3 by Marius Kruger
Add tests for log -r with non-exising revno's
361
    def test_log_nonexistent_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
362
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
363
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
364
                            "does not exist in branch:"],
4955.4.7 by Vincent Ladeuil
Some more cleanup.
365
                           ['log', '-r1234'])
3878.3.3 by Marius Kruger
Add tests for log -r with non-exising revno's
366
367
    def test_log_nonexistent_dotted_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
368
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
369
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
370
                            "does not exist in branch:"],
4955.4.7 by Vincent Ladeuil
Some more cleanup.
371
                           ['log',  '-r123.123'])
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
372
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
373
    def test_log_change_nonexistent_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
374
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
375
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
376
                            "does not exist in branch:"],
4955.4.7 by Vincent Ladeuil
Some more cleanup.
377
                           ['log',  '-c1234'])
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
378
379
    def test_log_change_nonexistent_dotted_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
380
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
381
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
382
                            "does not exist in branch:"],
4955.4.7 by Vincent Ladeuil
Some more cleanup.
383
                           ['log', '-c123.123'])
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
384
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
385
    def test_log_change_single_revno_only(self):
386
        self.make_minimal_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
387
        self.run_bzr_error(['brz: ERROR: Option --change does not'
388
                            ' accept revision ranges'],
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
389
                           ['log', '--change', '2..3'])
390
391
    def test_log_change_incompatible_with_revision(self):
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
392
        self.run_bzr_error(['brz: ERROR: --revision and --change'
393
                            ' are mutually exclusive'],
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
394
                           ['log', '--change', '2', '--revision', '3'])
395
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
396
    def test_log_nonexistent_file(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
397
        self.make_minimal_branch()
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
398
        # files that don't exist in either the basis tree or working tree
399
        # should give an error
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
400
        out, err = self.run_bzr('log does-not-exist', retcode=3)
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
401
        self.assertContainsRe(err,
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
402
                              'Path unknown at end or start of revision range: '
403
                              'does-not-exist')
2388.1.11 by Alexander Belchenko
changes after John's review
404
4955.5.2 by Vincent Ladeuil
Simplify tests.
405
    def test_log_reversed_revspecs(self):
406
        self.make_linear_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
407
        self.run_bzr_error(('brz: ERROR: Start revision must be older than '
408
                            'the end revision.\n',),
4955.5.2 by Vincent Ladeuil
Simplify tests.
409
                           ['log', '-r3..1'])
410
411
    def test_log_reversed_dotted_revspecs(self):
412
        self.make_merged_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
413
        self.run_bzr_error(('brz: ERROR: Start revision not found in '
414
                            'history of end revision.\n',),
4955.5.2 by Vincent Ladeuil
Simplify tests.
415
                           "log -r 1.1.1..1")
416
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
417
    def test_log_bad_message_re(self):
418
        """Bad --message argument gives a sensible message
5326.2.1 by Parth Malwankar
added InvalidPattern error.
419
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
420
        See https://bugs.launchpad.net/bzr/+bug/251352
421
        """
422
        self.make_minimal_branch()
423
        out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
424
        self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
425
        self.assertNotContainsRe(err, "Unprintable exception")
426
        self.assertEqual(out, '')
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
427
4955.4.7 by Vincent Ladeuil
Some more cleanup.
428
    def test_log_unsupported_timezone(self):
429
        self.make_linear_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
430
        self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
431
                            'options are "utc", "original", "local".'],
4955.4.7 by Vincent Ladeuil
Some more cleanup.
432
                           ['log', '--timezone', 'foo'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
433
5097.1.13 by Vincent Ladeuil
Add more tests.
434
    def test_log_exclude_ancestry_no_range(self):
435
        self.make_linear_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
436
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
437
                            ' requires -r with two revisions'],
5097.1.13 by Vincent Ladeuil
Add more tests.
438
                           ['log', '--exclude-common-ancestry'])
439
440
    def test_log_exclude_ancestry_single_revision(self):
441
        self.make_merged_branch()
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
442
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
443
                            ' requires two different revisions'],
5097.1.13 by Vincent Ladeuil
Add more tests.
444
                           ['log', '--exclude-common-ancestry',
445
                            '-r1.1.1..1.1.1'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
446
447
class TestLogTags(TestLog):
448
2388.1.3 by Erik Bagfors
tests for tags in log output
449
    def test_log_with_tags(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
450
        tree = self.make_linear_branch(format='dirstate-tags')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
451
        branch = tree.branch
452
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
453
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
454
        branch.tags.set_tag('tag3', branch.last_revision())
455
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
456
        log = self.run_bzr("log -r-1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
457
        self.assertTrue('tags: tag3' in log)
458
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
459
        log = self.run_bzr("log -r1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
460
        # I guess that we can't know the order of tags in the output
461
        # since dicts are unordered, need to check both possibilities
2388.1.11 by Alexander Belchenko
changes after John's review
462
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
463
2388.1.9 by Erik Bagfors
test for merges with tags in log
464
    def test_merged_log_with_tags(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
465
        branch1_tree = self.make_linear_branch('branch1',
466
                                               format='dirstate-tags')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
467
        branch1 = branch1_tree.branch
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
468
        branch2_tree = branch1_tree.controldir.sprout('branch2').open_workingtree()
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
469
        branch1_tree.commit(message='foobar', allow_pointless=True)
470
        branch1.tags.set_tag('tag1', branch1.last_revision())
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
471
        # tags don't propagate if we don't merge
472
        self.run_bzr('merge ../branch1', working_dir='branch2')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
473
        branch2_tree.commit(message='merge branch 1')
4511.3.11 by Marius Kruger
* fix tests again
474
        log = self.run_bzr("log -n0 -r-1", working_dir='branch2')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
475
        self.assertContainsRe(log, r'    tags: tag1')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
476
        log = self.run_bzr("log -n0 -r3.1.1", working_dir='branch2')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
477
        self.assertContainsRe(log, r'tags: tag1')
2388.1.3 by Erik Bagfors
tests for tags in log output
478
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
479
5971.1.44 by Jonathan Riddell
add testcase for --signatures
480
class TestLogSignatures(TestLog):
481
482
    def test_log_with_signatures(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
483
        self.requireFeature(features.gpg)
5971.1.44 by Jonathan Riddell
add testcase for --signatures
484
485
        tree = self.make_linear_branch(format='dirstate-tags')
486
487
        log = self.run_bzr("log --signatures")[0]
7045.4.30 by Jelmer Vernooij
Fix some more tests.
488
        self.assertTrue('signature: no signature' in log)
5971.1.44 by Jonathan Riddell
add testcase for --signatures
489
490
    def test_log_without_signatures(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
491
        self.requireFeature(features.gpg)
5971.1.44 by Jonathan Riddell
add testcase for --signatures
492
493
        tree = self.make_linear_branch(format='dirstate-tags')
494
495
        log = self.run_bzr("log")[0]
7045.4.30 by Jelmer Vernooij
Fix some more tests.
496
        self.assertFalse('signature: no signature' in log)
5971.1.44 by Jonathan Riddell
add testcase for --signatures
497
498
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
499
class TestLogVerbose(TestLog):
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
500
501
    def setUp(self):
502
        super(TestLogVerbose, self).setUp()
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
503
        self.make_minimal_branch()
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
504
505
    def assertUseShortDeltaFormat(self, cmd):
506
        log = self.run_bzr(cmd)[0]
507
        # Check that we use the short status format
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
508
        self.assertContainsRe(log, '(?m)^\\s*A  hello.txt$')
509
        self.assertNotContainsRe(log, '(?m)^\\s*added:$')
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
510
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
511
    def assertUseLongDeltaFormat(self, cmd):
512
        log = self.run_bzr(cmd)[0]
513
        # Check that we use the long status format
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
514
        self.assertNotContainsRe(log, '(?m)^\\s*A  hello.txt$')
515
        self.assertContainsRe(log, '(?m)^\\s*added:$')
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
516
517
    def test_log_short_verbose(self):
518
        self.assertUseShortDeltaFormat(['log', '--short', '-v'])
519
5945.1.3 by Martin von Gagern
Add blackbox tests for -S as an alias to --short.
520
    def test_log_s_verbose(self):
521
        self.assertUseShortDeltaFormat(['log', '-S', '-v'])
522
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
523
    def test_log_short_verbose_verbose(self):
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
524
        self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
525
526
    def test_log_long_verbose(self):
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
527
        # Check that we use the long status format, ignoring the verbosity
528
        # level
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
529
        self.assertUseLongDeltaFormat(['log', '--long', '-v'])
3874.1.4 by Vincent Ladeuil
Fixed as per Aarons' comment.
530
531
    def test_log_long_verbose_verbose(self):
3874.1.7 by Vincent Ladeuil
Restrict '-v' change to log --short only.
532
        # Check that we use the long status format, ignoring the verbosity
533
        # level
3874.1.8 by Vincent Ladeuil
Fixed as ber Robert's review.
534
        self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
3874.1.1 by Vincent Ladeuil
Fix #87179 by using the short status format when the short format is used for log.
535
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
536
4955.4.8 by Vincent Ladeuil
Simplify more tests.
537
class TestLogMerges(TestLogWithLogCatcher):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
538
539
    def setUp(self):
540
        super(TestLogMerges, self).setUp()
541
        self.make_branches_with_merges()
542
543
    def make_branches_with_merges(self):
544
        level0 = self.make_branch_and_tree('level0')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
545
        self.wt_commit(level0, 'in branch level0')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
546
        level1 = level0.controldir.sprout('level1').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
547
        self.wt_commit(level1, 'in branch level1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
548
        level2 = level1.controldir.sprout('level2').open_workingtree()
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
549
        self.wt_commit(level2, 'in branch level2')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
550
        level1.merge_from_branch(level2.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
551
        self.wt_commit(level1, 'merge branch level2')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
552
        level0.merge_from_branch(level1.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
553
        self.wt_commit(level0, 'merge branch level1')
3947.1.3 by Ian Clatworthy
blackbox tests
554
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
555
    def test_merges_are_indented_by_level(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
556
        self.run_bzr(['log', '-n0'], working_dir='level0')
557
        revnos_and_depth = [(r.revno, r.merge_depth)
558
                            for r in self.get_captured_revisions()]
559
        self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
560
                          ('1', 0)],
561
                         [(r.revno, r.merge_depth)
562
                            for r in self.get_captured_revisions()])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
563
3947.1.3 by Ian Clatworthy
blackbox tests
564
    def test_force_merge_revisions_off(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
565
        self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
3947.1.3 by Ian Clatworthy
blackbox tests
566
567
    def test_force_merge_revisions_on(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
568
        self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
569
                             working_dir='level0')
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
570
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
571
    def test_include_merged(self):
572
        # Confirm --include-merged gives the same output as -n0
6123.11.6 by Vincent Ladeuil
Add new paraneters add signature's ends, fix a test and a typo, check that no errors and no output is emitted when using assertLogRevnos.
573
        expected = ['2', '1.1.2', '1.2.1', '1.1.1', '1']
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
574
        self.assertLogRevnos(['--include-merged'],
6123.11.6 by Vincent Ladeuil
Add new paraneters add signature's ends, fix a test and a typo, check that no errors and no output is emitted when using assertLogRevnos.
575
                             expected, working_dir='level0')
6123.11.13 by Martin von Gagern
Rename --include-sidelines to --include-merged.
576
        self.assertLogRevnos(['--include-merged'],
6123.11.6 by Vincent Ladeuil
Add new paraneters add signature's ends, fix a test and a typo, check that no errors and no output is emitted when using assertLogRevnos.
577
                             expected, working_dir='level0')
6123.11.3 by Martin von Gagern
Add blackbox test for --include-sidelines option.
578
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
579
    def test_force_merge_revisions_N(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
580
        self.assertLogRevnos(['-n2'],
581
                             ['2', '1.1.2', '1.1.1', '1'],
582
                             working_dir='level0')
3947.1.3 by Ian Clatworthy
blackbox tests
583
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
584
    def test_merges_single_merge_rev(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
585
        self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
586
                                      [('1.1.2', 0), ('1.2.1', 1)],
587
                                      working_dir='level0')
2466.12.1 by Kent Gibson
Fix ``bzr log -r`` to support selecting merge revisions.
588
589
    def test_merges_partial_range(self):
4955.4.8 by Vincent Ladeuil
Simplify more tests.
590
        self.assertLogRevnosAndDepths(
591
                ['-n0', '-r1.1.1..1.1.2'],
592
                [('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
593
                working_dir='level0')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
594
4511.3.1 by Marius Kruger
add test_merges_partial_range_ignore_before_lower_bound
595
    def test_merges_partial_range_ignore_before_lower_bound(self):
4511.3.11 by Marius Kruger
* fix tests again
596
        """Dont show revisions before the lower bound's merged revs"""
4955.4.8 by Vincent Ladeuil
Simplify more tests.
597
        self.assertLogRevnosAndDepths(
598
                ['-n0', '-r1.1.2..2'],
599
                [('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
600
                working_dir='level0')
4511.3.1 by Marius Kruger
add test_merges_partial_range_ignore_before_lower_bound
601
6123.11.4 by Martin von Gagern
Introduce an option "--omit-merges" for "bzr log".
602
    def test_omit_merges_with_sidelines(self):
603
        self.assertLogRevnos(['--omit-merges', '-n0'], ['1.2.1', '1.1.1', '1'],
604
                             working_dir='level0')
605
606
    def test_omit_merges_without_sidelines(self):
607
        self.assertLogRevnos(['--omit-merges', '-n1'], ['1'],
608
                             working_dir='level0')
609
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
610
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
611
class TestLogDiff(TestLogWithLogCatcher):
612
613
    # FIXME: We need specific tests for each LogFormatter about how the diffs
614
    # are displayed: --long indent them by depth, --short use a fixed
615
    # indent and --line does't display them. -- vila 10019
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
616
617
    def setUp(self):
618
        super(TestLogDiff, self).setUp()
619
        self.make_branch_with_diffs()
620
621
    def make_branch_with_diffs(self):
622
        level0 = self.make_branch_and_tree('level0')
623
        self.build_tree(['level0/file1', 'level0/file2'])
624
        level0.add('file1')
625
        level0.add('file2')
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
626
        self.wt_commit(level0, 'in branch level0')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
627
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
628
        level1 = level0.controldir.sprout('level1').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
629
        self.build_tree_contents([('level1/file2', b'hello\n')])
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
630
        self.wt_commit(level1, 'in branch level1')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
631
        level0.merge_from_branch(level1.branch)
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
632
        self.wt_commit(level0, 'merge branch level1')
3943.5.3 by Ian Clatworthy
add tests
633
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
634
    def _diff_file1_revno1(self):
7067.9.1 by Jelmer Vernooij
Fix some log tests on Python 3.
635
        return b"""=== added file 'file1'
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
636
--- file1\t1970-01-01 00:00:00 +0000
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
637
+++ file1\t2005-11-22 00:00:00 +0000
3943.5.6 by Ian Clatworthy
feedback from jam's review
638
@@ -0,0 +1,1 @@
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
639
+contents of level0/file1
3943.5.6 by Ian Clatworthy
feedback from jam's review
640
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
641
"""
642
643
    def _diff_file2_revno2(self):
7067.9.1 by Jelmer Vernooij
Fix some log tests on Python 3.
644
        return b"""=== modified file 'file2'
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
645
--- file2\t2005-11-22 00:00:00 +0000
646
+++ file2\t2005-11-22 00:00:01 +0000
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
647
@@ -1,1 +1,1 @@
648
-contents of level0/file2
649
+hello
650
651
"""
652
653
    def _diff_file2_revno1_1_1(self):
7067.9.1 by Jelmer Vernooij
Fix some log tests on Python 3.
654
        return b"""=== modified file 'file2'
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
655
--- file2\t2005-11-22 00:00:00 +0000
656
+++ file2\t2005-11-22 00:00:01 +0000
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
657
@@ -1,1 +1,1 @@
658
-contents of level0/file2
659
+hello
660
661
"""
662
663
    def _diff_file2_revno1(self):
7067.9.1 by Jelmer Vernooij
Fix some log tests on Python 3.
664
        return b"""=== added file 'file2'
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
665
--- file2\t1970-01-01 00:00:00 +0000
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
666
+++ file2\t2005-11-22 00:00:00 +0000
3943.5.6 by Ian Clatworthy
feedback from jam's review
667
@@ -0,0 +1,1 @@
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
668
+contents of level0/file2
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
669
670
"""
671
4955.4.13 by Vincent Ladeuil
Remove dead code.
672
    def assertLogRevnosAndDiff(self, args, expected,
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
673
                            working_dir='.'):
674
        self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
675
        expected_revnos_and_depths = [
676
            (revno, depth) for revno, depth, diff in expected]
677
        # Check the revnos and depths first to make debugging easier
678
        self.assertEqual(expected_revnos_and_depths,
679
                         [(r.revno, r.merge_depth)
680
                           for r in self.get_captured_revisions()])
681
        # Now check the diffs, adding the revno  in case of failure
682
        fmt = 'In revno %s\n%s'
6631.2.2 by Martin
Run 2to3 itertools fixer and refactor
683
        for expected_rev, actual_rev in zip(expected,
684
                                            self.get_captured_revisions()):
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
685
            revno, depth, expected_diff = expected_rev
686
            actual_diff = actual_rev.diff
687
            self.assertEqualDiff(fmt % (revno, expected_diff),
688
                                 fmt % (revno, actual_diff))
689
690
    def test_log_diff_with_merges(self):
4955.4.13 by Vincent Ladeuil
Remove dead code.
691
        self.assertLogRevnosAndDiff(
692
            ['-n0'],
693
            [('2', 0, self._diff_file2_revno2()),
694
             ('1.1.1', 1, self._diff_file2_revno1_1_1()),
695
             ('1', 0, self._diff_file1_revno1()
696
              + self._diff_file2_revno1())],
697
            working_dir='level0')
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
698
699
700
    def test_log_diff_file1(self):
4955.4.13 by Vincent Ladeuil
Remove dead code.
701
        self.assertLogRevnosAndDiff(['-n0', 'file1'],
702
                                    [('1', 0, self._diff_file1_revno1())],
703
                                    working_dir='level0')
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
704
705
    def test_log_diff_file2(self):
4955.4.13 by Vincent Ladeuil
Remove dead code.
706
        self.assertLogRevnosAndDiff(['-n1', 'file2'],
707
                                    [('2', 0, self._diff_file2_revno2()),
708
                                     ('1', 0, self._diff_file2_revno1())],
709
                                    working_dir='level0')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
710
711
712
class TestLogUnicodeDiff(TestLog):
3943.5.4 by Ian Clatworthy
filter diff by file
713
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
714
    def test_log_show_diff_non_ascii(self):
715
        # Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
716
        message = u'Message with \xb5'
6855.4.1 by Jelmer Vernooij
Yet more bees.
717
        body = b'Body with \xb5\n'
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
718
        wt = self.make_branch_and_tree('.')
719
        self.build_tree_contents([('foo', body)])
720
        wt.add('foo')
721
        wt.commit(message=message)
722
        # check that command won't fail with unicode error
723
        # don't care about exact output because we have other tests for this
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
724
        out, err = self.run_bzr('log -p --long')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
725
        self.assertNotEqual('', out)
726
        self.assertEqual('', err)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
727
        out, err = self.run_bzr('log -p --short')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
728
        self.assertNotEqual('', out)
729
        self.assertEqual('', err)
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
730
        out, err = self.run_bzr('log -p --line')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
731
        self.assertNotEqual('', out)
732
        self.assertEqual('', err)
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
733
3943.5.3 by Ian Clatworthy
add tests
734
4325.4.3 by Vincent Ladeuil
More cleanups.
735
class TestLogEncodings(tests.TestCaseInTempDir):
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
736
737
    _mu = u'\xb5'
738
    _message = u'Message with \xb5'
739
740
    # Encodings which can encode mu
741
    good_encodings = [
742
        'utf-8',
743
        'latin-1',
744
        'iso-8859-1',
745
        'cp437', # Common windows encoding
4110.1.1 by Alexander Belchenko
Fixed problem with `log -p` and non-ascii content of files: show_diff should write the diff to exact [stdout] stream.
746
        'cp1251', # Russian windows encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
747
        'cp1258', # Common windows encoding
748
    ]
749
    # Encodings which cannot encode mu
750
    bad_encodings = [
751
        'ascii',
752
        'iso-8859-2',
753
        'koi8_r',
754
    ]
755
756
    def setUp(self):
4325.4.3 by Vincent Ladeuil
More cleanups.
757
        super(TestLogEncodings, self).setUp()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
758
        self.overrideAttr(osutils, '_cached_user_encoding')
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
759
760
    def create_branch(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
761
        brz = self.run_bzr
6622.1.30 by Jelmer Vernooij
Some more test fixes.
762
        brz('init')
6855.4.1 by Jelmer Vernooij
Yet more bees.
763
        self.build_tree_contents([('a', b'some stuff\n')])
6622.1.30 by Jelmer Vernooij
Some more test fixes.
764
        brz('add a')
765
        brz(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
766
767
    def try_encoding(self, encoding, fail=False):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
768
        brz = self.run_bzr
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
769
        if fail:
770
            self.assertRaises(UnicodeEncodeError,
771
                self._mu.encode, encoding)
772
            encoded_msg = self._message.encode(encoding, 'replace')
773
        else:
774
            encoded_msg = self._message.encode(encoding)
775
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
776
        old_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
777
        # This test requires that 'run_bzr' uses the current
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
778
        # breezy, because we override user_encoding, and expect
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
779
        # it to be used
780
        try:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
781
            osutils._cached_user_encoding = 'ascii'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
782
            # We should be able to handle any encoding
6622.1.30 by Jelmer Vernooij
Some more test fixes.
783
            out, err = brz('log', encoding=encoding)
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
784
            if not fail:
785
                # Make sure we wrote mu as we expected it to exist
7027.4.11 by Jelmer Vernooij
Fix some tests that fail with -Werror.
786
                if not PY3:
787
                    self.assertNotEqual(-1, out.find(encoded_msg))
788
                    out_unicode = out.decode(encoding)
789
                else:
790
                    out_unicode = out
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
791
                self.assertNotEqual(-1, out_unicode.find(self._message))
792
            else:
793
                self.assertNotEqual(-1, out.find('Message with ?'))
794
        finally:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
795
            osutils._cached_user_encoding = old_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
796
797
    def test_log_handles_encoding(self):
798
        self.create_branch()
799
800
        for encoding in self.good_encodings:
801
            self.try_encoding(encoding)
802
803
    def test_log_handles_bad_encoding(self):
804
        self.create_branch()
805
806
        for encoding in self.bad_encodings:
807
            self.try_encoding(encoding, fail=True)
808
809
    def test_stdout_encoding(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
810
        brz = self.run_bzr
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
811
        osutils._cached_user_encoding = "cp1251"
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
812
6622.1.30 by Jelmer Vernooij
Some more test fixes.
813
        brz('init')
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
814
        self.build_tree(['a'])
6622.1.30 by Jelmer Vernooij
Some more test fixes.
815
        brz('add a')
816
        brz(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
7065.3.5 by Jelmer Vernooij
Fix some tests.
817
        stdout, stderr = self.run_bzr_raw('log', encoding='cp866')
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
818
819
        message = stdout.splitlines()[-1]
820
821
        # explanation of the check:
822
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
823
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
824
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
825
        # This test should check that output of log command
826
        # encoded to sys.stdout.encoding
7065.3.5 by Jelmer Vernooij
Fix some tests.
827
        test_in_cp866 = b'\x92\xa5\xe1\xe2'
828
        test_in_cp1251 = b'\xd2\xe5\xf1\xf2'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
829
        # Make sure the log string is encoded in cp866
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
830
        self.assertEqual(test_in_cp866, message[2:])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
831
        # Make sure the cp1251 string is not found anywhere
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
832
        self.assertEqual(-1, stdout.find(test_in_cp1251))
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
833
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
834
4955.4.9 by Vincent Ladeuil
More simplifications.
835
class TestLogFile(TestLogWithLogCatcher):
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
836
837
    def test_log_local_branch_file(self):
838
        """We should be able to log files in local treeless branches"""
839
        tree = self.make_branch_and_tree('tree')
840
        self.build_tree(['tree/file'])
841
        tree.add('file')
842
        tree.commit('revision 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
843
        tree.controldir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
844
        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.
845
3943.6.1 by Ian Clatworthy
find file using the end revision
846
    def prepare_tree(self, complex=False):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
847
        # The complex configuration includes deletes and renames
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
848
        tree = self.make_branch_and_tree('parent')
849
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
850
        tree.add('file1')
851
        tree.commit('add file1')
852
        tree.add('file2')
853
        tree.commit('add file2')
854
        tree.add('file3')
855
        tree.commit('add file3')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
856
        child_tree = tree.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
857
        self.build_tree_contents([('child/file2', b'hello')])
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
858
        child_tree.commit(message='branch 1')
859
        tree.merge_from_branch(child_tree.branch)
860
        tree.commit(message='merge child branch')
3943.6.1 by Ian Clatworthy
find file using the end revision
861
        if complex:
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
862
            tree.remove('file2')
863
            tree.commit('remove file2')
864
            tree.rename_one('file3', 'file4')
865
            tree.commit('file3 is now called file4')
3943.6.1 by Ian Clatworthy
find file using the end revision
866
            tree.remove('file1')
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
867
            tree.commit('remove file1')
2359.1.1 by Kent Gibson
Fix ``bzr log <file>`` so it only logs the revisions that changed the file, and does it faster.
868
        os.chdir('parent')
3940.1.2 by Ian Clatworthy
add test
869
4955.4.9 by Vincent Ladeuil
More simplifications.
870
    # FIXME: It would be good to parametrize the following tests against all
871
    # formatters. But the revisions selection is not *currently* part of the
872
    # LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
873
    def test_log_file1(self):
874
        self.prepare_tree()
875
        self.assertLogRevnos(['-n0', 'file1'], ['1'])
876
877
    def test_log_file2(self):
878
        self.prepare_tree()
879
        # file2 full history
880
        self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
881
        # file2 in a merge revision
882
        self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
883
        # file2 in a mainline revision
884
        self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
885
        # file2 since a revision
886
        self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
887
        # file2 up to a revision
888
        self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
889
890
    def test_log_file3(self):
891
        self.prepare_tree()
892
        self.assertLogRevnos(['-n0', 'file3'], ['3'])
3940.1.2 by Ian Clatworthy
add test
893
3943.6.4 by Ian Clatworthy
review feedback from vila
894
    def test_log_file_historical_missing(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
895
        # Check logging a deleted file gives an error if the
896
        # file isn't found at the end or start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
897
        self.prepare_tree(complex=True)
7045.1.11 by Jelmer Vernooij
Some annotate fixes.
898
        err_msg = "Path unknown at end or start of revision range: file2"
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
899
        err = self.run_bzr('log file2', retcode=3)[1]
3943.6.1 by Ian Clatworthy
find file using the end revision
900
        self.assertContainsRe(err, err_msg)
901
3943.6.4 by Ian Clatworthy
review feedback from vila
902
    def test_log_file_historical_end(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
903
        # Check logging a deleted file is ok if the file existed
904
        # at the end the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
905
        self.prepare_tree(complex=True)
4955.4.9 by Vincent Ladeuil
More simplifications.
906
        self.assertLogRevnos(['-n0', '-r..4', 'file2'], ['4', '3.1.1', '2'])
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
907
3943.6.4 by Ian Clatworthy
review feedback from vila
908
    def test_log_file_historical_start(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
909
        # Check logging a deleted file is ok if the file existed
910
        # at the start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
911
        self.prepare_tree(complex=True)
4955.4.9 by Vincent Ladeuil
More simplifications.
912
        self.assertLogRevnos(['file1'], ['1'])
3943.6.1 by Ian Clatworthy
find file using the end revision
913
914
    def test_log_file_renamed(self):
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
915
        """File matched against revision range, not current tree."""
3943.6.1 by Ian Clatworthy
find file using the end revision
916
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
917
3943.6.1 by Ian Clatworthy
find file using the end revision
918
        # Check logging a renamed file gives an error by default
7045.1.11 by Jelmer Vernooij
Some annotate fixes.
919
        err_msg = "Path unknown at end or start of revision range: file3"
3943.6.1 by Ian Clatworthy
find file using the end revision
920
        err = self.run_bzr('log file3', retcode=3)[1]
921
        self.assertContainsRe(err, err_msg)
922
923
        # Check we can see a renamed file if we give the right end revision
4955.4.9 by Vincent Ladeuil
More simplifications.
924
        self.assertLogRevnos(['-r..4', 'file3'], ['3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
925
926
4955.4.10 by Vincent Ladeuil
More simplification.
927
class TestLogMultiple(TestLogWithLogCatcher):
4202.2.1 by Ian Clatworthy
get directory logging working again
928
929
    def prepare_tree(self):
930
        tree = self.make_branch_and_tree('parent')
931
        self.build_tree([
932
            'parent/file1',
933
            'parent/file2',
934
            'parent/dir1/',
935
            'parent/dir1/file5',
936
            'parent/dir1/dir2/',
937
            'parent/dir1/dir2/file3',
938
            'parent/file4'])
939
        tree.add('file1')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
940
        tree.commit('add file1')
4202.2.1 by Ian Clatworthy
get directory logging working again
941
        tree.add('file2')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
942
        tree.commit('add file2')
4202.2.1 by Ian Clatworthy
get directory logging working again
943
        tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
944
        tree.commit('add file3')
4202.2.1 by Ian Clatworthy
get directory logging working again
945
        tree.add('file4')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
946
        tree.commit('add file4')
4202.2.1 by Ian Clatworthy
get directory logging working again
947
        tree.add('dir1/file5')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
948
        tree.commit('add file5')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
949
        child_tree = tree.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
950
        self.build_tree_contents([('child/file2', b'hello')])
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
951
        child_tree.commit(message='branch 1')
4202.2.1 by Ian Clatworthy
get directory logging working again
952
        tree.merge_from_branch(child_tree.branch)
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
953
        tree.commit(message='merge child branch')
4202.2.1 by Ian Clatworthy
get directory logging working again
954
        os.chdir('parent')
955
956
    def test_log_files(self):
957
        """The log for multiple file should only list revs for those files"""
958
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
959
        self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
960
                             ['6', '5.1.1', '3', '2', '1'])
4202.2.1 by Ian Clatworthy
get directory logging working again
961
962
    def test_log_directory(self):
963
        """The log for a directory should show all nested files."""
964
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
965
        self.assertLogRevnos(['dir1'], ['5', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
966
967
    def test_log_nested_directory(self):
968
        """The log for a directory should show all nested files."""
969
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
970
        self.assertLogRevnos(['dir1/dir2'], ['3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
971
972
    def test_log_in_nested_directory(self):
973
        """The log for a directory should show all nested files."""
974
        self.prepare_tree()
975
        os.chdir("dir1")
4955.4.10 by Vincent Ladeuil
More simplification.
976
        self.assertLogRevnos(['.'], ['5', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
977
978
    def test_log_files_and_directories(self):
979
        """Logging files and directories together should be fine."""
980
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
981
        self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
982
983
    def test_log_files_and_dirs_in_nested_directory(self):
984
        """The log for a directory should show all nested files."""
985
        self.prepare_tree()
986
        os.chdir("dir1")
4955.4.10 by Vincent Ladeuil
More simplification.
987
        self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
988
989
990
class MainlineGhostTests(TestLogWithLogCatcher):
991
992
    def setUp(self):
993
        super(MainlineGhostTests, self).setUp()
994
        tree = self.make_branch_and_tree('')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
995
        tree.set_parent_ids([b"spooky"], allow_leftmost_as_ghost=True)
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
996
        tree.add('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
997
        tree.commit('msg1', rev_id=b'rev1')
998
        tree.commit('msg2', rev_id=b'rev2')
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
999
1000
    def test_log_range(self):
1001
        self.assertLogRevnos(["-r1..2"], ["2", "1"])
1002
1003
    def test_log_norange(self):
1004
        self.assertLogRevnos([], ["2", "1"])
1005
1006
    def test_log_range_open_begin(self):
1007
        (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
1008
        self.assertEqual(["2", "1"],
1009
                         [r.revno for r in self.get_captured_revisions()])
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1010
        self.assertEqual("brz: ERROR: Further revision history missing.\n",
1011
                stderr)
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
1012
1013
    def test_log_range_open_end(self):
1014
        self.assertLogRevnos(["-r1.."], ["2", "1"])
5935.2.1 by Jacek Sieka
Change the meaning of the log -m option to match and make it match message, committer, authors and bugs. --match-message and friends can be used to make more specific matches.
1015
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1016
5935.2.1 by Jacek Sieka
Change the meaning of the log -m option to match and make it match message, committer, authors and bugs. --match-message and friends can be used to make more specific matches.
1017
class TestLogMatch(TestLogWithLogCatcher):
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1018
5935.2.1 by Jacek Sieka
Change the meaning of the log -m option to match and make it match message, committer, authors and bugs. --match-message and friends can be used to make more specific matches.
1019
    def prepare_tree(self):
1020
        tree = self.make_branch_and_tree('')
1021
        self.build_tree(
1022
            ['/hello.txt', '/goodbye.txt'])
1023
        tree.add('hello.txt')
1024
        tree.commit(message='message1', committer='committer1', authors=['author1'])
1025
        tree.add('goodbye.txt')
1026
        tree.commit(message='message2', committer='committer2', authors=['author2'])
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1027
5935.2.1 by Jacek Sieka
Change the meaning of the log -m option to match and make it match message, committer, authors and bugs. --match-message and friends can be used to make more specific matches.
1028
    def test_message(self):
1029
        self.prepare_tree()
1030
        self.assertLogRevnos(["-m", "message1"], ["1"])
1031
        self.assertLogRevnos(["-m", "message2"], ["2"])
1032
        self.assertLogRevnos(["-m", "message"], ["2", "1"])
1033
        self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
1034
        self.assertLogRevnos(["--match-message", "message1"], ["1"])
1035
        self.assertLogRevnos(["--match-message", "message2"], ["2"])
1036
        self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
1037
        self.assertLogRevnos(["--match-message", "message1", 
1038
                              "--match-message", "message2"], ["2", "1"])
1039
        self.assertLogRevnos(["--message", "message1"], ["1"])
1040
        self.assertLogRevnos(["--message", "message2"], ["2"])
1041
        self.assertLogRevnos(["--message", "message"], ["2", "1"])
1042
        self.assertLogRevnos(["--match-message", "message1", 
1043
                              "--message", "message2"], ["2", "1"])
1044
        self.assertLogRevnos(["--message", "message1", 
1045
                              "--match-message", "message2"], ["2", "1"])
1046
1047
    def test_committer(self):
1048
        self.prepare_tree()
1049
        self.assertLogRevnos(["-m", "committer1"], ["1"])
1050
        self.assertLogRevnos(["-m", "committer2"], ["2"])
1051
        self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1052
        self.assertLogRevnos(["-m", "committer1", "-m", "committer2"], 
1053
                             ["2", "1"])
1054
        self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1055
        self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1056
        self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1057
        self.assertLogRevnos(["--match-committer", "committer1", 
1058
                              "--match-committer", "committer2"], ["2", "1"])
1059
1060
    def test_author(self):
1061
        self.prepare_tree()
1062
        self.assertLogRevnos(["-m", "author1"], ["1"])
1063
        self.assertLogRevnos(["-m", "author2"], ["2"])
1064
        self.assertLogRevnos(["-m", "author"], ["2", "1"])
1065
        self.assertLogRevnos(["-m", "author1", "-m", "author2"], 
1066
                             ["2", "1"])
1067
        self.assertLogRevnos(["--match-author", "author1"], ["1"])
1068
        self.assertLogRevnos(["--match-author", "author2"], ["2"])
1069
        self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1070
        self.assertLogRevnos(["--match-author", "author1", 
1071
                              "--match-author", "author2"], ["2", "1"])
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1072
1073
1074
class TestSmartServerLog(tests.TestCaseWithTransport):
1075
1076
    def test_standard_log(self):
1077
        self.setup_smart_server_with_call_log()
1078
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1079
        self.build_tree_contents([('branch/foo', b'thecontents')])
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1080
        t.add("foo")
1081
        t.commit("message")
1082
        self.reset_smart_call_log()
1083
        out, err = self.run_bzr(['log', self.get_url('branch')])
1084
        # This figure represent the amount of work to perform this use case. It
1085
        # is entirely ok to reduce this number if a test fails due to rpc_count
1086
        # being too low. If rpc_count increases, more network roundtrips have
1087
        # become necessary for this use case. Please do not adjust this number
1088
        # upwards without agreement from bzr's network support maintainers.
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
1089
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1090
        self.assertLength(1, self.hpss_connections)
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1091
        self.assertLength(9, self.hpss_calls)
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1092
1093
    def test_verbose_log(self):
1094
        self.setup_smart_server_with_call_log()
1095
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1096
        self.build_tree_contents([('branch/foo', b'thecontents')])
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1097
        t.add("foo")
1098
        t.commit("message")
1099
        self.reset_smart_call_log()
1100
        out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
1101
        # This figure represent the amount of work to perform this use case. It
1102
        # is entirely ok to reduce this number if a test fails due to rpc_count
1103
        # being too low. If rpc_count increases, more network roundtrips have
1104
        # become necessary for this use case. Please do not adjust this number
1105
        # upwards without agreement from bzr's network support maintainers.
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1106
        self.assertLength(10, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1107
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
1108
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6282.6.16 by Jelmer Vernooij
More tests.
1109
1110
    def test_per_file(self):
1111
        self.setup_smart_server_with_call_log()
1112
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
1113
        self.build_tree_contents([('branch/foo', b'thecontents')])
6282.6.16 by Jelmer Vernooij
More tests.
1114
        t.add("foo")
1115
        t.commit("message")
1116
        self.reset_smart_call_log()
1117
        out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
1118
        # This figure represent the amount of work to perform this use case. It
1119
        # is entirely ok to reduce this number if a test fails due to rpc_count
1120
        # being too low. If rpc_count increases, more network roundtrips have
1121
        # become necessary for this use case. Please do not adjust this number
1122
        # upwards without agreement from bzr's network support maintainers.
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1123
        self.assertLength(14, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1124
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
1125
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)