mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-15 22:26:40 +02:00
Basic support for adding a worktree
This commit is contained in:
parent
35e6e6347a
commit
1ce9a87544
@ -10,6 +10,12 @@ func NewWorktreeCommands(gitCommon *GitCommon) *WorktreeCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *WorktreeCommands) New(worktreePath string) error {
|
||||||
|
cmdArgs := NewGitCmd("worktree").Arg("add", worktreePath).ToArgv()
|
||||||
|
|
||||||
|
return self.cmd.New(cmdArgs).Run()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *WorktreeCommands) Delete(worktreePath string, force bool) error {
|
func (self *WorktreeCommands) Delete(worktreePath string, force bool) error {
|
||||||
cmdArgs := NewGitCmd("worktree").Arg("remove").ArgIf(force, "-f").Arg(worktreePath).ToArgv()
|
cmdArgs := NewGitCmd("worktree").Arg("remove").ArgIf(force, "-f").Arg(worktreePath).ToArgv()
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
|
import "github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
|
||||||
type IWorktreeHelper interface {
|
type IWorktreeHelper interface {
|
||||||
GetMainWorktreeName() string
|
GetMainWorktreeName() string
|
||||||
GetCurrentWorktreeName() string
|
GetCurrentWorktreeName() string
|
||||||
@ -25,6 +27,29 @@ func (self *WorktreeHelper) GetMainWorktreeName() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *WorktreeHelper) NewWorktree() error {
|
||||||
|
return self.c.Prompt(types.PromptOpts{
|
||||||
|
Title: self.c.Tr.NewWorktreePath,
|
||||||
|
HandleConfirm: func(response string) error {
|
||||||
|
self.c.LogAction(self.c.Tr.Actions.CreateWorktree)
|
||||||
|
if err := self.c.Git().Worktree.New(sanitizedBranchName(response)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//if self.c.CurrentContext() != self.contexts.Worktrees {
|
||||||
|
// if err := self.c.PushContext(self.contexts.Worktrees); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
// self.contexts.LocalCommits.SetSelectedLineIdx(0)
|
||||||
|
// self.contexts.Branches.SetSelectedLineIdx(0)
|
||||||
|
|
||||||
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//func (self *WorktreeHelper) GetCurrentWorktreeName() string {
|
//func (self *WorktreeHelper) GetCurrentWorktreeName() string {
|
||||||
// for _, worktree := range self.c.Model().Worktrees {
|
// for _, worktree := range self.c.Model().Worktrees {
|
||||||
// if worktree.Current() {
|
// if worktree.Current() {
|
||||||
|
@ -40,11 +40,11 @@ func (self *WorktreesController) GetKeybindings(opts types.KeybindingsOpts) []*t
|
|||||||
Handler: self.checkSelected(self.delete),
|
Handler: self.checkSelected(self.delete),
|
||||||
Description: self.c.Tr.DeleteWorktree,
|
Description: self.c.Tr.DeleteWorktree,
|
||||||
},
|
},
|
||||||
//{
|
{
|
||||||
// Key: opts.GetKey(opts.Config.Universal.New),
|
Key: opts.GetKey(opts.Config.Universal.New),
|
||||||
// Handler: self.create,
|
Handler: self.create,
|
||||||
// Description: self.c.Tr.LcCreateTag,
|
Description: self.c.Tr.CreateWorktree,
|
||||||
//},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return bindings
|
return bindings
|
||||||
@ -103,6 +103,10 @@ func (self *WorktreesController) GetOnRenderToMain() func() error {
|
|||||||
// return gui.dispatchSwitchToRepo(submodule.Path, true)
|
// return gui.dispatchSwitchToRepo(submodule.Path, true)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
func (self *WorktreesController) create() error {
|
||||||
|
return self.c.Helpers().Worktree.NewWorktree()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *WorktreesController) delete(worktree *models.Worktree) error {
|
func (self *WorktreesController) delete(worktree *models.Worktree) error {
|
||||||
if worktree.Main() {
|
if worktree.Main() {
|
||||||
return self.c.ErrorMsg(self.c.Tr.CantDeleteMainWorktree)
|
return self.c.ErrorMsg(self.c.Tr.CantDeleteMainWorktree)
|
||||||
@ -147,42 +151,6 @@ func (self *WorktreesController) deleteWithForce(worktree *models.Worktree, forc
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// func (self *WorktreesController) push(tag *models.Tag) error {
|
|
||||||
// title := utils.ResolvePlaceholderString(
|
|
||||||
// self.c.Tr.PushTagTitle,
|
|
||||||
// map[string]string{
|
|
||||||
// "tagName": tag.Name,
|
|
||||||
// },
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// return self.c.Prompt(types.PromptOpts{
|
|
||||||
// Title: title,
|
|
||||||
// InitialContent: "origin",
|
|
||||||
// FindSuggestionsFunc: self.helpers.Suggestions.GetRemoteSuggestionsFunc(),
|
|
||||||
// HandleConfirm: func(response string) error {
|
|
||||||
// return self.c.WithWaitingStatus(self.c.Tr.PushingTagStatus, func() error {
|
|
||||||
// self.c.LogAction(self.c.Tr.Actions.PushTag)
|
|
||||||
// err := self.git.Tag.Push(response, tag.Name)
|
|
||||||
// if err != nil {
|
|
||||||
// _ = self.c.Error(err)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func (self *WorktreesController) createResetMenu(tag *models.Tag) error {
|
|
||||||
// return self.helpers.Refs.CreateGitResetMenu(tag.Name)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func (self *WorktreesController) create() error {
|
|
||||||
// // leaving commit SHA blank so that we're just creating the tag for the current commit
|
|
||||||
// return self.helpers.Tags.CreateTagMenu("", func() { self.context().SetSelectedLineIdx(0) })
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (self *WorktreesController) GetOnClick() func() error {
|
func (self *WorktreesController) GetOnClick() func() error {
|
||||||
return self.checkSelected(self.enter)
|
return self.checkSelected(self.enter)
|
||||||
}
|
}
|
||||||
|
@ -554,6 +554,8 @@ type TranslationSet struct {
|
|||||||
NoWorktreesThisRepo string
|
NoWorktreesThisRepo string
|
||||||
MissingWorktree string
|
MissingWorktree string
|
||||||
MainWorktree string
|
MainWorktree string
|
||||||
|
CreateWorktree string
|
||||||
|
NewWorktreePath string
|
||||||
Name string
|
Name string
|
||||||
Branch string
|
Branch string
|
||||||
Path string
|
Path string
|
||||||
@ -688,6 +690,7 @@ type Actions struct {
|
|||||||
BisectSkip string
|
BisectSkip string
|
||||||
BisectMark string
|
BisectMark string
|
||||||
DeleteWorktree string
|
DeleteWorktree string
|
||||||
|
CreateWorktree string
|
||||||
}
|
}
|
||||||
|
|
||||||
const englishIntroPopupMessage = `
|
const englishIntroPopupMessage = `
|
||||||
@ -1269,6 +1272,8 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
NoWorktreesThisRepo: "No worktrees",
|
NoWorktreesThisRepo: "No worktrees",
|
||||||
MissingWorktree: "(missing)",
|
MissingWorktree: "(missing)",
|
||||||
MainWorktree: "(main)",
|
MainWorktree: "(main)",
|
||||||
|
CreateWorktree: "Create worktree",
|
||||||
|
NewWorktreePath: "New Worktree path",
|
||||||
Name: "Name",
|
Name: "Name",
|
||||||
Branch: "Branch",
|
Branch: "Branch",
|
||||||
Path: "Path",
|
Path: "Path",
|
||||||
@ -1380,6 +1385,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
BisectSkip: "Bisect skip",
|
BisectSkip: "Bisect skip",
|
||||||
BisectMark: "Bisect mark",
|
BisectMark: "Bisect mark",
|
||||||
DeleteWorktree: "Delete worktree",
|
DeleteWorktree: "Delete worktree",
|
||||||
|
CreateWorktree: "Create worktree",
|
||||||
},
|
},
|
||||||
Bisect: Bisect{
|
Bisect: Bisect{
|
||||||
Mark: "Mark current commit (%s) as %s",
|
Mark: "Mark current commit (%s) as %s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user