Skip to content

Commit

Permalink
fix: improve support for partially fetched remotes
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed May 28, 2021
1 parent 4bdabc6 commit 94ba589
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ func projectFromPath(path string) (*project, error) {
}
ref, err = project.Git.repo.Reference("refs/remotes/origin/HEAD", true)
if err != nil {
logger.Warn("failed to get main branch", zap.Error(err))
refs, _ := project.Git.repo.References()
_ = refs.ForEach(func(ref *plumbing.Reference) error {
if ref.Type() == plumbing.HashReference {
fmt.Println(ref)
logger.Debug("ref", zap.Stringer("ref", ref))
}
return nil
})
return nil, fmt.Errorf("failed to get main branch: %w", err)
project.Git.MainBranch = "n/a"
}
}
project.Git.MainBranch = strings.TrimPrefix(ref.Name().Short(), "origin/")
if project.Git.MainBranch != "n/a" {
project.Git.MainBranch = strings.TrimPrefix(ref.Name().Short(), "origin/")
}
}
if project.Git.MainBranch != "" && project.Git.CurrentBranch != "" {
if project.Git.MainBranch != "n/a" && project.Git.MainBranch != "" && project.Git.CurrentBranch != "" {
project.Git.InMainBranch = project.Git.MainBranch == project.Git.CurrentBranch
}

Expand Down

0 comments on commit 94ba589

Please sign in to comment.