summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-16 22:01:14 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-16 22:24:54 +1000
commitdb826b3c8795e47e3471ab76bc4bcb131892c224 (patch)
tree37938ead603d4da7697ba4391f91e173787b2b17 /pkg
parentbe658e7d64c8d120a6c7ca9c59cbb05957135c1d (diff)
add keybinding to create new branch off of commit
retain focus in commits panel surface prompt errors better description
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/commit.go6
-rw-r--r--pkg/commands/git.go4
-rw-r--r--pkg/gui/commits_panel.go24
-rw-r--r--pkg/gui/confirmation_panel.go2
-rw-r--r--pkg/gui/keybindings.go8
-rw-r--r--pkg/i18n/english.go3
6 files changed, 44 insertions, 3 deletions
diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go
index ea4192b33..f8f7491b4 100644
--- a/pkg/commands/commit.go
+++ b/pkg/commands/commit.go
@@ -1,5 +1,7 @@
package commands
+import "fmt"
+
// Commit : A git commit
type Commit struct {
Sha string
@@ -18,3 +20,7 @@ func (c *Commit) ShortSha() string {
}
return c.Sha[:8]
}
+
+func (c *Commit) NameWithSha() string {
+ return fmt.Sprintf("%s %s", c.Sha[:7], c.Name)
+}
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index f4fb4a424..b52c989d7 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -401,8 +401,8 @@ func (c *GitCommand) ResetToCommit(sha string, strength string, options RunComma
}
// NewBranch create new branch
-func (c *GitCommand) NewBranch(name string, baseBranch string) error {
- return c.OSCommand.RunCommand("git checkout -b %s %s", name, baseBranch)
+func (c *GitCommand) NewBranch(name string, base string) error {
+ return c.OSCommand.RunCommand("git checkout -b %s %s", name, base)
}
// CurrentBranchName get the current branch name and displayname.
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 728517b9b..d1f86d287 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -771,3 +771,27 @@ func (gui *Gui) handleClipboardCopyCommit(g *gocui.Gui, v *gocui.View) error {
return gui.OSCommand.CopyToClipboard(commit.Sha)
}
+
+func (gui *Gui) handleNewBranchOffCommit() error {
+ commit := gui.getSelectedCommit()
+ if commit == nil {
+ return nil
+ }
+
+ message := gui.Tr.TemplateLocalize(
+ "NewBranchNameBranchOff",
+ Teml{
+ "branchName": commit.NameWithSha(),
+ },
+ )
+
+ return gui.prompt(gui.getCommitsView(), message, "", func(response string) error {
+ if err := gui.GitCommand.NewBranch(response, commit.Sha); err != nil {
+ return err
+ }
+ gui.State.Panels.Commits.SelectedLine = 0
+ gui.State.Panels.Branches.SelectedLine = 0
+
+ return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
+ })
+}
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index e1aa29531..71fe20452 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -85,7 +85,7 @@ func (gui *Gui) wrappedPromptConfirmationFunction(function func(string) error, r
if function != nil {
if err := function(v.Buffer()); err != nil {
- return err
+ return gui.surfaceError(err)
}
}
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 6e4afceec..e149dc66d 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -778,6 +778,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{
ViewName: "commits",
Contexts: []string{"branch-commits"},
+ Key: gui.getKey("universal.new"),
+ Modifier: gocui.ModNone,
+ Handler: gui.wrappedHandler(gui.handleNewBranchOffCommit),
+ Description: gui.Tr.SLocalize("createNewBranchFromCommit"),
+ },
+ {
+ ViewName: "commits",
+ Contexts: []string{"branch-commits"},
Key: gui.getKey("commits.tagCommit"),
Handler: gui.handleTagCommit,
Description: gui.Tr.SLocalize("tagCommit"),
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 0815eeb73..71d0923c8 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -1167,6 +1167,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "UnstageLinesPrompt",
Other: "Are you sure you want to delete the selected lines (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipUnstageLineWarning' to true",
+ }, &i18n.Message{
+ ID: "createNewBranchFromCommit",
+ Other: "create new branch off of commit",
},
)
}