summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/git/branch.go18
-rw-r--r--pkg/git/cmd-stash.go8
2 files changed, 24 insertions, 2 deletions
diff --git a/pkg/git/branch.go b/pkg/git/branch.go
index 5277e20..e5facf8 100644
--- a/pkg/git/branch.go
+++ b/pkg/git/branch.go
@@ -33,7 +33,11 @@ func (e *RepoEntity) loadLocalBranches() error {
return err
}
defer bs.Close()
- headRef, _ := e.Repository.Head()
+ headRef, err := e.Repository.Head()
+ if err != nil {
+ return err
+ }
+ var branchFound bool
bs.ForEach(func(b *plumbing.Reference) error {
if b.Type() == plumbing.HashReference {
var push, pull string
@@ -65,11 +69,23 @@ func (e *RepoEntity) loadLocalBranches() error {
}
if b.Name() == headRef.Name() {
e.Branch = branch
+ branchFound = true
}
lbs = append(lbs, branch)
}
return nil
})
+ if !branchFound {
+ branch := &Branch{
+ Name: headRef.Hash().String(),
+ Reference: headRef,
+ Pushables: "?",
+ Pullables: "?",
+ Clean: e.isClean(),
+ }
+ lbs = append(lbs, branch)
+ e.Branch = branch
+ }
e.Branches = lbs
return err
}
diff --git a/pkg/git/cmd-stash.go b/pkg/git/cmd-stash.go
index 85e25e3..934628e 100644
--- a/pkg/git/cmd-stash.go
+++ b/pkg/git/cmd-stash.go
@@ -36,7 +36,8 @@ func (e *RepoEntity) loadStashedItems() error {
output := stashGet(e, "list")
stashIDRegex := regexp.MustCompile(`stash@{[\d]+}:`)
stashIDRegexInt := regexp.MustCompile(`[\d]+`)
- stashBranchRegex := regexp.MustCompile(`[\w]+: `)
+ stashBranchRegex := regexp.MustCompile(`^(.*?): `)
+ stashMsgRegex := regexp.MustCompile(`WIP on \(?([^)]*)\)?`)
stashHashRegex := regexp.MustCompile(`[\w]{7}`)
stashlist := strings.Split(output, "\n")
@@ -56,6 +57,11 @@ func (e *RepoEntity) loadStashedItems() error {
stashBranchRegexMatch := stashBranchRegex.FindString(trimmed)
branchName := stashBranchRegexMatch[:len(stashBranchRegexMatch)-2]
+ branchMatches := stashMsgRegex.FindStringSubmatch(branchName)
+ if len(branchMatches) >= 2 {
+ branchName = stashBranchRegexMatch[:len(stashBranchRegexMatch)-2]
+ }
+
// trim branch section
trimmed = stashBranchRegex.Split(trimmed, 2)[1]
hash := stashHashRegex.FindString(trimmed)