FMCorz
5/24/2016 - 2:43 AM

Prepare commit message hook for Moodle

Prepare commit message hook for Moodle

[alias]
        cb = "!echo $(b=$(git symbolic-ref -q HEAD); { [ -n \"$b\" ] && echo ${b##refs/heads/}; } || echo HEAD)"
# 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