Skip to content

Commit 1609b4a

Browse files
author
Joel Baranick
committed
Improve worktree panel
1 parent a79aa6d commit 1609b4a

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

pkg/commands/loaders/worktrees.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/jesseduffield/lazygit/pkg/commands/models"
55
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
66
"github.com/jesseduffield/lazygit/pkg/common"
7+
"path/filepath"
78
"strings"
89
)
910

@@ -44,18 +45,11 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
4445
Id: len(worktrees),
4546
Path: path,
4647
}
48+
} else if strings.HasPrefix(splitLine, "branch ") {
49+
branch := strings.SplitN(splitLine, " ", 2)[1]
50+
currentWorktree.Branch = filepath.Base(branch)
4751
}
4852
}
4953

50-
/*
51-
worktree /Users/jbaranick/Source/lazygit
52-
HEAD f6d6b5dec0432ffa953611700ab9b1ff0089f948
53-
branch refs/heads/worktree_support
54-
55-
worktree /Users/jbaranick/Source/lazygit/.worktrees/worktree_tests
56-
HEAD f6d6b5dec0432ffa953611700ab9b1ff0089f948
57-
branch refs/heads/worktree_tests
58-
*/
59-
6054
return worktrees, nil
6155
}

pkg/commands/models/worktree.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111

1212
// Worktree : A git worktree
1313
type Worktree struct {
14-
Id int
15-
Path string
14+
Id int
15+
Path string
16+
Branch string
1617
}
1718

1819
func (w *Worktree) RefName() string {

pkg/gui/worktrees_panel.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ func (gui *Gui) worktreesRenderToMain() error {
1919
if worktree.Missing() {
2020
missing = style.FgRed.Sprint(" (missing)")
2121
}
22-
task = types.NewRenderStringTask(fmt.Sprintf("%s\nPath: %s%s", style.FgGreen.Sprint(worktree.Name()), worktree.Path, missing))
22+
task = types.NewRenderStringTask(
23+
fmt.Sprintf(
24+
"Name: %s\nBranch: %s\nPath: %s%s\n",
25+
style.FgGreen.Sprint(worktree.Name()),
26+
style.FgYellow.Sprint(worktree.Branch),
27+
style.FgCyan.Sprint(worktree.Path),
28+
missing,
29+
),
30+
)
2331
}
2432

2533
return gui.c.RenderToMainViews(types.RefreshMainOpts{

0 commit comments

Comments
 (0)