1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
# GNU General Public License for more details.
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
87
89
log = self.runbzr("log -r 1..3")[0]
88
90
self.assertEquals(self.full_log, log)
92
def test_log_revno_n_path(self):
101
log = self.runbzr("log -r revno:2:branch1..revno:3:branch2",
103
log = self.runbzr("log -r revno:1:branch2..revno:3:branch2")[0]
104
self.assertEquals(self.full_log, log)
105
log = self.runbzr("log -r revno:1:branch2")[0]
106
self.assertTrue('revno: 1\n' in log)
107
self.assertTrue('revno: 2\n' not in log)
108
self.assertTrue('branch nick: branch2\n' in log)
109
self.assertTrue('branch nick: branch1\n' not in log)
111
def test_log_nonexistent_file(self):
112
# files that don't exist in either the basis tree or working tree
113
# should give an error
114
wt = self.make_branch_and_tree('.')
115
out, err = self.run_bzr('log', 'does-not-exist', retcode=3)
116
self.assertContainsRe(
117
err, 'Path does not have any revision history: does-not-exist')
91
119
class TestLogMerges(ExternalBase):
146
177
# but we dont have a nice pattern matcher hooked up yet, so:
147
# we check for the indenting of the commit message:
178
# we check for the indenting of the commit message and the
180
self.assertTrue('revno: 2' in out)
148
181
self.assertTrue(' merge branch 1' in out)
182
self.assertTrue(' revno: 1.1.2' in out)
149
183
self.assertTrue(' merge branch 2' in out)
184
self.assertTrue(' revno: 1.1.1.1' in out)
150
185
self.assertTrue(' branch 2' in out)
186
self.assertTrue(' revno: 1.1.1' in out)
151
187
self.assertTrue(' branch 1' in out)
188
self.assertTrue('revno: 1' in out)
152
189
self.assertTrue(' first post' in out)
153
190
self.assertEqual('', err)
193
class TestLogEncodings(TestCaseInTempDir):
196
_message = u'Message with \xb5'
198
# Encodings which can encode mu
203
'cp437', # Common windows encoding
204
'cp1251', # Alexander Belchenko's windows encoding
205
'cp1258', # Common windows encoding
207
# Encodings which cannot encode mu
215
TestCaseInTempDir.setUp(self)
216
self.user_encoding = bzrlib.user_encoding
219
bzrlib.user_encoding = self.user_encoding
220
TestCaseInTempDir.tearDown(self)
222
def create_branch(self):
225
open('a', 'wb').write('some stuff\n')
227
bzr('commit', '-m', self._message)
229
def try_encoding(self, encoding, fail=False):
232
self.assertRaises(UnicodeEncodeError,
233
self._mu.encode, encoding)
234
encoded_msg = self._message.encode(encoding, 'replace')
236
encoded_msg = self._message.encode(encoding)
238
old_encoding = bzrlib.user_encoding
239
# This test requires that 'run_bzr' uses the current
240
# bzrlib, because we override user_encoding, and expect
243
bzrlib.user_encoding = 'ascii'
244
# We should be able to handle any encoding
245
out, err = bzr('log', encoding=encoding)
247
# Make sure we wrote mu as we expected it to exist
248
self.assertNotEqual(-1, out.find(encoded_msg))
249
out_unicode = out.decode(encoding)
250
self.assertNotEqual(-1, out_unicode.find(self._message))
252
self.assertNotEqual(-1, out.find('Message with ?'))
254
bzrlib.user_encoding = old_encoding
256
def test_log_handles_encoding(self):
259
for encoding in self.good_encodings:
260
self.try_encoding(encoding)
262
def test_log_handles_bad_encoding(self):
265
for encoding in self.bad_encodings:
266
self.try_encoding(encoding, fail=True)
268
def test_stdout_encoding(self):
270
bzrlib.user_encoding = "cp1251"
273
self.build_tree(['a'])
275
bzr('commit', '-m', u'\u0422\u0435\u0441\u0442')
276
stdout, stderr = self.run_bzr('log', encoding='cp866')
278
message = stdout.splitlines()[-1]
280
# explanation of the check:
281
# u'\u0422\u0435\u0441\u0442' is word 'Test' in russian
282
# in cp866 encoding this is string '\x92\xa5\xe1\xe2'
283
# in cp1251 encoding this is string '\xd2\xe5\xf1\xf2'
284
# This test should check that output of log command
285
# encoded to sys.stdout.encoding
286
test_in_cp866 = '\x92\xa5\xe1\xe2'
287
test_in_cp1251 = '\xd2\xe5\xf1\xf2'
288
# Make sure the log string is encoded in cp866
289
self.assertEquals(test_in_cp866, message[2:])
290
# Make sure the cp1251 string is not found anywhere
291
self.assertEquals(-1, stdout.find(test_in_cp1251))
294
class TestLogFile(TestCaseWithTransport):
296
def test_log_local_branch_file(self):
297
"""We should be able to log files in local treeless branches"""
298
tree = self.make_branch_and_tree('tree')
299
self.build_tree(['tree/file'])
301
tree.commit('revision 1')
302
tree.bzrdir.destroy_workingtree()
303
self.run_bzr('log', 'tree/file')