Skip to content

Commit

Permalink
Merge branch 'PR/199'
Browse files Browse the repository at this point in the history
Closes #199
  • Loading branch information
frej committed Feb 8, 2020
2 parents fa8ebd9 + 8efbb57 commit 4bc6dec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
12 changes: 11 additions & 1 deletion plugins/branch_name_in_commit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
25 changes: 17 additions & 8 deletions plugins/branch_name_in_commit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 4bc6dec

Please sign in to comment.