1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

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 <elyas51000@gmail.com>
This commit is contained in:
Elias Assaf
2025-05-29 00:38:29 +03:00
parent 5b4d009f55
commit 816d0c0820

View File

@ -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
}