From 816d0c0820c3d3e45070621ac0664519ac0e6413 Mon Sep 17 00:00:00 2001 From: Elias Assaf Date: Thu, 29 May 2025 00:38:29 +0300 Subject: [PATCH] Add a function to suggest a branch name based on branchPrefix Moving the getter of the suggested branch name to a separate function allows us to reuse it in situations where we are not calling the regular create new branch function, such as move commits to a new branch Signed-off-by: Elias Assaf --- pkg/gui/controllers/helpers/refs_helper.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 808b7866f..2a73d30b1 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -325,13 +325,10 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest if suggestedBranchName == "" { var err error - suggestedBranchName, err = utils.ResolveTemplate(self.c.UserConfig().Git.BranchPrefix, nil, template.FuncMap{ - "runCommand": self.c.Git().Custom.TemplateFunctionRunCommand, - }) + suggestedBranchName, err = self.getSuggestedBranchName() if err != nil { return err } - suggestedBranchName = strings.ReplaceAll(suggestedBranchName, "\t", " ") } refresh := func() error { @@ -587,3 +584,14 @@ func (self *RefsHelper) ParseRemoteBranchName(fullBranchName string) (string, st func IsSwitchBranchUncommittedChangesError(err error) bool { return strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") } + +func (self *RefsHelper) getSuggestedBranchName() (string, error) { + suggestedBranchName, err := utils.ResolveTemplate(self.c.UserConfig().Git.BranchPrefix, nil, template.FuncMap{ + "runCommand": self.c.Git().Custom.TemplateFunctionRunCommand, + }) + if err != nil { + return suggestedBranchName, err + } + suggestedBranchName = strings.ReplaceAll(suggestedBranchName, "\t", " ") + return suggestedBranchName, nil +}