Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why it is not possible to git add .git/hooks/my-hook

I would like to have some hooks always present in a clone of a given repository. Is there a way to add a file in .git/hooks in the repository?

Thanks

like image 727
Mildred Avatar asked Mar 02 '11 08:03

Mildred


People also ask

Where do I put my git hooks?

All Git hooks are ordinary scripts that Git executes when certain events occur in the repository. This makes them very easy to install and configure. Hooks can reside in either local or server-side repositories, and they are only executed in response to actions in that repository.

How do you attach a Precommit hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

Can I push git hooks to remote?

You can import a remote Git repository in to Business Central and configure a post-commit Git hook to automatically push changes to that remote repository.


2 Answers

It is possible to define your own hooks in a git template, but even there, those hooks would be non-executable ones.

I.e. the user would still have to activate them (rename or activate the executable bit) once the repo is cloned.
That way, said user won't have any unwanted script executed without his/her full knowledge and explicit approval.
Doing otherwise would be too much of a security risk for anyone "blindly" cloning a repo.

like image 54
VonC Avatar answered Sep 18 '22 19:09

VonC


Sounds like a security risk to me. Just because you clone some repository doesn't mean you want to give it the right to execute code.

You could put a copy of hooks into the versioned code and include some script file to allow the user to copy them to his hooks directory easily. And of course one you have hooks installed you can use them to keep themselves up-to-date.

like image 26
CodesInChaos Avatar answered Sep 21 '22 19:09

CodesInChaos