in src/main/kotlin/org/jetbrains/qodana/GitLocator.kt [20:41]
fun create(repoPath: String, commitHash: String): GitLocator? {
return try {
val gitInPath = Path.of(repoPath).resolve(".git").toFile()
val repoFile = if (!gitInPath.exists()) {
// case of submodules we will try to regard it as a repo folder
Path.of(repoPath).toFile()
} else {
gitInPath
}
if (!repoFile.exists()) return null // repo doesn't exist
val git = Git.open(repoFile)
val repo = git.repository
val revWalk = RevWalk(repo)
val commitId = repo.resolve(commitHash) ?: return null // need to fetch the revision
val commit = revWalk.parseCommit(commitId)
GitLocator(repo, revWalk, commit.tree)
} catch (e: IOException) {
null
} catch (e: GitAPIException) {
null
}
}