Created
October 16, 2014 12:54
-
-
Save eXeC64/c826a07fba21edac8d95 to your computer and use it in GitHub Desktop.
git prepare-commit-msg hook for Mantid
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
#!/bin/sh | |
#Don't do anything on merge commits | |
[ "$2" = "merge" ] && exit 0 | |
#If there's already a message, do nothing | |
[ "$2" = "message" ] && exit 0 | |
[ "$2" = "template" ] && exit 0 | |
#For squash messages do nothing | |
[ "$2" = "squash" ] && exit 0 | |
CHANGES=$(git diff --staged | sed -e 's/^/#/') | |
#For ammending commits, merely add a diff to the end | |
if [ "$2" = "commit" ]; then | |
echo "#" >> "$1" | |
echo "$CHANGES" >> "$1" | |
exit 0 | |
fi | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
REF=$(echo "$NAME" | sed -r -e 's|.*/([0-9]+)_.*|Refs #\1|') | |
MSG=$(git status | sed -e 's/^/#/') | |
#For new changes, rewrite it ourselves | |
if [ "$NAME" != "(no branch)" ]; then | |
echo "$REF" > "$1" | |
echo "#" >> "$1" | |
echo "$MSG" >> "$1" | |
echo "#" >> "$1" | |
echo "$CHANGES" >> "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment