Created
February 12, 2015 15:20
-
-
Save attila/175dd0e42c7795f232db to your computer and use it in GitHub Desktop.
Enforce ticket references in Mercurial commit messages in Sourcetree on OS X
This file contains hidden or 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
[ui] | |
username=John Doe <[email protected]> | |
[hooks] | |
pretxncommit = ~/bin/requireCaseId.sh |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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