diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-11 09:53:46 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-03-16 10:20:27 +1100 |
commit | 0e008cc15f8e7cbb6869151d48ae30403bf4dc70 (patch) | |
tree | 16af0e998aeaa7e16477e2817376fd0ef38e2219 | |
parent | 1ad9c6faac18d5a683d631452e6a8f8f9c88b9da (diff) |
allow user to checkout old files
-rw-r--r-- | pkg/commands/git.go | 6 | ||||
-rw-r--r-- | pkg/gui/commit_files_panel.go | 11 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 18 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 3 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 3 |
6 files changed, 38 insertions, 6 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 3e0bf2441..96b25316c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -808,3 +808,9 @@ func (c *GitCommand) ShowCommitFile(commitID, file string) (string, error) { cmd := fmt.Sprintf("git show --color %s -- %s", commitID, file) return c.OSCommand.RunCommandWithOutput(cmd) } + +// CheckoutFile checks out the file for the given commit +func (c *GitCommand) CheckoutFile(commitSha, fileName string) error { + cmd := fmt.Sprintf("git checkout %s %s", commitSha, fileName) + return c.OSCommand.RunCommand(cmd) +} diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index cb4bee807..1d54a2bcf 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -51,3 +51,14 @@ func (gui *Gui) handleSwitchToCommitsPanel(g *gocui.Gui, v *gocui.View) error { } return gui.switchFocus(g, v, commitsView) } + +func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error { + commitSha := gui.State.Commits[gui.State.Panels.Commits.SelectedLine].Sha + fileName := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name + + if err := gui.GitCommand.CheckoutFile(commitSha, fileName); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 4f03a3c47..c5eb758e9 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -453,6 +453,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Modifier: gocui.ModNone, Handler: gui.handleSwitchToCommitsPanel, Description: gui.Tr.SLocalize("goBack"), + }, { + ViewName: "commitFiles", + Key: 'c', + Modifier: gocui.ModNone, + Handler: gui.handleCheckoutCommitFile, + Description: gui.Tr.SLocalize("checkoutCommitFile"), }, } @@ -471,12 +477,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { nextLine func(*gocui.Gui, *gocui.View) error focus func(*gocui.Gui, *gocui.View) error }{ - "menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect}, - "files": {prevLine: gui.handleFilesPrevLine, nextLine: gui.handleFilesNextLine, focus: gui.handleFilesFocus}, - "branches": {prevLine: gui.handleBranchesPrevLine, nextLine: gui.handleBranchesNextLine, focus: gui.handleBranchSelect}, - "commits": {prevLine: gui.handleCommitsPrevLine, nextLine: gui.handleCommitsNextLine, focus: gui.handleCommitSelect}, - "stash": {prevLine: gui.handleStashPrevLine, nextLine: gui.handleStashNextLine, focus: gui.handleStashEntrySelect}, - "status": {focus: gui.handleStatusSelect}, + "menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect}, + "files": {prevLine: gui.handleFilesPrevLine, nextLine: gui.handleFilesNextLine, focus: gui.handleFilesFocus}, + "branches": {prevLine: gui.handleBranchesPrevLine, nextLine: gui.handleBranchesNextLine, focus: gui.handleBranchSelect}, + "commits": {prevLine: gui.handleCommitsPrevLine, nextLine: gui.handleCommitsNextLine, focus: gui.handleCommitSelect}, + "stash": {prevLine: gui.handleStashPrevLine, nextLine: gui.handleStashNextLine, focus: gui.handleStashEntrySelect}, + "status": {focus: gui.handleStatusSelect}, "commitFiles": {prevLine: gui.handleCommitFilesPrevLine, nextLine: gui.handleCommitFilesNextLine, focus: gui.handleCommitFileSelect}, } diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 0d8cc2d63..4d2ee4236 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -655,6 +655,9 @@ func addDutch(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "NoCommiteFiles", Other: "No files for this commit", + }, &i18n.Message{ + ID: "checkoutCommitFile", + Other: "checkout file", }, ) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 4a0b40b27..c9eda4ce6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -678,6 +678,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "NoCommiteFiles", Other: "No files for this commit", + }, &i18n.Message{ + ID: "checkoutCommitFile", + Other: "checkout file", }, ) } diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index ba855eaf7..30462a7c3 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -638,6 +638,9 @@ func addPolish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "NoCommiteFiles", Other: "No files for this commit", + }, &i18n.Message{ + ID: "checkoutCommitFile", + Other: "checkout file", }, ) } |