mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
Hide worktree functionality on old git versions
This commit is contained in:
@ -38,6 +38,7 @@ type GitCommand struct {
|
|||||||
WorkingTree *git_commands.WorkingTreeCommands
|
WorkingTree *git_commands.WorkingTreeCommands
|
||||||
Bisect *git_commands.BisectCommands
|
Bisect *git_commands.BisectCommands
|
||||||
Worktree *git_commands.WorktreeCommands
|
Worktree *git_commands.WorktreeCommands
|
||||||
|
Version *git_commands.GitVersion
|
||||||
|
|
||||||
Loaders Loaders
|
Loaders Loaders
|
||||||
}
|
}
|
||||||
@ -159,6 +160,7 @@ func NewGitCommandAux(
|
|||||||
Bisect: bisectCommands,
|
Bisect: bisectCommands,
|
||||||
WorkingTree: workingTreeCommands,
|
WorkingTree: workingTreeCommands,
|
||||||
Worktree: worktreeCommands,
|
Worktree: worktreeCommands,
|
||||||
|
Version: version,
|
||||||
Loaders: Loaders{
|
Loaders: Loaders{
|
||||||
BranchLoader: branchLoader,
|
BranchLoader: branchLoader,
|
||||||
CommitFileLoader: commitFileLoader,
|
CommitFileLoader: commitFileLoader,
|
||||||
|
@ -69,3 +69,7 @@ func (v *GitVersion) IsOlderThan(major, minor, patch int) bool {
|
|||||||
func (v *GitVersion) IsOlderThanVersion(version *GitVersion) bool {
|
func (v *GitVersion) IsOlderThanVersion(version *GitVersion) bool {
|
||||||
return v.IsOlderThan(version.Major, version.Minor, version.Patch)
|
return v.IsOlderThan(version.Major, version.Minor, version.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *GitVersion) SupportsWorktrees() bool {
|
||||||
|
return !v.IsOlderThan(2, 5, 0)
|
||||||
|
}
|
||||||
|
@ -242,6 +242,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
controllers.AttachControllers(context, controllers.NewBasicCommitsController(common, context))
|
controllers.AttachControllers(context, controllers.NewBasicCommitsController(common, context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if gui.c.Git().Version.SupportsWorktrees() {
|
||||||
for _, context := range []controllers.CanViewWorktreeOptions{
|
for _, context := range []controllers.CanViewWorktreeOptions{
|
||||||
gui.State.Contexts.LocalCommits,
|
gui.State.Contexts.LocalCommits,
|
||||||
gui.State.Contexts.ReflogCommits,
|
gui.State.Contexts.ReflogCommits,
|
||||||
@ -253,6 +254,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
} {
|
} {
|
||||||
controllers.AttachControllers(context, controllers.NewWorktreeOptionsController(common, context))
|
controllers.AttachControllers(context, controllers.NewWorktreeOptionsController(common, context))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
controllers.AttachControllers(gui.State.Contexts.ReflogCommits,
|
controllers.AttachControllers(gui.State.Contexts.ReflogCommits,
|
||||||
reflogCommitsController,
|
reflogCommitsController,
|
||||||
|
@ -598,6 +598,11 @@ func (self *RefreshHelper) refreshRemotes() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshWorktrees() error {
|
func (self *RefreshHelper) refreshWorktrees() error {
|
||||||
|
if !self.c.Git().Version.SupportsWorktrees() {
|
||||||
|
self.c.Model().Worktrees = []*models.Worktree{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
worktrees, err := self.c.Git().Loaders.Worktrees.GetWorktrees()
|
worktrees, err := self.c.Git().Loaders.Worktrees.GetWorktrees()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.c.Error(err)
|
return self.c.Error(err)
|
||||||
|
@ -566,8 +566,7 @@ func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
||||||
return map[string][]context.TabView{
|
branchesTabs := []context.TabView{
|
||||||
"branches": {
|
|
||||||
{
|
{
|
||||||
Tab: gui.c.Tr.LocalBranchesTitle,
|
Tab: gui.c.Tr.LocalBranchesTitle,
|
||||||
ViewName: "localBranches",
|
ViewName: "localBranches",
|
||||||
@ -580,11 +579,19 @@ func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
|||||||
Tab: gui.c.Tr.TagsTitle,
|
Tab: gui.c.Tr.TagsTitle,
|
||||||
ViewName: "tags",
|
ViewName: "tags",
|
||||||
},
|
},
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if gui.c.Git().Version.SupportsWorktrees() {
|
||||||
|
branchesTabs = append(branchesTabs,
|
||||||
|
context.TabView{
|
||||||
Tab: gui.c.Tr.WorktreesTitle,
|
Tab: gui.c.Tr.WorktreesTitle,
|
||||||
ViewName: "worktrees",
|
ViewName: "worktrees",
|
||||||
},
|
},
|
||||||
},
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string][]context.TabView{
|
||||||
|
"branches": branchesTabs,
|
||||||
"commits": {
|
"commits": {
|
||||||
{
|
{
|
||||||
Tab: gui.c.Tr.CommitsTitle,
|
Tab: gui.c.Tr.CommitsTitle,
|
||||||
|
Reference in New Issue
Block a user