|
Re: read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown [message #1793850 is a reply to message #1793175] |
Fri, 17 August 2018 08:54 |
Christian Halstrick Messages: 274 Registered: July 2009 |
Senior Member |
|
|
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);
}
}
}
Ciao
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.03409 seconds