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

Replace whitespace with '-' when renaming a branch (#2990)

This commit is contained in:
Jesse Duffield
2023-09-09 17:34:57 +10:00
committed by GitHub
4 changed files with 40 additions and 4 deletions

View File

@ -600,7 +600,7 @@ func (self *BranchesController) rename(branch *models.Branch) error {
InitialContent: branch.Name,
HandleConfirm: func(newBranchName string) error {
self.c.LogAction(self.c.Tr.Actions.RenameBranch)
if err := self.c.Git().Branch.Rename(branch.Name, newBranchName); err != nil {
if err := self.c.Git().Branch.Rename(branch.Name, helpers.SanitizedBranchName(newBranchName)); err != nil {
return self.c.Error(err)
}

View File

@ -165,7 +165,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
InitialContent: suggestedBranchName,
HandleConfirm: func(response string) error {
self.c.LogAction(self.c.Tr.Actions.CreateBranch)
if err := self.c.Git().Branch.New(sanitizedBranchName(response), from); err != nil {
if err := self.c.Git().Branch.New(SanitizedBranchName(response), from); err != nil {
return err
}
@ -183,8 +183,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
})
}
// sanitizedBranchName will remove all spaces in favor of a dash "-" to meet
// SanitizedBranchName will remove all spaces in favor of a dash "-" to meet
// git's branch naming requirement.
func sanitizedBranchName(input string) string {
func SanitizedBranchName(input string) string {
return strings.Replace(input, " ", "-", -1)
}