Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which language can I use to write a hook script in Git?

Tags:

githooks

I would like to know the script languages that you can use inside hook script in Git.

I have been reading about how to use Git hooks but I have not seen anywhere the language that can be used, I have seen some examples that look they are written in Perl but I am not sure of that since I have never programmed in Perl.

like image 219
Sergio Prats Avatar asked Feb 07 '18 15:02

Sergio Prats


People also ask

Which scripting language is used in the default sample hook files?

The built-in scripts are mostly shell and PERL scripts, but you can use any scripting language you like as long as it can be run as an executable.

How do you make a commit 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.

What is the best description for Git hooks?

Git hooks are simple scripts that run before or after certain actions. They are useful for a variety of tasks, but primarily I find them useful for client-side validation so simple mistakes can be prevented. For example, you can test syntax on files being committed, you can even have tests run.


1 Answers

Any language, compiled or interpreted can be used (as long as the appropriate interpreter is available on the system).

The only requirement for hooks that run before events (e.g. pre-commit, pre-rebase, pre-push etc) and are allowed to block the event processing is to return the exit code 0 for success (let the operation continue) or a non-zero exit code to abort the operation.

The exit codes of the hooks that run after events (e.g. post-checkout, post-commit etc) do not matter; they cannot change anything, what had to be done has already been done before they were invoked.

Read the "Customizing Git - Git Hooks" page from the Git Book for details.

like image 75
axiac Avatar answered Sep 23 '22 16:09

axiac