Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git hooks : is there a clone hook?

We want to store some meta-information about the commit in an external database. During a clone or a checkout, this database should be referred and we copy the meta information to a file in the repo which is cloned. The database is required rather than just using a file is for the sake of indexing and searches etc ...

I thought if there is a clone hook, we could trigger this. I couldn't find the clone hooks in the sample in .git/hooks. is there one? is post-checkout hook the only possibility at client side?

like image 495
maxmelbin Avatar asked Apr 19 '12 12:04

maxmelbin


People also ask

Are Git hooks shared?

Introduction. Git hooks are a useful feature that can be used to manage the integrity of your source repository, it becomes much handier if the hooks can be shared between team members, as the hooks are localized to once's device's single project. Since all the git hook templates reside inside the folder .

Are git hooks cloned?

Hooks are local to any given Git repository, and they are not copied over to the new repository when you run git clone . And, since hooks are local, they can be altered by anybody with access to the repository.

What does hooks consist of in git?

Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle.


2 Answers

ok, one way to do this is to use the clone --template option.

Specify the location where the client side hooks will be stored as value to the --template switch. The hooks are copied to the clone, and the post-checkout hook is fired immediately!

like image 184
maxmelbin Avatar answered Oct 02 '22 01:10

maxmelbin


When you clone a remote repository, you can't run any client-side hooks because hooks are local to your working copy, and you're creating one from scratch. When you pull new changes from a remote repository, git will run your local post-merge hook if it exists.

There is nothing run on the server as the result of a pull operation. A push operation will trigger the servers's update and post-update hooks.

See the Git Book for more information.

like image 23
larsks Avatar answered Oct 01 '22 23:10

larsks