mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
refactor obtaining current branch name
This commit is contained in:
parent
775d910bdc
commit
a5f483fae9
@ -208,11 +208,6 @@ func includesInt(list []int, a int) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBranchName branch name
|
|
||||||
func (c *GitCommand) GetBranchName() (string, error) {
|
|
||||||
return c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetHard does the equivalent of `git reset --hard HEAD`
|
// ResetHard does the equivalent of `git reset --hard HEAD`
|
||||||
func (c *GitCommand) ResetHard() error {
|
func (c *GitCommand) ResetHard() error {
|
||||||
return c.Worktree.Reset(&gogit.ResetOptions{Mode: gogit.HardReset})
|
return c.Worktree.Reset(&gogit.ResetOptions{Mode: gogit.HardReset})
|
||||||
@ -268,11 +263,14 @@ func (c *GitCommand) NewBranch(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) CurrentBranchName() (string, error) {
|
func (c *GitCommand) CurrentBranchName() (string, error) {
|
||||||
output, err := c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD")
|
branchName, err := c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD")
|
||||||
|
if err != nil {
|
||||||
|
branchName, err = c.OSCommand.RunCommandWithOutput("git rev-parse --short HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return utils.TrimTrailingNewline(output), nil
|
}
|
||||||
|
return utils.TrimTrailingNewline(branchName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteBranch delete branch
|
// DeleteBranch delete branch
|
||||||
|
@ -35,15 +35,11 @@ func NewBranchListBuilder(log *logrus.Entry, gitCommand *commands.GitCommand) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BranchListBuilder) obtainCurrentBranch() *commands.Branch {
|
func (b *BranchListBuilder) obtainCurrentBranch() *commands.Branch {
|
||||||
// I used go-git for this, but that breaks if you've just done a git init,
|
branchName, err := b.GitCommand.CurrentBranchName()
|
||||||
// even though you're on 'master'
|
|
||||||
branchName, err := b.GitCommand.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD")
|
|
||||||
if err != nil {
|
|
||||||
branchName, err = b.GitCommand.OSCommand.RunCommandWithOutput("git rev-parse --short HEAD")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return &commands.Branch{Name: strings.TrimSpace(branchName), Recency: " *"}
|
return &commands.Branch{Name: strings.TrimSpace(branchName), Recency: " *"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user