mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-02 23:27:32 +02:00
Use branchPrefix on moving commits to a new branch
Signed-off-by: Elias Assaf <elyas51000@gmail.com>
This commit is contained in:
parent
816d0c0820
commit
fdf9726c37
@ -396,16 +396,21 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) {
|
withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) error {
|
||||||
prompt := utils.ResolvePlaceholderString(
|
prompt := utils.ResolvePlaceholderString(
|
||||||
self.c.Tr.NewBranchNameBranchOff,
|
self.c.Tr.NewBranchNameBranchOff,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"branchName": baseBranchName,
|
"branchName": baseBranchName,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
suggestedBranchName, err := self.getSuggestedBranchName()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
self.c.Prompt(types.PromptOpts{
|
self.c.Prompt(types.PromptOpts{
|
||||||
Title: prompt,
|
Title: prompt,
|
||||||
|
InitialContent: suggestedBranchName,
|
||||||
HandleConfirm: func(response string) error {
|
HandleConfirm: func(response string) error {
|
||||||
self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch)
|
self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch)
|
||||||
newBranchName := SanitizedBranchName(response)
|
newBranchName := SanitizedBranchName(response)
|
||||||
@ -414,6 +419,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
isMainBranch := lo.Contains(self.c.UserConfig().Git.MainBranches, currentBranch.Name)
|
isMainBranch := lo.Contains(self.c.UserConfig().Git.MainBranches, currentBranch.Name)
|
||||||
@ -428,8 +434,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
|
|||||||
Title: self.c.Tr.MoveCommitsToNewBranch,
|
Title: self.c.Tr.MoveCommitsToNewBranch,
|
||||||
Prompt: prompt,
|
Prompt: prompt,
|
||||||
HandleConfirm: func() error {
|
HandleConfirm: func() error {
|
||||||
withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
|
return withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@ -449,17 +454,15 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
|
|||||||
{
|
{
|
||||||
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchFromBaseItem, shortBaseBranchName),
|
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchFromBaseItem, shortBaseBranchName),
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error {
|
return withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error {
|
||||||
return self.moveCommitsToNewBranchOffOfMainBranch(currentBranch, newBranchName, baseBranchRef)
|
return self.moveCommitsToNewBranchOffOfMainBranch(currentBranch, newBranchName, baseBranchRef)
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchStackedItem, currentBranch.Name),
|
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchStackedItem, currentBranch.Name),
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
|
return withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,9 @@ var MoveCommitsToNewBranchKeepStacked = NewIntegrationTest(NewIntegrationTestArg
|
|||||||
Description: "Create a new branch from the commits that you accidentally made on the wrong branch; choosing stacked on current branch",
|
Description: "Create a new branch from the commits that you accidentally made on the wrong branch; choosing stacked on current branch",
|
||||||
ExtraCmdArgs: []string{},
|
ExtraCmdArgs: []string{},
|
||||||
Skip: false,
|
Skip: false,
|
||||||
SetupConfig: func(config *config.AppConfig) {},
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
config.GetUserConfig().Git.BranchPrefix = "myprefix/"
|
||||||
|
},
|
||||||
SetupRepo: func(shell *Shell) {
|
SetupRepo: func(shell *Shell) {
|
||||||
shell.EmptyCommit("initial commit")
|
shell.EmptyCommit("initial commit")
|
||||||
shell.CloneIntoRemote("origin")
|
shell.CloneIntoRemote("origin")
|
||||||
@ -42,12 +44,13 @@ var MoveCommitsToNewBranchKeepStacked = NewIntegrationTest(NewIntegrationTestArg
|
|||||||
|
|
||||||
t.ExpectPopup().Prompt().
|
t.ExpectPopup().Prompt().
|
||||||
Title(Equals("New branch name (branch is off of 'feature')")).
|
Title(Equals("New branch name (branch is off of 'feature')")).
|
||||||
|
InitialText(Equals("myprefix/")).
|
||||||
Type("new branch").
|
Type("new branch").
|
||||||
Confirm()
|
Confirm()
|
||||||
|
|
||||||
t.Views().Branches().
|
t.Views().Branches().
|
||||||
Lines(
|
Lines(
|
||||||
Contains("new-branch").DoesNotContain("↑").IsSelected(),
|
Contains("myprefix/new-branch").DoesNotContain("↑").IsSelected(),
|
||||||
Contains("feature ✓"),
|
Contains("feature ✓"),
|
||||||
Contains("master ✓"),
|
Contains("master ✓"),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user