I would like to launch a script locally when a branch is created.
I found that i must use a post-checkout hook and wrote the following script :
#! /bin/sh
# update hook
oldrev=$1
newrev=$2
type=$3
branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
echo "branch is $branch_name"
echo "oldrev is $oldrev and newrev is $newrev"
type_shortname(){
type="branch"
shortname="$(git symbolic-ref HEAD --short)"
}
NULL_SHA1=0000000000000000000000000000000000000000
if test $type = 1;then
type_shortname
fi
echo $type
echo $shortname
case $oldrev,$newrev in
$NULL_SHA1,*) action=create;;
*,*);;
esac
action_meth()
{
echo "create"
}
case $action,$type in
create,branch) action_meth;;
* );;
esac
exit 0
But new rev is not NULL_SHA1 has expected but exactly the same has old rev. From the git documentation it seems logical. And then no echo at all from action_meth()
.
My question is how can i detect that the branch on which we are moving is a newly created branch (and this locally as the point of new rev == NULL_SHA
seems to be ok when using an update hook server side).