@@ -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 {
@@ -399,16 +396,21 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
399396 return err
400397 }
401398
402- withNewBranchNamePrompt := func (baseBranchName string , f func (string , string ) error ) {
399+ withNewBranchNamePrompt := func (baseBranchName string , f func (string , string ) error ) error {
403400 prompt := utils .ResolvePlaceholderString (
404401 self .c .Tr .NewBranchNameBranchOff ,
405402 map [string ]string {
406403 "branchName" : baseBranchName ,
407404 },
408405 )
406+ suggestedBranchName , err := self .getSuggestedBranchName ()
407+ if err != nil {
408+ return err
409+ }
409410
410411 self .c .Prompt (types.PromptOpts {
411- Title : prompt ,
412+ Title : prompt ,
413+ InitialContent : suggestedBranchName ,
412414 HandleConfirm : func (response string ) error {
413415 self .c .LogAction (self .c .Tr .MoveCommitsToNewBranch )
414416 newBranchName := SanitizedBranchName (response )
@@ -417,6 +419,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
417419 })
418420 },
419421 })
422+ return nil
420423 }
421424
422425 isMainBranch := lo .Contains (self .c .UserConfig ().Git .MainBranches , currentBranch .Name )
@@ -431,8 +434,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
431434 Title : self .c .Tr .MoveCommitsToNewBranch ,
432435 Prompt : prompt ,
433436 HandleConfirm : func () error {
434- withNewBranchNamePrompt (currentBranch .Name , self .moveCommitsToNewBranchStackedOnCurrentBranch )
435- return nil
437+ return withNewBranchNamePrompt (currentBranch .Name , self .moveCommitsToNewBranchStackedOnCurrentBranch )
436438 },
437439 })
438440 return nil
@@ -452,17 +454,15 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
452454 {
453455 Label : fmt .Sprintf (self .c .Tr .MoveCommitsToNewBranchFromBaseItem , shortBaseBranchName ),
454456 OnPress : func () error {
455- withNewBranchNamePrompt (shortBaseBranchName , func (currentBranch string , newBranchName string ) error {
457+ return withNewBranchNamePrompt (shortBaseBranchName , func (currentBranch string , newBranchName string ) error {
456458 return self .moveCommitsToNewBranchOffOfMainBranch (currentBranch , newBranchName , baseBranchRef )
457459 })
458- return nil
459460 },
460461 },
461462 {
462463 Label : fmt .Sprintf (self .c .Tr .MoveCommitsToNewBranchStackedItem , currentBranch .Name ),
463464 OnPress : func () error {
464- withNewBranchNamePrompt (currentBranch .Name , self .moveCommitsToNewBranchStackedOnCurrentBranch )
465- return nil
465+ return withNewBranchNamePrompt (currentBranch .Name , self .moveCommitsToNewBranchStackedOnCurrentBranch )
466466 },
467467 },
468468 },
@@ -587,3 +587,14 @@ func (self *RefsHelper) ParseRemoteBranchName(fullBranchName string) (string, st
587587func IsSwitchBranchUncommittedChangesError (err error ) bool {
588588 return strings .Contains (err .Error (), "Please commit your changes or stash them before you switch branch" )
589589}
590+
591+ func (self * RefsHelper ) getSuggestedBranchName () (string , error ) {
592+ suggestedBranchName , err := utils .ResolveTemplate (self .c .UserConfig ().Git .BranchPrefix , nil , template.FuncMap {
593+ "runCommand" : self .c .Git ().Custom .TemplateFunctionRunCommand ,
594+ })
595+ if err != nil {
596+ return suggestedBranchName , err
597+ }
598+ suggestedBranchName = strings .ReplaceAll (suggestedBranchName , "\t " , " " )
599+ return suggestedBranchName , nil
600+ }
0 commit comments