Merge branch 'PR/199'

Closes #199
This commit is contained in:
Frej Drejhammar
2020-02-08 16:05:01 +01:00
2 changed files with 28 additions and 9 deletions

View File

@@ -6,5 +6,15 @@ 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.
Valid arguments are:
- `start`: write the branch name at the start of the commit
- `end`: write the branch name at the end of the commit
- `sameline`: if `start` specified, put a colon and a space
after the branch name, such that the commit message reads
`branch_name: first line of commit message`. Otherwise, the
branch name is on the first line of the commit message by itself.
- `skipmaster`: Don't write the branch name if the branch is `master`.
To use the plugin, add
`--plugin branch_name_in_commit=(start|end)`.
`--plugin branch_name_in_commit=<comma_separated_list_of_args>`.

View File

@@ -3,12 +3,21 @@ def build_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
args = {arg: True for arg in args.split(',')}
self.start = args.pop('start', False)
self.end = args.pop('end', False)
self.sameline = args.pop('sameline', False)
self.skip_master = args.pop('skipmaster', False)
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']
if self.sameline and not self.start:
raise ValueError("sameline option only allowed if 'start' given")
if args:
raise ValueError("Unknown args: " + ','.join(args))
def commit_message_filter(self, commit_data):
if not (self.skip_master and commit_data['branch'] == 'master'):
if self.start:
sep = ': ' if self.sameline else '\n'
commit_data['desc'] = commit_data['branch'] + sep + commit_data['desc']
if self.end:
commit_data['desc'] = commit_data['desc'] + '\n' + commit_data['branch']