1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-22 19:07:27 +01:00
php-phpbb/git-tools/hooks/prepare-commit-msg
Igor Wiedler 6a9304021f [git-tools] Improvements on prepare-commt-msg hook
prepare-commit-hook now uses `git symbolic-ref HEAD` instead of reading
$GIT_DIR/HEAD directly. This seems to be a more portable solution.

Thanks to Chris (cs278/ToonArmy) for the suggestion.
2010-03-13 13:10:14 +01:00

35 lines
842 B
Bash
Executable File

#!/bin/sh
#
# A hook to add [$branch] to the beginning of a commit message
# if certain conditions are met.
#
# This is a prepare-commit-msg hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks, example:
#
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
# .git/hooks/prepare-commit-msg
# get branch name
branch="$(git symbolic-ref HEAD)"
# exit if no branch name is present
# (eg. detached HEAD)
if [ $? -ne 0 ]
then
exit
fi
# strip off refs/heads/
branch="$(echo "$branch" | sed "s/refs\/heads\///g")"
# add [branchname] to commit message
# * only run when normal commit is made (without -m or -F;
# not a merge, etc.)
# * also make sure the branch name begins with bug/ or feature/
if [ "$2" = "" ] && [ $(echo "$branch" | grep -e "^\(bug\|feature\)/") ]
then
echo "[$branch] $(cat "$1")" > "$1"
fi