/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
1
# Copyright (C) 2010 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""bzr-commitfromnews - make commit messages from the changes in a NEWS file.
18
19
commitfromnews is enabled by default when installed.
20
6690.6.4 by Jelmer Vernooij
Improve documentation a bit.
21
To use, set the ``commit.template_from_files`` setting to a path and
22
just do a commit where the NEWS file for your project has a new section
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
23
added without providing a message to commit.
24
25
E.g.::
6690.6.4 by Jelmer Vernooij
Improve documentation a bit.
26
  $ echo "commit.template_from_files = NEWS" >> .bzr/branch/branch.conf
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
27
  $ echo "\n* new thing\n" >> NEWS
28
  $ bzr commit
29
  # editor pops open to let you tweak the message, and it starts with
30
    "* new thing" as the message to edit.
31
32
commitfromnews attempts to create a sensible default commit message by
33
including sections from a NEWS or ChangeLog file.
34
"""
35
7290.33.2 by Jelmer Vernooij
Add version_info to some plugins.
36
from ... import version_info  # noqa: F401
6690.6.2 by Jelmer Vernooij
Use lazy hook registration.
37
from ... import hooks
6690.6.3 by Jelmer Vernooij
The 'commitfromnews' plugin is now bundled.
38
from ...config import (
39
    option_registry,
40
    ListOption,
41
    )
42
43
option_registry.register(
6690.6.4 by Jelmer Vernooij
Improve documentation a bit.
44
    ListOption('commit.template_from_files', default=[], help="""\
45
List of fnmatch(2)-style shell file patterns to use when creating commit
46
templates.
47
"""))
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
48
49
50
def commit_template(commit, message):
51
    """Create a commit message for commit based on changes in the tree."""
6690.6.3 by Jelmer Vernooij
The 'commitfromnews' plugin is now bundled.
52
    config_stack = commit.work_tree.get_config_stack()
6690.6.4 by Jelmer Vernooij
Improve documentation a bit.
53
    filespec = config_stack.get('commit.template_from_files')
6690.6.3 by Jelmer Vernooij
The 'commitfromnews' plugin is now bundled.
54
    if filespec:
55
        from .committemplate import CommitTemplate
56
        template = CommitTemplate(commit, message, filespec)
57
        return template.make()
58
    return message
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
59
60
6690.6.1 by Jelmer Vernooij
Bundle the commitfromnews plugin.
61
def load_tests(loader, basic_tests, pattern):
62
    testmod_names = [
63
        'tests',
64
        ]
65
    basic_tests.addTest(loader.loadTestsFromModuleNames(
7143.15.2 by Jelmer Vernooij
Run autopep8.
66
        ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
6690.6.1 by Jelmer Vernooij
Bundle the commitfromnews plugin.
67
    return basic_tests
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
68
69
70
_registered = False
6690.6.2 by Jelmer Vernooij
Use lazy hook registration.
71
72
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
73
def register():
74
    """Register the plugin."""
75
    global _registered
76
    # Does not check registered because only tests call this, and they are
77
    # isolated.
78
    _registered = True
6690.6.2 by Jelmer Vernooij
Use lazy hook registration.
79
    hooks.install_lazy_named_hook(
80
        'breezy.msgeditor', 'hooks',
81
        'commit_message_template',
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
82
        commit_template, 'commitfromnews template')
83
6690.6.2 by Jelmer Vernooij
Use lazy hook registration.
84
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
85
register()