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:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user