This commit is contained in:
2023-12-05 19:03:27 +00:00
commit 6859e01192
11 changed files with 288 additions and 0 deletions

36
git/commit.go Normal file
View File

@@ -0,0 +1,36 @@
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)
}