mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
use selected branch as base when creating a new branch
This commit is contained in:
@ -327,8 +327,8 @@ func (c *GitCommand) ResetToCommit(sha string, strength string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBranch create new branch
|
// NewBranch create new branch
|
||||||
func (c *GitCommand) NewBranch(name string) error {
|
func (c *GitCommand) NewBranch(name string, baseBranch string) error {
|
||||||
return c.OSCommand.RunCommand("git checkout -b %s", name)
|
return c.OSCommand.RunCommand("git checkout -b %s %s", name, baseBranch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentBranchName is a function.
|
// CurrentBranchName is a function.
|
||||||
|
@ -636,12 +636,12 @@ func TestGitCommandNewBranch(t *testing.T) {
|
|||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd {
|
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd {
|
||||||
assert.EqualValues(t, "git", cmd)
|
assert.EqualValues(t, "git", cmd)
|
||||||
assert.EqualValues(t, []string{"checkout", "-b", "test"}, args)
|
assert.EqualValues(t, []string{"checkout", "-b", "test", "master"}, args)
|
||||||
|
|
||||||
return exec.Command("echo")
|
return exec.Command("echo")
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, gitCmd.NewBranch("test"))
|
assert.NoError(t, gitCmd.NewBranch("test", "master"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGitCommandDeleteBranch is a function.
|
// TestGitCommandDeleteBranch is a function.
|
||||||
|
@ -220,7 +220,10 @@ func (gui *Gui) getCheckedOutBranch() *commands.Branch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error {
|
||||||
branch := gui.getCheckedOutBranch()
|
branch := gui.getSelectedBranch()
|
||||||
|
if branch == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
message := gui.Tr.TemplateLocalize(
|
message := gui.Tr.TemplateLocalize(
|
||||||
"NewBranchNameBranchOff",
|
"NewBranchNameBranchOff",
|
||||||
Teml{
|
Teml{
|
||||||
@ -228,7 +231,7 @@ func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
gui.createPromptPanel(g, v, message, "", func(g *gocui.Gui, v *gocui.View) error {
|
gui.createPromptPanel(g, v, message, "", func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.GitCommand.NewBranch(gui.trimmedContent(v)); err != nil {
|
if err := gui.GitCommand.NewBranch(gui.trimmedContent(v), branch.Name); err != nil {
|
||||||
return gui.createErrorPanel(g, err.Error())
|
return gui.createErrorPanel(g, err.Error())
|
||||||
}
|
}
|
||||||
gui.refreshSidePanels(g)
|
gui.refreshSidePanels(g)
|
||||||
|
Reference in New Issue
Block a user