1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

added support for using spaces on branch names when creating new ones.

This commit is contained in:
caquillo07 2021-02-08 17:09:02 -05:00 committed by Jesse Duffield
parent 922c0887f1
commit 6df15ddf6e

View File

@ -497,7 +497,7 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
title: message,
initialContent: prefilledName,
handleConfirm: func(response string) error {
if err := gui.GitCommand.NewBranch(response, item.ID()); err != nil {
if err := gui.GitCommand.NewBranch(sanitizedBranchName(response), item.ID()); err != nil {
return err
}
@ -533,7 +533,7 @@ func (gui *Gui) getBranchNames() []string {
func (gui *Gui) findBranchNameSuggestions(input string) []*types.Suggestion {
branchNames := gui.getBranchNames()
matchingBranchNames := utils.FuzzySearch(input, branchNames)
matchingBranchNames := utils.FuzzySearch(sanitizedBranchName(input), branchNames)
suggestions := make([]*types.Suggestion, len(matchingBranchNames))
for i, branchName := range matchingBranchNames {
@ -545,3 +545,9 @@ func (gui *Gui) findBranchNameSuggestions(input string) []*types.Suggestion {
return suggestions
}
// sanitizedBranchName will remove all spaces in favor of a dash "-" to meet
// git's branch naming requirement.
func sanitizedBranchName(input string) string {
return strings.ReplaceAll(input, " ", "-")
}