gsquash/git/commit.go
2023-12-05 19:03:27 +00:00

37 lines
721 B
Go

package git
import "strconv"
// GetHash returns the commit hash for the current HEAD
func (g *Git) GetHash() (string, error) {
out, err := g.Execute("rev-parse", "HEAD")
if err != nil {
return "", err
}
return out, nil
}
// GetCommitRemote returns the commit hash for the current HEAD on the remote
func (g *Git) GetCommitRemote() (string, error) {
out, err := g.Execute("ls-remote", "origin", "HEAD")
if err != nil {
return "", err
}
return out, nil
}
// GetCommitsAhead returns the number of commits ahead of main
func (g *Git) GetCommitsAhead() (int, error) {
out, err := g.Execute("rev-list", "--count", "HEAD", "^"+g.MainBranch)
if err != nil {
return 0, err
}
return strconv.Atoi(out)
}