Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Git hooks in eclipse
Git hooks in eclipse [message #1698215] Fri, 12 June 2015 08:41 Go to next message
Daniel van Dijk is currently offline Daniel van DijkFriend
Messages: 3
Registered: June 2015
Junior Member
In commits:
https://git.eclipse.org/r/#/c/40504/
https://git.eclipse.org/r/#/c/40506/
git hook integration was introduced for JGit.

Is it possible to make use of git hooks in eclipse? Especially the pre-commit hook.
Re: Git hooks in eclipse [message #1698499 is a reply to message #1698215] Tue, 16 June 2015 06:42 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 234
Registered: July 2009
Senior Member
simply use it. E.g. rename in your repo <root>/.git/hooks/pre-commit.sample to <root>/.git/hooks/pre-commit . Then from EGit to to commit a file with non-ascii path and you'll see the error message coming from this hook.

  • Attachment: lub14.png
    (Size: 248.02KB, Downloaded 433 times)


Ciao
Chris
Re: Git hooks in eclipse [message #1698506 is a reply to message #1698499] Tue, 16 June 2015 07:14 Go to previous messageGo to next message
Daniel van Dijk is currently offline Daniel van DijkFriend
Messages: 3
Registered: June 2015
Junior Member
This doesn't work for me. When I try to commit using Git via bash (edit: either the windows client 'Git bash', the command line or tortoise git) the hook works as expected, but Eclipse completely ignores it.

I use Eclipse Version: Luna Service Release 2 (4.4.2) on Windows and Eclipse Git Team Provider 3.7.1.201504261725-r.

Maybe the (Linux?) version you are using is newer?

[Updated on: Mon, 22 June 2015 08:00]

Report message to a moderator

Re: Git hooks in eclipse [message #1698542 is a reply to message #1698506] Tue, 16 June 2015 10:13 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 234
Registered: July 2009
Senior Member
Now I get it. You are running on windows. Typically 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). I saw the same problems as you and after installing cygwin the hooks


Ciao
Chris
Re: Git hooks in eclipse [message #1699154 is a reply to message #1698542] Mon, 22 June 2015 08:02 Go to previous messageGo to next message
Daniel van Dijk is currently offline Daniel van DijkFriend
Messages: 3
Registered: June 2015
Junior Member
I have no trouble running git hooks, the Git bash, git from command line, tortoiseGit and other programms respond to it as expected. (Note that in my previous message I used unfortunate wording when referring to the clients I'm using.)

If I understand correctly, Egit implemented all git commands natively. If this is correct, than changing git client wouldn't change anything in how Eclipse performs git commands.

Did you manage to get git hooks working in Eclipse in Windows using cygwin?

I use this script to test:
#!/bin/sh
cat <<\EOF
Not allowed to commit.
EOF
exit 1


Re: Git hooks in eclipse [message #1714882 is a reply to message #1698215] Tue, 17 November 2015 13:04 Go to previous messageGo to next message
Christoph Zauner is currently offline Christoph ZaunerFriend
Messages: 7
Registered: October 2015
Junior Member
As of JGit v4.1.0 support for hooks is only enabled when the JGit file system layer detects a POSIX or a Win32 + Cygwin file system. The JGit file system class hierachy is as follows:

->abstract class FS: Does not support hooks.
-->class FS_POSIX: Supports hooks.
-->class FS_Win32: Does not support hooks.
--->class FS_Win32_Cygwin: Supports hooks. 


The default implementation of runHookIfPresent(...) in FS does not support running hooks:

public ProcessResult runHookIfPresent(Repository repository,
		final String hookName,
		String[] args, PrintStream outRedirect, PrintStream errRedirect,
		String stdinArgs) throws JGitInternalException {
	
	return new ProcessResult(Status.NOT_SUPPORTED);
}


And how does the FS layer decide if it's running on a Win32 or FS_Win32 + Cygwin file system? The presece of a Cygwin installation is determined by the isCygwin() function in the FS_Win32_Cygwin class:

It simply checks if the Windows PATH variable contains the file cygpath.exe. See here for the source code of the FS_Win32_Cygwin class. (Reminder: The java.library.path is pre-populated with the PATH entries when running under Windows.)

So in order for the git hooks to be called by JGit when running under Windows you have to do two things:

1. Install Cygwin (do not forget to install the git package)
2. Add the Cygwin bin folder (e.g. cygwin64\system\bin) to the Windows PATH environmental variable.

- Chris
Re: Git hooks in eclipse [message #1715068 is a reply to message #1714882] Wed, 18 November 2015 22:54 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 932
Registered: July 2009
Senior Member
third option would be to implement hook support in FS_Win32, maybe you want to contribute that ?
Re: Git hooks in eclipse [message #1715070 is a reply to message #1715068] Wed, 18 November 2015 22:57 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 932
Registered: July 2009
Senior Member
in case you are considering this: here is the contributor guide
https://wiki.eclipse.org/EGit/Contributor_Guide
Re: Git hooks in eclipse [message #1716527 is a reply to message #1698215] Fri, 04 December 2015 15:12 Go to previous messageGo to next message
JP Math is currently offline JP MathFriend
Messages: 3
Registered: April 2015
Junior Member
As far as I understood, there is also support for the post-commit hook (https://git.eclipse.org/r/#/c/35791/). Do you know if this will be included in the next version of JGit?

[Updated on: Thu, 10 December 2015 08:53]

Report message to a moderator

Re: Git hooks in eclipse [message #1716689 is a reply to message #1716527] Mon, 07 December 2015 14:39 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 932
Registered: July 2009
Senior Member
this change needs to be reworked since the way how hooks are implemented in JGit changed since this change stalled
Re: Git hooks in eclipse [message #1721554 is a reply to message #1698499] Thu, 28 January 2016 09:52 Go to previous messageGo to next message
Stefano Callegari is currently offline Stefano CallegariFriend
Messages: 1
Registered: January 2016
Junior Member
Christian Halstrick wrote on Tue, 16 June 2015 06:42
simply use it. E.g. rename in your repo <root>/.git/hooks/pre-commit.sample to <root>/.git/hooks/pre-commit . Then from EGit to to commit a file with non-ascii path and you'll see the error message coming from this hook.



This not works for me.

I have also tried a my pre-commit script that works if I execute the commit by hand.

My machine is Linux (Debian SID) with the last version of eclipse and EGit (downloaded from their sites).

What I miss?

Thanks

Stefano
Re: Git hooks in eclipse [message #1722060 is a reply to message #1698215] Tue, 02 February 2016 14:40 Go to previous messageGo to next message
ran greenberg is currently offline ran greenbergFriend
Messages: 4
Registered: January 2016
Junior Member
i am also having problems with hooks on my window machine
i have Mars eclipse and i added the hooks to the <root>.git
i have installed cygwin and added it to my Windows path
but still get
An internal error occurred
Exception caught during execution of "commit-msg" hook.

is there any way to get the hooks to work ??
Re: Git hooks in eclipse [message #1722472 is a reply to message #1722060] Fri, 05 February 2016 07:59 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 932
Registered: July 2009
Senior Member
Hooks should be installed in the .git/hooks directory of the respective repository.

Are there any stack traces written to the Eclipse error log when this fails ?

Which version of EGit/Eclipse are you using ?
Re: Git hooks in eclipse [message #1722507 is a reply to message #1715068] Fri, 05 February 2016 10:42 Go to previous messageGo to next message
Christoph Zauner is currently offline Christoph ZaunerFriend
Messages: 7
Registered: October 2015
Junior Member
Matthias Sohn wrote on Wed, 18 November 2015 22:54
third option would be to implement hook support in FS_Win32, maybe you want to contribute that ?


The first thing I do when I am forced to use the Windows OS is to install Cygwin Smile Therefore I have absolutely no problem if one has to have Cygwin installed to enable git hooks in EGit. Besides, writing git hooks when you only have the tools available a naked Windows offers seems fairly cumbersome to me. I am sure hardly anybody would want to write his hooks using the cmd.exe shell.
Re: Git hooks in eclipse [message #1722660 is a reply to message #1722060] Mon, 08 February 2016 06:56 Go to previous messageGo to next message
Christoph Zauner is currently offline Christoph ZaunerFriend
Messages: 7
Registered: October 2015
Junior Member
ran greenberg wrote on Tue, 02 February 2016 14:40
i am also having problems with hooks on my window machine
i have Mars eclipse and i added the hooks to the <root>.git
i have installed cygwin and added it to my Windows path
but still get
An internal error occurred
Exception caught during execution of "commit-msg" hook.

is there any way to get the hooks to work ??


Make sure that the git hook script does use Unix style line endings (just line feed characters). Windows uses a carriage return together with line feed character as a newline separator. This can sometimes lead to problems when using Cygwin but writting the bash scripts using a Windows editor like Notepad++.
Re: Git hooks in eclipse [message #1732313 is a reply to message #1698215] Sun, 15 May 2016 15:53 Go to previous messageGo to next message
Elyahu Eaton is currently offline Elyahu EatonFriend
Messages: 3
Registered: May 2016
Junior Member
Hi,

The PATH solution didn't work for me. I am using

MARS 2
EGI 4.5.1
Jgit 4.5.2

I added the C:\...\Git\bin to my PATH as sh.exe is found there

My hook is the "update" one, which exist on the server side.

When do you accept that EGIT will fully support running the GIT hooks ?without being dependent on any environment variables that can be changed by the uses so it is actually a very big security vulnerability.

Thanks,
Eli.
Re: Git hooks in eclipse [message #1732462 is a reply to message #1732313] Tue, 17 May 2016 13:06 Go to previous messageGo to next message
Elyahu Eaton is currently offline Elyahu EatonFriend
Messages: 3
Registered: May 2016
Junior Member
Hi,

I opened a bug on that -
https://bugs.eclipse.org/bugs/show_bug.cgi?id=493721

It happens on any hook, even on a "pre-commit" which is a client side hook. EGIT is not reading the hook file at all, no output is returned when executing the relevant GIT command that suppose to trigger the hook.

Cygwin installation didn't help

using either the full path in the hook, like "/c/cygwin/bin/sh.exe", Or, putting the path to sh.exe in the PATH environment variable also didn't help.

I used a 3 line hook:
#/bin/sh.exe
echo "Here"
exit 1

IMHO it's a blocker bug, am I wrong ?

Thanks,
Eli
Re: Git hooks in eclipse [message #1732763 is a reply to message #1732462] Fri, 20 May 2016 05:30 Go to previous messageGo to next message
Lokesh Singal is currently offline Lokesh SingalFriend
Messages: 1
Registered: May 2016
Junior Member
Hello,

The same issue occurred to me when running "pre-commit" hook using eclipse Egit.

Whats worked for me was :
1. Installed cygwin64 as i have 64 bit windows, make sure you have correct "Cygwin" installed along with the git packages.
2. Set the path in your environment variable like C:\cygwin64\bin
3. Restart your system
4. My pre-commit file contained this snippet
#!/bin/sh
echo >&2 Test pre-commit hook.
	exit 1


Thanks,
Hope it might help.
Re: Git hooks in eclipse [message #1733093 is a reply to message #1732763] Tue, 24 May 2016 03:32 Go to previous messageGo to next message
Elyahu Eaton is currently offline Elyahu EatonFriend
Messages: 3
Registered: May 2016
Junior Member
Hi,

IMHO, its not a solution.

Running hooks shouldn't be dependent on PATH and installation of stuff which is totally not relevant to GIT

Thanks,
Eli
Re: Git hooks in eclipse [message #1761194 is a reply to message #1732763] Mon, 08 May 2017 18:24 Go to previous message
Kishor Patil is currently offline Kishor PatilFriend
Messages: 1
Registered: May 2017
Junior Member
Hello Lokesh,

I'm on Windows 7 Enterprise.
I'm using Spring Tool Suite 3.8.4.RELEASE (Eclipse Neaon.3 4.6.3)

I followed all your instructions :

Installed cygwin in C:\cygwin64\bin
I ensured cygpath.exe is in the bin directory
I updated my PATH to add C:\cygwin64\bin
I installed windows git bash 2.12.2.windows.2
I restarted my machine

My precommit hook works from git bash command but doesn't work from within STS.

Is there something I'm missing? Please help



Previous Topic:HELP WITH EGIT
Next Topic:Need help with JGit API and symbolic links
Goto Forum:
  


Current Time: Sat Jun 24 03:27:44 GMT 2017

Powered by FUDForum. Page generated in 0.12681 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software