Created
May 3, 2012 04:40
-
-
Save keyo/2583189 to your computer and use it in GitHub Desktop.
HG Fogbugz Mercurial Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
HG Fogbugz Mercurial Extension | |
Prevents committing bad BugIDs | |
Add to .hgrc or mercurial.ini | |
[extensions] | |
fogbugz = C:\Users\User\hg_extensions\hgfogbugz.py | |
""" | |
import re | |
import mercurial, sys, os | |
_branch_regex = re.compile('(feature|bug|case|bugid|fogbugz)_(?P<bugid>\d+)') | |
_commit_regex = re.compile(r'\b(?P<case>(review|case|bug[zs]?(\s| )*(id)?:?)s?(\s| )*([#:; ]| )+)((([ ,:;#]|and)*)(?P<bugid>\d+))+',re.I) | |
def pretxncommithook(ui, repo, **kwargs): | |
""" | |
Checks a single commit message for adherence to commit message rules. | |
To use add the following to your project .hg/hgrc for each | |
project you want to check, or to your user hgrc/mercurial.ini to apply to all projects. | |
[hooks] | |
pretxncommit.hgfogbugz = python:hgfogbugz.pretxncommithook | |
""" | |
commit_message = repo['tip'].description() | |
branch = repo['tip'].branch() | |
commit_match = _commit_regex.match(commit_message) | |
branch_match = _branch_regex.match(branch) | |
if commit_match and branch_match and (commit_match.group('bugid') != branch_match.group('bugid')): | |
ui.warn('Commit bugid does not match with branch name bugid.\n') | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment