1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-02 09:21:40 +02:00

Replace whitespace with '-' when renaming a branch

This commit is contained in:
Cal Courtney 2023-09-05 13:34:38 +01:00
parent a3cd1e93be
commit c3ca77d6bf
4 changed files with 40 additions and 4 deletions

View File

@ -557,7 +557,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)
}

View File

@ -0,0 +1,35 @@
package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var Rename = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Rename a branch, replacing spaces in the name with dashes",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("master"),
).
Press(keys.Branches.RenameBranch).
Tap(func() {
t.ExpectPopup().Prompt().
Title(Contains("Enter new branch name")).
InitialText(Equals("master")).
Clear().
Type("new branch name").
Confirm()
}).
Lines(
Contains("new-branch-name"),
)
},
})

View File

@ -46,6 +46,7 @@ var tests = []*components.IntegrationTest{
branch.RebaseCancelOnConflict,
branch.RebaseDoesNotAutosquash,
branch.RebaseFromMarkedBase,
branch.Rename,
branch.Reset,
branch.ResetUpstream,
branch.SetUpstream,