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

Show base ref suggestions when creating worktree

This commit is contained in:
Jesse Duffield 2023-07-16 20:38:22 +10:00
parent 71422a8549
commit 2e68967e02
2 changed files with 14 additions and 15 deletions

View File

@ -21,10 +21,10 @@ func (gui *Gui) resetHelpersAndControllers() {
recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon)
reposHelper := helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo)
refsHelper := helpers.NewRefsHelper(helperCommon)
worktreeHelper := helpers.NewWorktreeHelper(helperCommon, reposHelper, refsHelper)
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon)
worktreeHelper := helpers.NewWorktreeHelper(helperCommon, reposHelper, refsHelper, suggestionsHelper)
rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, refsHelper)
suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon)
setCommitSummary := gui.getCommitMessageSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage })
setCommitDescription := gui.getCommitMessageSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitDescription })

View File

@ -22,16 +22,18 @@ type IWorktreeHelper interface {
}
type WorktreeHelper struct {
c *HelperCommon
reposHelper *ReposHelper
refsHelper *RefsHelper
c *HelperCommon
reposHelper *ReposHelper
refsHelper *RefsHelper
suggestionsHelper *SuggestionsHelper
}
func NewWorktreeHelper(c *HelperCommon, reposHelper *ReposHelper, refsHelper *RefsHelper) *WorktreeHelper {
func NewWorktreeHelper(c *HelperCommon, reposHelper *ReposHelper, refsHelper *RefsHelper, suggestionsHelper *SuggestionsHelper) *WorktreeHelper {
return &WorktreeHelper{
c: c,
reposHelper: reposHelper,
refsHelper: refsHelper,
c: c,
reposHelper: reposHelper,
refsHelper: refsHelper,
suggestionsHelper: suggestionsHelper,
}
}
@ -65,15 +67,14 @@ func (self *WorktreeHelper) IsWorktreePathMissing(w *models.Worktree) bool {
}
func (self *WorktreeHelper) NewWorktree() error {
// what is the current branch?
branch := self.refsHelper.GetCheckedOutRef()
currentBranchName := branch.RefName()
f := func(detached bool) error {
return self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.NewWorktreeBranch,
InitialContent: currentBranchName,
// TODO: suggestions
Title: self.c.Tr.NewWorktreeBranch,
InitialContent: currentBranchName,
FindSuggestionsFunc: self.suggestionsHelper.GetRefsSuggestionsFunc(),
HandleConfirm: func(base string) error {
canCheckoutBase := base != currentBranchName
return self.NewWorktreeCheckout(base, canCheckoutBase, detached)
@ -129,7 +130,6 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
// prompt for the new branch name where a blank means we just check out the branch
return self.c.Prompt(types.PromptOpts{
Title: fmt.Sprintf("New branch name (leave blank to checkout %s)", base),
// TODO: suggestions
HandleConfirm: func(branchName string) error {
opts.Branch = branchName
@ -140,7 +140,6 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
// prompt for the new branch name where a blank means we just check out the branch
return self.c.Prompt(types.PromptOpts{
Title: "New branch name",
// TODO: suggestions
HandleConfirm: func(branchName string) error {
if branchName == "" {
return self.c.ErrorMsg("Branch name cannot be blank")