0

I am working in Eclipse Mars (4.5.2) with EGit (4.1.1) on Windows8. I try to launch a pre-commit hook from within eclipse using GitForWindows.

I started the pre-commit file with: #!/bin/sh

and gave the PATH Variable GITFORWINDOWS with the path to the bin folder in which the sh.exe of my GitForWindows installation is stored (C:\Program Files\Git\bin).

If I do git commit in the GitBash, pre-commit is executed correctly, thus an error is thrown if a certain string is detected in the staged files. If I commit in Eclipse nothing happens. What am I doing wrong?


EDIT

I tried it with Cygwin as well. While it is working from the cygwin terminal (as well as from the GitInWindows terminal) it is not working from within eclipse.

I set the PATH to C:\cygwin64\bin where the sh.exe is.

Can line returns be a problem? I have LF so far.

Rattlesnake
  • 143
  • 3
  • 12
  • Possible duplicate of [Egit hooks do not get triggered](http://stackoverflow.com/questions/6232026/egit-hooks-do-not-get-triggered) – Rüdiger Herrmann Apr 22 '16 at 12:23
  • EGit and JGit support (some) hooks since 4.2. See here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=299315 – Rüdiger Herrmann Apr 22 '16 at 12:24
  • In the duplicate you proposed I found no solution to my problem though! It only mentions that git hooks are implemented in EGit by now and should be working. – Rattlesnake Apr 25 '16 at 06:21
  • As I said in the above comment: EGit 4.1 does not yet support hooks. If you follow the link to [bug 299315](https://bugs.eclipse.org/bugs/show_bug.cgi?id=299315) in the answer, you'll read the EGit 4.2 has some support for hooks. But you are using EGit 4.1 – Rüdiger Herrmann Apr 25 '16 at 07:27

2 Answers2

0

To run hooks from with in Eclipse (Egit) you need to do the following:

Hooks are implemented as scripts which need to be executed by "/bin/sh".

But on a plain windows machine you don't have a sh.exe.
So, you need to install cygwin and add <cygwin_root>/bin to your PATH.

Make sure that during cygwin installation you also install git (because the hook scripts want to execute git commands).

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • In [this answer](http://stackoverflow.com/questions/32440968/hook-is-not-working-eclipse-egit-client) GitForWindows is named as alternative for Cygwin. What is the difference between the two of them? I found a sh.exe in GitForWindows as well – Rattlesnake Apr 22 '16 at 11:41
  • Since version 2 there is a new windows client names GitForWindows which is an alternative git windows client. It has some special code for windows and it can be found here: https://github.com/git-for-windows – CodeWizard Apr 22 '16 at 11:42
  • I would like to use GitForWindows instead of Cygwin, as it is installed already. If it is an equivalent alternative I should be able to use it for the hooks, setting the `PATH` variable to its `sh.exe`. Still it doesn't work. – Rattlesnake Apr 25 '16 at 06:23
0

Setting the PATH variable for Cygwin worked in the end. I had to restart the computer though.

It still is not working for GitForWindows. This might be due to the fact that JGit has a FS_Win32_Cygwin class which extracts the path to the sh.exe from the 'PATH' variable. Such a class might not exist for GitForWindows (yet). More information here.

The version (4.1.1) of my EGit doesn't seem to play a role.

Rattlesnake
  • 143
  • 3
  • 12