1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr log."""
24
from bzrlib.tests.blackbox import ExternalBase
25
from bzrlib.tests import TestCaseInTempDir, TestCaseWithTransport
28
class TestLog(ExternalBase):
30
def _prepare(self, format=None):
32
self.runbzr("init --format="+format)
35
self.build_tree(['hello.txt', 'goodbye.txt', 'meep.txt'])
36
self.runbzr("add hello.txt")
37
self.runbzr("commit -m message1 hello.txt")
38
self.runbzr("add goodbye.txt")
39
self.runbzr("commit -m message2 goodbye.txt")
40
self.runbzr("add meep.txt")
41
self.runbzr("commit -m message3 meep.txt")
42
self.full_log = self.runbzr("log")[0]
44
def test_log_null_end_revspec(self):
46
self.assertTrue('revno: 1\n' in self.full_log)
47
self.assertTrue('revno: 2\n' in self.full_log)
48
self.assertTrue('revno: 3\n' in self.full_log)
49
self.assertTrue('message:\n message1\n' in self.full_log)
50
self.assertTrue('message:\n message2\n' in self.full_log)
51
self.assertTrue('message:\n message3\n' in self.full_log)
53
log = self.runbzr("log -r 1..")[0]
54
self.assertEquals(log, self.full_log)
56
def test_log_null_begin_revspec(self):
58
log = self.runbzr("log -r ..3")[0]
59
self.assertEquals(self.full_log, log)
61
def test_log_null_both_revspecs(self):
63
log = self.runbzr("log -r ..")[0]
64
self.assertEquals(self.full_log, log)
66
def test_log_negative_begin_revspec_full_log(self):
68
log = self.runbzr("log -r -3..")[0]
69
self.assertEquals(self.full_log, log)
71
def test_log_negative_both_revspec_full_log(self):
73
log = self.runbzr("log -r -3..-1")[0]
74
self.assertEquals(self.full_log, log)
76
def test_log_negative_both_revspec_partial(self):
78
log = self.runbzr("log -r -3..-2")[0]
79
self.assertTrue('revno: 1\n' in log)
80
self.assertTrue('revno: 2\n' in log)
81
self.assertTrue('revno: 3\n' not in log)
83
def test_log_negative_begin_revspec(self):
85
log = self.runbzr("log -r -2..")[0]
86
self.assertTrue('revno: 1\n' not in log)
87
self.assertTrue('revno: 2\n' in log)
88
self.assertTrue('revno: 3\n' in log)
90
def test_log_postive_revspecs(self):
92
log = self.runbzr("log -r 1..3")[0]
93
self.assertEquals(self.full_log, log)
95
def test_log_revno_n_path(self):
104
log = self.runbzr("log -r revno:2:branch1..revno:3:branch2",
106
log = self.runbzr("log -r revno:1:branch2..revno:3:branch2")[0]
107
self.assertEquals(self.full_log, log)
108
log = self.runbzr("log -r revno:1:branch2")[0]
109
self.assertTrue('revno: 1\n' in log)
110
self.assertTrue('revno: 2\n' not in log)
111
self.assertTrue('branch nick: branch2\n' in log)
112
self.assertTrue('branch nick: branch1\n' not in log)
114
def test_log_nonexistent_file(self):
115
# files that don't exist in either the basis tree or working tree
116
# should give an error
117
wt = self.make_branch_and_tree('.')
118
out, err = self.run_bzr('log', 'does-not-exist', retcode=3)
119
self.assertContainsRe(
120
err, 'Path does not have any revision history: does-not-exist')
122
def test_log_with_tags(self):
123
self._prepare(format='dirstate-tags')
124
self.runbzr('tag -r1 tag1')
125
self.runbzr('tag -r1 tag1.1')
126
self.runbzr('tag tag3')
128
log = self.runbzr("log -r-1")[0]
129
self.assertTrue('tags: tag3' in log)
131
log = self.runbzr("log -r1")[0]
132
# I guess that we can't know the order of tags in the output
133
# since dicts are unordered, need to check both possibilities
134
self.assertContainsRe(log, r'tags: (tag1, tag1\.1|tag1\.1, tag1)')
136
def test_merged_log_with_tags(self):
139
self._prepare(format='dirstate-tags')
141
self.runbzr('branch branch1 branch2')
143
self.runbzr('commit -m foobar --unchanged')
144
self.runbzr('tag tag1')
145
os.chdir('../branch2')
146
self.runbzr('merge ../branch1')
147
self.runbzr('commit -m merge_branch_1')
148
log = self.runbzr("log -r-1")[0]
149
self.assertContainsRe(log, r' tags: tag1')
151
def test_log_limit(self):
153
log = self.runbzr("log --limit 2")[0]
154
self.assertTrue('revno: 1\n' not in log)
155
self.assertTrue('revno: 2\n' in log)
156
self.assertTrue('revno: 3\n' in log)
159
class TestLogMerges(ExternalBase):
161
def test_merges_are_indented_by_level(self):
162
self.build_tree(['parent/'])
163
self.run_bzr('init', 'parent')
164
self.run_bzr('commit', '-m', 'first post', '--unchanged', 'parent')
165
self.run_bzr('branch', 'parent', 'child')
166
self.run_bzr('commit', '-m', 'branch 1', '--unchanged', 'child')
167
self.run_bzr('branch', 'child', 'smallerchild')
168
self.run_bzr('commit', '-m', 'branch 2', '--unchanged', 'smallerchild')
170
self.run_bzr('merge', '../smallerchild')
171
self.run_bzr('commit', '-m', 'merge branch 2')
172
os.chdir('../parent')
173
self.run_bzr('merge', '../child')
174
self.run_bzr('commit', '-m', 'merge branch 1')
175
out,err = self.run_bzr('log')
176
# the log will look something like:
177
# self.assertEqual("""\
178
#------------------------------------------------------------
180
#committer: Robert Collins <foo@example.com>
182
#timestamp: Tue 2006-03-28 22:31:40 +1100
185
# ------------------------------------------------------------
187
# merged: foo@example.com-20060328113140-91f43cfb46dc2863
188
# committer: Robert Collins <foo@example.com>
190
# timestamp: Tue 2006-03-28 22:31:40 +1100
193
# ------------------------------------------------------------
195
# merged: foo@example.com-20060328113140-1ba24f850a0ef573
196
# committer: Robert Collins <foo@example.com>
197
# branch nick: smallerchild
198
# timestamp: Tue 2006-03-28 22:31:40 +1100
201
# ------------------------------------------------------------
203
# merged: foo@example.com-20060328113140-5749a4757a8ac792
204
# committer: Robert Collins <foo@example.com>
206
# timestamp: Tue 2006-03-28 22:31:40 +1100
209
#------------------------------------------------------------
211
#committer: Robert Collins <foo@example.com>
213
#timestamp: Tue 2006-03-28 22:31:39 +1100
217
# but we dont have a nice pattern matcher hooked up yet, so:
218
# we check for the indenting of the commit message and the
220
self.assertTrue('revno: 2' in out)
221
self.assertTrue(' merge branch 1' in out)
222
self.assertTrue(' revno: 1.1.2' in out)
223
self.assertTrue(' merge branch 2' in out)
224
self.assertTrue(' revno: 1.1.1.1' in out)
225
self.assertTrue(' branch 2' in out)
226
self.assertTrue(' revno: 1.1.1' in out)
227
self.assertTrue(' branch 1' in out)
228
self.assertTrue('revno: 1' in out)
229
self.assertTrue(' first post' in out)
230
self.assertEqual('', err)
233
class TestLogEncodings(TestCaseInTempDir):
236
_message = u'Message with \xb5'
238
# Encodings which can encode mu
243
'cp437', # Common windows encoding
244
'cp1251', # Alexander Belchenko's windows encoding
245
'cp1258', # Common windows encoding
247
# Encodings which cannot encode mu
255
TestCaseInTempDir.setUp(self)
256
self.user_encoding = bzrlib.user_encoding
259
bzrlib.user_encoding = self.user_encoding
260
TestCaseInTempDir.tearDown(self)
262
def create_branch(self):
265
open('a', 'wb').write('some stuff\n')
267
bzr('commit', '-m', self._message)
269
def try_encoding(self, encoding, fail=False):
272
self.assertRaises(UnicodeEncodeError,
273
self._mu.encode, encoding)
274
encoded_msg = self._message.encode(encoding, 'replace')
276
encoded_msg = self._message.encode(encoding)
278
old_encoding = bzrlib.user_encoding
279
# This test requires that 'run_bzr' uses the current
280
# bzrlib, because we override user_encoding, and expect
283
bzrlib.user_encoding = 'ascii'
284
# We should be able to handle any encoding
285
out, err = bzr('log', encoding=encoding)
287
# Make sure we wrote mu as we expected it to exist
288
self.assertNotEqual(-1, out.find(encoded_msg))
289
out_unicode = out.decode(encoding)
290
self.assertNotEqual(-1, out_unicode.find(self._message))
292
self.assertNotEqual(-1, out.find('Message with ?'))
294
bzrlib.user_encoding = old_encoding
296
def test_log_handles_encoding(self):
299
for encoding in self.good_encodings:
300
self.try_encoding(encoding)
302
def test_log_handles_bad_encoding(self):
305
for encoding in self.bad_encodings:
306
self.try_encoding(encoding, fail=True)
308
def test_stdout_encoding(self):
310
bzrlib.user_encoding = "cp1251"
313
self.build_tree(['a'])
315
bzr('commit', '-m', u'\u0422\u0435\u0441\u0442')
316
stdout, stderr = self.run_bzr('log', encoding='cp866')
318
message = stdout.splitlines()[-1]
320
# explanation of the check:
321
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
322
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
323
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
324
# This test should check that output of log command
325
# encoded to sys.stdout.encoding
326
test_in_cp866 = '\x92\xa5\xe1\xe2'
327
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
328
# Make sure the log string is encoded in cp866
329
self.assertEquals(test_in_cp866, message[2:])
330
# Make sure the cp1251 string is not found anywhere
331
self.assertEquals(-1, stdout.find(test_in_cp1251))
334
class TestLogFile(TestCaseWithTransport):
336
def test_log_local_branch_file(self):
337
"""We should be able to log files in local treeless branches"""
338
tree = self.make_branch_and_tree('tree')
339
self.build_tree(['tree/file'])
341
tree.commit('revision 1')
342
tree.bzrdir.destroy_workingtree()
343
self.run_bzr('log', 'tree/file')
345
def test_log_file(self):
346
"""The log for a particular file should only list revs for that file"""
347
tree = self.make_branch_and_tree('parent')
348
self.build_tree(['parent/file1', 'parent/file2', 'parent/file3'])
350
tree.commit('add file1')
352
tree.commit('add file2')
354
tree.commit('add file3')
355
self.run_bzr('branch', 'parent', 'child')
356
print >> file('child/file2', 'wb'), 'hello'
357
self.run_bzr('commit', '-m', 'branch 1', 'child')
359
self.run_bzr('merge', '../child')
360
self.run_bzr('commit', '-m', 'merge child branch')
362
log = self.run_bzr('log', 'file1')[0]
363
self.assertContainsRe(log, 'revno: 1\n')
364
self.assertNotContainsRe(log, 'revno: 2\n')
365
self.assertNotContainsRe(log, 'revno: 3\n')
366
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
367
self.assertNotContainsRe(log, 'revno: 4\n')
368
log = self.run_bzr('log', 'file2')[0]
369
self.assertNotContainsRe(log, 'revno: 1\n')
370
self.assertContainsRe(log, 'revno: 2\n')
371
self.assertNotContainsRe(log, 'revno: 3\n')
372
self.assertContainsRe(log, 'revno: 3.1.1\n')
373
self.assertContainsRe(log, 'revno: 4\n')
374
log = self.run_bzr('log', 'file3')[0]
375
self.assertNotContainsRe(log, 'revno: 1\n')
376
self.assertNotContainsRe(log, 'revno: 2\n')
377
self.assertContainsRe(log, 'revno: 3\n')
378
self.assertNotContainsRe(log, 'revno: 3.1.1\n')
379
self.assertNotContainsRe(log, 'revno: 4\n')