Skip to content

Instantly share code, notes, and snippets.

@attila
Created February 12, 2015 15:20
Show Gist options
  • Save attila/175dd0e42c7795f232db to your computer and use it in GitHub Desktop.
Save attila/175dd0e42c7795f232db to your computer and use it in GitHub Desktop.
Enforce ticket references in Mercurial commit messages in Sourcetree on OS X
[ui]
username=John Doe <johndoen@example.com>
[hooks]
pretxncommit = ~/bin/requireCaseId.sh
#!/bin/bash
# Check that a commit contains ticket references
# Path to hg executable.
HG_BIN="/Applications/SourceTree.app/Contents/Resources/mercurial_local/$HG"
PATTERN="(\<[A-Z]+-[0-9]+|(none)) +(.*)+|(^merge)|(tag .+ for changeset [0-9a-f]{12})"
$HG_BIN log -r $HG_NODE:$HG_NODE --template {desc} | egrep -q "$PATTERN"
result=$?
if [ $result -ne 0 ]; then
echo
echo 'Missing JIRA ticket number, please add "PROJECT-1234" or "PROJECT-none".
Ensure you add a meaningful commit message as well.'
echo
fi
exit $result
#!/bin/bash
# Check that a commit contains ticket references
# Path to hg executable.
HG_BIN="/Applications/SourceTree.app/Contents/Resources/mercurial_local/$HG"
PATTERN="(\<Case:? *[0-9]|(none))|(^merge)|(tag .+ for changeset [0-9a-f]{12})"
$HG_BIN log -r $HG_NODE:$HG_NODE --template {desc} | egrep -q -i "$PATTERN"
result=$?
if [ $result -ne 0 ]; then
echo
echo 'Commit message does not contain "Case (number)" or "Case: none"'
echo
fi
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment