~bzr-pqm/bzr/bzr.dev

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
# Copyright (C) 2005, 2006, 2009 Canonical Ltd
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


"""Black-box tests for default log_formats/log_formatters
"""


import os


from bzrlib.branch import Branch
from bzrlib.tests import TestCaseInTempDir
from bzrlib.config import (ensure_config_dir_exists, config_filename)


class TestLogFormats(TestCaseInTempDir):

    def test_log_default_format(self):
        self.setup_config()

        self.run_bzr('init')
        open('a', 'wb').write('foo\n')
        self.run_bzr('add a')

        self.run_bzr('commit -m 1')
        open('a', 'wb').write('baz\n')

        self.run_bzr('commit -m 2')

        # only the lines formatter is this short
        self.assertEquals(3, len(self.run_bzr('log')[0].split('\n')))

    def test_log_format_arg(self):
        self.run_bzr('init')
        open('a', 'wb').write('foo\n')
        self.run_bzr('add a')

        self.run_bzr('commit -m 1')
        open('a', 'wb').write('baz\n')

        self.run_bzr('commit -m 2')

        # only the lines formatter is this short
        self.assertEquals(7,
            len(self.run_bzr('log --log-format short')[0].split('\n')))

    def test_missing_default_format(self):
        self.setup_config()

        os.mkdir('a')
        os.chdir('a')
        self.run_bzr('init')

        open('a', 'wb').write('foo\n')
        self.run_bzr('add a')
        self.run_bzr('commit -m 1')

        os.chdir('..')
        self.run_bzr('branch a b')
        os.chdir('a')

        open('a', 'wb').write('bar\n')
        self.run_bzr('commit -m 2')

        open('a', 'wb').write('baz\n')
        self.run_bzr('commit -m 3')

        os.chdir('../b')

        self.assertEquals(5,
            len(self.run_bzr('missing', retcode=1)[0].split('\n')))

        os.chdir('..')

    def test_missing_format_arg(self):
        self.setup_config()

        os.mkdir('a')
        os.chdir('a')
        self.run_bzr('init')

        open('a', 'wb').write('foo\n')
        self.run_bzr('add a')
        self.run_bzr('commit -m 1')

        os.chdir('..')
        self.run_bzr('branch a b')
        os.chdir('a')

        open('a', 'wb').write('bar\n')
        self.run_bzr('commit -m 2')

        open('a', 'wb').write('baz\n')
        self.run_bzr('commit -m 3')

        os.chdir('../b')

        self.assertEquals(9,
            len(self.run_bzr('missing --log-format short',
                retcode=1)[0].split('\n')))

        os.chdir('..')

    def test_logformat_gnu_changelog(self):
        # from http://launchpad.net/bugs/29582/
        self.setup_config()
        repo_url = self.make_trivial_history()

        out, err = self.run_bzr(
            ['log', self.get_url('repo/a'),
             '--log-format=gnu-changelog',
             '--timezone=utc'])
        self.assertEquals(err, '')
        self.assertEqualDiff(out,
"""2009-03-03  Joe Foo  <joe@foo.com>

\tcommit 1

""")

    def make_trivial_history(self):
        """Make a one-commit history and return the URL of the branch"""
        repo = self.make_repository('repo', shared=True, format='1.6')
        bb = self.make_branch_builder('repo/a')
        bb.start_series()
        bb.build_snapshot('rev-1', None,
            [('add', ('', 'root-id', 'directory', ''))],
            timestamp=1236045060)
        bb.finish_series()
        return self.get_url('repo/a')

    def setup_config(self):
        if os.path.isfile(config_filename()):
                # Something is wrong in environment,
                # we risk overwriting users config
                self.assert_(config_filename() + "exists, abort")

        ensure_config_dir_exists()
        CONFIG=("[DEFAULT]\n"
                "email=Joe Foo <joe@foo.com>\n"
                "log_format=line\n")

        open(config_filename(),'wb').write(CONFIG)