Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] git hooks for [e|j]git

I think it's ok to start with this simplest possible solution.

AFAIK on some platforms spawning another process from Java copies the JVM's heap which
may cause problems on large jgit based server instances e.g. Gerrit which typically run with
a pretty large heap (we use 48GB at the moment). Hence we should have a way to disable
execution of the hooks in jgit.

Integrating the pre-commit hook with the staging view could be challenging since it's not
opened explicitly triggered by a user action. So it's not clear when to trigger this hook.


On Fri, Oct 17, 2014 at 10:25 AM, Laurent Goubet <laurent.goubet@xxxxxxx> wrote:
Hi Andrey, Team,

We are also interested at Obeo about this support for the git hooks, and we'd also be interested to contribute this into E|JGit .

We also think that the "simplest possible" solution outlined here would be sufficient for most cases... since implementing something more complex would involve unreliable solutions : the hooks must be defined "per repository"; so they must be somehow read directly from the repository. If we implemented them in Java so that EGit and JGit can have their own hooks API, we'll need to involve class loaders and that too often proves too bug-prone for too litle gain. Reading and executing the hooks as cgit does seems like the most reliable solution, even if not the most portable.

As I gather, there are currently 12 client-side hooks available to command line users :
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • post-rewrite
  • applypatch-msg
  • pre-applypatch
  • post-applypatch
  • pre-rebase
  • post-checkout
  • post-merge
  • pre-auto-gc

They're named with these hard-coded strings as their file name and are set as executable, and located in the <git repo>/.git/hooks folder. Only one of each is allowed (though that "one" can be specifically designed to chain others). They can be written in just about any language available on the user machine.

These work well on linux but will fail on windows, unless executed through msysgit or a unix-emulator such as cygwin... I think that having the same limitation in E|JGit is not really an issue. The implementation should probably use FS#runInShell(...) instead of Runtime.exec(...) to make use of cygwin when detected though.

Andrey didn't receive any answer to his proposal to contribute last month. Should we implement that proposal and push a patch to gerrit? Andrey, would you be interested in splitting the effort somehow?

Laurent Goubet

On 16/10/2014 16:10, Andrey Loskutov wrote:

We at Advantest see the need of adding pre-commit/pre-receive etc hooks to [e|j]git so that egit UI behavior "matches" CLI git behavior as defined in [1].

I think I found related bug [2] and asked there what the smallest possible implementation should do, but so far no one responded. Therefore I would like to ask same question here again.

Is support for pre-/post- etc hooks on anyone plan for [e|j]git 3.6? 
If not, does it make sense to add it to?

I'm offering to contribute simplest possible "Runtime.exec()" based solution which would "just work", but I would like to know what is the common agreement on the requested functionality.

IMHO the smallest possible implementation would need:

 * somehow read all the available hooks
 * run the appropriate git hook before/after appropriate jgit command using "Runtime.exec()" or platform-dependent "execution" API hook (similat to FS hooks)
 * allow to have egit UI callbacks for prompting/displaying hook output etc

Anything I'm missing here (for the *basic* feature set)?


Kind regards,
Andrey Loskutov
jgit-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

jgit-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top