summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-08 13:19:38 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-08 18:44:15 +1100
commit19146d61b1d16f93242d803652c1ed3c4dc24689 (patch)
treefc9105c7013fb04bb0b7dd705f608a55157646f5
parente541b809ce0c7062c46368082224716d90696993 (diff)
use selected branch as base when creating a new branch
-rw-r--r--pkg/commands/git.go4
-rw-r--r--pkg/commands/git_test.go4
-rw-r--r--pkg/gui/branches_panel.go7
3 files changed, 9 insertions, 6 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 588cec80e..00ec296de 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -327,8 +327,8 @@ func (c *GitCommand) ResetToCommit(sha string, strength string) error {
}
// NewBranch create new branch
-func (c *GitCommand) NewBranch(name string) error {
- return c.OSCommand.RunCommand("git checkout -b %s", name)
+func (c *GitCommand) NewBranch(name string, baseBranch string) error {
+ return c.OSCommand.RunCommand("git checkout -b %s %s", name, baseBranch)
}
// CurrentBranchName is a function.
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index fabeb6375..779e31f68 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -636,12 +636,12 @@ func TestGitCommandNewBranch(t *testing.T) {
gitCmd := NewDummyGitCommand()
gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.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")
}
- assert.NoError(t, gitCmd.NewBranch("test"))
+ assert.NoError(t, gitCmd.NewBranch("test", "master"))
}
// TestGitCommandDeleteBranch is a function.
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 90d8a2758..44cd9415b 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -220,7 +220,10 @@ func (gui *Gui) getCheckedOutBranch() *commands.Branch {
}
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(
"NewBranchNameBranchOff",
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 {
- 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())
}
gui.refreshSidePanels(g)