Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egit seems to ignore commit-msg hook, either in global git hooks or in repository hooks #74

Closed
davidmichaelkarr opened this issue Jan 10, 2025 · 8 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@davidmichaelkarr
Copy link

Version

7.1.0.202411261347-r

Operating System

Windows

Eclipse version

2024-12

Bug description

I have developed a small Windows application that works perfectly fine as the "commit-msg" hook with command-line git. I use it to validate the presence of a JIRA ticket id in the commit comment. I've tested it with the command-line in several different variations, and it works perfectly fine. I then tried testing the same commit test cases in Eclipse, and it seems like it is ignoring the hook entirely. My initial testing was with a global hook, using the "core.hooksPath" property, but I also tested this by storing the executable in the ".git/hooks" subdirectory of the repository. That was also apparently ignored.

Actual behavior

I tested with a comment that did not have a valid jira ticket in the comment, and it did not block the commit.

Expected behavior

I should see an error message in the commit result dialog, and it should block the commit.

Relevant log output

I saw nothing in the Eclipse log relevant to this.

Other information

No response

@davidmichaelkarr davidmichaelkarr added the bug Something isn't working label Jan 10, 2025
@tomaswolf
Copy link
Contributor

This is a git-for-windows thing that is not implemented in JGit: if git-for-windows cannot find a hook "hook-name", it looks for a file "hook-name.exe" instead, and executes that. See git-for-windows/git@235be51fbe and the current code in hooks.c. STRIP_EXTENSION is defined as ".exe" on Windows...

@davidmichaelkarr
Copy link
Author

So are you saying that it would only use the "commit-msg" hook if the file name was exactly "commit-msg", not "commit-msg.exe"? If so, that would mean it couldn't actually execute the hook, as it would need the extension for that to run.

This sure seems like a bug.

@tomaswolf
Copy link
Contributor

Exactly. It's simply not implemented in JGit. Someone would have to sit down and do so.

@davidmichaelkarr
Copy link
Author

I thought perhaps I could fool it by also storing a file named "commit-msg" with no extension in the directory (empty file), but that appeared to also have no effect.

@tomaswolf
Copy link
Contributor

I'm closing this as a duplicate of eclipse-jgit/jgit#128 then.

@tomaswolf tomaswolf closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2025
@tomaswolf tomaswolf added the duplicate This issue or pull request already exists label Jan 11, 2025
@Bananeweizen
Copy link
Contributor

I'm not using hooks, so I might be completely wrong, but wouldn't it be possible to have a non-exe hook script which calls the executable, forwards all arguments and delegates the return value, stdout, and errout?

@tomaswolf
Copy link
Contributor

Well... as I looked through the code of JGit yesterday late at night I got the impression that calling hooks is not implemented at all on Windows. (Function FS.runHookIfPresent() just returns "not supported" and is not overridden in FS_Win32.) It is implemented for Windows/Cygwin. (Minus the exe-suffix hack.) For plain Windows, one would have to call the bash delivered with git-for-windows, if that can be found. It's not entirely clear to me what to do with any paths passed as arguments or environment variables. Probably Windows-syntax but using forward slashes (like Cygwin) would work, but I'm not sure.

@davidmichaelkarr
Copy link
Author

Ok, if we DID have Cygwin or hopefully git bash installed on Windows, what would be required to get this working? I imagine I won't be able to directly use the native executable (.exe file), but if I can store a bash script called "commit-msg" that just executes the installed native application installed in the PATH, I could deal with that. I thought I read something about it detecting "cygpath" being in the global PATH. Cygwin doesn't require that, or at least that is not the case for me right now (I do have Cygwin installed), and I verified this by opening a cmd shell and looking at the PATH set there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants