/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
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
32
from breezy.tests import (
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
33
    test_log,
5971.1.49 by Jonathan Riddell
import features in test
34
    features,
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
35
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
36
from breezy.tests.matchers import ContainsNoVfsCalls
3144.7.9 by Guillermo Gonzalez
* bzrlib.log.show_roperties don't hide handler errors
37
38
4955.4.17 by Vincent Ladeuil
Use a data factory for commit properties and reduce code duplication.
39
class TestLog(tests.TestCaseWithTransport, test_log.TestLogMixin):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
40
41
    def make_minimal_branch(self, path='.', format=None):
42
        tree = self.make_branch_and_tree(path, format=format)
43
        self.build_tree([path + '/hello.txt'])
44
        tree.add('hello.txt')
45
        tree.commit(message='message1')
46
        return tree
47
48
    def make_linear_branch(self, path='.', format=None):
2809.1.2 by Daniel Watkins
Removed unnecessary check as per abentley's on-list comments.
49
        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.
50
        self.build_tree(
51
            [path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
52
        tree.add('hello.txt')
53
        tree.commit(message='message1')
54
        tree.add('goodbye.txt')
55
        tree.commit(message='message2')
56
        tree.add('meep.txt')
57
        tree.commit(message='message3')
58
        return tree
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
59
4369.2.1 by Marius Kruger
add some leftover log tests
60
    def make_merged_branch(self, path='.', format=None):
4369.2.2 by Marius Kruger
use make_linear_branch in make_merged_branch
61
        tree = self.make_linear_branch(path, format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
62
        tree2 = tree.controldir.sprout('tree2',
4369.2.2 by Marius Kruger
use make_linear_branch in make_merged_branch
63
            revision_id=tree.branch.get_rev_id(1)).open_workingtree()
4369.2.1 by Marius Kruger
add some leftover log tests
64
        tree2.commit(message='tree2 message2')
65
        tree2.commit(message='tree2 message3')
66
        tree.merge_from_branch(tree2.branch)
67
        tree.commit(message='merge')
68
        return tree
69
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
70
4955.5.2 by Vincent Ladeuil
Simplify tests.
71
class TestLogWithLogCatcher(TestLog):
72
73
    def setUp(self):
74
        super(TestLogWithLogCatcher, self).setUp()
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
75
        # Capture log formatter creations
4955.5.2 by Vincent Ladeuil
Simplify tests.
76
        class MyLogFormatter(test_log.LogCatcher):
77
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
78
            def __new__(klass, *args, **kwargs):
79
                self.log_catcher = test_log.LogCatcher(*args, **kwargs)
80
                # Always return our own log formatter
81
                return self.log_catcher
5340.15.1 by John Arbash Meinel
supersede exc-info branch
82
        # Break cycle with closure over self on cleanup by removing method
83
        self.addCleanup(setattr, MyLogFormatter, "__new__", None)
4955.5.2 by Vincent Ladeuil
Simplify tests.
84
85
        def getme(branch):
86
                # Always return our own log formatter class hijacking the
87
                # default behavior (which requires setting up a config
88
                # variable)
89
            return MyLogFormatter
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
90
        self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
4955.5.2 by Vincent Ladeuil
Simplify tests.
91
4955.4.8 by Vincent Ladeuil
Simplify more tests.
92
    def get_captured_revisions(self):
5340.12.14 by Martin
Revert changes to bb.test_log which caused some failures
93
        return self.log_catcher.revisions
4955.4.8 by Vincent Ladeuil
Simplify more tests.
94
6123.11.10 by Martin von Gagern
Print deprecation warnings for all uses of include_merges.
95
    def assertLogRevnos(self, args, expected_revnos, working_dir='.',
96
                        out='', err=''):
97
        actual_out, actual_err = self.run_bzr(['log'] + args,
98
                                              working_dir=working_dir)
99
        self.assertEqual(out, actual_out)
100
        self.assertEqual(err, actual_err)
4955.4.8 by Vincent Ladeuil
Simplify more tests.
101
        self.assertEqual(expected_revnos,
102
                         [r.revno for r in self.get_captured_revisions()])
103
104
    def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
105
                                working_dir='.'):
106
        self.run_bzr(['log'] + args, working_dir=working_dir)
107
        self.assertEqual(expected_revnos_and_depths,
108
                         [(r.revno, r.merge_depth)
109
                           for r in self.get_captured_revisions()])
4955.5.2 by Vincent Ladeuil
Simplify tests.
110
111
112
class TestLogRevSpecs(TestLogWithLogCatcher):
113
114
    def test_log_no_revspec(self):
115
        self.make_linear_branch()
116
        self.assertLogRevnos([], ['3', '2', '1'])
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
117
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
118
    def test_log_null_end_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
119
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
120
        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
121
122
    def test_log_null_begin_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
123
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
124
        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
125
126
    def test_log_null_both_revspecs(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
127
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
128
        self.assertLogRevnos(['-r..'], ['3', '2', '1'])
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
129
1553.4.2 by Michael Ellerman
Make bzr log -r .. work, fixes bug #4609. Add a bunch of tests to make sure
130
    def test_log_negative_begin_revspec_full_log(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
131
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
132
        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
133
134
    def test_log_negative_both_revspec_full_log(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
135
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
136
        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
137
138
    def test_log_negative_both_revspec_partial(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
139
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
140
        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
141
142
    def test_log_negative_begin_revspec(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
143
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
144
        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
145
2978.4.1 by Kent Gibson
Logging revision 0 returns error.
146
    def test_log_positive_revspecs(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
147
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
148
        self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
1624.1.3 by Robert Collins
Convert log to use the new tsort.merge_sort routine.
149
4369.2.1 by Marius Kruger
add some leftover log tests
150
    def test_log_dotted_revspecs(self):
151
        self.make_merged_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
152
        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.
153
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
154
    def test_log_limit(self):
155
        tree = self.make_branch_and_tree('.')
156
        # We want more commits than our batch size starts at
157
        for pos in range(10):
158
            tree.commit("%s" % pos)
4955.5.2 by Vincent Ladeuil
Simplify tests.
159
        self.assertLogRevnos(['--limit', '2'], ['10', '9'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
160
161
    def test_log_limit_short(self):
162
        self.make_linear_branch()
4955.5.2 by Vincent Ladeuil
Simplify tests.
163
        self.assertLogRevnos(['-l', '2'], ['3', '2'])
164
4955.4.7 by Vincent Ladeuil
Some more cleanup.
165
    def test_log_change_revno(self):
166
        self.make_linear_branch()
167
        self.assertLogRevnos(['-c1'], ['1'])
168
5318.1.2 by Martin von Gagern
Add blackbox test for "bzr log -r branch:../bar".
169
    def test_branch_revspec(self):
170
        foo = self.make_branch_and_tree('foo')
171
        bar = self.make_branch_and_tree('bar')
172
        self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
173
        foo.add('foo.txt')
174
        bar.add('bar.txt')
175
        foo.commit(message='foo')
176
        bar.commit(message='bar')
177
        self.run_bzr('log -r branch:../bar', working_dir='foo')
178
        self.assertEqual([bar.branch.get_rev_id(1)],
179
                         [r.rev.revision_id
180
                          for r in self.get_captured_revisions()])
181
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
182
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
183
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
184
185
    def test_exclude_common_ancestry_simple_revnos(self):
186
        self.make_linear_branch()
187
        self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
188
                             ['3', '2'])
189
190
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
191
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
192
193
    def setUp(self):
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
194
        super(TestLogMergedLinearAncestry, self).setUp()
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
195
        # FIXME: Using a MemoryTree would be even better here (but until we
196
        # stop calling run_bzr, there is no point) --vila 100118.
197
        builder = branchbuilder.BranchBuilder(self.get_transport())
198
        builder.start_series()
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
199
        # 1
200
        # | \
201
        # 2  1.1.1
202
        # | / |
203
        # 3  1.1.2
204
        # |   |
205
        # |  1.1.3
206
        # | / |
207
        # 4  1.1.4
208
        # | /
209
        # 5
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
210
        # | \
211
        # | 5.1.1
212
        # | /
213
        # 6
5268.4.1 by Vincent Ladeuil
Failing test for bug #575631.
214
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
215
        # mainline
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
216
        builder.build_snapshot(None, [
217
            ('add', ('', 'root-id', 'directory', ''))],
218
            revision_id='1')
219
        builder.build_snapshot(['1'], [], revision_id='2')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
220
        # branch
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
221
        builder.build_snapshot(['1'], [], revision_id='1.1.1')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
222
        # merge branch into mainline
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
223
        builder.build_snapshot(['2', '1.1.1'], [], revision_id='3')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
224
        # new commits in branch
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
225
        builder.build_snapshot(['1.1.1'], [], revision_id='1.1.2')
226
        builder.build_snapshot(['1.1.2'], [], revision_id='1.1.3')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
227
        # merge branch into mainline
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
228
        builder.build_snapshot(['3', '1.1.3'], [], revision_id='4')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
229
        # merge mainline into branch
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
230
        builder.build_snapshot(['1.1.3', '4'], [], revision_id='1.1.4')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
231
        # merge branch into mainline
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
232
        builder.build_snapshot(['4', '1.1.4'], [], revision_id='5')
233
        builder.build_snapshot(['5'], [], revision_id='5.1.1')
234
        builder.build_snapshot(['5', '5.1.1'], [], revision_id='6')
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
235
        builder.finish_series()
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
236
237
    def test_n0(self):
238
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
239
                             ['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.
240
4955.4.5 by Vincent Ladeuil
Start reproducing the problems reported in the bug.
241
    def test_n0_forward(self):
242
        self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
243
                             ['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
244
245
    def test_n1(self):
4955.4.6 by Vincent Ladeuil
Switch to branchbuilder to avoid the cost of test.script.
246
        # 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.
247
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
248
                             ['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
249
250
    def test_n1_forward(self):
251
        self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
252
                             ['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
253
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
254
    def test_fallback_when_end_rev_is_not_on_mainline(self):
255
        self.assertLogRevnos(['-n1', '-r1.1.1..5.1.1'],
256
                             # We don't get 1.1.1 because we say -n1
257
                             ['5.1.1', '5', '4', '3'])
258
4955.5.2 by Vincent Ladeuil
Simplify tests.
259
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
260
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
261
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
262
    def setUp(self):
263
        super(Test_GenerateAllRevisions, self).setUp()
264
        builder = self.make_branch_with_many_merges()
265
        b = builder.get_branch()
266
        b.lock_read()
267
        self.addCleanup(b.unlock)
268
        self.branch = b
269
4955.7.5 by Vincent Ladeuil
Fixed as per Ian's review.
270
    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.
271
        builder = branchbuilder.BranchBuilder(self.get_transport())
272
        builder.start_series()
273
        # The graph below may look a bit complicated (and it may be but I've
274
        # banged my head enough on it) but the bug requires at least dotted
275
        # 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
276
        # 1
277
        # | \
278
        # 2  1.1.1
279
        # | X
280
        # 3  2.1.1
281
        # |   |    \
282
        # |  2.1.2  2.2.1
283
        # |   |    X
284
        # |  2.1.3  \
285
        # | /       /
286
        # 4        /
287
        # |       /
288
        # 5 -----/
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
289
        builder.build_snapshot(None, [
290
            ('add', ('', 'root-id', 'directory', ''))], revision_id='1')
291
        builder.build_snapshot(['1'], [], revision_id='2')
292
        builder.build_snapshot(['1'], [], revision_id='1.1.1')
293
        builder.build_snapshot(['2'], [], revision_id='2.1.1')
294
        builder.build_snapshot(['2', '1.1.1'], [], revision_id='3')
295
        builder.build_snapshot(['2.1.1'], [], revision_id='2.1.2')
296
        builder.build_snapshot(['2.1.1'], [], revision_id='2.2.1')
297
        builder.build_snapshot(['2.1.2', '2.2.1'], [], revision_id='2.1.3')
298
        builder.build_snapshot(['3', '2.1.3'], [], revision_id='4')
299
        builder.build_snapshot(['4', '2.1.2'], [], revision_id='5')
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
300
        builder.finish_series()
301
        return builder
302
303
    def test_not_an_ancestor(self):
304
        self.assertRaises(errors.BzrCommandError,
305
                          log._generate_all_revisions,
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
306
                          self.branch, '1.1.1', '2.1.3', 'reverse',
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
307
                          delayed_graph_generation=True)
308
309
    def test_wrong_order(self):
310
        self.assertRaises(errors.BzrCommandError,
311
                          log._generate_all_revisions,
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
312
                          self.branch, '5', '2.1.3', 'reverse',
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
313
                          delayed_graph_generation=True)
314
5092.1.1 by Vincent Ladeuil
Reproduce bug #519862.
315
    def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
316
        revs = log._generate_all_revisions(
317
            self.branch, None, '2.1.3',
318
            'reverse', delayed_graph_generation=True)
319
4955.7.3 by Vincent Ladeuil
Check ancestry so we don't output random revisions.
320
4955.5.2 by Vincent Ladeuil
Simplify tests.
321
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
322
323
    def test_log_revno_n_path_wrong_namespace(self):
324
        self.make_linear_branch('branch1')
325
        self.make_linear_branch('branch2')
326
        # There is no guarantee that a path exist between two arbitrary
327
        # revisions.
328
        self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
329
330
    def test_log_revno_n_path_correct_order(self):
331
        self.make_linear_branch('branch2')
332
        self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
333
                             ['3', '2', '1'])
4955.5.2 by Vincent Ladeuil
Simplify tests.
334
335
    def test_log_revno_n_path(self):
336
        self.make_linear_branch('branch2')
337
        self.assertLogRevnos(['-rrevno:1:branch2'],
338
                             ['1'])
339
        rev_props = self.log_catcher.revisions[0].rev.properties
340
        self.assertEqual('branch2', rev_props['branch-nick'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
341
342
343
class TestLogErrors(TestLog):
344
4955.5.2 by Vincent Ladeuil
Simplify tests.
345
    def test_log_zero_revspec(self):
346
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
347
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
348
                           ['log', '-r0'])
349
350
    def test_log_zero_begin_revspec(self):
351
        self.make_linear_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
352
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
353
                           ['log', '-r0..2'])
354
355
    def test_log_zero_end_revspec(self):
356
        self.make_linear_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
357
        self.run_bzr_error(['brz: ERROR: Logging revision 0 is invalid.'],
4955.5.2 by Vincent Ladeuil
Simplify tests.
358
                           ['log', '-r-2..0'])
359
3878.3.3 by Marius Kruger
Add tests for log -r with non-exising revno's
360
    def test_log_nonexistent_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
361
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
362
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
4955.4.7 by Vincent Ladeuil
Some more cleanup.
363
                            "does not exist in branch:"],
364
                           ['log', '-r1234'])
3878.3.3 by Marius Kruger
Add tests for log -r with non-exising revno's
365
366
    def test_log_nonexistent_dotted_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
367
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
368
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
4955.4.7 by Vincent Ladeuil
Some more cleanup.
369
                            "does not exist in branch:"],
370
                           ['log',  '-r123.123'])
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
371
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
372
    def test_log_change_nonexistent_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
373
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
374
        self.run_bzr_error(["brz: ERROR: Requested revision: '1234' "
4955.4.7 by Vincent Ladeuil
Some more cleanup.
375
                            "does not exist in branch:"],
376
                           ['log',  '-c1234'])
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
377
378
    def test_log_change_nonexistent_dotted_revno(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
379
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
380
        self.run_bzr_error(["brz: ERROR: Requested revision: '123.123' "
4955.4.7 by Vincent Ladeuil
Some more cleanup.
381
                            "does not exist in branch:"],
382
                           ['log', '-c123.123'])
3878.3.2 by Marius Kruger
Add tests for log -c with non-exising revno's
383
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
384
    def test_log_change_single_revno_only(self):
385
        self.make_minimal_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
386
        self.run_bzr_error(['brz: ERROR: Option --change does not'
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
387
                           ' accept revision ranges'],
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
388
                           ['log', '--change', '2..3'])
389
390
    def test_log_change_incompatible_with_revision(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
391
        self.run_bzr_error(['brz: ERROR: --revision and --change'
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
392
                           ' are mutually exclusive'],
3734.1.1 by Vincent Ladeuil
Fix bug #248427 by adding a --change option to log.
393
                           ['log', '--change', '2', '--revision', '3'])
394
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
395
    def test_log_nonexistent_file(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
396
        self.make_minimal_branch()
2100.1.1 by wang
Running ``bzr log`` on nonexistent file gives an error instead of the
397
        # files that don't exist in either the basis tree or working tree
398
        # should give an error
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
399
        out, err = self.run_bzr('log does-not-exist', retcode=3)
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
400
        self.assertContainsRe(err,
401
                              'Path unknown at end or start of revision range: '
402
                              'does-not-exist')
2388.1.11 by Alexander Belchenko
changes after John's review
403
4955.5.2 by Vincent Ladeuil
Simplify tests.
404
    def test_log_reversed_revspecs(self):
405
        self.make_linear_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
406
        self.run_bzr_error(('brz: ERROR: Start revision must be older than '
4955.5.2 by Vincent Ladeuil
Simplify tests.
407
                            'the end revision.\n',),
408
                           ['log', '-r3..1'])
409
410
    def test_log_reversed_dotted_revspecs(self):
411
        self.make_merged_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
412
        self.run_bzr_error(('brz: ERROR: Start revision not found in '
6376.1.1 by Vincent Ladeuil
Relax constraints on bzr log -rX..Y by falling back to the slower implementation when needed
413
                            'history of end revision.\n',),
4955.5.2 by Vincent Ladeuil
Simplify tests.
414
                           "log -r 1.1.1..1")
415
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
416
    def test_log_bad_message_re(self):
417
        """Bad --message argument gives a sensible message
5326.2.1 by Parth Malwankar
added InvalidPattern error.
418
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
419
        See https://bugs.launchpad.net/bzr/+bug/251352
420
        """
421
        self.make_minimal_branch()
422
        out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
5326.2.1 by Parth Malwankar
added InvalidPattern error.
423
        self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
5339.1.1 by Parth Malwankar
fixes errors.InvalidPattern to work on Python2.5
424
        self.assertNotContainsRe(err, "Unprintable exception")
5326.2.1 by Parth Malwankar
added InvalidPattern error.
425
        self.assertEqual(out, '')
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
426
4955.4.7 by Vincent Ladeuil
Some more cleanup.
427
    def test_log_unsupported_timezone(self):
428
        self.make_linear_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
429
        self.run_bzr_error(['brz: ERROR: Unsupported timezone format "foo", '
4955.4.7 by Vincent Ladeuil
Some more cleanup.
430
                            'options are "utc", "original", "local".'],
431
                           ['log', '--timezone', 'foo'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
432
5097.1.13 by Vincent Ladeuil
Add more tests.
433
    def test_log_exclude_ancestry_no_range(self):
434
        self.make_linear_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
435
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
5097.1.13 by Vincent Ladeuil
Add more tests.
436
                            ' requires -r with two revisions'],
437
                           ['log', '--exclude-common-ancestry'])
438
439
    def test_log_exclude_ancestry_single_revision(self):
440
        self.make_merged_branch()
6622.1.29 by Jelmer Vernooij
Fix some more tests.
441
        self.run_bzr_error(['brz: ERROR: --exclude-common-ancestry'
5097.1.13 by Vincent Ladeuil
Add more tests.
442
                            ' requires two different revisions'],
443
                           ['log', '--exclude-common-ancestry',
444
                            '-r1.1.1..1.1.1'])
4955.5.1 by Vincent Ladeuil
Split some tests to better characterize the classes
445
446
class TestLogTags(TestLog):
447
2388.1.3 by Erik Bagfors
tests for tags in log output
448
    def test_log_with_tags(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
449
        tree = self.make_linear_branch(format='dirstate-tags')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
450
        branch = tree.branch
451
        branch.tags.set_tag('tag1', branch.get_rev_id(1))
452
        branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
3842.2.5 by Vincent Ladeuil
Better fix for bug #300055.
453
        branch.tags.set_tag('tag3', branch.last_revision())
454
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
455
        log = self.run_bzr("log -r-1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
456
        self.assertTrue('tags: tag3' in log)
457
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
458
        log = self.run_bzr("log -r1")[0]
2388.1.3 by Erik Bagfors
tests for tags in log output
459
        # I guess that we can't know the order of tags in the output
460
        # since dicts are unordered, need to check both possibilities
2388.1.11 by Alexander Belchenko
changes after John's review
461
        self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
462
2388.1.9 by Erik Bagfors
test for merges with tags in log
463
    def test_merged_log_with_tags(self):
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
464
        branch1_tree = self.make_linear_branch('branch1',
465
                                               format='dirstate-tags')
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
466
        branch1 = branch1_tree.branch
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
467
        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.
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]
2388.1.11 by Alexander Belchenko
changes after John's review
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]
2466.12.2 by Kent Gibson
shift log output with only merge revisions to the left margin
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]
487
        self.assertTrue('signature: no signature' in log)
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]
495
        self.assertFalse('signature: no signature' in log)
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
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
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
3947.1.7 by Ian Clatworthy
tweak indenting/offsetting for --short given dotted revno lengths
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)
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(
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(
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()
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
628
        self.build_tree_contents([('level1/file2', '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):
634
        return """=== 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):
643
        return """=== 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):
653
        return """=== 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):
663
        return """=== 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,
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
672
                            working_dir='.'):
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)
679
                           for r in self.get_captured_revisions()])
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()),
694
             ('1', 0, self._diff_file1_revno1()
695
              + self._diff_file2_revno1())],
696
            working_dir='level0')
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
697
698
699
    def test_log_diff_file1(self):
4955.4.13 by Vincent Ladeuil
Remove dead code.
700
        self.assertLogRevnosAndDiff(['-n0', 'file1'],
701
                                    [('1', 0, self._diff_file1_revno1())],
702
                                    working_dir='level0')
4955.4.11 by Vincent Ladeuil
Give some tests a better focus and simplify them accordingly.
703
704
    def test_log_diff_file2(self):
4955.4.13 by Vincent Ladeuil
Remove dead code.
705
        self.assertLogRevnosAndDiff(['-n1', 'file2'],
706
                                    [('2', 0, self._diff_file2_revno2()),
707
                                     ('1', 0, self._diff_file2_revno1())],
708
                                    working_dir='level0')
4325.4.5 by Vincent Ladeuil
Some cleanup in blackbox log tests.
709
710
711
class TestLogUnicodeDiff(TestLog):
3943.5.4 by Ian Clatworthy
filter diff by file
712
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.
713
    def test_log_show_diff_non_ascii(self):
714
        # Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
715
        message = u'Message with \xb5'
716
        body = 'Body with \xb5\n'
717
        wt = self.make_branch_and_tree('.')
718
        self.build_tree_contents([('foo', body)])
719
        wt.add('foo')
720
        wt.commit(message=message)
721
        # check that command won't fail with unicode error
722
        # don't care about exact output because we have other tests for this
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
723
        out, err = self.run_bzr('log -p --long')
724
        self.assertNotEqual('', out)
725
        self.assertEqual('', err)
726
        out, err = self.run_bzr('log -p --short')
727
        self.assertNotEqual('', out)
728
        self.assertEqual('', err)
729
        out, err = self.run_bzr('log -p --line')
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.
730
        self.assertNotEqual('', out)
731
        self.assertEqual('', err)
732
3943.5.3 by Ian Clatworthy
add tests
733
4325.4.3 by Vincent Ladeuil
More cleanups.
734
class TestLogEncodings(tests.TestCaseInTempDir):
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
735
736
    _mu = u'\xb5'
737
    _message = u'Message with \xb5'
738
739
    # Encodings which can encode mu
740
    good_encodings = [
741
        'utf-8',
742
        'latin-1',
743
        'iso-8859-1',
744
        '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.
745
        'cp1251', # Russian windows encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
746
        'cp1258', # Common windows encoding
747
    ]
748
    # Encodings which cannot encode mu
749
    bad_encodings = [
750
        'ascii',
751
        'iso-8859-2',
752
        'koi8_r',
753
    ]
754
755
    def setUp(self):
4325.4.3 by Vincent Ladeuil
More cleanups.
756
        super(TestLogEncodings, self).setUp()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
757
        self.overrideAttr(osutils, '_cached_user_encoding')
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
758
759
    def create_branch(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
760
        brz = self.run_bzr
6622.1.30 by Jelmer Vernooij
Some more test fixes.
761
        brz('init')
4955.4.16 by Vincent Ladeuil
Be windows-friendly and don't left opened files behind.
762
        self.build_tree_contents([('a', 'some stuff\n')])
6622.1.30 by Jelmer Vernooij
Some more test fixes.
763
        brz('add a')
764
        brz(['commit', '-m', self._message])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
765
766
    def try_encoding(self, encoding, fail=False):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
767
        brz = self.run_bzr
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
768
        if fail:
769
            self.assertRaises(UnicodeEncodeError,
770
                self._mu.encode, encoding)
771
            encoded_msg = self._message.encode(encoding, 'replace')
772
        else:
773
            encoded_msg = self._message.encode(encoding)
774
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
775
        old_encoding = osutils._cached_user_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
776
        # This test requires that 'run_bzr' uses the current
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
777
        # breezy, because we override user_encoding, and expect
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
778
        # it to be used
779
        try:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
780
            osutils._cached_user_encoding = 'ascii'
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
781
            # We should be able to handle any encoding
6622.1.30 by Jelmer Vernooij
Some more test fixes.
782
            out, err = brz('log', encoding=encoding)
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
783
            if not fail:
784
                # Make sure we wrote mu as we expected it to exist
785
                self.assertNotEqual(-1, out.find(encoded_msg))
786
                out_unicode = out.decode(encoding)
787
                self.assertNotEqual(-1, out_unicode.find(self._message))
788
            else:
789
                self.assertNotEqual(-1, out.find('Message with ?'))
790
        finally:
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
791
            osutils._cached_user_encoding = old_encoding
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
792
793
    def test_log_handles_encoding(self):
794
        self.create_branch()
795
796
        for encoding in self.good_encodings:
797
            self.try_encoding(encoding)
798
799
    def test_log_handles_bad_encoding(self):
800
        self.create_branch()
801
802
        for encoding in self.bad_encodings:
803
            self.try_encoding(encoding, fail=True)
804
805
    def test_stdout_encoding(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
806
        brz = self.run_bzr
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
807
        osutils._cached_user_encoding = "cp1251"
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
808
6622.1.30 by Jelmer Vernooij
Some more test fixes.
809
        brz('init')
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
810
        self.build_tree(['a'])
6622.1.30 by Jelmer Vernooij
Some more test fixes.
811
        brz('add a')
812
        brz(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
813
        stdout, stderr = self.run_bzr('log', encoding='cp866')
814
815
        message = stdout.splitlines()[-1]
816
817
        # explanation of the check:
818
        # u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
819
        # in cp866  encoding this is string '\x92\xa5\xe1\xe2'
820
        # in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
821
        # This test should check that output of log command
822
        # encoded to sys.stdout.encoding
823
        test_in_cp866 = '\x92\xa5\xe1\xe2'
824
        test_in_cp1251 = '\xd2\xe5\xf1\xf2'
825
        # Make sure the log string is encoded in cp866
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
826
        self.assertEqual(test_in_cp866, message[2:])
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
827
        # Make sure the cp1251 string is not found anywhere
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
828
        self.assertEqual(-1, stdout.find(test_in_cp1251))
1685.1.5 by John Arbash Meinel
Merged test_log.py.moved into test_log.py
829
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
830
4955.4.9 by Vincent Ladeuil
More simplifications.
831
class TestLogFile(TestLogWithLogCatcher):
1551.10.18 by Aaron Bentley
Log works in local treeless branches (#84247)
832
833
    def test_log_local_branch_file(self):
834
        """We should be able to log files in local treeless branches"""
835
        tree = self.make_branch_and_tree('tree')
836
        self.build_tree(['tree/file'])
837
        tree.add('file')
838
        tree.commit('revision 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
839
        tree.controldir.destroy_workingtree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
840
        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.
841
3943.6.1 by Ian Clatworthy
find file using the end revision
842
    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
843
        # 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.
844
        tree = self.make_branch_and_tree('parent')
845
        self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
846
        tree.add('file1')
847
        tree.commit('add file1')
848
        tree.add('file2')
849
        tree.commit('add file2')
850
        tree.add('file3')
851
        tree.commit('add file3')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
852
        child_tree = tree.controldir.sprout('child').open_workingtree()
2664.14.1 by Daniel Watkins
Fixed tests.blackbox.test_log to use internals where appropriate.
853
        self.build_tree_contents([('child/file2', 'hello')])
854
        child_tree.commit(message='branch 1')
855
        tree.merge_from_branch(child_tree.branch)
856
        tree.commit(message='merge child branch')
3943.6.1 by Ian Clatworthy
find file using the end revision
857
        if complex:
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
858
            tree.remove('file2')
859
            tree.commit('remove file2')
860
            tree.rename_one('file3', 'file4')
861
            tree.commit('file3 is now called file4')
3943.6.1 by Ian Clatworthy
find file using the end revision
862
            tree.remove('file1')
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
863
            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.
864
        os.chdir('parent')
3940.1.2 by Ian Clatworthy
add test
865
4955.4.9 by Vincent Ladeuil
More simplifications.
866
    # FIXME: It would be good to parametrize the following tests against all
867
    # formatters. But the revisions selection is not *currently* part of the
868
    # LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
869
    def test_log_file1(self):
870
        self.prepare_tree()
871
        self.assertLogRevnos(['-n0', 'file1'], ['1'])
872
873
    def test_log_file2(self):
874
        self.prepare_tree()
875
        # file2 full history
876
        self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
877
        # file2 in a merge revision
878
        self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
879
        # file2 in a mainline revision
880
        self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
881
        # file2 since a revision
882
        self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
883
        # file2 up to a revision
884
        self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
885
886
    def test_log_file3(self):
887
        self.prepare_tree()
888
        self.assertLogRevnos(['-n0', 'file3'], ['3'])
3940.1.2 by Ian Clatworthy
add test
889
3943.6.4 by Ian Clatworthy
review feedback from vila
890
    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
891
        # Check logging a deleted file gives an error if the
892
        # file isn't found at the end or start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
893
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
894
        err_msg = "Path unknown at end or start of revision range: file2"
895
        err = self.run_bzr('log file2', retcode=3)[1]
3943.6.1 by Ian Clatworthy
find file using the end revision
896
        self.assertContainsRe(err, err_msg)
897
3943.6.4 by Ian Clatworthy
review feedback from vila
898
    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
899
        # Check logging a deleted file is ok if the file existed
900
        # at the end the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
901
        self.prepare_tree(complex=True)
4955.4.9 by Vincent Ladeuil
More simplifications.
902
        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
903
3943.6.4 by Ian Clatworthy
review feedback from vila
904
    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
905
        # Check logging a deleted file is ok if the file existed
906
        # at the start of the revision range
3943.6.4 by Ian Clatworthy
review feedback from vila
907
        self.prepare_tree(complex=True)
4955.4.9 by Vincent Ladeuil
More simplifications.
908
        self.assertLogRevnos(['file1'], ['1'])
3943.6.1 by Ian Clatworthy
find file using the end revision
909
910
    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
911
        """File matched against revision range, not current tree."""
3943.6.1 by Ian Clatworthy
find file using the end revision
912
        self.prepare_tree(complex=True)
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
913
3943.6.1 by Ian Clatworthy
find file using the end revision
914
        # Check logging a renamed file gives an error by default
3943.6.3 by Ian Clatworthy
search the start tree if the end tree doesn't have a file
915
        err_msg = "Path unknown at end or start of revision range: file3"
3943.6.1 by Ian Clatworthy
find file using the end revision
916
        err = self.run_bzr('log file3', retcode=3)[1]
917
        self.assertContainsRe(err, err_msg)
918
919
        # Check we can see a renamed file if we give the right end revision
4955.4.9 by Vincent Ladeuil
More simplifications.
920
        self.assertLogRevnos(['-r..4', 'file3'], ['3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
921
922
4955.4.10 by Vincent Ladeuil
More simplification.
923
class TestLogMultiple(TestLogWithLogCatcher):
4202.2.1 by Ian Clatworthy
get directory logging working again
924
925
    def prepare_tree(self):
926
        tree = self.make_branch_and_tree('parent')
927
        self.build_tree([
928
            'parent/file1',
929
            'parent/file2',
930
            'parent/dir1/',
931
            'parent/dir1/file5',
932
            'parent/dir1/dir2/',
933
            'parent/dir1/dir2/file3',
934
            'parent/file4'])
935
        tree.add('file1')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
936
        tree.commit('add file1')
4202.2.1 by Ian Clatworthy
get directory logging working again
937
        tree.add('file2')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
938
        tree.commit('add file2')
4202.2.1 by Ian Clatworthy
get directory logging working again
939
        tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
940
        tree.commit('add file3')
4202.2.1 by Ian Clatworthy
get directory logging working again
941
        tree.add('file4')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
942
        tree.commit('add file4')
4202.2.1 by Ian Clatworthy
get directory logging working again
943
        tree.add('dir1/file5')
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
944
        tree.commit('add file5')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
945
        child_tree = tree.controldir.sprout('child').open_workingtree()
4202.2.1 by Ian Clatworthy
get directory logging working again
946
        self.build_tree_contents([('child/file2', 'hello')])
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
947
        child_tree.commit(message='branch 1')
4202.2.1 by Ian Clatworthy
get directory logging working again
948
        tree.merge_from_branch(child_tree.branch)
4202.2.2 by Ian Clatworthy
improve signal-to-noise ratio in tests
949
        tree.commit(message='merge child branch')
4202.2.1 by Ian Clatworthy
get directory logging working again
950
        os.chdir('parent')
951
952
    def test_log_files(self):
953
        """The log for multiple file should only list revs for those files"""
954
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
955
        self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
956
                             ['6', '5.1.1', '3', '2', '1'])
4202.2.1 by Ian Clatworthy
get directory logging working again
957
958
    def test_log_directory(self):
959
        """The log for a directory should show all nested files."""
960
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
961
        self.assertLogRevnos(['dir1'], ['5', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
962
963
    def test_log_nested_directory(self):
964
        """The log for a directory should show all nested files."""
965
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
966
        self.assertLogRevnos(['dir1/dir2'], ['3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
967
968
    def test_log_in_nested_directory(self):
969
        """The log for a directory should show all nested files."""
970
        self.prepare_tree()
971
        os.chdir("dir1")
4955.4.10 by Vincent Ladeuil
More simplification.
972
        self.assertLogRevnos(['.'], ['5', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
973
974
    def test_log_files_and_directories(self):
975
        """Logging files and directories together should be fine."""
976
        self.prepare_tree()
4955.4.10 by Vincent Ladeuil
More simplification.
977
        self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
4202.2.1 by Ian Clatworthy
get directory logging working again
978
979
    def test_log_files_and_dirs_in_nested_directory(self):
980
        """The log for a directory should show all nested files."""
981
        self.prepare_tree()
982
        os.chdir("dir1")
4955.4.10 by Vincent Ladeuil
More simplification.
983
        self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
984
985
986
class MainlineGhostTests(TestLogWithLogCatcher):
987
988
    def setUp(self):
989
        super(MainlineGhostTests, self).setUp()
990
        tree = self.make_branch_and_tree('')
991
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
992
        tree.add('')
993
        tree.commit('msg1', rev_id='rev1')
994
        tree.commit('msg2', rev_id='rev2')
995
996
    def test_log_range(self):
997
        self.assertLogRevnos(["-r1..2"], ["2", "1"])
998
999
    def test_log_norange(self):
1000
        self.assertLogRevnos([], ["2", "1"])
1001
1002
    def test_log_range_open_begin(self):
1003
        (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
1004
        self.assertEqual(["2", "1"],
1005
                         [r.revno for r in self.get_captured_revisions()])
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1006
        self.assertEqual("brz: ERROR: Further revision history missing.\n",
1007
                stderr)
5691.1.2 by Jelmer Vernooij
Add tests for ghosts in mainline during log.
1008
1009
    def test_log_range_open_end(self):
1010
        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.
1011
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1012
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.
1013
class TestLogMatch(TestLogWithLogCatcher):
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1014
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
    def prepare_tree(self):
1016
        tree = self.make_branch_and_tree('')
1017
        self.build_tree(
1018
            ['/hello.txt', '/goodbye.txt'])
1019
        tree.add('hello.txt')
1020
        tree.commit(message='message1', committer='committer1', authors=['author1'])
1021
        tree.add('goodbye.txt')
1022
        tree.commit(message='message2', committer='committer2', authors=['author2'])
6716.2.2 by Jelmer Vernooij
Deal with ghost revisions in mainline in bzr log.
1023
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.
1024
    def test_message(self):
1025
        self.prepare_tree()
1026
        self.assertLogRevnos(["-m", "message1"], ["1"])
1027
        self.assertLogRevnos(["-m", "message2"], ["2"])
1028
        self.assertLogRevnos(["-m", "message"], ["2", "1"])
1029
        self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
1030
        self.assertLogRevnos(["--match-message", "message1"], ["1"])
1031
        self.assertLogRevnos(["--match-message", "message2"], ["2"])
1032
        self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
1033
        self.assertLogRevnos(["--match-message", "message1", 
1034
                              "--match-message", "message2"], ["2", "1"])
1035
        self.assertLogRevnos(["--message", "message1"], ["1"])
1036
        self.assertLogRevnos(["--message", "message2"], ["2"])
1037
        self.assertLogRevnos(["--message", "message"], ["2", "1"])
1038
        self.assertLogRevnos(["--match-message", "message1", 
1039
                              "--message", "message2"], ["2", "1"])
1040
        self.assertLogRevnos(["--message", "message1", 
1041
                              "--match-message", "message2"], ["2", "1"])
1042
1043
    def test_committer(self):
1044
        self.prepare_tree()
1045
        self.assertLogRevnos(["-m", "committer1"], ["1"])
1046
        self.assertLogRevnos(["-m", "committer2"], ["2"])
1047
        self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1048
        self.assertLogRevnos(["-m", "committer1", "-m", "committer2"], 
1049
                             ["2", "1"])
1050
        self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1051
        self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1052
        self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1053
        self.assertLogRevnos(["--match-committer", "committer1", 
1054
                              "--match-committer", "committer2"], ["2", "1"])
1055
1056
    def test_author(self):
1057
        self.prepare_tree()
1058
        self.assertLogRevnos(["-m", "author1"], ["1"])
1059
        self.assertLogRevnos(["-m", "author2"], ["2"])
1060
        self.assertLogRevnos(["-m", "author"], ["2", "1"])
1061
        self.assertLogRevnos(["-m", "author1", "-m", "author2"], 
1062
                             ["2", "1"])
1063
        self.assertLogRevnos(["--match-author", "author1"], ["1"])
1064
        self.assertLogRevnos(["--match-author", "author2"], ["2"])
1065
        self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1066
        self.assertLogRevnos(["--match-author", "author1", 
1067
                              "--match-author", "author2"], ["2", "1"])
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1068
1069
1070
class TestSmartServerLog(tests.TestCaseWithTransport):
1071
1072
    def test_standard_log(self):
1073
        self.setup_smart_server_with_call_log()
1074
        t = self.make_branch_and_tree('branch')
1075
        self.build_tree_contents([('branch/foo', 'thecontents')])
1076
        t.add("foo")
1077
        t.commit("message")
1078
        self.reset_smart_call_log()
1079
        out, err = self.run_bzr(['log', self.get_url('branch')])
1080
        # This figure represent the amount of work to perform this use case. It
1081
        # is entirely ok to reduce this number if a test fails due to rpc_count
1082
        # being too low. If rpc_count increases, more network roundtrips have
1083
        # become necessary for this use case. Please do not adjust this number
1084
        # upwards without agreement from bzr's network support maintainers.
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
1085
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1086
        self.assertLength(1, self.hpss_connections)
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1087
        self.assertLength(9, self.hpss_calls)
6283.1.15 by Jelmer Vernooij
Move log tests to bzrlib.tests.blackbox.test_log.
1088
1089
    def test_verbose_log(self):
1090
        self.setup_smart_server_with_call_log()
1091
        t = self.make_branch_and_tree('branch')
1092
        self.build_tree_contents([('branch/foo', 'thecontents')])
1093
        t.add("foo")
1094
        t.commit("message")
1095
        self.reset_smart_call_log()
1096
        out, err = self.run_bzr(['log', '-v', self.get_url('branch')])
1097
        # This figure represent the amount of work to perform this use case. It
1098
        # is entirely ok to reduce this number if a test fails due to rpc_count
1099
        # being too low. If rpc_count increases, more network roundtrips have
1100
        # become necessary for this use case. Please do not adjust this number
1101
        # upwards without agreement from bzr's network support maintainers.
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1102
        self.assertLength(10, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1103
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
1104
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6282.6.16 by Jelmer Vernooij
More tests.
1105
1106
    def test_per_file(self):
1107
        self.setup_smart_server_with_call_log()
1108
        t = self.make_branch_and_tree('branch')
1109
        self.build_tree_contents([('branch/foo', 'thecontents')])
1110
        t.add("foo")
1111
        t.commit("message")
1112
        self.reset_smart_call_log()
1113
        out, err = self.run_bzr(['log', '-v', self.get_url('branch') + "/foo"])
1114
        # This figure represent the amount of work to perform this use case. It
1115
        # is entirely ok to reduce this number if a test fails due to rpc_count
1116
        # being too low. If rpc_count increases, more network roundtrips have
1117
        # become necessary for this use case. Please do not adjust this number
1118
        # upwards without agreement from bzr's network support maintainers.
6404.6.11 by Vincent Ladeuil
3 more hpss calls down the drain \o/
1119
        self.assertLength(14, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
1120
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
1121
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)