diff --git a/windowPatchset.go b/windowPatchset.go index 8c3ab8e..c24ec57 100644 --- a/windowPatchset.go +++ b/windowPatchset.go @@ -10,6 +10,7 @@ import ( "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" "go.wit.com/gui" @@ -175,31 +176,21 @@ func (r *patchWindow) addPatchset(grid *gui.Node, pset *forgepb.Patchset) { if repo == nil { continue } - var win *repoPatchWindow - grid.NewButton("View", func() { - if win != nil { - win.Toggle() - log.Info("TRYING TO TOGGLE WINDOW") - return + // var win *repoPatchWindow + grid.NewButton("apply", func() { + filename, _ := savePatch(p) + if err := applyPatch(repo, filename); err != nil { + log.Info("warn user of git am error", err) } - // win = makeRepoPatchWindow(repo, p) - win.Show() + // win.Show() }) grid.NewCheckbox("").SetChecked(true) grid.NewCheckbox("").SetChecked(true) - grid.NewButton("save", func() { - // savePatchset(p) - /* - 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("save patch to /tmp", func() { + savePatch(p) + // for _, pat := range patches { + // } }) /* 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/ func savePatchset(pset *forgepb.Patchset) error { log.Info("savePatches() NAME", pset.Name)