diff options
-rw-r--r-- | docs/keybindings/Keybindings_en.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_nl.md | 1 | ||||
-rw-r--r-- | docs/keybindings/Keybindings_pl.md | 1 | ||||
-rw-r--r-- | pkg/commands/commit.go | 6 | ||||
-rw-r--r-- | pkg/commands/git.go | 4 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 24 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 8 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 |
9 files changed, 47 insertions, 3 deletions
diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 26fbd2b1f..e28142755 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -144,6 +144,7 @@ <kbd>v</kbd>: paste commits (cherry-pick) <kbd>enter</kbd>: view commit's files <kbd>space</kbd>: checkout commit + <kbd>n</kbd>: create new branch off of commit <kbd>T</kbd>: tag commit <kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection <kbd>,</kbd>: previous page diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 227d8e028..567bf4d25 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -144,6 +144,7 @@ <kbd>v</kbd>: plak commits (cherry-pick) <kbd>enter</kbd>: bekijk gecommite bestanden <kbd>space</kbd>: checkout commit + <kbd>n</kbd>: create new branch off of commit <kbd>T</kbd>: tag commit <kbd>ctrl+r</kbd>: reset cherry-picked (gecopieerde) commits selectie <kbd>,</kbd>: vorige pagina diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 0026a1c51..bc288f107 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -144,6 +144,7 @@ <kbd>v</kbd>: paste commits (cherry-pick) <kbd>enter</kbd>: view commit's files <kbd>space</kbd>: checkout commit + <kbd>n</kbd>: create new branch off of commit <kbd>T</kbd>: tag commit <kbd>ctrl+r</kbd>: reset cherry-picked (copied) commits selection <kbd>,</kbd>: previous page 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", }, ) } |