0

I am trying to read Git Notes information from a custom ref refs/notes/abcd of a particular commit in a repository using JGit

Here is what I tried:

Repository repository = repositoryManager.openRepository(repoName);
Git git = new Git(repository);
ObjectId oid = repository.resolve("5740b142a7b5f66768a2d904b267dccaef1a095f");
Note note = git.notesShow().setNotesRef("refs/notes/abcd").setObjectId(oid).call();
ObjectLoader loader = repository.open(note.getData());
byte[] data = loader.getBytes();
System.out.println(new String(data, "utf-8"));

I get the following compilation error:

error: incompatible types: org.eclipse.jgit.lib.ObjectId cannot be converted to org.eclipse.jgit.revwalk.RevObject

How do I pass a RevObject variable to Git setObjectId() given a commit-sha string?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79

1 Answers1

1

With a RevWalk, the object id can be parsed and the resulting RevCommit can be passed to the ShowNoteCommand.

For example:

RevCommit commit;
try( RevWalk revWalk = new RevWalk( repository ) ) {
  commit = revWalk.parseCommit( oid );
}

git.notesShow().setObjectId( commit )...
Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • See also the ready-to-run example at https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/AddAndListNoteOfCommit.java in my [jgit-cookbook](https://github.com/centic9/jgit-cookbook/) – centic Sep 13 '17 at 17:50