From 6a9304021f41cd8319ccb009bb24792ffc5438bc Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 13 Mar 2010 13:04:44 +0100 Subject: [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. --- git-tools/hooks/prepare-commit-msg | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'git-tools/hooks/prepare-commit-msg') diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index e1e05d67b8..354b539cc1 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -10,15 +10,25 @@ # # ln -s ../../git-tools/hooks/prepare-commit-msg \\ # .git/hooks/prepare-commit-msg -# -# Make sure it is executable. -# strip off ref: refs/heads/ -branch="$(cat $GIT_DIR/HEAD | sed 's/ref: refs\/heads\///g')" +# 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" +if [ "$2" = "" ] && [ $(echo "$branch" | grep -e "^\(bug\|feature\)/") ] +then + echo "[$branch] $(cat "$1")" > "$1" fi -- cgit v1.2.1 From 3e5236dcd62f1d0b18cd3c92661a2287b5bbf2d6 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 3 Apr 2010 02:13:48 +0100 Subject: [git-tools] Prepend the branch to the commit message for all branches. --- git-tools/hooks/prepare-commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools/hooks/prepare-commit-msg') diff --git a/git-tools/hooks/prepare-commit-msg b/git-tools/hooks/prepare-commit-msg index 354b539cc1..033cb187c7 100755 --- a/git-tools/hooks/prepare-commit-msg +++ b/git-tools/hooks/prepare-commit-msg @@ -28,7 +28,7 @@ branch="$(echo "$branch" | sed "s/refs\/heads\///g")" # * 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\)/") ] +if [ "$2" = "" ] then echo "[$branch] $(cat "$1")" > "$1" fi -- cgit v1.2.1