revert to using the direct git command for getting the current branch because it breaks if you've just done a git init

This commit is contained in:
Jesse Duffield 2018-08-10 22:08:12 +10:00
parent eb9f01ecfa
commit 95b7c1d0a4

View file

@ -22,13 +22,10 @@ func newBranchListBuilder() *branchListBuilder {
} }
func (b *branchListBuilder) obtainCurrentBranch() Branch { func (b *branchListBuilder) obtainCurrentBranch() Branch {
// Using git-go whenever possible // I used go-git for this, but that breaks if you've just done a git init,
head, err := r.Head() // even though you're on 'master'
if err != nil { branchName, _ := runDirectCommand("git symbolic-ref --short HEAD")
panic(err) return Branch{Name: strings.TrimSpace(branchName), Recency: " *"}
}
name := head.Name().Short()
return Branch{Name: name, Recency: " *"}
} }
func (*branchListBuilder) obtainReflogBranches() []Branch { func (*branchListBuilder) obtainReflogBranches() []Branch {
@ -77,12 +74,15 @@ func (b *branchListBuilder) appendNewBranches(finalBranches, newBranches, existi
func (b *branchListBuilder) build() []Branch { func (b *branchListBuilder) build() []Branch {
branches := make([]Branch, 0) branches := make([]Branch, 0)
head := b.obtainCurrentBranch() head := b.obtainCurrentBranch()
validBranches := b.obtainSafeBranches() safeBranches := b.obtainSafeBranches()
if len(safeBranches) == 0 {
return append(branches, head)
}
reflogBranches := b.obtainReflogBranches() reflogBranches := b.obtainReflogBranches()
reflogBranches = uniqueByName(append([]Branch{head}, reflogBranches...)) reflogBranches = uniqueByName(append([]Branch{head}, reflogBranches...))
branches = b.appendNewBranches(branches, reflogBranches, validBranches, true) branches = b.appendNewBranches(branches, reflogBranches, safeBranches, true)
branches = b.appendNewBranches(branches, validBranches, branches, false) branches = b.appendNewBranches(branches, safeBranches, branches, false)
return branches return branches
} }