Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
HG Fogbugz Mercurial Extension
HG Fogbugz Mercurial Extension
Prevents committing bad BugIDs
Add to .hgrc or mercurial.ini
fogbugz = C:\Users\User\hg_extensions\
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.
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 ('bugid') !='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
You can’t perform that action at this time.