From 54708233ac595067937f09851fa58a0a326ca71f Mon Sep 17 00:00:00 2001 From: Joel Baranick Date: Fri, 2 Sep 2022 20:08:36 -0700 Subject: [PATCH] Improve worktree panel --- pkg/commands/git_commands/worktree_loader.go | 14 ++++---------- pkg/commands/models/worktree.go | 5 +++-- pkg/gui/controllers/worktrees_controller.go | 10 +++++++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/commands/git_commands/worktree_loader.go b/pkg/commands/git_commands/worktree_loader.go index 8dc7dcbe5..4b65caee1 100644 --- a/pkg/commands/git_commands/worktree_loader.go +++ b/pkg/commands/git_commands/worktree_loader.go @@ -1,6 +1,7 @@ package git_commands import ( + "path/filepath" "strings" "github.com/jesseduffield/lazygit/pkg/commands/models" @@ -46,18 +47,11 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) { Id: len(worktrees), Path: path, } + } else if strings.HasPrefix(splitLine, "branch ") { + branch := strings.SplitN(splitLine, " ", 2)[1] + currentWorktree.Branch = filepath.Base(branch) } } - /* - worktree /Users/jbaranick/Source/lazygit - HEAD f6d6b5dec0432ffa953611700ab9b1ff0089f948 - branch refs/heads/worktree_support - - worktree /Users/jbaranick/Source/lazygit/.worktrees/worktree_tests - HEAD f6d6b5dec0432ffa953611700ab9b1ff0089f948 - branch refs/heads/worktree_tests - */ - return worktrees, nil } diff --git a/pkg/commands/models/worktree.go b/pkg/commands/models/worktree.go index c4e31a9d3..f02dc184c 100644 --- a/pkg/commands/models/worktree.go +++ b/pkg/commands/models/worktree.go @@ -11,8 +11,9 @@ import ( // Worktree : A git worktree type Worktree struct { - Id int - Path string + Id int + Path string + Branch string } func (w *Worktree) RefName() string { diff --git a/pkg/gui/controllers/worktrees_controller.go b/pkg/gui/controllers/worktrees_controller.go index c54ab9db0..bff498277 100644 --- a/pkg/gui/controllers/worktrees_controller.go +++ b/pkg/gui/controllers/worktrees_controller.go @@ -59,7 +59,15 @@ func (self *WorktreesController) GetOnRenderToMain() func() error { if worktree.Missing() { missing = style.FgRed.Sprint(" (missing)") } - task = types.NewRenderStringTask(fmt.Sprintf("%s\nPath: %s%s", style.FgGreen.Sprint(worktree.Name()), worktree.Path, missing)) + task = types.NewRenderStringTask( + fmt.Sprintf( + "Name: %s\nBranch: %s\nPath: %s%s\n", + style.FgGreen.Sprint(worktree.Name()), + style.FgYellow.Sprint(worktree.Branch), + style.FgCyan.Sprint(worktree.Path), + missing, + ), + ) } return self.c.RenderToMainViews(types.RefreshMainOpts{