53
45
tree.commit(message='message2')
54
46
tree.add('meep.txt')
55
47
tree.commit(message='message3')
58
def make_merged_branch(self, path='.', format=None):
59
tree = self.make_linear_branch(path, format)
60
tree2 = tree.bzrdir.sprout('tree2',
61
revision_id=tree.branch.get_rev_id(1)).open_workingtree()
62
tree2.commit(message='tree2 message2')
63
tree2.commit(message='tree2 message3')
64
tree.merge_from_branch(tree2.branch)
65
tree.commit(message='merge')
69
class TestLogWithLogCatcher(TestLog):
72
super(TestLogWithLogCatcher, self).setUp()
73
# Capture log formatter creations
74
class MyLogFormatter(test_log.LogCatcher):
76
def __new__(klass, *args, **kwargs):
77
self.log_catcher = test_log.LogCatcher(*args, **kwargs)
78
# Always return our own log formatter
79
return self.log_catcher
82
# Always return our own log formatter class hijacking the
83
# default behavior (which requires setting up a config
86
self.overrideAttr(log.log_formatter_registry, 'get_default', getme)
88
def get_captured_revisions(self):
89
return self.log_catcher.revisions
91
def assertLogRevnos(self, args, expected_revnos, working_dir='.'):
92
self.run_bzr(['log'] + args, working_dir=working_dir)
93
self.assertEqual(expected_revnos,
94
[r.revno for r in self.get_captured_revisions()])
96
def assertLogRevnosAndDepths(self, args, expected_revnos_and_depths,
98
self.run_bzr(['log'] + args, working_dir=working_dir)
99
self.assertEqual(expected_revnos_and_depths,
100
[(r.revno, r.merge_depth)
101
for r in self.get_captured_revisions()])
104
class TestLogRevSpecs(TestLogWithLogCatcher):
106
def test_log_no_revspec(self):
107
self.make_linear_branch()
108
self.assertLogRevnos([], ['3', '2', '1'])
48
self.full_log = self.run_bzr(["log", path])[0]
110
51
def test_log_null_end_revspec(self):
111
self.make_linear_branch()
112
self.assertLogRevnos(['-r1..'], ['3', '2', '1'])
53
self.assertTrue('revno: 1\n' in self.full_log)
54
self.assertTrue('revno: 2\n' in self.full_log)
55
self.assertTrue('revno: 3\n' in self.full_log)
56
self.assertTrue('message:\n message1\n' in self.full_log)
57
self.assertTrue('message:\n message2\n' in self.full_log)
58
self.assertTrue('message:\n message3\n' in self.full_log)
60
log = self.run_bzr("log -r 1..")[0]
61
self.assertEqualDiff(log, self.full_log)
114
63
def test_log_null_begin_revspec(self):
115
self.make_linear_branch()
116
self.assertLogRevnos(['-r..3'], ['3', '2', '1'])
65
log = self.run_bzr("log -r ..3")[0]
66
self.assertEqualDiff(self.full_log, log)
118
68
def test_log_null_both_revspecs(self):
119
self.make_linear_branch()
120
self.assertLogRevnos(['-r..'], ['3', '2', '1'])
70
log = self.run_bzr("log -r ..")[0]
71
self.assertEqualDiff(self.full_log, log)
73
def test_log_zero_revspec(self):
75
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
78
def test_log_zero_begin_revspec(self):
80
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
83
def test_log_zero_end_revspec(self):
85
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
88
def test_log_unsupported_timezone(self):
90
self.run_bzr_error('bzr: ERROR: Unsupported timezone format "foo", '
91
'options are "utc", "original", "local".',
92
['log', '--timezone', 'foo'])
122
94
def test_log_negative_begin_revspec_full_log(self):
123
self.make_linear_branch()
124
self.assertLogRevnos(['-r-3..'], ['3', '2', '1'])
96
log = self.run_bzr("log -r -3..")[0]
97
self.assertEqualDiff(self.full_log, log)
126
99
def test_log_negative_both_revspec_full_log(self):
127
self.make_linear_branch()
128
self.assertLogRevnos(['-r-3..-1'], ['3', '2', '1'])
101
log = self.run_bzr("log -r -3..-1")[0]
102
self.assertEqualDiff(self.full_log, log)
130
104
def test_log_negative_both_revspec_partial(self):
131
self.make_linear_branch()
132
self.assertLogRevnos(['-r-3..-2'], ['2', '1'])
106
log = self.run_bzr("log -r -3..-2")[0]
107
self.assertTrue('revno: 1\n' in log)
108
self.assertTrue('revno: 2\n' in log)
109
self.assertTrue('revno: 3\n' not in log)
134
111
def test_log_negative_begin_revspec(self):
135
self.make_linear_branch()
136
self.assertLogRevnos(['-r-2..'], ['3', '2'])
113
log = self.run_bzr("log -r -2..")[0]
114
self.assertTrue('revno: 1\n' not in log)
115
self.assertTrue('revno: 2\n' in log)
116
self.assertTrue('revno: 3\n' in log)
138
118
def test_log_positive_revspecs(self):
139
self.make_linear_branch()
140
self.assertLogRevnos(['-r1..3'], ['3', '2', '1'])
142
def test_log_dotted_revspecs(self):
143
self.make_merged_branch()
144
self.assertLogRevnos(['-n0', '-r1..1.1.1'], ['1.1.1', '1'])
146
def test_log_limit(self):
147
tree = self.make_branch_and_tree('.')
148
# We want more commits than our batch size starts at
149
for pos in range(10):
150
tree.commit("%s" % pos)
151
self.assertLogRevnos(['--limit', '2'], ['10', '9'])
153
def test_log_limit_short(self):
154
self.make_linear_branch()
155
self.assertLogRevnos(['-l', '2'], ['3', '2'])
157
def test_log_change_revno(self):
158
self.make_linear_branch()
159
self.assertLogRevnos(['-c1'], ['1'])
162
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
165
super(TestLogMergedLinearAncestry, self).setUp()
166
# FIXME: Using a MemoryTree would be even better here (but until we
167
# stop calling run_bzr, there is no point) --vila 100118.
168
builder = branchbuilder.BranchBuilder(self.get_transport())
169
builder.start_series()
171
builder.build_snapshot('1', None, [
172
('add', ('', 'root-id', 'directory', ''))])
173
builder.build_snapshot('2', ['1'], [])
175
builder.build_snapshot('1.1.1', ['1'], [])
176
# merge branch into mainline
177
builder.build_snapshot('3', ['2', '1.1.1'], [])
178
# new commits in branch
179
builder.build_snapshot('1.1.2', ['1.1.1'], [])
180
builder.build_snapshot('1.1.3', ['1.1.2'], [])
181
# merge branch into mainline
182
builder.build_snapshot('4', ['3', '1.1.3'], [])
183
# merge mainline into branch
184
builder.build_snapshot('1.1.4', ['1.1.3', '4'], [])
185
# merge branch into mainline
186
builder.build_snapshot('5', ['4', '1.1.4'], [])
187
builder.finish_series()
190
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4'],
191
['1.1.4', '4', '1.1.3', '1.1.2', '3', '1.1.1'])
192
def test_n0_forward(self):
193
self.assertLogRevnos(['-n0', '-r1.1.1..1.1.4', '--forward'],
194
['3', '1.1.1', '4', '1.1.2', '1.1.3', '1.1.4'])
197
# starting from 1.1.4 we follow the left-hand ancestry
198
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4'],
199
['1.1.4', '1.1.3', '1.1.2', '1.1.1'])
201
def test_n1_forward(self):
202
self.assertLogRevnos(['-n1', '-r1.1.1..1.1.4', '--forward'],
203
['1.1.1', '1.1.2', '1.1.3', '1.1.4'])
206
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
208
def make_branch_with_many_merges(self, path='.', format=None):
209
builder = branchbuilder.BranchBuilder(self.get_transport())
210
builder.start_series()
211
# The graph below may look a bit complicated (and it may be but I've
212
# banged my head enough on it) but the bug requires at least dotted
213
# revnos *and* merged revisions below that.
214
builder.build_snapshot('1', None, [
215
('add', ('', 'root-id', 'directory', ''))])
216
builder.build_snapshot('2', ['1'], [])
217
builder.build_snapshot('1.1.1', ['1'], [])
218
builder.build_snapshot('2.1.1', ['2'], [])
219
builder.build_snapshot('3', ['2', '1.1.1'], [])
220
builder.build_snapshot('2.1.2', ['2.1.1'], [])
221
builder.build_snapshot('2.2.1', ['2.1.1'], [])
222
builder.build_snapshot('2.1.3', ['2.1.2', '2.2.1'], [])
223
builder.build_snapshot('4', ['3', '2.1.3'], [])
224
builder.build_snapshot('5', ['4', '2.1.2'], [])
225
builder.finish_series()
228
def test_not_an_ancestor(self):
229
builder = self.make_branch_with_many_merges()
230
b = builder.get_branch()
232
self.addCleanup(b.unlock)
233
self.assertRaises(errors.BzrCommandError,
234
log._generate_all_revisions,
235
b, '1.1.1', '2.1.3', 'reverse',
236
delayed_graph_generation=True)
238
def test_wrong_order(self):
239
builder = self.make_branch_with_many_merges()
240
b = builder.get_branch()
242
self.addCleanup(b.unlock)
243
self.assertRaises(errors.BzrCommandError,
244
log._generate_all_revisions,
245
b, '5', '2.1.3', 'reverse',
246
delayed_graph_generation=True)
249
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
251
def test_log_revno_n_path_wrong_namespace(self):
252
self.make_linear_branch('branch1')
253
self.make_linear_branch('branch2')
254
# There is no guarantee that a path exist between two arbitrary
256
self.run_bzr("log -r revno:2:branch1..revno:3:branch2", retcode=3)
258
def test_log_revno_n_path_correct_order(self):
259
self.make_linear_branch('branch2')
260
self.assertLogRevnos(['-rrevno:1:branch2..revno:3:branch2'],
120
log = self.run_bzr("log -r 1..3")[0]
121
self.assertEqualDiff(self.full_log, log)
123
def test_log_reversed_revspecs(self):
125
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
126
'the end revision.\n',),
263
129
def test_log_revno_n_path(self):
264
self.make_linear_branch('branch2')
265
self.assertLogRevnos(['-rrevno:1:branch2'],
267
rev_props = self.log_catcher.revisions[0].rev.properties
268
self.assertEqual('branch2', rev_props['branch-nick'])
271
class TestLogErrors(TestLog):
273
def test_log_zero_revspec(self):
274
self.make_minimal_branch()
275
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
278
def test_log_zero_begin_revspec(self):
279
self.make_linear_branch()
280
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
283
def test_log_zero_end_revspec(self):
284
self.make_linear_branch()
285
self.run_bzr_error(['bzr: ERROR: Logging revision 0 is invalid.'],
130
self._prepare(path='branch1')
131
self._prepare(path='branch2')
132
log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
134
log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
135
self.assertEqualDiff(self.full_log, log)
136
log = self.run_bzr("log -r revno:1:branch2")[0]
137
self.assertTrue('revno: 1\n' in log)
138
self.assertTrue('revno: 2\n' not in log)
139
self.assertTrue('branch nick: branch2\n' in log)
140
self.assertTrue('branch nick: branch1\n' not in log)
288
142
def test_log_nonexistent_revno(self):
289
self.make_minimal_branch()
290
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
291
"does not exist in branch:"],
144
(out, err) = self.run_bzr_error(args="log -r 1234",
145
error_regexes=["bzr: ERROR: Requested revision: '1234' "
146
"does not exist in branch:"])
294
148
def test_log_nonexistent_dotted_revno(self):
295
self.make_minimal_branch()
296
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
297
"does not exist in branch:"],
298
['log', '-r123.123'])
150
(out, err) = self.run_bzr_error(args="log -r 123.123",
151
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
152
"does not exist in branch:"])
154
def test_log_change_revno(self):
156
expected_log = self.run_bzr("log -r 1")[0]
157
log = self.run_bzr("log -c 1")[0]
158
self.assertEqualDiff(expected_log, log)
300
160
def test_log_change_nonexistent_revno(self):
301
self.make_minimal_branch()
302
self.run_bzr_error(["bzr: ERROR: Requested revision: '1234' "
303
"does not exist in branch:"],
162
(out, err) = self.run_bzr_error(args="log -c 1234",
163
error_regexes=["bzr: ERROR: Requested revision: '1234' "
164
"does not exist in branch:"])
306
166
def test_log_change_nonexistent_dotted_revno(self):
307
self.make_minimal_branch()
308
self.run_bzr_error(["bzr: ERROR: Requested revision: '123.123' "
309
"does not exist in branch:"],
310
['log', '-c123.123'])
168
(out, err) = self.run_bzr_error(args="log -c 123.123",
169
error_regexes=["bzr: ERROR: Requested revision: '123.123' "
170
"does not exist in branch:"])
312
def test_log_change_single_revno_only(self):
313
self.make_minimal_branch()
314
self.run_bzr_error(['bzr: ERROR: Option --change does not'
315
' accept revision ranges'],
172
def test_log_change_single_revno(self):
174
self.run_bzr_error('bzr: ERROR: Option --change does not'
175
' accept revision ranges',
316
176
['log', '--change', '2..3'])
318
178
def test_log_change_incompatible_with_revision(self):
319
self.run_bzr_error(['bzr: ERROR: --revision and --change'
320
' are mutually exclusive'],
180
self.run_bzr_error('bzr: ERROR: --revision and --change'
181
' are mutually exclusive',
321
182
['log', '--change', '2', '--revision', '3'])
323
184
def test_log_nonexistent_file(self):
324
self.make_minimal_branch()
325
185
# files that don't exist in either the basis tree or working tree
326
186
# should give an error
187
wt = self.make_branch_and_tree('.')
327
188
out, err = self.run_bzr('log does-not-exist', retcode=3)
328
self.assertContainsRe(err,
329
'Path unknown at end or start of revision range: '
332
def test_log_reversed_revspecs(self):
333
self.make_linear_branch()
334
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
335
'the end revision.\n',),
338
def test_log_reversed_dotted_revspecs(self):
339
self.make_merged_branch()
340
self.run_bzr_error(('bzr: ERROR: Start revision not found in '
341
'left-hand history of end revision.\n',),
344
def test_log_bad_message_re(self):
345
"""Bad --message argument gives a sensible message
347
See https://bugs.launchpad.net/bzr/+bug/251352
349
self.make_minimal_branch()
350
out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
351
self.assertEqual("bzr: ERROR: Invalid regular expression"
352
" in log message filter"
354
": nothing to repeat\n", err)
355
self.assertEqual('', out)
357
def test_log_unsupported_timezone(self):
358
self.make_linear_branch()
359
self.run_bzr_error(['bzr: ERROR: Unsupported timezone format "foo", '
360
'options are "utc", "original", "local".'],
361
['log', '--timezone', 'foo'])
364
class TestLogTags(TestLog):
189
self.assertContainsRe(
190
err, 'Path unknown at end or start of revision range: does-not-exist')
366
192
def test_log_with_tags(self):
367
tree = self.make_linear_branch(format='dirstate-tags')
193
tree = self._prepare(format='dirstate-tags')
368
194
branch = tree.branch
369
195
branch.tags.set_tag('tag1', branch.get_rev_id(1))
370
196
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
429
294
self.assertUseLongDeltaFormat(['log', '--long', '-vv'])
432
class TestLogMerges(TestLogWithLogCatcher):
435
super(TestLogMerges, self).setUp()
436
self.make_branches_with_merges()
438
def make_branches_with_merges(self):
439
level0 = self.make_branch_and_tree('level0')
440
self.wt_commit(level0, 'in branch level0')
441
level1 = level0.bzrdir.sprout('level1').open_workingtree()
442
self.wt_commit(level1, 'in branch level1')
443
level2 = level1.bzrdir.sprout('level2').open_workingtree()
444
self.wt_commit(level2, 'in branch level2')
445
level1.merge_from_branch(level2.branch)
446
self.wt_commit(level1, 'merge branch level2')
447
level0.merge_from_branch(level1.branch)
448
self.wt_commit(level0, 'merge branch level1')
297
class TestLogMerges(TestCaseWithoutPropsHandler):
300
parent_tree = self.make_branch_and_tree('parent')
301
parent_tree.commit(message='first post', allow_pointless=True)
302
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
303
child_tree.commit(message='branch 1', allow_pointless=True)
305
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
306
smaller_tree.commit(message='branch 2', allow_pointless=True)
307
child_tree.merge_from_branch(smaller_tree.branch)
308
child_tree.commit(message='merge branch 2')
309
parent_tree.merge_from_branch(child_tree.branch)
310
parent_tree.commit(message='merge branch 1')
313
def _prepare_short(self):
314
parent_tree = self.make_branch_and_tree('parent')
315
parent_tree.commit(message='first post',
316
timestamp=1132586700, timezone=36000,
317
committer='Joe Foo <joe@foo.com>')
318
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
319
child_tree.commit(message='branch 1',
320
timestamp=1132586800, timezone=36000,
321
committer='Joe Foo <joe@foo.com>')
323
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
324
smaller_tree.commit(message='branch 2',
325
timestamp=1132586900, timezone=36000,
326
committer='Joe Foo <joe@foo.com>')
327
child_tree.merge_from_branch(smaller_tree.branch)
328
child_tree.commit(message='merge branch 2',
329
timestamp=1132587000, timezone=36000,
330
committer='Joe Foo <joe@foo.com>')
331
parent_tree.merge_from_branch(child_tree.branch)
332
parent_tree.commit(message='merge branch 1',
333
timestamp=1132587100, timezone=36000,
334
committer='Joe Foo <joe@foo.com>')
450
337
def test_merges_are_indented_by_level(self):
451
self.run_bzr(['log', '-n0'], working_dir='level0')
452
revnos_and_depth = [(r.revno, r.merge_depth)
453
for r in self.get_captured_revisions()]
454
self.assertEqual([('2', 0), ('1.1.2', 1), ('1.2.1', 2), ('1.1.1', 1),
456
[(r.revno, r.merge_depth)
457
for r in self.get_captured_revisions()])
339
out,err = self.run_bzr('log -n0')
340
self.assertEqual('', err)
341
log = normalize_log(out)
342
self.assertEqualDiff(log, """\
343
------------------------------------------------------------
345
committer: Lorem Ipsum <test@example.com>
350
------------------------------------------------------------
352
committer: Lorem Ipsum <test@example.com>
357
------------------------------------------------------------
359
committer: Lorem Ipsum <test@example.com>
360
branch nick: smallerchild
364
------------------------------------------------------------
366
committer: Lorem Ipsum <test@example.com>
371
------------------------------------------------------------
373
committer: Lorem Ipsum <test@example.com>
459
380
def test_force_merge_revisions_off(self):
460
self.assertLogRevnos(['-n1'], ['2', '1'], working_dir='level0')
382
out,err = self.run_bzr('log --long -n1')
383
self.assertEqual('', err)
384
log = normalize_log(out)
385
self.assertEqualDiff(log, """\
386
------------------------------------------------------------
388
committer: Lorem Ipsum <test@example.com>
393
------------------------------------------------------------
395
committer: Lorem Ipsum <test@example.com>
400
------------------------------------------------------------
401
Use --levels 0 (or -n0) to see merged revisions.
462
404
def test_force_merge_revisions_on(self):
463
self.assertLogRevnos(['-n0'], ['2', '1.1.2', '1.2.1', '1.1.1', '1'],
464
working_dir='level0')
466
def test_include_merges(self):
467
# Confirm --include-merges gives the same output as -n0
468
self.assertLogRevnos(['--include-merges'],
469
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
470
working_dir='level0')
471
self.assertLogRevnos(['--include-merges'],
472
['2', '1.1.2', '1.2.1', '1.1.1', '1'],
473
working_dir='level0')
474
out_im, err_im = self.run_bzr('log --include-merges',
475
working_dir='level0')
476
out_n0, err_n0 = self.run_bzr('log -n0', working_dir='level0')
477
self.assertEqual('', err_im)
478
self.assertEqual('', err_n0)
479
self.assertEqual(out_im, out_n0)
405
self._prepare_short()
406
out,err = self.run_bzr('log --short -n0')
407
self.assertEqual('', err)
408
log = normalize_log(out)
409
self.assertEqualDiff(log, """\
410
2 Joe Foo\t2005-11-22 [merge]
413
1.1.2 Joe Foo\t2005-11-22 [merge]
416
1.2.1 Joe Foo\t2005-11-22
419
1.1.1 Joe Foo\t2005-11-22
422
1 Joe Foo\t2005-11-22
481
427
def test_force_merge_revisions_N(self):
482
self.assertLogRevnos(['-n2'],
483
['2', '1.1.2', '1.1.1', '1'],
484
working_dir='level0')
428
self._prepare_short()
429
out,err = self.run_bzr('log --short -n2')
430
self.assertEqual('', err)
431
log = normalize_log(out)
432
self.assertEqualDiff(log, """\
433
2 Joe Foo\t2005-11-22 [merge]
436
1.1.2 Joe Foo\t2005-11-22 [merge]
439
1.1.1 Joe Foo\t2005-11-22
442
1 Joe Foo\t2005-11-22
486
447
def test_merges_single_merge_rev(self):
487
self.assertLogRevnosAndDepths(['-n0', '-r1.1.2'],
488
[('1.1.2', 0), ('1.2.1', 1)],
489
working_dir='level0')
449
out,err = self.run_bzr('log -n0 -r1.1.2')
450
self.assertEqual('', err)
451
log = normalize_log(out)
452
self.assertEqualDiff(log, """\
453
------------------------------------------------------------
455
committer: Lorem Ipsum <test@example.com>
460
------------------------------------------------------------
462
committer: Lorem Ipsum <test@example.com>
463
branch nick: smallerchild
491
469
def test_merges_partial_range(self):
492
self.assertLogRevnosAndDepths(
493
['-n0', '-r1.1.1..1.1.2'],
494
[('1.1.2', 0), ('1.2.1', 1), ('1.1.1', 0)],
495
working_dir='level0')
497
def test_merges_partial_range_ignore_before_lower_bound(self):
498
"""Dont show revisions before the lower bound's merged revs"""
499
self.assertLogRevnosAndDepths(
500
['-n0', '-r1.1.2..2'],
501
[('2', 0), ('1.1.2', 1), ('1.2.1', 2)],
502
working_dir='level0')
505
class TestLogDiff(TestLogWithLogCatcher):
507
# FIXME: We need specific tests for each LogFormatter about how the diffs
508
# are displayed: --long indent them by depth, --short use a fixed
509
# indent and --line does't display them. -- vila 10019
512
super(TestLogDiff, self).setUp()
513
self.make_branch_with_diffs()
515
def make_branch_with_diffs(self):
516
level0 = self.make_branch_and_tree('level0')
517
self.build_tree(['level0/file1', 'level0/file2'])
520
self.wt_commit(level0, 'in branch level0')
522
level1 = level0.bzrdir.sprout('level1').open_workingtree()
523
self.build_tree_contents([('level1/file2', 'hello\n')])
524
self.wt_commit(level1, 'in branch level1')
525
level0.merge_from_branch(level1.branch)
526
self.wt_commit(level0, 'merge branch level1')
528
def _diff_file1_revno1(self):
529
return """=== added file 'file1'
530
--- file1\t1970-01-01 00:00:00 +0000
531
+++ file1\t2005-11-22 00:00:00 +0000
533
+contents of level0/file1
537
def _diff_file2_revno2(self):
538
return """=== modified file 'file2'
539
--- file2\t2005-11-22 00:00:00 +0000
540
+++ file2\t2005-11-22 00:00:01 +0000
542
-contents of level0/file2
547
def _diff_file2_revno1_1_1(self):
548
return """=== modified file 'file2'
549
--- file2\t2005-11-22 00:00:00 +0000
550
+++ file2\t2005-11-22 00:00:01 +0000
552
-contents of level0/file2
557
def _diff_file2_revno1(self):
558
return """=== added file 'file2'
559
--- file2\t1970-01-01 00:00:00 +0000
560
+++ file2\t2005-11-22 00:00:00 +0000
562
+contents of level0/file2
566
def assertLogRevnosAndDiff(self, args, expected,
568
self.run_bzr(['log', '-p'] + args, working_dir=working_dir)
569
expected_revnos_and_depths = [
570
(revno, depth) for revno, depth, diff in expected]
571
# Check the revnos and depths first to make debugging easier
572
self.assertEqual(expected_revnos_and_depths,
573
[(r.revno, r.merge_depth)
574
for r in self.get_captured_revisions()])
575
# Now check the diffs, adding the revno in case of failure
576
fmt = 'In revno %s\n%s'
577
for expected_rev, actual_rev in izip(expected,
578
self.get_captured_revisions()):
579
revno, depth, expected_diff = expected_rev
580
actual_diff = actual_rev.diff
581
self.assertEqualDiff(fmt % (revno, expected_diff),
582
fmt % (revno, actual_diff))
584
def test_log_diff_with_merges(self):
585
self.assertLogRevnosAndDiff(
587
[('2', 0, self._diff_file2_revno2()),
588
('1.1.1', 1, self._diff_file2_revno1_1_1()),
589
('1', 0, self._diff_file1_revno1()
590
+ self._diff_file2_revno1())],
591
working_dir='level0')
594
def test_log_diff_file1(self):
595
self.assertLogRevnosAndDiff(['-n0', 'file1'],
596
[('1', 0, self._diff_file1_revno1())],
597
working_dir='level0')
599
def test_log_diff_file2(self):
600
self.assertLogRevnosAndDiff(['-n1', 'file2'],
601
[('2', 0, self._diff_file2_revno2()),
602
('1', 0, self._diff_file2_revno1())],
603
working_dir='level0')
606
class TestLogUnicodeDiff(TestLog):
471
out, err = self.run_bzr('log -n0 -r1.1.1..1.1.2')
472
self.assertEqual('', err)
473
log = normalize_log(out)
474
self.assertEqualDiff(log, """\
475
------------------------------------------------------------
477
committer: Lorem Ipsum <test@example.com>
482
------------------------------------------------------------
484
committer: Lorem Ipsum <test@example.com>
485
branch nick: smallerchild
489
------------------------------------------------------------
491
committer: Lorem Ipsum <test@example.com>
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_with_merges(self):
528
out,err = self.run_bzr('log -p -n0')
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):
583
out,err = self.run_bzr('log -p --short')
584
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
603
\x20\x20\x20\x20\x20\x20
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
610
Use --levels 0 (or -n0) to see merged revisions.
613
def test_log_show_diff_line(self):
615
out,err = self.run_bzr('log -p --line')
616
self.assertEqual('', err)
617
log = normalize_log(out)
618
# Not supported by this formatter so expect plain output
619
self.assertEqualDiff(subst_dates(log), """\
620
2: Lorem Ipsum 2005-11-22 [merge] merge branch 1
621
1: Lorem Ipsum 2005-11-22 first post
624
def test_log_show_diff_file(self):
625
"""Only the diffs for the given file are to be shown"""
627
out,err = self.run_bzr('log -p --short file2')
628
self.assertEqual('', err)
629
log = normalize_log(out)
630
self.assertEqualDiff(subst_dates(log), """\
631
2 Lorem Ipsum\t2005-11-22 [merge]
633
=== modified file 'file2'
634
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
635
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
637
-contents of parent/file2
640
1 Lorem Ipsum\t2005-11-22
642
=== added file 'file2'
643
--- file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
644
+++ file2\tYYYY-MM-DD HH:MM:SS +ZZZZ
646
+contents of parent/file2
648
Use --levels 0 (or -n0) to see merged revisions.
650
out,err = self.run_bzr('log -p --short file1')
651
self.assertEqual('', err)
652
log = normalize_log(out)
653
self.assertEqualDiff(subst_dates(log), """\
654
1 Lorem Ipsum\t2005-11-22
656
=== added file 'file1'
657
--- file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
658
+++ file1\tYYYY-MM-DD HH:MM:SS +ZZZZ
660
+contents of parent/file1
608
664
def test_log_show_diff_non_ascii(self):
609
665
# Smoke test for bug #328007 UnicodeDecodeError on 'log -p'
758
818
tree.commit('remove file1')
759
819
os.chdir('parent')
761
# FIXME: It would be good to parametrize the following tests against all
762
# formatters. But the revisions selection is not *currently* part of the
763
# LogFormatter contract, so using LogCatcher is sufficient -- vila 100118
764
def test_log_file1(self):
766
self.assertLogRevnos(['-n0', 'file1'], ['1'])
768
def test_log_file2(self):
771
self.assertLogRevnos(['-n0', 'file2'], ['4', '3.1.1', '2'])
772
# file2 in a merge revision
773
self.assertLogRevnos(['-n0', '-r3.1.1', 'file2'], ['3.1.1'])
774
# file2 in a mainline revision
775
self.assertLogRevnos(['-n0', '-r4', 'file2'], ['4', '3.1.1'])
776
# file2 since a revision
777
self.assertLogRevnos(['-n0', '-r3..', 'file2'], ['4', '3.1.1'])
778
# file2 up to a revision
779
self.assertLogRevnos(['-n0', '-r..3', 'file2'], ['2'])
781
def test_log_file3(self):
783
self.assertLogRevnos(['-n0', 'file3'], ['3'])
821
def test_log_file(self):
822
"""The log for a particular file should only list revs for that file"""
824
log = self.run_bzr('log -n0 file1')[0]
825
self.assertContainsRe(log, 'revno: 1\n')
826
self.assertNotContainsRe(log, 'revno: 2\n')
827
self.assertNotContainsRe(log, 'revno: 3\n')
828
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
829
self.assertNotContainsRe(log, 'revno: 4 ')
830
log = self.run_bzr('log -n0 file2')[0]
831
self.assertNotContainsRe(log, 'revno: 1\n')
832
self.assertContainsRe(log, 'revno: 2\n')
833
self.assertNotContainsRe(log, 'revno: 3\n')
834
self.assertContainsRe(log, 'revno: 3.1.1\n')
835
self.assertContainsRe(log, 'revno: 4 ')
836
log = self.run_bzr('log -n0 file3')[0]
837
self.assertNotContainsRe(log, 'revno: 1\n')
838
self.assertNotContainsRe(log, 'revno: 2\n')
839
self.assertContainsRe(log, 'revno: 3\n')
840
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
841
self.assertNotContainsRe(log, 'revno: 4 ')
842
log = self.run_bzr('log -n0 -r3.1.1 file2')[0]
843
self.assertNotContainsRe(log, 'revno: 1\n')
844
self.assertNotContainsRe(log, 'revno: 2\n')
845
self.assertNotContainsRe(log, 'revno: 3\n')
846
self.assertContainsRe(log, 'revno: 3.1.1\n')
847
self.assertNotContainsRe(log, 'revno: 4 ')
848
log = self.run_bzr('log -n0 -r4 file2')[0]
849
self.assertNotContainsRe(log, 'revno: 1\n')
850
self.assertNotContainsRe(log, 'revno: 2\n')
851
self.assertNotContainsRe(log, 'revno: 3\n')
852
self.assertContainsRe(log, 'revno: 3.1.1\n')
853
self.assertContainsRe(log, 'revno: 4 ')
854
log = self.run_bzr('log -n0 -r3.. file2')[0]
855
self.assertNotContainsRe(log, 'revno: 1\n')
856
self.assertNotContainsRe(log, 'revno: 2\n')
857
self.assertNotContainsRe(log, 'revno: 3\n')
858
self.assertContainsRe(log, 'revno: 3.1.1\n')
859
self.assertContainsRe(log, 'revno: 4 ')
860
log = self.run_bzr('log -n0 -r..3 file2')[0]
861
self.assertNotContainsRe(log, 'revno: 1\n')
862
self.assertContainsRe(log, 'revno: 2\n')
863
self.assertNotContainsRe(log, 'revno: 3\n')
864
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
865
self.assertNotContainsRe(log, 'revno: 4 ')
785
867
def test_log_file_historical_missing(self):
786
868
# Check logging a deleted file gives an error if the
812
906
self.assertContainsRe(err, err_msg)
814
908
# Check we can see a renamed file if we give the right end revision
815
self.assertLogRevnos(['-r..4', 'file3'], ['3'])
818
class TestLogMultiple(TestLogWithLogCatcher):
909
log, err = self.run_bzr('log -r..4 file3')
910
self.assertEquals('', err)
911
self.assertNotContainsRe(log, 'revno: 1\n')
912
self.assertNotContainsRe(log, 'revno: 2\n')
913
self.assertContainsRe(log, 'revno: 3\n')
914
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
915
self.assertNotContainsRe(log, 'revno: 4 ')
917
def test_line_log_file(self):
918
"""The line log for a file should only list relevant mainline revs"""
919
# Note: this also implicitly covers the short logging case.
920
# We test using --line in preference to --short because matching
921
# revnos in the output of --line is more reliable.
924
# full history of file1
925
log = self.run_bzr('log --line file1')[0]
926
self.assertContainsRe(log, '^1:', re.MULTILINE)
927
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
928
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
929
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
930
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
932
# full history of file2
933
log = self.run_bzr('log --line file2')[0]
934
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
935
self.assertContainsRe(log, '^2:', re.MULTILINE)
936
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
937
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
938
self.assertContainsRe(log, '^4:', re.MULTILINE)
940
# full history of file3
941
log = self.run_bzr('log --line file3')[0]
942
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
943
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
944
self.assertContainsRe(log, '^3:', re.MULTILINE)
945
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
946
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
948
# file in a merge revision
949
log = self.run_bzr('log --line -r3.1.1 file2')[0]
950
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
951
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
952
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
953
self.assertContainsRe(log, '^3.1.1:', re.MULTILINE)
954
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
956
# file in a mainline revision
957
log = self.run_bzr('log --line -r4 file2')[0]
958
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
959
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
960
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
961
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
962
self.assertContainsRe(log, '^4:', re.MULTILINE)
964
# file since a revision
965
log = self.run_bzr('log --line -r3.. file2')[0]
966
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
967
self.assertNotContainsRe(log, '^2:', re.MULTILINE)
968
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
969
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
970
self.assertContainsRe(log, '^4:', re.MULTILINE)
972
# file up to a revision
973
log = self.run_bzr('log --line -r..3 file2')[0]
974
self.assertNotContainsRe(log, '^1:', re.MULTILINE)
975
self.assertContainsRe(log, '^2:', re.MULTILINE)
976
self.assertNotContainsRe(log, '^3:', re.MULTILINE)
977
self.assertNotContainsRe(log, '^3.1.1:', re.MULTILINE)
978
self.assertNotContainsRe(log, '^4:', re.MULTILINE)
981
class TestLogMultiple(TestCaseWithTransport):
820
983
def prepare_tree(self):
821
984
tree = self.make_branch_and_tree('parent')