0

I am trying to plug egit in Eclipse to run my pre-commit hooks. But it doesn't seem to work.

I found a similar SO Question but that doesn't seem to be working in my case.

Here is what all I got as required tools

  1. GitForWindows in place
  2. Pre-commit hooks configured
    • Works well from command line and Tortoise git as well.

As suggested from answers and comments section in the aforementioned linked question, I did add the cygpath.exe empty file in C:\Program Files\Git\bin and put this in path. Also, I verified that cygpath.exe is already available in C:\Program Files\Git\usr\bin alongside ssh.exe, bash.exe.

Again, both C:\Program Files\Git\bin and C:\Program Files\Git\usr\bin are added to System variables and user variables under Environment variables in my Windows 10.

Additional info

  • Eclipse Version: Photon Release (4.8.0)
  • Eclipse Egit : 5.x version
srk
  • 4,857
  • 12
  • 65
  • 109
  • You will find more information in the Eclipse forum: https://www.eclipse.org/forums/index.php?t=msg&th=1067404&goto=1698542msg_1698542 – howlger Aug 30 '18 at 13:48
  • @howlger: Thanks for link, but that didn't help – srk Aug 31 '18 at 10:57

1 Answers1

3

Hooks in EGit/JGit on Windows do not require Git for Windows to be installed (JGit implements Git in Java, it does not redirect to the command line Git).

The installation directory of cygpath.exe must be in the PATH because Cygwin is required on Windows to execute a Git hook (which is bash scripts).

In your case, the empty cygpath.exe file will cause the wrong directory to be used.

For more details see this Eclipse forum discussion or look into the JGit Java code here.

See also this blog post by Christoph Zauner with more details (note, the list of supported hooks is outdated, but the concepts are still the same).

howlger
  • 31,050
  • 11
  • 59
  • 99
  • @howgler: I configured hooks in another directory instead of default `.hooks/` and updated in `config`, but now to make egit plugin understand, just placed pre-commit file in `.hooks` and it worked partially. BUT, my powershell console output is not displayed in eclipse egit alert box. It simply says, ` Rejected by "pre-commit" hook.` – srk Aug 31 '18 at 14:04
  • Yes. Unfortunately, this has not yet been implemented. See [Eclipse bug 536659](https://bugs.eclipse.org/bugs/show_bug.cgi?id=536659) (you might vote for this bug and comment there). – howlger Aug 31 '18 at 15:10
  • This blog deep-dives into the issue and is quite worth a read to better understand: https://zauner.nllk.net/post/0001-git-hooks-currently-supported-by-jgit/ – Robert Sep 02 '20 at 16:38
  • @Robert Thanks for the link. I have added it to my answer. – howlger Sep 02 '20 at 23:12