Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Last active June 30, 2016 17:00
Show Gist options
  • Save FMCorz/ce6250e01ace1edb1dcaa6ec69568532 to your computer and use it in GitHub Desktop.
Save FMCorz/ce6250e01ace1edb1dcaa6ec69568532 to your computer and use it in GitHub Desktop.
Prepare commit message hook for Moodle
# Add this to .git/hooks/prepare-commit-msg
# Then chmod +x .git/hooks/prepare-commit-msg
#
# /!\ Note, it is assumed that you have the alias `git cb`
# which returns the current branch.
if [ -z "$2" ]; then
branch=`git cb`
mdl=`expr match "$branch" 'MDL-\([0-9]\+\)-.*'`
if [ -n "$mdl" ]; then
echo -n "MDL-$mdl \n" > .git/CREATECOMMITMSG
cat $1 >> .git/CREATECOMMITMSG
mv .git/CREATECOMMITMSG $1
fi
fi
[alias]
cb = "!echo $(b=$(git symbolic-ref -q HEAD); { [ -n \"$b\" ] && echo ${b##refs/heads/}; } || echo HEAD)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment