Skip to content

Instantly share code, notes, and snippets.

@matagus
Created July 20, 2010 22:15
Show Gist options
  • Save matagus/483686 to your computer and use it in GitHub Desktop.
Save matagus/483686 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from mercurial import util
import re
def check_references(*args, **kwargs):
"""
Checks that commit message contains a reference to or closes an issue.
Useful when using Redmine.
Usage in .hgrc:
[hooks]
pretxncommit = python:/path/to/this/file.py:check_references
"""
repo = kwargs["repo"]
node_id = kwargs["node"]
changeset = repo[node_id]
description =changeset.description()
DESCRIPTION_CHECKS = (
"this references #\d+", "this closes #\d+",
)
lets_commit = False
for regexp in DESCRIPTION_CHECKS:
if re.search(regexp, description, re.I):
# message is ok, let's commit!
lets_commit = True
break
if lets_commit:
return False
# this will rollback the changeset
raise util.Abort("Please reference some issue using "\
"'This references #<issue>' or close it using 'This closes #<issue>'.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment