46
52
tree.commit(message='message2')
47
53
tree.add('meep.txt')
48
54
tree.commit(message='message3')
49
self.full_log = self.run_bzr(["log", path])[0]
57
def make_merged_branch(self, path='.', format=None):
58
tree = self.make_linear_branch(path, format)
59
tree2 = tree.bzrdir.sprout('tree2',
60
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
61
tree2.commit(message='tree2 message2')
62
tree2.commit(message='tree2 message3')
63
tree.merge_from_branch(tree2.branch)
64
tree.commit(message='merge')
68
class TestLogWithLogCatcher(TestLog):
71
super(TestLogWithLogCatcher, self).setUp()
72
# Capture log formatter creations
73
class MyLogFormatter(test_log.LogCatcher):
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
79
# Break cycle with closure over self on cleanup by removing method
80
self.addCleanup(setattr, MyLogFormatter, "__new__", None)
83
# Always return our own log formatter class hijacking the
84
# default behavior (which requires setting up a config
87
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
89
def get_captured_revisions(self):
90
return self.log_catcher.revisions
92
def assertLogRevnos(self, args, expected_revnos, working_dir='.'):
93
self.run_bzr(['log'] + args, working_dir=working_dir)
94
self.assertEqual(expected_revnos,
95
[r.revno for r in self.get_captured_revisions()])
97
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
99
self.run_bzr(['log'] + args, working_dir=working_dir)
100
self.assertEqual(expected_revnos_and_depths,
101
[(r.revno, r.merge_depth)
102
for r in self.get_captured_revisions()])
105
class TestLogRevSpecs(TestLogWithLogCatcher):
107
def test_log_no_revspec(self):
108
self.make_linear_branch()
109
self.assertLogRevnos([], ['3', '2', '1'])
52
111
def test_log_null_end_revspec(self):
54
self.assertTrue('revno: 1\n' in self.full_log)
55
self.assertTrue('revno: 2\n' in self.full_log)
56
self.assertTrue('revno: 3\n' in self.full_log)
57
self.assertTrue('message:\n message1\n' in self.full_log)
58
self.assertTrue('message:\n message2\n' in self.full_log)
59
self.assertTrue('message:\n message3\n' in self.full_log)
61
log = self.run_bzr("log -r 1..")[0]
62
self.assertEqualDiff(log, self.full_log)
112
self.make_linear_branch()
113
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
64
115
def test_log_null_begin_revspec(self):
66
log = self.run_bzr("log -r ..3")[0]
67
self.assertEqualDiff(self.full_log, log)
116
self.make_linear_branch()
117
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
69
119
def test_log_null_both_revspecs(self):
71
log = self.run_bzr("log -r ..")[0]
72
self.assertEqualDiff(self.full_log, log)
120
self.make_linear_branch()
121
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
123
def test_log_negative_begin_revspec_full_log(self):
124
self.make_linear_branch()
125
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
127
def test_log_negative_both_revspec_full_log(self):
128
self.make_linear_branch()
129
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
131
def test_log_negative_both_revspec_partial(self):
132
self.make_linear_branch()
133
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
135
def test_log_negative_begin_revspec(self):
136
self.make_linear_branch()
137
self.assertLogRevnos(['-r-2..'], ['3', '2'])
139
def test_log_positive_revspecs(self):
140
self.make_linear_branch()
141
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
143
def test_log_dotted_revspecs(self):
144
self.make_merged_branch()
145
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
147
def test_log_limit(self):
148
tree = self.make_branch_and_tree('.')
149
# We want more commits than our batch size starts at
150
for pos in range(10):
151
tree.commit("%s" % pos)
152
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
154
def test_log_limit_short(self):
155
self.make_linear_branch()
156
self.assertLogRevnos(['-l', '2'], ['3', '2'])
158
def test_log_change_revno(self):
159
self.make_linear_branch()
160
self.assertLogRevnos(['-c1'], ['1'])
162
def test_branch_revspec(self):
163
foo = self.make_branch_and_tree('foo')
164
bar = self.make_branch_and_tree('bar')
165
self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
168
foo.commit(message='foo')
169
bar.commit(message='bar')
170
self.run_bzr('log -r branch:../bar', working_dir='foo')
171
self.assertEqual([bar.branch.get_rev_id(1)],
173
for r in self.get_captured_revisions()])
176
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
178
def test_exclude_common_ancestry_simple_revnos(self):
179
self.make_linear_branch()
180
self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
184
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
187
super(TestLogMergedLinearAncestry, self).setUp()
188
# FIXME: Using a MemoryTree would be even better here (but until we
189
# stop calling run_bzr, there is no point) --vila 100118.
190
builder = branchbuilder.BranchBuilder(self.get_transport())
191
builder.start_series()
205
builder.build_snapshot('1', None, [
206
('add', ('', 'root-id', 'directory', ''))])
207
builder.build_snapshot('2', ['1'], [])
209
builder.build_snapshot('1.1.1', ['1'], [])
210
# merge branch into mainline
211
builder.build_snapshot('3', ['2', '1.1.1'], [])
212
# new commits in branch
213
builder.build_snapshot('1.1.2', ['1.1.1'], [])
214
builder.build_snapshot('1.1.3', ['1.1.2'], [])
215
# merge branch into mainline
216
builder.build_snapshot('4', ['3', '1.1.3'], [])
217
# merge mainline into branch
218
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
219
# merge branch into mainline
220
builder.build_snapshot('5', ['4', '1.1.4'], [])
221
builder.finish_series()
224
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
225
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
226
def test_n0_forward(self):
227
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
228
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
231
# starting from 1.1.4 we follow the left-hand ancestry
232
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
233
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
235
def test_n1_forward(self):
236
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
237
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
240
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
243
super(Test_GenerateAllRevisions, self).setUp()
244
builder = self.make_branch_with_many_merges()
245
b = builder.get_branch()
247
self.addCleanup(b.unlock)
250
def make_branch_with_many_merges(self, path='.', format=None):
251
builder = branchbuilder.BranchBuilder(self.get_transport())
252
builder.start_series()
253
# The graph below may look a bit complicated (and it may be but I've
254
# banged my head enough on it) but the bug requires at least dotted
255
# revnos *and* merged revisions below that.
256
builder.build_snapshot('1', None, [
257
('add', ('', 'root-id', 'directory', ''))])
258
builder.build_snapshot('2', ['1'], [])
259
builder.build_snapshot('1.1.1', ['1'], [])
260
builder.build_snapshot('2.1.1', ['2'], [])
261
builder.build_snapshot('3', ['2', '1.1.1'], [])
262
builder.build_snapshot('2.1.2', ['2.1.1'], [])
263
builder.build_snapshot('2.2.1', ['2.1.1'], [])
264
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
265
builder.build_snapshot('4', ['3', '2.1.3'], [])
266
builder.build_snapshot('5', ['4', '2.1.2'], [])
267
builder.finish_series()
270
def test_not_an_ancestor(self):
271
self.assertRaises(errors.BzrCommandError,
272
log._generate_all_revisions,
273
self.branch, '1.1.1', '2.1.3', 'reverse',
274
delayed_graph_generation=True)
276
def test_wrong_order(self):
277
self.assertRaises(errors.BzrCommandError,
278
log._generate_all_revisions,
279
self.branch, '5', '2.1.3', 'reverse',
280
delayed_graph_generation=True)
282
def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
283
revs = log._generate_all_revisions(
284
self.branch, None, '2.1.3',
285
'reverse', delayed_graph_generation=True)
288
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
290
def test_log_revno_n_path_wrong_namespace(self):
291
self.make_linear_branch('branch1')
292
self.make_linear_branch('branch2')
293
# There is no guarantee that a path exist between two arbitrary
295
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
297
def test_log_revno_n_path_correct_order(self):
298
self.make_linear_branch('branch2')
299
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
302
def test_log_revno_n_path(self):
303
self.make_linear_branch('branch2')
304
self.assertLogRevnos(['-rrevno:1:branch2'],
306
rev_props = self.log_catcher.revisions[0].rev.properties
307
self.assertEqual('branch2', rev_props['branch-nick'])
310
class TestLogErrors(TestLog):
74
312
def test_log_zero_revspec(self):
76
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
313
self.make_minimal_branch()
314
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
79
317
def test_log_zero_begin_revspec(self):
81
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
318
self.make_linear_branch()
319
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
82
320
['log', '-r0..2'])
84
322
def test_log_zero_end_revspec(self):
86
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
323
self.make_linear_branch()
324
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
87
325
['log', '-r-2..0'])
89
def test_log_unsupported_timezone(self):
91
self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
92
'options are "utc", "original", "local".',
93
['log', '--timezone', 'foo'])
95
def test_log_negative_begin_revspec_full_log(self):
97
log = self.run_bzr("log -r -3..")[0]
98
self.assertEqualDiff(self.full_log, log)
100
def test_log_negative_both_revspec_full_log(self):
102
log = self.run_bzr("log -r -3..-1")[0]
103
self.assertEqualDiff(self.full_log, log)
105
def test_log_negative_both_revspec_partial(self):
107
log = self.run_bzr("log -r -3..-2")[0]
108
self.assertTrue('revno: 1\n' in log)
109
self.assertTrue('revno: 2\n' in log)
110
self.assertTrue('revno: 3\n' not in log)
112
def test_log_negative_begin_revspec(self):
114
log = self.run_bzr("log -r -2..")[0]
115
self.assertTrue('revno: 1\n' not in log)
116
self.assertTrue('revno: 2\n' in log)
117
self.assertTrue('revno: 3\n' in log)
119
def test_log_positive_revspecs(self):
121
log = self.run_bzr("log -r 1..3")[0]
122
self.assertEqualDiff(self.full_log, log)
124
def test_log_reversed_revspecs(self):
126
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
127
'the end revision.\n',),
130
def test_log_revno_n_path(self):
131
self._prepare(path='branch1')
132
self._prepare(path='branch2')
133
log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
135
log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
136
self.assertEqualDiff(self.full_log, log)
137
log = self.run_bzr("log -r revno:1:branch2")[0]
138
self.assertTrue('revno: 1\n' in log)
139
self.assertTrue('revno: 2\n' not in log)
140
self.assertTrue('branch nick: branch2\n' in log)
141
self.assertTrue('branch nick: branch1\n' not in log)
143
327
def test_log_nonexistent_revno(self):
145
(out, err) = self.run_bzr_error(args="log -r 1234",
146
error_regexes=["bzr: ERROR: Requested revision: '1234' "
147
"does not exist in branch:"])
328
self.make_minimal_branch()
329
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
330
"does not exist in branch:"],
149
333
def test_log_nonexistent_dotted_revno(self):
151
(out, err) = self.run_bzr_error(args="log -r 123.123",
152
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
153
"does not exist in branch:"])
155
def test_log_change_revno(self):
157
expected_log = self.run_bzr("log -r 1")[0]
158
log = self.run_bzr("log -c 1")[0]
159
self.assertEqualDiff(expected_log, log)
334
self.make_minimal_branch()
335
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
336
"does not exist in branch:"],
337
['log', '-r123.123'])
161
339
def test_log_change_nonexistent_revno(self):
163
(out, err) = self.run_bzr_error(args="log -c 1234",
164
error_regexes=["bzr: ERROR: Requested revision: '1234' "
165
"does not exist in branch:"])
340
self.make_minimal_branch()
341
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
342
"does not exist in branch:"],
167
345
def test_log_change_nonexistent_dotted_revno(self):
169
(out, err) = self.run_bzr_error(args="log -c 123.123",
170
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
171
"does not exist in branch:"])
346
self.make_minimal_branch()
347
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
348
"does not exist in branch:"],
349
['log', '-c123.123'])
173
def test_log_change_single_revno(self):
175
self.run_bzr_error('bzr: ERROR: Option --change does not'
176
' accept revision ranges',
351
def test_log_change_single_revno_only(self):
352
self.make_minimal_branch()
353
self.run_bzr_error(['bzr: ERROR: Option --change does not'
354
' accept revision ranges'],
177
355
['log', '--change', '2..3'])
179
357
def test_log_change_incompatible_with_revision(self):
181
self.run_bzr_error('bzr: ERROR: --revision and --change'
182
' are mutually exclusive',
358
self.run_bzr_error(['bzr: ERROR: --revision and --change'
359
' are mutually exclusive'],
183
360
['log', '--change', '2', '--revision', '3'])
185
362
def test_log_nonexistent_file(self):
363
self.make_minimal_branch()
186
364
# files that don't exist in either the basis tree or working tree
187
365
# should give an error
188
wt = self.make_branch_and_tree('.')
189
366
out, err = self.run_bzr('log does-not-exist', retcode=3)
190
self.assertContainsRe(
191
err, 'Path unknown at end or start of revision range: does-not-exist')
367
self.assertContainsRe(err,
368
'Path unknown at end or start of revision range: '
371
def test_log_reversed_revspecs(self):
372
self.make_linear_branch()
373
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
374
'the end revision.\n',),
377
def test_log_reversed_dotted_revspecs(self):
378
self.make_merged_branch()
379
self.run_bzr_error(('bzr: ERROR: Start revision not found in '
380
'left-hand history of end revision.\n',),
383
def test_log_bad_message_re(self):
384
"""Bad --message argument gives a sensible message
386
See https://bugs.launchpad.net/bzr/+bug/251352
388
self.make_minimal_branch()
389
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
390
self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
391
self.assertNotContainsRe(err, "Unprintable exception")
392
self.assertEqual(out, '')
394
def test_log_unsupported_timezone(self):
395
self.make_linear_branch()
396
self.run_bzr_error(['bzr: ERROR: Unsupported timezone format "foo", '
397
'options are "utc", "original", "local".'],
398
['log', '--timezone', 'foo'])
400
def test_log_exclude_ancestry_no_range(self):
401
self.make_linear_branch()
402
self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
403
' requires -r with two revisions'],
404
['log', '--exclude-common-ancestry'])
406
def test_log_exclude_ancestry_single_revision(self):
407
self.make_merged_branch()
408
self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
409
' requires two different revisions'],
410
['log', '--exclude-common-ancestry',
413
class TestLogTags(TestLog):
193
415
def test_log_with_tags(self):
194
tree = self._prepare(format='dirstate-tags')
416
tree = self.make_linear_branch(format='dirstate-tags')
195
417
branch = tree.branch
196
418
branch.tags.set_tag('tag1', branch.get_rev_id(1))
197
419
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
282
500
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
285
class TestLogMerges(TestCaseWithoutPropsHandler):
288
parent_tree = self.make_branch_and_tree('parent')
289
parent_tree.commit(message='first post', allow_pointless=True)
290
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
291
child_tree.commit(message='branch 1', allow_pointless=True)
293
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
294
smaller_tree.commit(message='branch 2', allow_pointless=True)
295
child_tree.merge_from_branch(smaller_tree.branch)
296
child_tree.commit(message='merge branch 2')
297
parent_tree.merge_from_branch(child_tree.branch)
298
parent_tree.commit(message='merge branch 1')
301
def _prepare_short(self):
302
parent_tree = self.make_branch_and_tree('parent')
303
parent_tree.commit(message='first post',
304
timestamp=1132586700, timezone=36000,
305
committer='Joe Foo <joe@foo.com>')
306
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
307
child_tree.commit(message='branch 1',
308
timestamp=1132586800, timezone=36000,
309
committer='Joe Foo <joe@foo.com>')
311
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
312
smaller_tree.commit(message='branch 2',
313
timestamp=1132586900, timezone=36000,
314
committer='Joe Foo <joe@foo.com>')
315
child_tree.merge_from_branch(smaller_tree.branch)
316
child_tree.commit(message='merge branch 2',
317
timestamp=1132587000, timezone=36000,
318
committer='Joe Foo <joe@foo.com>')
319
parent_tree.merge_from_branch(child_tree.branch)
320
parent_tree.commit(message='merge branch 1',
321
timestamp=1132587100, timezone=36000,
322
committer='Joe Foo <joe@foo.com>')
503
class TestLogMerges(TestLogWithLogCatcher):
506
super(TestLogMerges, self).setUp()
507
self.make_branches_with_merges()
509
def make_branches_with_merges(self):
510
level0 = self.make_branch_and_tree('level0')
511
self.wt_commit(level0, 'in branch level0')
512
level1 = level0.bzrdir.sprout('level1').open_workingtree()
513
self.wt_commit(level1, 'in branch level1')
514
level2 = level1.bzrdir.sprout('level2').open_workingtree()
515
self.wt_commit(level2, 'in branch level2')
516
level1.merge_from_branch(level2.branch)
517
self.wt_commit(level1, 'merge branch level2')
518
level0.merge_from_branch(level1.branch)
519
self.wt_commit(level0, 'merge branch level1')
325
521
def test_merges_are_indented_by_level(self):
327
out,err = self.run_bzr('log')
328
self.assertEqual('', err)
329
log = normalize_log(out)
330
self.assertEqualDiff(log, """\
331
------------------------------------------------------------
333
committer: Lorem Ipsum <test@example.com>
338
------------------------------------------------------------
340
committer: Lorem Ipsum <test@example.com>
345
------------------------------------------------------------
347
committer: Lorem Ipsum <test@example.com>
348
branch nick: smallerchild
352
------------------------------------------------------------
354
committer: Lorem Ipsum <test@example.com>
359
------------------------------------------------------------
361
committer: Lorem Ipsum <test@example.com>
522
self.run_bzr(['log', '-n0'], working_dir='level0')
523
revnos_and_depth = [(r.revno, r.merge_depth)
524
for r in self.get_captured_revisions()]
525
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
527
[(r.revno, r.merge_depth)
528
for r in self.get_captured_revisions()])
368
530
def test_force_merge_revisions_off(self):
370
out,err = self.run_bzr('log --long -n1')
371
self.assertEqual('', err)
372
log = normalize_log(out)
373
self.assertEqualDiff(log, """\
374
------------------------------------------------------------
376
committer: Lorem Ipsum <test@example.com>
381
------------------------------------------------------------
383
committer: Lorem Ipsum <test@example.com>
531
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
390
533
def test_force_merge_revisions_on(self):
391
self._prepare_short()
392
out,err = self.run_bzr('log --short -n0')
393
self.assertEqual('', err)
394
log = normalize_log(out)
395
self.assertEqualDiff(log, """\
396
2 Joe Foo\t2005-11-22 [merge]
399
1.1.2 Joe Foo\t2005-11-22 [merge]
402
1.2.1 Joe Foo\t2005-11-22
405
1.1.1 Joe Foo\t2005-11-22
408
1 Joe Foo\t2005-11-22
534
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
535
working_dir='level0')
537
def test_include_merges(self):
538
# Confirm --include-merges gives the same output as -n0
539
self.assertLogRevnos(['--include-merges'],
540
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
541
working_dir='level0')
542
self.assertLogRevnos(['--include-merges'],
543
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
544
working_dir='level0')
545
out_im, err_im = self.run_bzr('log --include-merges',
546
working_dir='level0')
547
out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
548
self.assertEqual('', err_im)
549
self.assertEqual('', err_n0)
550
self.assertEqual(out_im, out_n0)
413
552
def test_force_merge_revisions_N(self):
414
self._prepare_short()
415
out,err = self.run_bzr('log --short -n2')
416
self.assertEqual('', err)
417
log = normalize_log(out)
418
self.assertEqualDiff(log, """\
419
2 Joe Foo\t2005-11-22 [merge]
422
1.1.2 Joe Foo\t2005-11-22 [merge]
425
1.1.1 Joe Foo\t2005-11-22
428
1 Joe Foo\t2005-11-22
553
self.assertLogRevnos(['-n2'],
554
['2', '1.1.2', '1.1.1', '1'],
555
working_dir='level0')
433
557
def test_merges_single_merge_rev(self):
435
out,err = self.run_bzr('log -r1.1.2')
436
self.assertEqual('', err)
437
log = normalize_log(out)
438
self.assertEqualDiff(log, """\
439
------------------------------------------------------------
441
committer: Lorem Ipsum <test@example.com>
446
------------------------------------------------------------
448
committer: Lorem Ipsum <test@example.com>
449
branch nick: smallerchild
558
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
559
[('1.1.2', 0), ('1.2.1', 1)],
560
working_dir='level0')
455
562
def test_merges_partial_range(self):
457
out, err = self.run_bzr('log -r1.1.1..1.1.2')
458
self.assertEqual('', err)
459
log = normalize_log(out)
460
self.assertEqualDiff(log, """\
461
------------------------------------------------------------
463
committer: Lorem Ipsum <test@example.com>
468
------------------------------------------------------------
470
committer: Lorem Ipsum <test@example.com>
471
branch nick: smallerchild
475
------------------------------------------------------------
477
committer: Lorem Ipsum <test@example.com>
484
def test_merges_nonsupporting_formatter(self):
485
# This "feature" of log formatters is madness. If a log
486
# formatter cannot display a dotted-revno, it ought to ignore it.
487
# Otherwise, a linear sequence is always expected to be handled now.
488
raise KnownFailure('log formatters must support linear sequences now')
490
err_msg = 'Selected log formatter only supports mainline revisions.'
491
# The single revision case is tested in the core tests
492
# since all standard formatters support single merge revisions.
493
out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
494
self.assertContainsRe(err, err_msg)
495
out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
496
self.assertContainsRe(err, err_msg)
499
def subst_dates(string):
500
"""Replace date strings with constant values."""
501
return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
502
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
505
class TestLogDiff(TestCaseWithoutPropsHandler):
508
parent_tree = self.make_branch_and_tree('parent')
509
self.build_tree(['parent/file1', 'parent/file2'])
510
parent_tree.add('file1')
511
parent_tree.add('file2')
512
parent_tree.commit(message='first post',
513
timestamp=1132586655, timezone=36000,
514
committer='Lorem Ipsum <test@example.com>')
515
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
516
self.build_tree_contents([('child/file2', 'hello\n')])
517
child_tree.commit(message='branch 1',
518
timestamp=1132586700, timezone=36000,
519
committer='Lorem Ipsum <test@example.com>')
520
parent_tree.merge_from_branch(child_tree.branch)
521
parent_tree.commit(message='merge branch 1',
522
timestamp=1132586800, timezone=36000,
523
committer='Lorem Ipsum <test@example.com>')
526
def test_log_show_diff_long(self):
528
out,err = self.run_bzr('log -p')
529
self.assertEqual('', err)
530
log = normalize_log(out)
531
self.assertEqualDiff(subst_dates(log), """\
532
------------------------------------------------------------
534
committer: Lorem Ipsum <test@example.com>
540
=== modified file 'file2'
541
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
542
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
544
-contents of parent/file2
546
------------------------------------------------------------
548
committer: Lorem Ipsum <test@example.com>
554
=== modified file 'file2'
555
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
556
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
558
-contents of parent/file2
560
------------------------------------------------------------
562
committer: Lorem Ipsum <test@example.com>
568
=== added file 'file1'
569
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
570
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
572
+contents of parent/file1
574
=== added file 'file2'
575
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
576
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
578
+contents of parent/file2
581
def test_log_show_diff_short(self):
563
self.assertLogRevnosAndDepths(
564
['-n0', '-r1.1.1..1.1.2'],
565
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
566
working_dir='level0')
568
def test_merges_partial_range_ignore_before_lower_bound(self):
569
"""Dont show revisions before the lower bound's merged revs"""
570
self.assertLogRevnosAndDepths(
571
['-n0', '-r1.1.2..2'],
572
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
573
working_dir='level0')
576
class TestLogDiff(TestLogWithLogCatcher):
578
# FIXME: We need specific tests for each LogFormatter about how the diffs
579
# are displayed: --long indent them by depth, --short use a fixed
580
# indent and --line does't display them. -- vila 10019
583
super(TestLogDiff, self).setUp()
584
self.make_branch_with_diffs()
586
def make_branch_with_diffs(self):
587
level0 = self.make_branch_and_tree('level0')
588
self.build_tree(['level0/file1', 'level0/file2'])
591
self.wt_commit(level0, 'in branch level0')
593
level1 = level0.bzrdir.sprout('level1').open_workingtree()
594
self.build_tree_contents([('level1/file2', 'hello\n')])
595
self.wt_commit(level1, 'in branch level1')
596
level0.merge_from_branch(level1.branch)
597
self.wt_commit(level0, 'merge branch level1')
599
def _diff_file1_revno1(self):
600
return """=== added file 'file1'
601
--- file1\t1970-01-01 00:00:00 +0000
602
+++ file1\t2005-11-22 00:00:00 +0000
604
+contents of level0/file1
608
def _diff_file2_revno2(self):
609
return """=== modified file 'file2'
610
--- file2\t2005-11-22 00:00:00 +0000
611
+++ file2\t2005-11-22 00:00:01 +0000
613
-contents of level0/file2
618
def _diff_file2_revno1_1_1(self):
619
return """=== modified file 'file2'
620
--- file2\t2005-11-22 00:00:00 +0000
621
+++ file2\t2005-11-22 00:00:01 +0000
623
-contents of level0/file2
628
def _diff_file2_revno1(self):
629
return """=== added file 'file2'
630
--- file2\t1970-01-01 00:00:00 +0000
631
+++ file2\t2005-11-22 00:00:00 +0000
633
+contents of level0/file2
637
def assertLogRevnosAndDiff(self, args, expected,
639
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
640
expected_revnos_and_depths = [
641
(revno, depth) for revno, depth, diff in expected]
642
# Check the revnos and depths first to make debugging easier
643
self.assertEqual(expected_revnos_and_depths,
644
[(r.revno, r.merge_depth)
645
for r in self.get_captured_revisions()])
646
# Now check the diffs, adding the revno in case of failure
647
fmt = 'In revno %s\n%s'
648
for expected_rev, actual_rev in izip(expected,
649
self.get_captured_revisions()):
650
revno, depth, expected_diff = expected_rev
651
actual_diff = actual_rev.diff
652
self.assertEqualDiff(fmt % (revno, expected_diff),
653
fmt % (revno, actual_diff))
655
def test_log_diff_with_merges(self):
656
self.assertLogRevnosAndDiff(
658
[('2', 0, self._diff_file2_revno2()),
659
('1.1.1', 1, self._diff_file2_revno1_1_1()),
660
('1', 0, self._diff_file1_revno1()
661
+ self._diff_file2_revno1())],
662
working_dir='level0')
665
def test_log_diff_file1(self):
666
self.assertLogRevnosAndDiff(['-n0', 'file1'],
667
[('1', 0, self._diff_file1_revno1())],
668
working_dir='level0')
670
def test_log_diff_file2(self):
671
self.assertLogRevnosAndDiff(['-n1', 'file2'],
672
[('2', 0, self._diff_file2_revno2()),
673
('1', 0, self._diff_file2_revno1())],
674
working_dir='level0')
677
class TestLogUnicodeDiff(TestLog):
679
def test_log_show_diff_non_ascii(self):
680
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
681
message = u'Message with \xb5'
682
body = 'Body with \xb5\n'
683
wt = self.make_branch_and_tree('.')
684
self.build_tree_contents([('foo', body)])
686
wt.commit(message=message)
687
# check that command won't fail with unicode error
688
# don't care about exact output because we have other tests for this
689
out,err = self.run_bzr('log -p --long')
690
self.assertNotEqual('', out)
691
self.assertEqual('', err)
583
692
out,err = self.run_bzr('log -p --short')
693
self.assertNotEqual('', out)
584
694
self.assertEqual('', err)
585
log = normalize_log(out)
586
self.assertEqualDiff(subst_dates(log), """\
587
2 Lorem Ipsum\t2005-11-22 [merge]
589
=== modified file 'file2'
590
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
591
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
593
-contents of parent/file2
596
1 Lorem Ipsum\t2005-11-22
598
=== added file 'file1'
599
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
600
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
602
+contents of parent/file1
604
=== added file 'file2'
605
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
606
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
608
+contents of parent/file2
612
def test_log_show_diff_line(self):
614
695
out,err = self.run_bzr('log -p --line')
615
self.assertEqual('', err)
616
log = normalize_log(out)
617
# Not supported by this formatter so expect plain output
618
self.assertEqualDiff(subst_dates(log), """\
619
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
620
1: Lorem Ipsum 2005-11-22 first post
623
def test_log_show_diff_file(self):
624
"""Only the diffs for the given file are to be shown"""
626
out,err = self.run_bzr('log -p --short file2')
627
self.assertEqual('', err)
628
log = normalize_log(out)
629
self.assertEqualDiff(subst_dates(log), """\
630
2 Lorem Ipsum\t2005-11-22 [merge]
632
=== modified file 'file2'
633
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
634
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
636
-contents of parent/file2
639
1 Lorem Ipsum\t2005-11-22
641
=== added file 'file2'
642
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
643
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
645
+contents of parent/file2
648
out,err = self.run_bzr('log -p --short file1')
649
self.assertEqual('', err)
650
log = normalize_log(out)
651
self.assertEqualDiff(subst_dates(log), """\
652
1 Lorem Ipsum\t2005-11-22
654
=== added file 'file1'
655
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
656
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
658
+contents of parent/file1
663
class TestLogEncodings(TestCaseInTempDir):
696
self.assertNotEqual('', out)
697
self.assertEqual('', err)
700
class TestLogEncodings(tests.TestCaseInTempDir):
666
703
_message = u'Message with \xb5'
796
829
tree.commit('remove file1')
797
830
os.chdir('parent')
799
def test_log_file(self):
800
"""The log for a particular file should only list revs for that file"""
802
log = self.run_bzr('log file1')[0]
803
self.assertContainsRe(log, 'revno: 1\n')
804
self.assertNotContainsRe(log, 'revno: 2\n')
805
self.assertNotContainsRe(log, 'revno: 3\n')
806
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
807
self.assertNotContainsRe(log, 'revno: 4\n')
808
log = self.run_bzr('log file2')[0]
809
self.assertNotContainsRe(log, 'revno: 1\n')
810
self.assertContainsRe(log, 'revno: 2\n')
811
self.assertNotContainsRe(log, 'revno: 3\n')
812
self.assertContainsRe(log, 'revno: 3.1.1\n')
813
self.assertContainsRe(log, 'revno: 4\n')
814
log = self.run_bzr('log file3')[0]
815
self.assertNotContainsRe(log, 'revno: 1\n')
816
self.assertNotContainsRe(log, 'revno: 2\n')
817
self.assertContainsRe(log, 'revno: 3\n')
818
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
819
self.assertNotContainsRe(log, 'revno: 4\n')
820
log = self.run_bzr('log -r3.1.1 file2')[0]
821
self.assertNotContainsRe(log, 'revno: 1\n')
822
self.assertNotContainsRe(log, 'revno: 2\n')
823
self.assertNotContainsRe(log, 'revno: 3\n')
824
self.assertContainsRe(log, 'revno: 3.1.1\n')
825
self.assertNotContainsRe(log, 'revno: 4\n')
826
log = self.run_bzr('log -r4 file2')[0]
827
self.assertNotContainsRe(log, 'revno: 1\n')
828
self.assertNotContainsRe(log, 'revno: 2\n')
829
self.assertNotContainsRe(log, 'revno: 3\n')
830
self.assertContainsRe(log, 'revno: 3.1.1\n')
831
self.assertContainsRe(log, 'revno: 4\n')
832
log = self.run_bzr('log -r3.. file2')[0]
833
self.assertNotContainsRe(log, 'revno: 1\n')
834
self.assertNotContainsRe(log, 'revno: 2\n')
835
self.assertNotContainsRe(log, 'revno: 3\n')
836
self.assertContainsRe(log, 'revno: 3.1.1\n')
837
self.assertContainsRe(log, 'revno: 4\n')
838
log = self.run_bzr('log -r..3 file2')[0]
839
self.assertNotContainsRe(log, 'revno: 1\n')
840
self.assertContainsRe(log, 'revno: 2\n')
841
self.assertNotContainsRe(log, 'revno: 3\n')
842
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
843
self.assertNotContainsRe(log, 'revno: 4\n')
832
# FIXME: It would be good to parametrize the following tests against all
833
# formatters. But the revisions selection is not *currently* part of the
834
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
835
def test_log_file1(self):
837
self.assertLogRevnos(['-n0', 'file1'], ['1'])
839
def test_log_file2(self):
842
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
843
# file2 in a merge revision
844
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
845
# file2 in a mainline revision
846
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
847
# file2 since a revision
848
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
849
# file2 up to a revision
850
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
852
def test_log_file3(self):
854
self.assertLogRevnos(['-n0', 'file3'], ['3'])
845
856
def test_log_file_historical_missing(self):
846
857
# Check logging a deleted file gives an error if the
884
883
self.assertContainsRe(err, err_msg)
886
885
# Check we can see a renamed file if we give the right end revision
887
log, err = self.run_bzr('log -r..4 file3')
888
self.assertEquals('', err)
889
self.assertNotContainsRe(log, 'revno: 1\n')
890
self.assertNotContainsRe(log, 'revno: 2\n')
891
self.assertContainsRe(log, 'revno: 3\n')
892
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
893
self.assertNotContainsRe(log, 'revno: 4\n')
895
def test_line_log_file(self):
896
"""The line log for a file should only list relevant mainline revs"""
897
# Note: this also implicitly covers the short logging case.
898
# We test using --line in preference to --short because matching
899
# revnos in the output of --line is more reliable.
902
# full history of file1
903
log = self.run_bzr('log --line file1')[0]
904
self.assertContainsRe(log, '^1:', re.MULTILINE)
905
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
906
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
907
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
908
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
910
# full history of file2
911
log = self.run_bzr('log --line file2')[0]
912
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
913
self.assertContainsRe(log, '^2:', re.MULTILINE)
914
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
915
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
916
self.assertContainsRe(log, '^4:', re.MULTILINE)
918
# full history of file3
919
log = self.run_bzr('log --line file3')[0]
920
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
921
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
922
self.assertContainsRe(log, '^3:', re.MULTILINE)
923
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
924
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
926
# file in a merge revision
927
log = self.run_bzr('log --line -r3.1.1 file2')[0]
928
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
929
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
930
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
931
self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
932
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
934
# file in a mainline revision
935
log = self.run_bzr('log --line -r4 file2')[0]
936
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
937
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
938
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
939
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
940
self.assertContainsRe(log, '^4:', re.MULTILINE)
942
# file since a revision
943
log = self.run_bzr('log --line -r3.. file2')[0]
944
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
945
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
946
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
947
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
948
self.assertContainsRe(log, '^4:', re.MULTILINE)
950
# file up to a revision
951
log = self.run_bzr('log --line -r..3 file2')[0]
952
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
953
self.assertContainsRe(log, '^2:', re.MULTILINE)
954
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
955
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
956
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
886
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
889
class TestLogMultiple(TestLogWithLogCatcher):
891
def prepare_tree(self):
892
tree = self.make_branch_and_tree('parent')
899
'parent/dir1/dir2/file3',
902
tree.commit('add file1')
904
tree.commit('add file2')
905
tree.add(['dir1', 'dir1/dir2', 'dir1/dir2/file3'])
906
tree.commit('add file3')
908
tree.commit('add file4')
909
tree.add('dir1/file5')
910
tree.commit('add file5')
911
child_tree = tree.bzrdir.sprout('child').open_workingtree()
912
self.build_tree_contents([('child/file2', 'hello')])
913
child_tree.commit(message='branch 1')
914
tree.merge_from_branch(child_tree.branch)
915
tree.commit(message='merge child branch')
918
def test_log_files(self):
919
"""The log for multiple file should only list revs for those files"""
921
self.assertLogRevnos(['file1', 'file2', 'dir1/dir2/file3'],
922
['6', '5.1.1', '3', '2', '1'])
924
def test_log_directory(self):
925
"""The log for a directory should show all nested files."""
927
self.assertLogRevnos(['dir1'], ['5', '3'])
929
def test_log_nested_directory(self):
930
"""The log for a directory should show all nested files."""
932
self.assertLogRevnos(['dir1/dir2'], ['3'])
934
def test_log_in_nested_directory(self):
935
"""The log for a directory should show all nested files."""
938
self.assertLogRevnos(['.'], ['5', '3'])
940
def test_log_files_and_directories(self):
941
"""Logging files and directories together should be fine."""
943
self.assertLogRevnos(['file4', 'dir1/dir2'], ['4', '3'])
945
def test_log_files_and_dirs_in_nested_directory(self):
946
"""The log for a directory should show all nested files."""
949
self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
952
class MainlineGhostTests(TestLogWithLogCatcher):
955
super(MainlineGhostTests, self).setUp()
956
tree = self.make_branch_and_tree('')
957
tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
959
tree.commit('msg1', rev_id='rev1')
960
tree.commit('msg2', rev_id='rev2')
962
def test_log_range(self):
963
self.assertLogRevnos(["-r1..2"], ["2", "1"])
965
def test_log_norange(self):
966
self.assertLogRevnos([], ["2", "1"])
968
def test_log_range_open_begin(self):
969
raise tests.KnownFailure("log with ghosts fails. bug #726466")
970
(stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
971
self.assertEqual(["2", "1"],
972
[r.revno for r in self.get_captured_revisions()])
973
self.assertEquals("bzr: ERROR: Further revision history missing.", stderr)
975
def test_log_range_open_end(self):
976
self.assertLogRevnos(["-r1.."], ["2", "1"])