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