mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-26 09:00:57 +02:00
allow user to checkout old files
This commit is contained in:
parent
1ad9c6faac
commit
0e008cc15f
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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},
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -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",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -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",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user