Skip to content

Commit 816d0c0

Browse files
committed
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 <[email protected]>
1 parent 5b4d009 commit 816d0c0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,10 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
325325
if suggestedBranchName == "" {
326326
var err error
327327

328-
suggestedBranchName, err = utils.ResolveTemplate(self.c.UserConfig().Git.BranchPrefix, nil, template.FuncMap{
329-
"runCommand": self.c.Git().Custom.TemplateFunctionRunCommand,
330-
})
328+
suggestedBranchName, err = self.getSuggestedBranchName()
331329
if err != nil {
332330
return err
333331
}
334-
suggestedBranchName = strings.ReplaceAll(suggestedBranchName, "\t", " ")
335332
}
336333

337334
refresh := func() error {
@@ -587,3 +584,14 @@ func (self *RefsHelper) ParseRemoteBranchName(fullBranchName string) (string, st
587584
func IsSwitchBranchUncommittedChangesError(err error) bool {
588585
return strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch")
589586
}
587+
588+
func (self *RefsHelper) getSuggestedBranchName() (string, error) {
589+
suggestedBranchName, err := utils.ResolveTemplate(self.c.UserConfig().Git.BranchPrefix, nil, template.FuncMap{
590+
"runCommand": self.c.Git().Custom.TemplateFunctionRunCommand,
591+
})
592+
if err != nil {
593+
return suggestedBranchName, err
594+
}
595+
suggestedBranchName = strings.ReplaceAll(suggestedBranchName, "\t", " ")
596+
return suggestedBranchName, nil
597+
}

0 commit comments

Comments
 (0)