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