diff options
| author | Jeff Carr <[email protected]> | 2025-03-11 12:15:12 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-11 12:15:12 -0500 |
| commit | 74a6d4bdfbc104b93b6d6e56bda9d70e07b8b597 (patch) | |
| tree | c57ac489a133d9362a7e24877f5b6e201b8cbb98 /windowPatches.go | |
| parent | 422d853020cf1725c14bd7a85477b68b8d90b31b (diff) | |
resurrect code I deleted for 'git am'v0.22.106
Diffstat (limited to 'windowPatches.go')
| -rw-r--r-- | windowPatches.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/windowPatches.go b/windowPatches.go index f11152b..b23735b 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -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 +} |
