This is the approach I used as indicated on the Jgit mailing list:
Check if git repository exists:
if (RepositoryCache.FileKey.isGitRepository(new File(<path_to_repo>), FS.DETECTED)) {
But this is not enough to check if the git clone was βsuccessfulβ. A partial clone could make isGitRepository () evaluate true. To check if the git clone was successfully executed, you need to check at least one non-null link:
private static boolean hasAtLeastOneReference(Repository repo) { for (Ref ref : repo.getAllRefs().values()) { if (ref.getObjectId() == null) continue; return true; } return false; }
Thanks to Shawn Pearce for the answer!
source share