==============================================================
public class App {
private static final String REMOTE_URL = "
https://github.com/a-golubnichenko/RevWalkIssue.git";
private static final String[] COMMIT_IDS = new String[]{
"78d7e33dbdb82d1d303026e8812814b0b0049b68",
"4b99b7948a35cb4fa09ed827c2ab81c5686ff2e2",
"0ef74d9705d8a7bdf7f41ee778693b262bdb050e"
};
public static void main(String[] args) throws IOException, GitAPIException {
File localPath = File.createTempFile("TestGitRepository", "");
if (!localPath.delete()) {
throw new IOException("Could not delete temporary file " + localPath);
}
try {
System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
try (Git result = Git.cloneRepository()
.setBare(true)
.setURI(REMOTE_URL)
.setCloneAllBranches(true)
.setCloneSubmodules(true)
.setDirectory(localPath)
.call()) {
System.out.println("Having repository: " + result.getRepository().getDirectory());
}
try (Repository repository = FileRepositoryBuilder.create(localPath);
RevWalk revWalk = new RevWalk(repository)) {
for (String commitId : COMMIT_IDS) {
RevCommit revCommit = revWalk.parseCommit(ObjectId.fromString(commitId));
System.out.printf("Message '%s' for commit <%s> %n", revCommit.getFullMessage(), commitId);
List<Ref> branchesReachableFrom = RevWalkUtils.findBranchesReachableFrom(
revCommit, revWalk, repository.getAllRefs().values());
System.out.println("Reachable branches: " + branchesReachableFrom);
}
}
} finally {
FileUtils.deleteDirectory(localPath);
}
}
}
==============================================================