resurrect code I deleted for 'git am'
This commit is contained in:
parent
422d853020
commit
74a6d4bdfb
|
@ -5,12 +5,14 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"go.wit.com/gui"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/lib/protobuf/gitpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -57,6 +59,30 @@ func makePatchesWin(patches *forgepb.Patches) *stdPatchTableWin {
|
|||
|
||||
grid.NewButton("reload", func() {
|
||||
})
|
||||
grid.NewButton("Apply All", func() {
|
||||
var count int
|
||||
all := patches.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
rn := p.RepoNamespace
|
||||
repo := me.forge.FindByGoPath(rn)
|
||||
if repo == nil {
|
||||
log.Info("Could not figure out repo path", rn)
|
||||
return
|
||||
}
|
||||
filename, err := savePatch(p)
|
||||
if err != nil {
|
||||
log.Info("savePatch() failed", err)
|
||||
return
|
||||
}
|
||||
count += 1
|
||||
if err := applyPatch(repo, filename); err != nil {
|
||||
log.Info("warn user of git am error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Info("ALL PATCHES WORKED! count =", count)
|
||||
})
|
||||
|
||||
// make a box at the bottom of the window for the protobuf table
|
||||
dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")
|
||||
|
@ -101,3 +127,23 @@ func AddPatchesPB(tbox *gui.Node, pb *forgepb.Patches) *forgepb.PatchesTable {
|
|||
t.ShowTable()
|
||||
return t
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue