1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Black-box tests for bzr log."""
import os
import bzrlib
from bzrlib.tests.blackbox import ExternalBase
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
from bzrlib.tests.test_log import (
normalize_log,
)
class TestLog(ExternalBase):
def _prepare(self, path='.', format=None):
tree = self.make_branch_and_tree(path, format=format)
self.build_tree(
[path + '/hello.txt', path + '/goodbye.txt', path + '/meep.txt'])
tree.add('hello.txt')
tree.commit(message='message1')
tree.add('goodbye.txt')
tree.commit(message='message2')
tree.add('meep.txt')
tree.commit(message='message3')
self.full_log = self.run_bzr(["log", path])[0]
return tree
def test_log_null_end_revspec(self):
self._prepare()
self.assertTrue('revno: 1\n' in self.full_log)
self.assertTrue('revno: 2\n' in self.full_log)
self.assertTrue('revno: 3\n' in self.full_log)
self.assertTrue('message:\n message1\n' in self.full_log)
self.assertTrue('message:\n message2\n' in self.full_log)
self.assertTrue('message:\n message3\n' in self.full_log)
log = self.run_bzr("log -r 1..")[0]
self.assertEqualDiff(log, self.full_log)
def test_log_null_begin_revspec(self):
self._prepare()
log = self.run_bzr("log -r ..3")[0]
self.assertEqualDiff(self.full_log, log)
def test_log_null_both_revspecs(self):
self._prepare()
log = self.run_bzr("log -r ..")[0]
self.assertEqualDiff(self.full_log, log)
def test_log_zero_revspec(self):
self._prepare()
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
['log', '-r0'])
def test_log_zero_begin_revspec(self):
self._prepare()
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
['log', '-r0..2'])
def test_log_zero_end_revspec(self):
self._prepare()
self.run_bzr_error('bzr: ERROR: Logging revision 0 is invalid.',
['log', '-r-2..0'])
def test_log_negative_begin_revspec_full_log(self):
self._prepare()
log = self.run_bzr("log -r -3..")[0]
self.assertEqualDiff(self.full_log, log)
def test_log_negative_both_revspec_full_log(self):
self._prepare()
log = self.run_bzr("log -r -3..-1")[0]
self.assertEqualDiff(self.full_log, log)
def test_log_negative_both_revspec_partial(self):
self._prepare()
log = self.run_bzr("log -r -3..-2")[0]
self.assertTrue('revno: 1\n' in log)
self.assertTrue('revno: 2\n' in log)
self.assertTrue('revno: 3\n' not in log)
def test_log_negative_begin_revspec(self):
self._prepare()
log = self.run_bzr("log -r -2..")[0]
self.assertTrue('revno: 1\n' not in log)
self.assertTrue('revno: 2\n' in log)
self.assertTrue('revno: 3\n' in log)
def test_log_positive_revspecs(self):
self._prepare()
log = self.run_bzr("log -r 1..3")[0]
self.assertEqualDiff(self.full_log, log)
def test_log_reversed_revspecs(self):
self._prepare()
self.run_bzr_error(('bzr: ERROR: Start revision must be older than '
'the end revision.\n',),
['log', '-r3..1'])
def test_log_revno_n_path(self):
self._prepare(path='branch1')
self._prepare(path='branch2')
log = self.run_bzr("log -r revno:2:branch1..revno:3:branch2",
retcode=3)[0]
log = self.run_bzr("log -r revno:1:branch2..revno:3:branch2")[0]
self.assertEqualDiff(self.full_log, log)
log = self.run_bzr("log -r revno:1:branch2")[0]
self.assertTrue('revno: 1\n' in log)
self.assertTrue('revno: 2\n' not in log)
self.assertTrue('branch nick: branch2\n' in log)
self.assertTrue('branch nick: branch1\n' not in log)
def test_log_nonexistent_file(self):
# files that don't exist in either the basis tree or working tree
# should give an error
wt = self.make_branch_and_tree('.')
out, err = self.run_bzr('log does-not-exist', retcode=3)
self.assertContainsRe(
err, 'Path does not have any revision history: does-not-exist')
def test_log_with_tags(self):
tree = self._prepare(format='dirstate-tags')
branch = tree.branch
branch.tags.set_tag('tag1', branch.get_rev_id(1))
branch.tags.set_tag('tag1.1', branch.get_rev_id(1))
branch.tags.set_tag('tag3', branch.last_revision())
log = self.run_bzr("log -r-1")[0]
self.assertTrue('tags: tag3' in log)
log = self.run_bzr("log -r1")[0]
# I guess that we can't know the order of tags in the output
# since dicts are unordered, need to check both possibilities
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
def test_merged_log_with_tags(self):
branch1_tree = self._prepare(path='branch1', format='dirstate-tags')
branch1 = branch1_tree.branch
branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
branch1_tree.commit(message='foobar', allow_pointless=True)
branch1.tags.set_tag('tag1', branch1.last_revision())
os.chdir('branch2')
self.run_bzr('merge ../branch1') # tags don't propagate otherwise
branch2_tree.commit(message='merge branch 1')
log = self.run_bzr("log -r-1")[0]
self.assertContainsRe(log, r' tags: tag1')
log = self.run_bzr("log -r3.1.1")[0]
self.assertContainsRe(log, r'tags: tag1')
def test_log_limit(self):
self._prepare()
log = self.run_bzr("log --limit 2")[0]
self.assertTrue('revno: 1\n' not in log)
self.assertTrue('revno: 2\n' in log)
self.assertTrue('revno: 3\n' in log)
class TestLogMerges(ExternalBase):
def _prepare(self):
parent_tree = self.make_branch_and_tree('parent')
parent_tree.commit(message='first post', allow_pointless=True)
child_tree = parent_tree.bzrdir.sprout('child').open_workingtree()
child_tree.commit(message='branch 1', allow_pointless=True)
smaller_tree = \
child_tree.bzrdir.sprout('smallerchild').open_workingtree()
smaller_tree.commit(message='branch 2', allow_pointless=True)
child_tree.merge_from_branch(smaller_tree.branch)
child_tree.commit(message='merge branch 2')
parent_tree.merge_from_branch(child_tree.branch)
parent_tree.commit(message='merge branch 1')
os.chdir('parent')
def test_merges_are_indented_by_level(self):
self._prepare()
out,err = self.run_bzr('log')
self.assertEqual('', err)
log = normalize_log(out)
self.assertEqualDiff(log, """\
------------------------------------------------------------
revno: 2
committer: Lorem Ipsum <test@example.com>
branch nick: parent
timestamp: Just now
message:
merge branch 1
------------------------------------------------------------
revno: 1.1.2
committer: Lorem Ipsum <test@example.com>
branch nick: child
timestamp: Just now
message:
merge branch 2
------------------------------------------------------------
revno: 1.1.1.1.1
committer: Lorem Ipsum <test@example.com>
branch nick: smallerchild
timestamp: Just now
message:
branch 2
------------------------------------------------------------
revno: 1.1.1
committer: Lorem Ipsum <test@example.com>
branch nick: child
timestamp: Just now
message:
branch 1
------------------------------------------------------------
revno: 1
committer: Lorem Ipsum <test@example.com>
branch nick: parent
timestamp: Just now
message:
first post
""")
def test_merges_single_merge_rev(self):
self._prepare()
out,err = self.run_bzr('log -r1.1.2')
self.assertEqual('', err)
log = normalize_log(out)
self.assertEqualDiff(log, """\
------------------------------------------------------------
revno: 1.1.2
committer: Lorem Ipsum <test@example.com>
branch nick: child
timestamp: Just now
message:
merge branch 2
------------------------------------------------------------
revno: 1.1.1.1.1
committer: Lorem Ipsum <test@example.com>
branch nick: smallerchild
timestamp: Just now
message:
branch 2
""")
def test_merges_partial_range(self):
self._prepare()
out,err = self.run_bzr('log -r1.1.1..1.1.2')
self.assertEqual('', err)
log = normalize_log(out)
self.assertEqualDiff(log, """\
------------------------------------------------------------
revno: 1.1.2
committer: Lorem Ipsum <test@example.com>
branch nick: child
timestamp: Just now
message:
merge branch 2
------------------------------------------------------------
revno: 1.1.1.1.1
committer: Lorem Ipsum <test@example.com>
branch nick: smallerchild
timestamp: Just now
message:
branch 2
------------------------------------------------------------
revno: 1.1.1
committer: Lorem Ipsum <test@example.com>
branch nick: child
timestamp: Just now
message:
branch 1
""")
def test_merges_nonsupporting_formatter(self):
self._prepare()
err_msg = 'Selected log formatter only supports mainline revisions.'
# The single revision case is tested in the core tests
# since all standard formatters support single merge revisions.
out,err = self.run_bzr('log --short -r1..1.1.2', retcode=3)
self.assertContainsRe(err, err_msg)
out,err = self.run_bzr('log --short -r1.1.1..1.1.2', retcode=3)
self.assertContainsRe(err, err_msg)
class TestLogEncodings(TestCaseInTempDir):
_mu = u'\xb5'
_message = u'Message with \xb5'
# Encodings which can encode mu
good_encodings = [
'utf-8',
'latin-1',
'iso-8859-1',
'cp437', # Common windows encoding
'cp1251', # Alexander Belchenko's windows encoding
'cp1258', # Common windows encoding
]
# Encodings which cannot encode mu
bad_encodings = [
'ascii',
'iso-8859-2',
'koi8_r',
]
def setUp(self):
TestCaseInTempDir.setUp(self)
self.user_encoding = bzrlib.user_encoding
def tearDown(self):
bzrlib.user_encoding = self.user_encoding
TestCaseInTempDir.tearDown(self)
def create_branch(self):
bzr = self.run_bzr
bzr('init')
open('a', 'wb').write('some stuff\n')
bzr('add a')
bzr(['commit', '-m', self._message])
def try_encoding(self, encoding, fail=False):
bzr = self.run_bzr
if fail:
self.assertRaises(UnicodeEncodeError,
self._mu.encode, encoding)
encoded_msg = self._message.encode(encoding, 'replace')
else:
encoded_msg = self._message.encode(encoding)
old_encoding = bzrlib.user_encoding
# This test requires that 'run_bzr' uses the current
# bzrlib, because we override user_encoding, and expect
# it to be used
try:
bzrlib.user_encoding = 'ascii'
# We should be able to handle any encoding
out, err = bzr('log', encoding=encoding)
if not fail:
# Make sure we wrote mu as we expected it to exist
self.assertNotEqual(-1, out.find(encoded_msg))
out_unicode = out.decode(encoding)
self.assertNotEqual(-1, out_unicode.find(self._message))
else:
self.assertNotEqual(-1, out.find('Message with ?'))
finally:
bzrlib.user_encoding = old_encoding
def test_log_handles_encoding(self):
self.create_branch()
for encoding in self.good_encodings:
self.try_encoding(encoding)
def test_log_handles_bad_encoding(self):
self.create_branch()
for encoding in self.bad_encodings:
self.try_encoding(encoding, fail=True)
def test_stdout_encoding(self):
bzr = self.run_bzr
bzrlib.user_encoding = "cp1251"
bzr('init')
self.build_tree(['a'])
bzr('add a')
bzr(['commit', '-m', u'\u0422\u0435\u0441\u0442'])
stdout, stderr = self.run_bzr('log', encoding='cp866')
message = stdout.splitlines()[-1]
# explanation of the check:
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
# This test should check that output of log command
# encoded to sys.stdout.encoding
test_in_cp866 = '\x92\xa5\xe1\xe2'
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
# Make sure the log string is encoded in cp866
self.assertEquals(test_in_cp866, message[2:])
# Make sure the cp1251 string is not found anywhere
self.assertEquals(-1, stdout.find(test_in_cp1251))
class TestLogFile(TestCaseWithTransport):
def test_log_local_branch_file(self):
"""We should be able to log files in local treeless branches"""
tree = self.make_branch_and_tree('tree')
self.build_tree(['tree/file'])
tree.add('file')
tree.commit('revision 1')
tree.bzrdir.destroy_workingtree()
self.run_bzr('log tree/file')
def test_log_file(self):
"""The log for a particular file should only list revs for that file"""
tree = self.make_branch_and_tree('parent')
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
tree.add('file1')
tree.commit('add file1')
tree.add('file2')
tree.commit('add file2')
tree.add('file3')
tree.commit('add file3')
child_tree = tree.bzrdir.sprout('child').open_workingtree()
self.build_tree_contents([('child/file2', 'hello')])
child_tree.commit(message='branch 1')
tree.merge_from_branch(child_tree.branch)
tree.commit(message='merge child branch')
os.chdir('parent')
log = self.run_bzr('log file1')[0]
self.assertContainsRe(log, 'revno: 1\n')
self.assertNotContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
self.assertNotContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log file2')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertContainsRe(log, 'revno: 3.1.1\n')
self.assertContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log file3')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertNotContainsRe(log, 'revno: 2\n')
self.assertContainsRe(log, 'revno: 3\n')
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
self.assertNotContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log -r3.1.1 file2')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertNotContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertContainsRe(log, 'revno: 3.1.1\n')
self.assertNotContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log -r4 file2')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertNotContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertContainsRe(log, 'revno: 3.1.1\n')
self.assertContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log -r3.. file2')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertNotContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertContainsRe(log, 'revno: 3.1.1\n')
self.assertContainsRe(log, 'revno: 4\n')
log = self.run_bzr('log -r..3 file2')[0]
self.assertNotContainsRe(log, 'revno: 1\n')
self.assertContainsRe(log, 'revno: 2\n')
self.assertNotContainsRe(log, 'revno: 3\n')
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
self.assertNotContainsRe(log, 'revno: 4\n')
|