mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
Display short SHA when in detached HEAD
state
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) getCurrentBranch(path string) string {
|
func (gui *Gui) getCurrentBranch(path string) string {
|
||||||
@ -21,8 +22,16 @@ func (gui *Gui) getCurrentBranch(path string) string {
|
|||||||
headFile, err := ioutil.ReadFile(filepath.Join(path, "HEAD"))
|
headFile, err := ioutil.ReadFile(filepath.Join(path, "HEAD"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
content := strings.TrimSpace(string(headFile))
|
content := strings.TrimSpace(string(headFile))
|
||||||
branch := strings.TrimPrefix(content, "ref: refs/heads/")
|
refsPrefix := "ref: refs/heads/"
|
||||||
return branch, nil
|
branchDisplay := ""
|
||||||
|
if strings.HasPrefix(content, refsPrefix) {
|
||||||
|
// is a branch
|
||||||
|
branchDisplay = strings.TrimPrefix(content, refsPrefix)
|
||||||
|
} else {
|
||||||
|
// detached HEAD state, displaying short SHA
|
||||||
|
branchDisplay = utils.ShortSha(content)
|
||||||
|
}
|
||||||
|
return branchDisplay, nil
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -47,7 +56,7 @@ func (gui *Gui) getCurrentBranch(path string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "HEAD"
|
return "unknown branch"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCreateRecentReposMenu() error {
|
func (gui *Gui) handleCreateRecentReposMenu() error {
|
||||||
|
Reference in New Issue
Block a user