~bzr-pqm/bzr/bzr.dev

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