com.heroku.sdk.deploy.util.GitUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of heroku-deploy Show documentation
Show all versions of heroku-deploy Show documentation
Library for deploying Java applications to Heroku
package com.heroku.sdk.deploy.util;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
public class GitUtils {
public static Optional getHeadCommitHash(Path projectDirectory) throws IOException {
try {
Git git = Git.open(projectDirectory.toFile());
ObjectId objectId = git.getRepository().resolve(Constants.HEAD);
return Optional.of(objectId.getName());
} catch (RepositoryNotFoundException e) {
return Optional.empty();
}
}
}