smarter git pull

This commit is contained in:
Jeff Carr 2025-01-28 21:50:07 -06:00
parent eee88af0ce
commit 438a8812f6
4 changed files with 22 additions and 16 deletions

View File

@ -33,7 +33,7 @@ plugin:
rm -f resources/*.so rm -f resources/*.so
cp ../../toolkits/gocui/gocui.so resources/ cp ../../toolkits/gocui/gocui.so resources/
andlabs: andlabs: install
forge --gui andlabs forge --gui andlabs
gocui: install gocui: install

View File

@ -12,34 +12,33 @@ import (
) )
// saves the patches in ~/.config/forge/currentpatches/ // saves the patches in ~/.config/forge/currentpatches/
func savePatchset(pset *forgepb.Patchset) bool { func savePatchset(pset *forgepb.Patchset) error {
log.Info("applyPatches() NAME", pset.Name) log.Info("savePatches() NAME", pset.Name)
log.Info("applyPatches() COMMENT", pset.Comment) log.Info("savePatches() COMMENT", pset.Comment)
log.Info("applyPatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName()) log.Info("savePatches() GIT_AUTHOR_NAME", pset.GetGitAuthorName())
log.Info("applyPatches() GIT_AUTHOR_EMAIL", pset.GetGitAuthorEmail()) log.Info("savePatches() GIT_AUTHOR_EMAIL", pset.GetGitAuthorEmail())
log.Info("applyPatches() Branch Name", pset.GetStartBranchName()) log.Info("savePatches() Branch Name", pset.GetStartBranchName())
log.Info("applyPatches() Start Hash", pset.GetStartBranchHash()) log.Info("savePatches() Start Hash", pset.GetStartBranchHash())
var count int var count int
var bad int var bad int
var lasterr error
all := pset.Patches.SortByFilename() all := pset.Patches.SortByFilename()
for all.Scan() { for all.Scan() {
p := all.Next() p := all.Next()
// basedir := me.forge.GetGoSrc()
basedir := filepath.Join(os.Getenv("FORGE_CONFIG"), "currentpatches") basedir := filepath.Join(os.Getenv("FORGE_CONFIG"), "currentpatches")
if fullname, err := savePatchFile(p, basedir); err != nil { if fullname, err := savePatchFile(p, basedir); err != nil {
log.Info(fullname, "save failed", err) log.Info(fullname, "save failed", err)
continue
} else {
bad += 1 bad += 1
lasterr = err
} }
count += 1 count += 1
} }
log.Info("pset has", count, "total patches, ", bad, "bad save patches") log.Info("pset has", count, "total patches, ", bad, "bad save patches")
if bad == 0 { if bad == 0 {
return true return lasterr
} }
return false return nil
} }
// returns bad if patches can not be applied // returns bad if patches can not be applied

View File

@ -14,12 +14,19 @@ func rillPull(repo *gitpb.Repo) error {
return nil return nil
} }
t, _ := repo.LastGitPull() t, _ := repo.LastGitPull()
if time.Since(t) < time.Minute*10 { if time.Since(t) < time.Minute*10 && !argv.Force {
if argv.Verbose { if argv.Verbose {
log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t))) log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t)))
} }
return nil return nil
} }
cur := repo.GetCurrentBranchName()
if !repo.IsBranchRemote(cur) {
if argv.Verbose {
log.Info(repo.GetFullPath(), "branch is not remote", cur)
}
return nil
}
var cmd []string var cmd []string
cmd = append(cmd, "git", "pull") cmd = append(cmd, "git", "pull")

View File

@ -130,8 +130,8 @@ func (r *patchesWindow) addPatchset(line string) {
log.Info(name, "was nil") log.Info(name, "was nil")
return return
} }
if !savePatchset(pset) { if err := savePatchset(pset); err != nil {
log.Info("Save: some patches are bad", name) log.Info("Save: some patches are bad", name, err)
return return
} }
}) })