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:
parent
a3cd1e93be
commit
c3ca77d6bf
@ -557,7 +557,7 @@ func (self *BranchesController) rename(branch *models.Branch) error {
|
|||||||
InitialContent: branch.Name,
|
InitialContent: branch.Name,
|
||||||
HandleConfirm: func(newBranchName string) error {
|
HandleConfirm: func(newBranchName string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.RenameBranch)
|
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)
|
return self.c.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
|
|||||||
InitialContent: suggestedBranchName,
|
InitialContent: suggestedBranchName,
|
||||||
HandleConfirm: func(response string) error {
|
HandleConfirm: func(response string) error {
|
||||||
self.c.LogAction(self.c.Tr.Actions.CreateBranch)
|
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
|
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.
|
// git's branch naming requirement.
|
||||||
func sanitizedBranchName(input string) string {
|
func SanitizedBranchName(input string) string {
|
||||||
return strings.Replace(input, " ", "-", -1)
|
return strings.Replace(input, " ", "-", -1)
|
||||||
}
|
}
|
||||||
|
35
pkg/integration/tests/branch/rename.go
Normal file
35
pkg/integration/tests/branch/rename.go
Normal 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"),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
@ -46,6 +46,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
branch.RebaseCancelOnConflict,
|
branch.RebaseCancelOnConflict,
|
||||||
branch.RebaseDoesNotAutosquash,
|
branch.RebaseDoesNotAutosquash,
|
||||||
branch.RebaseFromMarkedBase,
|
branch.RebaseFromMarkedBase,
|
||||||
|
branch.Rename,
|
||||||
branch.Reset,
|
branch.Reset,
|
||||||
branch.ResetUpstream,
|
branch.ResetUpstream,
|
||||||
branch.SetUpstream,
|
branch.SetUpstream,
|
||||||
|
Loading…
Reference in New Issue
Block a user