Reputation: 31
I'm using JGit to extract diffs between two commits but I often face a problem that JGit throws MissingObjectException
and says missing unknown commit ID like this:
org.eclipse.jgit.errors.MissingObjectException: Missing unknown 9eae334e9492f55a841e6eb7ab302ff11d03ab21
at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:168)
at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:236)
at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:890)
at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:800)
at collect.CollectTestcase.autoExtraction(CollectTestcase.java:99)*
It often happens when running the code
RevWalk walk = new RevWalk(repo);
walk.parseCommit(commitId)
Does someone knows what's wrong with it?
Upvotes: 3
Views: 6280
Reputation: 20985
JGit throws a MissingObjectException
if there is no object with the given ID in the repository.
There are different types of objects in git, common are commits, blobs, and trees.
RevWalk
offers API to search for specific types, like parseCommit
, as well as for any type of object with parseAny
. The information, that you were searching for a commit, gets lost along the way which leads to the confusing 'unknown' in the error message. It should actually read 'Missing commit abc...'.
But despite the irritating message, it means that there is no such commit. Either you are passing the ID of an object of a different type, e.g. a tree object, or there is no such object at all. You can use parseAny
to see if there is an object with the given ID. If an object could be found, use getType
of the returned RevObject
to find out which type it is.
Upvotes: 2