1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-11 11:42:12 +02:00

support patched adding

This commit is contained in:
Jesse Duffield 2018-08-07 19:50:35 +10:00
parent b541987007
commit 5a624764a8
3 changed files with 19 additions and 0 deletions

View File

@ -63,6 +63,19 @@ func handleFilePress(g *gocui.Gui, v *gocui.View) error {
return handleFileSelect(g, v)
}
func handleAddPatch(g *gocui.Gui, v *gocui.View) error {
file, err := getSelectedFile(g)
if err != nil {
if err == ErrNoFiles {
return nil
}
return err
}
gitAddPatch(g, file.Name)
return err
}
func getSelectedFile(g *gocui.Gui) (GitFile, error) {
if len(state.GitFiles) == 0 {
return GitFile{}, ErrNoFiles

View File

@ -347,6 +347,10 @@ func openFile(g *gocui.Gui, filename string) (string, error) {
return runCommand(cmdName + " " + cmdTrail)
}
func gitAddPatch(g *gocui.Gui, filename string) {
runSubProcess(g, "git", "add", "-p", filename)
}
func editFile(g *gocui.Gui, filename string) (string, error) {
editor := os.Getenv("VISUAL")
if editor == "" {
@ -355,6 +359,7 @@ func editFile(g *gocui.Gui, filename string) (string, error) {
if editor == "" {
editor = "vi"
}
runSubProcess(g, editor, filename)
return "", nil
}

1
gui.go
View File

@ -106,6 +106,7 @@ func keybindings(g *gocui.Gui) error {
Binding{ViewName: "files", Key: 'r', Modifier: gocui.ModNone, Handler: handleRefreshFiles},
Binding{ViewName: "files", Key: 'S', Modifier: gocui.ModNone, Handler: handleStashSave},
Binding{ViewName: "files", Key: 'a', Modifier: gocui.ModNone, Handler: handleAbortMerge},
Binding{ViewName: "files", Key: 't', Modifier: gocui.ModNone, Handler: handleAddPatch},
Binding{ViewName: "main", Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, Handler: handleSelectTop},
Binding{ViewName: "main", Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, Handler: handleSelectBottom},
Binding{ViewName: "main", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: handleEscapeMerge},