mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Merge 83b182bbe0 into 8924bca76f
This commit is contained in:
commit
187f571a5e
|
|
@ -343,6 +343,10 @@ type GitConfig struct {
|
|||
CommitPrefixes map[string][]CommitPrefixConfig `yaml:"commitPrefixes"`
|
||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-branch-name-prefix
|
||||
BranchPrefix string `yaml:"branchPrefix"`
|
||||
// Specifies the character used to replace whitespace in branch names when creating new branches.
|
||||
// By default, spaces are replaced with dashes ("-").
|
||||
// Some teams use underscores ("_") or other characters.
|
||||
BranchWhitespaceReplacement string `yaml:"branchWhitespaceReplacement"`
|
||||
// If true, parse emoji strings in commit messages e.g. render :rocket: as 🚀
|
||||
// (This should really be under 'gui', not 'git')
|
||||
ParseEmoji bool `yaml:"parseEmoji"`
|
||||
|
|
@ -969,6 +973,7 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig {
|
|||
DisableForcePushing: false,
|
||||
CommitPrefixes: map[string][]CommitPrefixConfig(nil),
|
||||
BranchPrefix: "",
|
||||
BranchWhitespaceReplacement: "-",
|
||||
ParseEmoji: false,
|
||||
TruncateCopiedCommitHashesTo: 12,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -736,7 +736,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, helpers.SanitizedBranchName(newBranchName)); err != nil {
|
||||
if err := self.c.Git().Branch.Rename(branch.Name, self.c.Helpers().Refs.SanitizedBranchNameWithConfig(newBranchName)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -390,7 +390,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)
|
||||
newBranchName := SanitizedBranchName(response)
|
||||
newBranchName := self.SanitizedBranchNameWithConfig(response)
|
||||
newBranchFunc := self.c.Git().Branch.New
|
||||
if newBranchName != suggestedBranchName {
|
||||
newBranchFunc = self.c.Git().Branch.NewWithoutTracking
|
||||
|
|
@ -465,7 +465,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
|
|||
InitialContent: suggestedBranchName,
|
||||
HandleConfirm: func(response string) error {
|
||||
self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch)
|
||||
newBranchName := SanitizedBranchName(response)
|
||||
newBranchName := self.SanitizedBranchNameWithConfig(response)
|
||||
return self.c.WithWaitingStatus(self.c.Tr.MovingCommitsToNewBranchStatus, func(gocui.Task) error {
|
||||
return f(newBranchName)
|
||||
})
|
||||
|
|
@ -619,10 +619,20 @@ func (self *RefsHelper) CanMoveCommitsToNewBranch() *types.DisabledReason {
|
|||
return nil
|
||||
}
|
||||
|
||||
// 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, " ", "-")
|
||||
// SanitizedBranchName will remove all spaces in favor of the specified replacement
|
||||
// character to meet git's branch naming requirement.
|
||||
func SanitizedBranchName(input string, replacement string) string {
|
||||
return strings.ReplaceAll(input, " ", replacement)
|
||||
}
|
||||
|
||||
// SanitizedBranchNameWithConfig returns a sanitized branch name using the
|
||||
// user's configured whitespace replacement character.
|
||||
func (self *RefsHelper) SanitizedBranchNameWithConfig(input string) string {
|
||||
replacement := self.c.UserConfig().Git.BranchWhitespaceReplacement
|
||||
if replacement == "" {
|
||||
replacement = "-"
|
||||
}
|
||||
return SanitizedBranchName(input, replacement)
|
||||
}
|
||||
|
||||
// Checks if the given branch name is a remote branch, and returns the name of
|
||||
|
|
|
|||
Loading…
Reference in a new issue