40
44
We should also test the LogFormatter.
45
46
def __init__(self):
46
47
super(LogCatcher, self).__init__(to_file=None)
49
def log_revision(self, revision):
50
self.logs.append(revision)
53
class TestShowLog(TestCaseWithTransport):
50
def show(self, revno, rev, delta):
58
class SimpleLogTest(TestCaseWithTransport):
55
60
def checkDelta(self, delta, **kw):
56
61
"""Check the filenames touched by a delta are as expected."""
57
62
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
58
63
expected = kw.get(n, [])
65
# tests are written with unix paths; fix them up for windows
67
# expected = [x.replace('/', os.sep) for x in expected]
59
69
# strip out only the path components
60
70
got = [x[0] for x in getattr(delta, n)]
61
71
self.assertEquals(expected, got)
153
163
self.log("escaped commit message: %r", committed_msg)
154
164
self.assert_(msg == committed_msg)
156
def test_deltas_in_merge_revisions(self):
157
"""Check deltas created for both mainline and merge revisions"""
158
eq = self.assertEquals
159
wt = self.make_branch_and_tree('parent')
160
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
163
wt.commit(message='add file1 and file2')
164
self.run_bzr('branch', 'parent', 'child')
165
os.unlink('child/file1')
166
print >> file('child/file2', 'wb'), 'hello'
167
self.run_bzr('commit', '-m', 'remove file1 and modify file2', 'child')
169
self.run_bzr('merge', '../child')
170
wt.commit('merge child branch')
174
lf.supports_merge_revisions = True
175
show_log(b, lf, verbose=True)
177
logentry = lf.logs[0]
178
eq(logentry.revno, '2')
179
eq(logentry.rev.message, 'merge child branch')
181
self.checkDelta(d, removed=['file1'], modified=['file2'])
182
logentry = lf.logs[1]
183
eq(logentry.revno, '1.1.1')
184
eq(logentry.rev.message, 'remove file1 and modify file2')
186
self.checkDelta(d, removed=['file1'], modified=['file2'])
187
logentry = lf.logs[2]
188
eq(logentry.revno, '1')
189
eq(logentry.rev.message, 'add file1 and file2')
191
self.checkDelta(d, added=['file1', 'file2'])
194
def make_commits_with_trailing_newlines(wt):
195
"""Helper method for LogFormatter tests"""
198
open('a', 'wb').write('hello moto\n')
200
wt.commit('simple log message', rev_id='a1'
201
, timestamp=1132586655.459960938, timezone=-6*3600
202
, committer='Joe Foo <joe@foo.com>')
203
open('b', 'wb').write('goodbye\n')
205
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
206
, timestamp=1132586842.411175966, timezone=-6*3600
207
, committer='Joe Foo <joe@foo.com>')
209
open('c', 'wb').write('just another manic monday\n')
211
wt.commit('single line with trailing newline\n', rev_id='a3'
212
, timestamp=1132587176.835228920, timezone=-6*3600
213
, committer = 'Joe Foo <joe@foo.com>')
217
class TestShortLogFormatter(TestCaseWithTransport):
219
166
def test_trailing_newlines(self):
220
167
wt = self.make_branch_and_tree('.')
221
b = make_commits_with_trailing_newlines(wt)
170
open('a', 'wb').write('hello moto\n')
172
wt.commit('simple log message', rev_id='a1'
173
, timestamp=1132586655.459960938, timezone=-6*3600
174
, committer='Joe Foo <joe@foo.com>')
175
open('b', 'wb').write('goodbye\n')
177
wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
178
, timestamp=1132586842.411175966, timezone=-6*3600
179
, committer='Joe Foo <joe@foo.com>')
181
open('c', 'wb').write('just another manic monday\n')
183
wt.commit('single line with trailing newline\n', rev_id='a3'
184
, timestamp=1132587176.835228920, timezone=-6*3600
185
, committer = 'Joe Foo <joe@foo.com>')
223
188
lf = ShortLogFormatter(to_file=sio)
240
class TestLongLogFormatter(TestCaseWithTransport):
242
def normalize_log(self,log):
243
"""Replaces the variable lines of logs with fixed lines"""
244
committer = 'committer: Lorem Ipsum <test@example.com>'
245
lines = log.splitlines(True)
246
for idx,line in enumerate(lines):
247
stripped_line = line.lstrip()
248
indent = ' ' * (len(line) - len(stripped_line))
249
if stripped_line.startswith('committer:'):
250
lines[idx] = indent + committer + '\n'
251
if stripped_line.startswith('timestamp:'):
252
lines[idx] = indent + 'timestamp: Just now\n'
253
return ''.join(lines)
205
lf = LongLogFormatter(to_file=sio)
207
self.assertEquals(sio.getvalue(), """\
208
------------------------------------------------------------
210
committer: Joe Foo <joe@foo.com>
212
timestamp: Mon 2005-11-21 09:32:56 -0600
214
single line with trailing newline
215
------------------------------------------------------------
217
committer: Joe Foo <joe@foo.com>
219
timestamp: Mon 2005-11-21 09:27:22 -0600
224
------------------------------------------------------------
226
committer: Joe Foo <joe@foo.com>
228
timestamp: Mon 2005-11-21 09:24:15 -0600
255
233
def test_verbose_log(self):
256
234
"""Verbose log includes changed files
288
def test_merges_are_indented_by_level(self):
289
wt = self.make_branch_and_tree('parent')
290
wt.commit('first post')
291
self.run_bzr('branch', 'parent', 'child')
292
self.run_bzr('commit', '-m', 'branch 1', '--unchanged', 'child')
293
self.run_bzr('branch', 'child', 'smallerchild')
294
self.run_bzr('commit', '-m', 'branch 2', '--unchanged', 'smallerchild')
296
self.run_bzr('merge', '../smallerchild')
297
self.run_bzr('commit', '-m', 'merge branch 2')
298
os.chdir('../parent')
299
self.run_bzr('merge', '../child')
300
wt.commit('merge branch 1')
303
lf = LongLogFormatter(to_file=sio)
304
show_log(b, lf, verbose=True)
305
log = self.normalize_log(sio.getvalue())
306
self.assertEqualDiff("""\
307
------------------------------------------------------------
309
committer: Lorem Ipsum <test@example.com>
314
------------------------------------------------------------
316
committer: Lorem Ipsum <test@example.com>
321
------------------------------------------------------------
323
committer: Lorem Ipsum <test@example.com>
324
branch nick: smallerchild
328
------------------------------------------------------------
330
committer: Lorem Ipsum <test@example.com>
335
------------------------------------------------------------
337
committer: Lorem Ipsum <test@example.com>
344
def test_verbose_merge_revisions_contain_deltas(self):
345
wt = self.make_branch_and_tree('parent')
346
self.build_tree(['parent/f1', 'parent/f2'])
348
wt.commit('first post')
349
self.run_bzr('branch', 'parent', 'child')
350
os.unlink('child/f1')
351
print >> file('child/f2', 'wb'), 'hello'
352
self.run_bzr('commit', '-m', 'removed f1 and modified f2', 'child')
354
self.run_bzr('merge', '../child')
355
wt.commit('merge branch 1')
358
lf = LongLogFormatter(to_file=sio)
359
show_log(b, lf, verbose=True)
360
log = self.normalize_log(sio.getvalue())
361
self.assertEqualDiff("""\
362
------------------------------------------------------------
364
committer: Lorem Ipsum <test@example.com>
373
------------------------------------------------------------
375
committer: Lorem Ipsum <test@example.com>
379
removed f1 and modified f2
384
------------------------------------------------------------
386
committer: Lorem Ipsum <test@example.com>
396
def test_trailing_newlines(self):
397
wt = self.make_branch_and_tree('.')
398
b = make_commits_with_trailing_newlines(wt)
400
lf = LongLogFormatter(to_file=sio)
402
self.assertEqualDiff(sio.getvalue(), """\
403
------------------------------------------------------------
405
committer: Joe Foo <joe@foo.com>
407
timestamp: Mon 2005-11-21 09:32:56 -0600
409
single line with trailing newline
410
------------------------------------------------------------
412
committer: Joe Foo <joe@foo.com>
414
timestamp: Mon 2005-11-21 09:27:22 -0600
419
------------------------------------------------------------
421
committer: Joe Foo <joe@foo.com>
423
timestamp: Mon 2005-11-21 09:24:15 -0600
429
class TestLineLogFormatter(TestCaseWithTransport):
431
266
def test_line_log(self):
432
267
"""Line log should show revno
450
285
log_contents = logfile.read()
451
286
self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
453
def test_short_log_with_merges(self):
454
wt = self.make_branch_and_memory_tree('.')
458
wt.commit('rev-1', rev_id='rev-1',
459
timestamp=1132586655, timezone=36000,
460
committer='Joe Foo <joe@foo.com>')
461
wt.commit('rev-merged', rev_id='rev-2a',
462
timestamp=1132586700, timezone=36000,
463
committer='Joe Foo <joe@foo.com>')
464
wt.set_parent_ids(['rev-1', 'rev-2a'])
465
wt.branch.set_last_revision_info(1, 'rev-1')
466
wt.commit('rev-2', rev_id='rev-2b',
467
timestamp=1132586800, timezone=36000,
468
committer='Joe Foo <joe@foo.com>')
470
formatter = ShortLogFormatter(to_file=logfile)
471
show_log(wt.branch, formatter)
473
self.assertEqualDiff("""\
474
2 Joe Foo\t2005-11-22 [merge]
477
1 Joe Foo\t2005-11-22
480
""", logfile.getvalue())
484
def test_trailing_newlines(self):
485
wt = self.make_branch_and_tree('.')
486
b = make_commits_with_trailing_newlines(wt)
488
lf = LineLogFormatter(to_file=sio)
490
self.assertEqualDiff(sio.getvalue(), """\
491
3: Joe Foo 2005-11-21 single line with trailing newline
492
2: Joe Foo 2005-11-21 multiline
493
1: Joe Foo 2005-11-21 simple log message
497
class TestGetViewRevisions(TestCaseWithTransport):
499
288
def make_tree_with_commits(self):
500
289
"""Create a tree with well-known revision ids"""
501
290
wt = self.make_branch_and_tree('tree1')