1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-01 00:54:58 +02:00

refactor obtaining current branch name

This commit is contained in:
Jesse Duffield
2018-11-14 19:08:42 +11:00
parent 775d910bdc
commit a5f483fae9
2 changed files with 9 additions and 15 deletions

View File

@ -35,15 +35,11 @@ func NewBranchListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand) (*
}
func (b *BranchListBuilder) obtainCurrentBranch() *commands.Branch {
// I used go-git for this, but that breaks if you've just done a git init,
// even though you're on 'master'
branchName, err := b.GitCommand.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD")
branchName, err := b.GitCommand.CurrentBranchName()
if err != nil {
branchName, err = b.GitCommand.OSCommand.RunCommandWithOutput("git rev-parse --short HEAD")
if err != nil {
panic(err.Error())
}
panic(err.Error())
}
return &commands.Branch{Name: strings.TrimSpace(branchName), Recency: " *"}
}