25
from bzrlib.branch import Branch
26
from bzrlib.tests import TestCaseInTempDir
27
from bzrlib.config import (ensure_config_dir_exists, config_filename)
30
class TestLogFormats(TestCaseInTempDir):
31
class TestLogFormats(tests.TestCaseWithTransport):
34
super(TestLogFormats, self).setUp()
36
# Create a config file with some useful variables
37
conf_path = config.config_filename()
38
if os.path.isfile(conf_path):
39
# Something is wrong in environment,
40
# we risk overwriting users config
41
self.fail("%s exists" % conf_path)
43
config.ensure_config_dir_exists()
44
f = open(conf_path,'wb')
47
email=Joe Foo <joe@foo.com>
53
def _make_simple_branch(self, relpath='.'):
54
wt = self.make_branch_and_tree(relpath)
55
wt.commit('first revision')
56
wt.commit('second revision')
32
59
def test_log_default_format(self):
36
open('a', 'wb').write('foo\n')
39
self.run_bzr('commit -m 1')
40
open('a', 'wb').write('baz\n')
42
self.run_bzr('commit -m 2')
44
# only the lines formatter is this short
45
self.assertEquals(3, len(self.run_bzr('log')[0].split('\n')))
60
self._make_simple_branch()
61
# only the lines formatter is this short, one line by revision
62
log = self.run_bzr('log')[0]
63
self.assertEquals(2, len(log.splitlines()))
47
65
def test_log_format_arg(self):
49
open('a', 'wb').write('foo\n')
52
self.run_bzr('commit -m 1')
53
open('a', 'wb').write('baz\n')
55
self.run_bzr('commit -m 2')
57
# only the lines formatter is this short
59
len(self.run_bzr('log --log-format short')[0].split('\n')))
66
self._make_simple_branch()
67
log = self.run_bzr(['log', '--log-format', 'short'])[0]
61
69
def test_missing_default_format(self):
68
open('a', 'wb').write('foo\n')
70
self.run_bzr('commit -m 1')
73
self.run_bzr('branch a b')
76
open('a', 'wb').write('bar\n')
77
self.run_bzr('commit -m 2')
79
open('a', 'wb').write('baz\n')
80
self.run_bzr('commit -m 3')
85
len(self.run_bzr('missing', retcode=1)[0].split('\n')))
70
wt = self._make_simple_branch('a')
71
self.run_bzr(['branch', 'a', 'b'])
72
wt.commit('third revision')
73
wt.commit('fourth revision')
75
missing = self.run_bzr('missing', retcode=1, working_dir='b')[0]
76
# one line for 'Using save location'
77
# one line for 'You are missing 2 revision(s)'
78
# one line by missing revision (the line log format is used as
80
self.assertEquals(4, len(missing.splitlines()))
89
82
def test_missing_format_arg(self):
96
open('a', 'wb').write('foo\n')
98
self.run_bzr('commit -m 1')
101
self.run_bzr('branch a b')
104
open('a', 'wb').write('bar\n')
105
self.run_bzr('commit -m 2')
107
open('a', 'wb').write('baz\n')
108
self.run_bzr('commit -m 3')
113
len(self.run_bzr('missing --log-format short',
114
retcode=1)[0].split('\n')))
83
wt = self._make_simple_branch('a')
84
self.run_bzr(['branch', 'a', 'b'])
85
wt.commit('third revision')
86
wt.commit('fourth revision')
88
missing = self.run_bzr(['missing', '--log-format', 'short'],
89
retcode=1, working_dir='b')[0]
90
# one line for 'Using save location'
91
# one line for 'You are missing 2 revision(s)'
92
# three lines by missing revision
93
self.assertEquals(8, len(missing.splitlines()))
118
95
def test_logformat_gnu_changelog(self):
119
96
# from http://launchpad.net/bugs/29582/
121
repo_url = self.make_trivial_history()
123
out, err = self.run_bzr(
124
['log', self.get_url('repo/a'),
125
'--log-format=gnu-changelog',
127
self.assertEquals(err, '')
128
self.assertEqualDiff(out,
129
"""2009-03-03 Joe Foo <joe@foo.com>
135
def make_trivial_history(self):
136
"""Make a one-commit history and return the URL of the branch"""
137
repo = self.make_repository('repo', shared=True, format='1.6')
138
bb = self.make_branch_builder('repo/a')
140
bb.build_snapshot('rev-1', None,
141
[('add', ('', 'root-id', 'directory', ''))],
142
timestamp=1236045060)
144
return self.get_url('repo/a')
146
def setup_config(self):
147
if os.path.isfile(config_filename()):
148
# Something is wrong in environment,
149
# we risk overwriting users config
150
self.assert_(config_filename() + "exists, abort")
152
ensure_config_dir_exists()
153
CONFIG=("[DEFAULT]\n"
154
"email=Joe Foo <joe@foo.com>\n"
157
open(config_filename(),'wb').write(CONFIG)
97
wt = self.make_branch_and_tree('.')
98
wt.commit('first revision', timestamp=1236045060,
101
log, err = self.run_bzr(['log', '--log-format', 'gnu-changelog',
103
self.assertEquals('', err)
104
expected = """2009-03-03 Joe Foo <joe@foo.com>
109
self.assertEqualDiff(expected, log)