Bug 516419 - Quarantined commits cannot be parsed in the pre-receive hook
Summary: Quarantined commits cannot be parsed in the pre-receive hook
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.8   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-10 10:45 EDT by ákos tajti CLA
Modified: 2017-05-11 05:13 EDT (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 ákos tajti CLA 2017-05-10 10:45:27 EDT
We built a pre-receive hook to check the format of the commit messages before they're accepted. For this we call a java application from the hook which is built on JGit. We use a RevWalk object to walk through the new commits. Since git 2.11 this solution does not work, because the line below throws an exception:

RevCommit commit = rw.parseCommit(ref.getLeaf().getObjectId());
rw.markStart(commit); // the exception is thrown here

The exception:

Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing commit c96c33d3c9a7793836caa6260a5fd69637d348ca
	at org.eclipse.jgit.storage.file.WindowCursor.open(WindowCursor.java:126)
	at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:855)
	at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:136)
	at org.eclipse.jgit.revwalk.RevWalk.markStart(RevWalk.java:282)
	at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:237)
	at org.eclipse.jgit.api.LogCommand.add(LogCommand.java:155)

As far as I understood the problem is that git no longer stores the new commits in the repo, but stores them in the quarantine. Is there a way to access the commits in the quarantine using JGit?
Comment 1 Christian Halstrick CLA 2017-05-11 02:22:23 EDT
What do you mean with "since git 2.11". What is the exact use case and how does the native git version comes into play. Are you running JGit and native git parallel on repos on the server side?
Comment 2 ákos tajti CLA 2017-05-11 03:08:56 EDT
Hi Christian,

yes, we run native git on the server and we call the java code from the pre-receive hook started by the native git. And this is where jgit comes into play. So the pre-receive hook starts the java app built on jgit and we try to parse the incoming changes. 
Since git 2.1.1 our code does not work, I guess because the incoming changes are stored in a quarantine directory since that version.
Comment 4 Christian Halstrick CLA 2017-05-11 05:13:39 EDT
Ok, thanks for the explanation. Now I got the point.

Yes, I think you are pointing to a missing feature in JGit. We are currently not inspecting the environment and setting up a repo with additional object directories before we execute the hook. I guess that would be required now. The repo could receive multiple pushes and just adding all incoming-* folders to the list of object directories is not correct. Also making sure that all new git objects created by the hook are put into the temporary object directory first has to be implemented. 

Maybe as a workaround this can be done in the java based hook. Inspect the environment for information about extra object directory and tweak the jgit repository to also look there. Just thinking loud ....