diff --git a/README.md b/README.md index b808d88..34c6bf0 100644 --- a/README.md +++ b/README.md @@ -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} diff --git a/plugins/branch_name_in_commit/README.md b/plugins/branch_name_in_commit/README.md new file mode 100644 index 0000000..b11982b --- /dev/null +++ b/plugins/branch_name_in_commit/README.md @@ -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)`. diff --git a/plugins/branch_name_in_commit/__init__.py b/plugins/branch_name_in_commit/__init__.py new file mode 100644 index 0000000..20abe5b --- /dev/null +++ b/plugins/branch_name_in_commit/__init__.py @@ -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']