Bug 581417 - JGit lfs does not recognize the pre-push hook from git lfs and incorrectly warns the user about a hook conflict
Summary: JGit lfs does not recognize the pre-push hook from git lfs and incorrectly wa...
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 6.2   Edit
Hardware: All Windows 11
: P3 normal with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-25 05:29 EST by Simon Sohrt CLA
Modified: 2023-11-27 04:59 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Sohrt CLA 2023-01-25 05:29:04 EST
This bug occurs, when git lfs and jgit lfs are used simultaneously in the same repo. git lfs installs a pre-push commit into lfs repos. 

The presence of this pre-push hook is detected by jgit lfs in org.eclipse.jgit.hooks.Hooks.prePush(). Unfortunately, jgit does not recognize that the hook was installed by git lfs and incorrectly warns the user with the following message: "LFS built-in hook conflicts with existing pre-push hook in repository". Even though jgit lfs warns the user, the correct PrePushHook-object is created by jgit and everything works as expected. 

This bug was always present in jgit lfs, but I only started observing this bug after using eclipse 2022-12. The reason for this is that the following bug was fixed in egit: https://bugs.eclipse.org/bugs/show_bug.cgi?id=580910. Now the erroneous output of jgit is shown to the users of eclipse 2022-12 (before the bugfix, the output was simply now shown).

I suggest the following solution: jgit lfs tries to determine if the pre-push hook was installed by git lfs. If jgit lfs recognizes the hook, no error output is shown to the user. If jgit lfs does not recognize the pre-push hook, the error message is shown to the user. This is also the approach that git lfs uses (see here: https://github.com/git-lfs/git-lfs/blob/main/lfs/hook.go). The downside of this solution is that the pre-push hook might change in the future (there are already three versions of this pre-push hook that git lfs installs and recognizes). Thus every time git lfs updates the pre-push hook, jgit must also be updated to detect the newly added pre-push hook. 

Another solution might be that jgit always executes the PrePushHook and after that, it executes the native pre-push hook. The upside of this solution is that changes of the pre-push by git lfs must not be monitored. The downside is that jgit is now behaving differently from git, because jgit is now executing two pre-push hooks, but git is only able to execute one pre-push hook (see: https://github.com/git-lfs/git-lfs/issues/2865#issuecomment-475445369).
Comment 1 Simon Sohrt CLA 2023-11-27 04:59:32 EST
I am willing to work on this issue, but only if there is a realistic chance for a merge. 

What requirments must the patch fulfill to be merged? Which of the two proposed solutions (see comment above) is preferred by the JGit maintainers?