Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown
read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown [message #1793175] Tue, 31 July 2018 20:17 Go to next message
Eclipse UserFriend
Hello,

I write a snipet to read git commit from some git repo. But it failed to read some repo. Here are the error

grafana-master/grafana-plugins/.git indexed repo failed
org.eclipse.jgit.errors.MissingObjectException: Missing unknown 7202bc6573821ed3ba371c895fff0b00102674d2
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:889)
at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:799)

- the repo is https://github.com/grafana/grafana-plugins, it is clone locally
- the repo is clean, no local change or commit
- my jgit version is latest 5.0.1.201806211838-r
- my code is as follow

Repository repository = repositoryBuilder.setGitDir(gitFolder)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.setMustExist(true)
.build();
Git git = new Git(repository);
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(lastCommitId);

It failed in the last line 'RevCommit commit = walk.parseCommit(lastCommitId);'

I also try to read git repo with git.log().all().call();
but it still failed with the same error.

That code work well with other repos, but failed to read some repo.

Please advice me how to solve this issue.

Thanks.
Tien
Re: read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown [message #1793850 is a reply to message #1793175] Fri, 17 August 2018 04:54 Go to previous message
Eclipse UserFriend
For me this code works when called with "https://github.com/grafana/grafana-plugins" and "HEAD"

public class CloneRepoIntoTmpAndInspectHEAD {
	public static void main(String args[]) throws IOException, GitAPIException, JGitInternalException {
		Path tmp = Files.createTempDirectory("JGitTest_" + CloneRepoIntoTmpAndInspectHEAD.class.getName());
		try (Git git = Git.cloneRepository().setDirectory(tmp.toFile()).setURI(args[0]).setBare(false).call()) {
			System.out.println("Repo " + args[0] + " cloned to " + tmp);
			Repository repo = git.getRepository();
			ObjectId lastCommitId = repo.resolve(Constants.HEAD);
			try (RevWalk walk = new RevWalk(repo)) {
				RevCommit commit = walk.parseCommit(lastCommitId);
				System.out.println("Commit " + lastCommitId + " has message " + commit.getShortMessage());
			}
		} finally {
			Files.walk(tmp).map(Path::toFile).sorted((o1, o2) -> -o1.compareTo(o2)).forEach(File::delete);
		}
	}
}
Previous Topic:Help:A cycle was detected when generating the classpath
Next Topic:Java 11 Compatibility check: JGit
Goto Forum:
  


Current Time: Thu Jul 03 20:29:50 EDT 2025

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

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

Back to the top