Skip to content

Commit

Permalink
fix: get branch name error on checkout a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 17, 2022
1 parent 2ac5fce commit 0f24553
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ jobs:
run: |
pwd
go test -v -cover ./...
go run ./cmd/chlog last head
# go run ./cmd/chlog last head
10 changes: 10 additions & 0 deletions _examples/some.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# git commands

get commit for a tag:

```shell
% git rev-parse refs/tags/v0.2.0
a0e902f129d1f9dbf2190ee89e9fc6fd387cb885

```

7 changes: 4 additions & 3 deletions repo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gitw

import (
"path"
"strings"

"github.com/gookit/goutil/arrutil"
Expand Down Expand Up @@ -122,14 +121,16 @@ func (r *Repo) CurrentBranch() string {
// cat .git/HEAD
// OR
// git symbolic-ref HEAD // out: refs/heads/fea_pref
str, err := r.Cmd("symbolic-ref", "HEAD").Output()
// git symbolic-ref --short -q HEAD // on checkout tag, run will error
// git rev-parse --abbrev-ref -q HEAD
str, err := r.gw.RevParse("--abbrev-ref", "-q", "HEAD").Output()
if err != nil {
r.setErr(err)
return ""
}

// eg: fea_pref
brName = path.Base(FirstLine(str))
brName = FirstLine(str)
r.cache.Set(cacheCurrentBranch, brName)

return brName
Expand Down

0 comments on commit 0f24553

Please sign in to comment.