summaryrefslogtreecommitdiffstats
path: root/pkg/git
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-11-14 19:17:05 +1100
committerJesse Duffield <jessedduffield@gmail.com>2018-11-14 21:19:12 +1100
commit0eb1e4a86bee71158b8a5a2f73368cdf6d330283 (patch)
tree493b35eebc90b6692a5782f695bd226744f5123e /pkg/git
parenta5f483fae97fa16b9291761e74acdc35a669df76 (diff)
change how we build our list of branches to support detached heads
Diffstat (limited to 'pkg/git')
-rw-r--r--pkg/git/branch_list_builder.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/pkg/git/branch_list_builder.go b/pkg/git/branch_list_builder.go
index 821f7b9b1..60ec4e060 100644
--- a/pkg/git/branch_list_builder.go
+++ b/pkg/git/branch_list_builder.go
@@ -40,7 +40,7 @@ func (b *BranchListBuilder) obtainCurrentBranch() *commands.Branch {
panic(err.Error())
}
- return &commands.Branch{Name: strings.TrimSpace(branchName), Recency: " *"}
+ return &commands.Branch{Name: strings.TrimSpace(branchName)}
}
func (b *BranchListBuilder) obtainReflogBranches() []*commands.Branch {
@@ -57,7 +57,7 @@ func (b *BranchListBuilder) obtainReflogBranches() []*commands.Branch {
branch := &commands.Branch{Name: branchName, Recency: timeNumber + timeUnit}
branches = append(branches, branch)
}
- return branches
+ return uniqueByName(branches)
}
func (b *BranchListBuilder) obtainSafeBranches() []*commands.Branch {
@@ -99,11 +99,8 @@ func (b *BranchListBuilder) Build() []*commands.Branch {
branches := make([]*commands.Branch, 0)
head := b.obtainCurrentBranch()
safeBranches := b.obtainSafeBranches()
- if len(safeBranches) == 0 {
- return append(branches, head)
- }
+
reflogBranches := b.obtainReflogBranches()
- reflogBranches = uniqueByName(append([]*commands.Branch{head}, reflogBranches...))
for i, reflogBranch := range reflogBranches {
reflogBranches[i].Name = sanitisedReflogName(reflogBranch, safeBranches)
}
@@ -111,6 +108,12 @@ func (b *BranchListBuilder) Build() []*commands.Branch {
branches = b.appendNewBranches(branches, reflogBranches, safeBranches, true)
branches = b.appendNewBranches(branches, safeBranches, branches, false)
+ if len(branches) == 0 || branches[0].Name != head.Name {
+ branches = append([]*commands.Branch{head}, branches...)
+ }
+
+ branches[0].Recency = " *"
+
return branches
}