Git discovery in cache after checking that we are creating a new branch

I would like to run the script locally when the branch is created.

I found that I have to use the hook after checking 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 the new rev is not NULL_SHA1 expected, but the old rev has exactly the same. From the git documentation, this seems logical. And then there is no echo at all from action_meth()

.

My question is, how can I detect that the branch we are moving on is a newly created branch (and this is local as the point new rev == NULL_SHA

seems to be acceptable when using the server side of grabbing updates).

+3


source to share


1 answer


I suppose the client post-checkout hook is called after the branch is created .
This means that it is not designed to detect the creation of a branch.

Anything you could check if:



0


source







All Articles