Skip to content

Instantly share code, notes, and snippets.

@eXeC64
Created October 16, 2014 12:54
Show Gist options
  • Save eXeC64/c826a07fba21edac8d95 to your computer and use it in GitHub Desktop.
Save eXeC64/c826a07fba21edac8d95 to your computer and use it in GitHub Desktop.
git prepare-commit-msg hook for Mantid
#!/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