From 95b7c1d0a45503fc327f474714142bc0077c1a0c Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 10 Aug 2018 22:08:12 +1000 Subject: [PATCH] revert to using the direct git command for getting the current branch because it breaks if you've just done a git init --- branch_list_builder.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/branch_list_builder.go b/branch_list_builder.go index 5393bea3e..113a5a44a 100644 --- a/branch_list_builder.go +++ b/branch_list_builder.go @@ -22,13 +22,10 @@ func newBranchListBuilder() *branchListBuilder { } func (b *branchListBuilder) obtainCurrentBranch() Branch { - // Using git-go whenever possible - head, err := r.Head() - if err != nil { - panic(err) - } - name := head.Name().Short() - return Branch{Name: name, Recency: " *"} + // I used go-git for this, but that breaks if you've just done a git init, + // even though you're on 'master' + branchName, _ := runDirectCommand("git symbolic-ref --short HEAD") + return Branch{Name: strings.TrimSpace(branchName), Recency: " *"} } func (*branchListBuilder) obtainReflogBranches() []Branch { @@ -77,12 +74,15 @@ func (b *branchListBuilder) appendNewBranches(finalBranches, newBranches, existi func (b *branchListBuilder) build() []Branch { branches := make([]Branch, 0) head := b.obtainCurrentBranch() - validBranches := b.obtainSafeBranches() + safeBranches := b.obtainSafeBranches() + if len(safeBranches) == 0 { + return append(branches, head) + } reflogBranches := b.obtainReflogBranches() reflogBranches = uniqueByName(append([]Branch{head}, reflogBranches...)) - branches = b.appendNewBranches(branches, reflogBranches, validBranches, true) - branches = b.appendNewBranches(branches, validBranches, branches, false) + branches = b.appendNewBranches(branches, reflogBranches, safeBranches, true) + branches = b.appendNewBranches(branches, safeBranches, branches, false) return branches }