commit 1
This commit is contained in:
36
git/commit.go
Normal file
36
git/commit.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user