Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pre-fetch hook functionality in git

Tags:

git

in my scenario i maintain a svn-synchronized git repository on a server. all developers in my group use this repository to get their updates.
i couldn't find a way to trigger an automatic "git svn fetch" (or any other command) before a developer fetches the latest changes.
my current workaround is to have a cron job that syncs in svn related changes every 5 minutes. is it possible to have this kind of a pre-fetch hook at all?
thanks

like image 829
oliver Avatar asked Aug 07 '09 09:08

oliver


People also ask

What is pre hook git?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.

How pre-commit hook works?

The hook runs before a commit is accepted to git, and if the hook script fails (ie if it returns a non-zero exit code) the commit is aborted. This is powerful! It means you can automatically run linters to statically analyze your code and make sure it is high quality and syntax-error-free before the code is committed.

What is the use of hooks 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.

What are pre hooks?

pre-hook (plural pre-hooks) (computing, programming) A section of code that runs immediately before a hook call.


1 Answers

There is no pre-defined hook that will allow you to do exactly what you want.

If your developers are fetching over ssh, you might be able to create a wrapper script for git-upload-pack which hides the real git-upload-pack and calls git svn fetch on the repository (while being absolutely sure to squash all output and errors) before execing the real git-upload-pack.

This might be quite fiddly to set up and make robust, though. You might be better off providing a way for your developers to manually cause a call to git svn fetch on the remote repository and encouraging them to use an alternative fetch alias that does this first (and waits for it to complete!) before doing the real fetch.

like image 101
CB Bailey Avatar answered Sep 17 '22 15:09

CB Bailey