Add branch_name_in_commit plugin

This commit is contained in:
Johan Henkens
2018-12-05 09:24:15 -08:00
parent 679103795b
commit 5e7895ca6b
3 changed files with 27 additions and 2 deletions

View File

@@ -145,8 +145,9 @@ class Filter:
#Or don't pass, if you want to do some init code here
```
Beyond the boilerplate initialization, you can see the one of the
defined filter methods in the [dos2unix](./plugins/dos2unix) plugin.
Beyond the boilerplate initialization, you can see the two different
defined filter methods in the [dos2unix](./plugins/dos2unix) and
[branch_name_in_commit](./plugins/branch_name_in_commit) plugins.
```
commit_data = {'branch': branch, 'parents': parents, 'author': author, 'desc': desc}

View File

@@ -0,0 +1,10 @@
## Branch Name in Commit Message
Mercurial has a much stronger notion of branches than Git,
and some parties may not wish to lose the branch information
during the migration to Git. You can use this plugin to either
prepend or append the branch name from the mercurial
commit into the commit message in Git.
To use the plugin, add
`--plugin branch_name_in_commit=(start|end)`.

View File

@@ -0,0 +1,14 @@
def build_filter(args):
return Filter(args)
class Filter:
def __init__(self, args):
if not args in ['start','end']:
raise Exception('Cannot have branch name anywhere but start and end')
self.pos = args
def commit_message_filter(self,commit_data):
if self.pos == 'start':
commit_data['desc'] = commit_data['branch'] + '\n' + commit_data['desc']
if self.pos == 'end':
commit_data['desc'] = commit_data['desc'] + '\n' + commit_data['branch']