1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00

Basic support for adding a worktree

This commit is contained in:
Joel Baranick 2022-09-02 21:38:16 -07:00 committed by Jesse Duffield
parent 35e6e6347a
commit 1ce9a87544
4 changed files with 46 additions and 41 deletions

View File

@ -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 {
cmdArgs := NewGitCmd("worktree").Arg("remove").ArgIf(force, "-f").Arg(worktreePath).ToArgv()

View File

@ -1,5 +1,7 @@
package helpers
import "github.com/jesseduffield/lazygit/pkg/gui/types"
type IWorktreeHelper interface {
GetMainWorktreeName() string
GetCurrentWorktreeName() string
@ -25,6 +27,29 @@ func (self *WorktreeHelper) GetMainWorktreeName() string {
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 {
// for _, worktree := range self.c.Model().Worktrees {
// if worktree.Current() {

View File

@ -40,11 +40,11 @@ func (self *WorktreesController) GetKeybindings(opts types.KeybindingsOpts) []*t
Handler: self.checkSelected(self.delete),
Description: self.c.Tr.DeleteWorktree,
},
//{
// Key: opts.GetKey(opts.Config.Universal.New),
// Handler: self.create,
// Description: self.c.Tr.LcCreateTag,
//},
{
Key: opts.GetKey(opts.Config.Universal.New),
Handler: self.create,
Description: self.c.Tr.CreateWorktree,
},
}
return bindings
@ -103,6 +103,10 @@ func (self *WorktreesController) GetOnRenderToMain() func() error {
// 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 {
if worktree.Main() {
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 {
return self.checkSelected(self.enter)
}

View File

@ -554,6 +554,8 @@ type TranslationSet struct {
NoWorktreesThisRepo string
MissingWorktree string
MainWorktree string
CreateWorktree string
NewWorktreePath string
Name string
Branch string
Path string
@ -688,6 +690,7 @@ type Actions struct {
BisectSkip string
BisectMark string
DeleteWorktree string
CreateWorktree string
}
const englishIntroPopupMessage = `
@ -1269,6 +1272,8 @@ func EnglishTranslationSet() TranslationSet {
NoWorktreesThisRepo: "No worktrees",
MissingWorktree: "(missing)",
MainWorktree: "(main)",
CreateWorktree: "Create worktree",
NewWorktreePath: "New Worktree path",
Name: "Name",
Branch: "Branch",
Path: "Path",
@ -1380,6 +1385,7 @@ func EnglishTranslationSet() TranslationSet {
BisectSkip: "Bisect skip",
BisectMark: "Bisect mark",
DeleteWorktree: "Delete worktree",
CreateWorktree: "Create worktree",
},
Bisect: Bisect{
Mark: "Mark current commit (%s) as %s",