##
# Collection of git functions
# vim: set filetype=sh
##

##
# Get commit message for pre-receive commit or received commit
##
function get_commit_message() {
	declare commit="$1"

	if [ -z "$commit" ]; then
		echo >&2 'Error: Commit not provided from which to extract message'
		return 1
	fi

	local commitmsg=`git --git-dir=$GIT_DIR cat-file commit $commit | sed '1,/^$/d'`

	if [ $? -gt 0 ]; then
		echo >&2 "Error: Problem extracting commit message from $commit. Message: $commitmsg"
		return 1
	fi

	echo "$commitmsg"

	return 0
}
