diff --git a/pkg/utils/git/repo.go b/pkg/utils/git/repo.go index 2ede823de..4b472afe7 100644 --- a/pkg/utils/git/repo.go +++ b/pkg/utils/git/repo.go @@ -21,19 +21,8 @@ func Repo() (*gogit.Repository, error) { return gogit.PlainOpen(root) } -func CurrentBranch() (b string, err error) { - repo, err := Repo() - if err != nil { - return - } - - ref, err := repo.Head() - if err != nil { - return - } - - b = ref.Name().Short() - return +func CurrentBranch() (string, error) { + return GitRaw("rev-parse", "--abbrev-ref", "HEAD") } func HasUpstreamChanges() (bool, string, error) { @@ -41,13 +30,19 @@ func HasUpstreamChanges() (bool, string, error) { if err != nil { return false, "", err } + fmt.Printf("repo: %#v\n", repo) + + headRef, err := GitRaw("rev-parse", "--symbolic-full-name", "HEAD") + if err != nil { + return false, "", err + } - ref, err := repo.Head() + headSha, err := GitRaw("rev-parse", "HEAD") if err != nil { return false, "", err } - res, err := GitRaw("ls-remote", "origin", "-h", fmt.Sprintf("refs/heads/%s", ref.Name().Short())) + res, err := GitRaw("ls-remote", "origin", "-h", headRef) if err != nil { return false, "", err } @@ -62,7 +57,7 @@ func HasUpstreamChanges() (bool, string, error) { } } - return remote == ref.Hash().String(), remote, nil + return remote == headSha, remote, nil } func Init() (string, error) {