vintrojan
vintrojan

Reputation: 1547

How to execute a client-side Git hook?

I am having problem while implementing a pre-push hook. The developers need to run a static code analyzer before they push the code to the git repo. But usually they don't and hence break the build.

Thus, I have written a pre-push hook; which is a shell script to execute the static code analysis ( and copied to .git/hooks) directory but it is not working correctly. This has to be a client-side hook but it is not working as expected. And I dont want to implement this functionality in a pre-commit or post-commit hook since I want static code analysis to be done on the developer's machine before he/she pushes the code (and not when he/she) commits the code.

Thus, please provide your insight as to how I can execute a task (static code analysis) on the client machine before git push command.

Upvotes: 0

Views: 1132

Answers (1)

kba
kba

Reputation: 1177

As @sestus said, hooks need to be set up client-side, they are not part of the Git repository. It makes sense if you consider that Git is a distributed system and hooks can execute arbitrary code.

What you can do is check in the script into the repository (e.g. to $REPO_ROOT/git-hooks/pre-push) and use the build toolchain of your project to set the up a symlink (ln -s ../../git-hooks/pre-push .git/hooks).

Upvotes: 1

Related Questions