Skip to content

Commit

Permalink
Use git rev-parse instead of gogit.Repository.Head() to find out he…
Browse files Browse the repository at this point in the history
…ad branch & sha
  • Loading branch information
maciejp-ro committed Oct 3, 2023
1 parent a79a77c commit 7053b73
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions pkg/utils/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,28 @@ 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) {
repo, err := Repo()
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
}
Expand All @@ -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) {
Expand Down

0 comments on commit 7053b73

Please sign in to comment.