I need a way to delete Git repository branches more conveniently cause an `update hook' is blocking them:
Command
git push -v -f --no-verify --delete origin test_branch
Output
remote: fatal: Not a valid commit name 0000000000000000000000000000000000000000
remote: error: hook declined to update refs/heads/test_branch
I'm currently disabling the update hook temporarily, performing the delete, and then restoring the hook, so I'm looking for suggestions for something better, even perhaps altering the Perl Git hook.
I don't know anything about Perl or Git hooks, so I have these questions
I can't give a message to the
push
action. What is the best way to achieve something like this?Is there any way to get the
push --delete
event from the hook?Something like
if ${push --delete} then skip hook checks
Is there any way to create a custom parameter to the
push
operation in order to skip the hook? Something likeif command line contains --imgod then skip hook checks
I'm totally groping in the dark.
This is the update
hook definition from the Git documentation
UPDATE HOOK This hook is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. Just before updating the ref on the remote repository, the update hook is invoked. Its exit status determines the success or failure of the ref update.
The hook executes once for each ref to be updated, and takes three parameters:
the name of the ref being updated,
the old object name stored in the ref,
and the new object name to be stored in the ref
A zero exit from the update hook allows the ref to be updated. Exiting with a non-zero status prevents git-receive-pack from updating that ref.
This hook can be used to prevent forced update on certain refs by making sure that the object name is a commit object that is a descendant of the commit object named by the old object name. That is, to enforce a "fast-forward only" policy.
It could also be used to log the old..new status. However, it does not know the entire set of branches, so it would end up firing one e-mail per ref when used naively, though. The post-receive hook is more suited to that.
In an environment that restricts the users' access only to git commands over the wire, this hook can be used to implement access control without relying on filesystem ownership and group membership. See git-shell[1] for how you might use the login shell to restrict the user’s access to only git commands.
Both standard output and standard error output are forwarded to git send-pack on the other end, so you can simply echo messages for the user.
The default update hook, when enabled—and with hooks.allowunannotated config option unset or set to false—prevents unannotated tags to be pushed.
ANSWER:
i found a way to catch the branch deletion event into the update hook and to skip the logic of the hook in all the other cases:
zero="0000000000000000000000000000000000000000"
if [ "$refname" == "refs/heads/*"] && [ "$newrev" == "$zero" ];
then
exit 0
else
perform_your_checks()
fi
more info can be found in the update.sample GIT template.