allows patches to be applied

This commit is contained in:
Jeff Carr 2025-02-09 16:17:47 -06:00
parent 396161f6c1
commit 9e64b36566
1 changed files with 31 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import (
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui" "go.wit.com/gui"
@ -175,31 +176,21 @@ func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
if repo == nil { if repo == nil {
continue continue
} }
var win *repoPatchWindow // var win *repoPatchWindow
grid.NewButton("View", func() { grid.NewButton("apply", func() {
if win != nil { filename, _ := savePatch(p)
win.Toggle() if err := applyPatch(repo, filename); err != nil {
log.Info("TRYING TO TOGGLE WINDOW") log.Info("warn user of git am error", err)
return
} }
// win = makeRepoPatchWindow(repo, p) // win = makeRepoPatchWindow(repo, p)
win.Show() // win.Show()
}) })
grid.NewCheckbox("").SetChecked(true) grid.NewCheckbox("").SetChecked(true)
grid.NewCheckbox("").SetChecked(true) grid.NewCheckbox("").SetChecked(true)
grid.NewButton("save", func() { grid.NewButton("save patch to /tmp", func() {
// savePatchset(p) savePatch(p)
/* // for _, pat := range patches {
for _, p := range patches { // }
_, filen := filepath.Split(p.Filename)
tmpname := filepath.Join("/tmp", filen)
log.Info("saving as", tmpname, p.Filename)
raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
raw.Write(p.Data)
raw.Close()
}
*/
}) })
/* /*
grid.NewButton("view hash", func() { grid.NewButton("view hash", func() {
@ -215,6 +206,26 @@ func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) {
} }
} }
func applyPatch(repo *gitpb.Repo, filename string) error {
cmd := []string{"git", "am", filename}
_, err := repo.RunVerbose(cmd)
return err
}
func savePatch(p *forgepb.Patch) (string, error) {
_, filen := filepath.Split(p.Filename)
tmpname := filepath.Join("/tmp", filen)
log.Info("saving as", tmpname, p.Filename)
raw, err := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return "", err
}
raw.Write(p.Data)
raw.Close()
return tmpname, nil
}
// saves the patches in ~/.config/forge/currentpatches/ // saves the patches in ~/.config/forge/currentpatches/
func savePatchset(pset *forgepb.Patchset) error { func savePatchset(pset *forgepb.Patchset) error {
log.Info("savePatches() NAME", pset.Name) log.Info("savePatches() NAME", pset.Name)