stop apply if repos are dirty
This commit is contained in:
parent
92ff05cf6f
commit
79ec3ce469
|
@ -8,10 +8,12 @@ import (
|
|||
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/lib/protobuf/gitpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func dumpPatchset(pset *forgepb.Patchs) error {
|
||||
// returns bad if patches can not be applied
|
||||
func dumpPatchset(pset *forgepb.Patchs) bool {
|
||||
log.Info("applyPatches() NAME", pset.Name)
|
||||
log.Info("applyPatches() COMMENT", pset.Comment)
|
||||
log.Info("applyPatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName())
|
||||
|
@ -20,28 +22,70 @@ func dumpPatchset(pset *forgepb.Patchs) error {
|
|||
log.Info("applyPatches() Start Hash", pset.GetStartBranchHash())
|
||||
|
||||
var count int
|
||||
var bad int
|
||||
all := pset.SortByFilename()
|
||||
for all.Scan() {
|
||||
p := all.Next()
|
||||
// log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment)
|
||||
if IsValidPatch(p) {
|
||||
// ok
|
||||
} else {
|
||||
bad += 1
|
||||
}
|
||||
count += 1
|
||||
}
|
||||
log.Info("pset has", count, "total patches, ", bad, "bad patches")
|
||||
if bad == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsValidPatch(p *forgepb.Patch) bool {
|
||||
basepath, filename := filepath.Split(p.Filename)
|
||||
repo := me.forge.FindByGoPath(basepath)
|
||||
if repo == nil {
|
||||
log.Info("can not apply patch! repo not found", basepath, filename)
|
||||
continue
|
||||
return false
|
||||
}
|
||||
if repo.DevelHash() != p.StartHash {
|
||||
log.Info("can not apply patch! devel hash mismatch", basepath, filename)
|
||||
continue
|
||||
return false
|
||||
}
|
||||
log.Info("start:", p.StartHash, "end:", p.CommitHash, "file:", basepath, filename, "devel version", repo.GetDevelVersion())
|
||||
count += 1
|
||||
for _, line := range p.Files {
|
||||
log.Info("\t", line)
|
||||
}
|
||||
log.Info("pset has", count, "patches")
|
||||
return nil
|
||||
return true
|
||||
}
|
||||
|
||||
func applyPatches(pset *forgepb.Patchs) error {
|
||||
// re-run git CheckDirty() on everything
|
||||
func IsAnythingDirty() bool {
|
||||
me.found = new(gitpb.Repos)
|
||||
findAll() // select all the repos
|
||||
doCheckDirty()
|
||||
me.found = new(gitpb.Repos)
|
||||
findDirty()
|
||||
if len(me.found.Repos) == 0 {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// From 18ee541f89be2e9f9a91c54873da87885e8ffdf5 Mon Sep 17 00:00:00 2001
|
||||
// From: Jeff Carr <jcarr@wit.com>
|
||||
// Date: Sun, 5 Jan 2025 01:18:47 -0600
|
||||
// Subject: [PATCH] 'forge dirty' will find and list only dirty repos
|
||||
|
||||
// list patches in jcarr but not in devel
|
||||
// git log --format="%H %Subject" jcarr --not devel
|
||||
func countCurrentPatches(repo *gitpb.Repo) int {
|
||||
cmd := []string{"git", "log", "--format=\"%H %s\"", "--no-merges", "jcarr", "--not", "devel"}
|
||||
result := repo.Run(cmd)
|
||||
return len(result.Stdout)
|
||||
}
|
||||
|
||||
func applyPatchset(pset *forgepb.Patchs) error {
|
||||
var everythingworked bool = true
|
||||
tmpdir, err := os.MkdirTemp("", "forge")
|
||||
if err != nil {
|
||||
|
|
29
findRepos.go
29
findRepos.go
|
@ -45,35 +45,6 @@ func (f *FindCmd) findRepos() {
|
|||
findAll()
|
||||
}
|
||||
|
||||
/*
|
||||
func findRepos(fargv *FindCmd) {
|
||||
if fargv == nil {
|
||||
findMine()
|
||||
return
|
||||
}
|
||||
if fargv.All {
|
||||
findAll()
|
||||
return
|
||||
}
|
||||
|
||||
if fargv.Private {
|
||||
findPrivate()
|
||||
return
|
||||
}
|
||||
|
||||
if fargv.Mine {
|
||||
findMine()
|
||||
return
|
||||
}
|
||||
if fargv.Favorites {
|
||||
findFavorites()
|
||||
return
|
||||
}
|
||||
|
||||
findMine()
|
||||
}
|
||||
*/
|
||||
|
||||
func findPrivate() {
|
||||
all := me.forge.Repos.SortByFullPath()
|
||||
for all.Scan() {
|
||||
|
|
2
main.go
2
main.go
|
@ -81,7 +81,7 @@ func main() {
|
|||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
if err = applyPatches(pset); err == nil {
|
||||
if err = applyPatchset(pset); err == nil {
|
||||
okExit("applied patch ok")
|
||||
}
|
||||
badExit(err)
|
||||
|
|
|
@ -164,17 +164,40 @@ func submitPatchesBox(box *gui.Node) *patchSummary {
|
|||
}
|
||||
})
|
||||
|
||||
s.grid.NewButton("Show Patchsets", func() {
|
||||
s.grid.NewButton("List Patchsets", func() {
|
||||
listPatches()
|
||||
})
|
||||
|
||||
s.grid.NewButton("Get Latest Patchset", func() {
|
||||
s.grid.NewButton("Show Latest Patchset", func() {
|
||||
lastp := lastPatch()
|
||||
pset, err := getPatch(lastp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dumpPatchset(pset)
|
||||
|
||||
if !dumpPatchset(pset) {
|
||||
log.Info("some patches are bad")
|
||||
return
|
||||
}
|
||||
if IsAnythingDirty() {
|
||||
log.Info("You can't apply patches when repos are dirty")
|
||||
doCobol()
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
s.grid.NewButton("Apply Latest Patchset", func() {
|
||||
lastp := lastPatch()
|
||||
pset, err := getPatch(lastp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if IsAnythingDirty() {
|
||||
log.Info("You can't apply patches when repos are dirty")
|
||||
doCobol()
|
||||
return
|
||||
}
|
||||
applyPatchset(pset)
|
||||
})
|
||||
|
||||
s.grid.NewButton("Show Repos", func() {
|
||||
|
|
Loading…
Reference in New Issue