Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Git hooks in python/bash scripts [closed]

Tags:

git

githooks

I have recently needed to write git hooks, for all commits to reference a particular ticket.

I was hoping for a place to start learning. All the stuff in the pro git book is written in Ruby. Since Ruby is not my strong suit, can anybody share tutorials about git hooks written in other languages? (I'd particularly prefer Python or Bash scripts.)

like image 329
myusuf3 Avatar asked Jul 22 '10 17:07

myusuf3


People also ask

Can I write a Git hook in Python?

All the examples are written as shell scripts, with some Perl thrown in, but any properly named executable scripts will work fine – you can write them in Ruby or Python or whatever language you are familiar with. If you want to use the bundled hook scripts, you'll have to rename them; their file names all end with .

How are Git hooks executed?

The pre-receive hook is executed every time somebody uses git push to push commits to the repository. It should always reside in the remote repository that is the destination of the push, not in the originating repository.

How do I disable pre-commit hooks?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.


1 Answers

Here is an example of using Python for a hook. In general the hooks are language agnostic. You use the script to do some work or to exit with a 0/other return code to alter the flow of a git process.

like image 191
Peter Loron Avatar answered Sep 23 '22 22:09

Peter Loron