You've already forked go-semantic-release
fix(branch): get branch from detached HEAD
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
dist: xenial
|
||||
|
||||
git:
|
||||
depth: false
|
||||
|
||||
language: go
|
||||
go:
|
||||
- 1.12.x
|
||||
@@ -23,7 +26,6 @@ before_script:
|
||||
|
||||
script:
|
||||
- golangci-lint run ./...
|
||||
- git checkout master
|
||||
- go test -v ./...
|
||||
- go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||
- echo "Building version `./build/go-semantic-release-temp next`"
|
||||
|
||||
@@ -54,9 +54,29 @@ func (g *GitUtil) GetBranch() (string, error) {
|
||||
}
|
||||
|
||||
if !ref.Name().IsBranch() {
|
||||
return "", fmt.Errorf("no branch found, found %s, please checkout a branch (git checkout <BRANCH>)", ref.Name().String())
|
||||
}
|
||||
branches, err := g.Repository.Branches()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var currentBranch string
|
||||
found := branches.ForEach(func(p *plumbing.Reference) error {
|
||||
|
||||
if p.Name().IsBranch() && p.Name().Short() != "origin" {
|
||||
currentBranch = p.Name().Short()
|
||||
return fmt.Errorf("break")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if found != nil {
|
||||
log.Debugf("Found branch from HEAD %s", currentBranch)
|
||||
return currentBranch, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no branch found, found %s, please checkout a branch (git checkout -b <BRANCH>)", ref.Name().String())
|
||||
}
|
||||
log.Debugf("Found branch %s", ref.Name().Short())
|
||||
return ref.Name().Short(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user