diff options
Diffstat (limited to 'doPatch.go')
| -rw-r--r-- | doPatch.go | 74 |
1 files changed, 43 insertions, 31 deletions
@@ -35,7 +35,7 @@ func isPatchingSafe() bool { } func doPatch() (string, error) { - if argv.Patch.Submit != nil { + if argv.Patch.Submit { return "Submitted", doPatchSubmit() } @@ -50,13 +50,8 @@ func doPatch() (string, error) { return footer, err } - if argv.Patch.List != nil { - err := doPatchList() - return "listed patches", err - } - - err := doPatchList() - return "listed patches. where is my footer?", err + s, err := doPatchList() + return s, err } // submit's current working patches @@ -78,13 +73,14 @@ func doPatchSubmit() error { return err } -func doPatchList() error { +func doPatchList() (string, error) { curpatches := forgepb.NewPatches() curpatches.Filename = "/tmp/curpatches.pb" if err := curpatches.Load(); err != nil { - return err + return "fix curpatches.pb", err } curpatches.PrintTable() + var needfix int for patch := range curpatches.IterAll() { repo := me.forge.Repos.FindByNamespace(patch.Namespace) if repo == nil { @@ -93,41 +89,57 @@ func doPatchList() error { } newId, newHash, err := isPatchIdApplied(repo, patch) if errors.Is(err, ErrorGitPullOnDirty) { - log.Info("a patch with that comment couldn't be found in the repo") + // log.Info("a patch with that comment couldn't be found in the repo") } else if err != nil { log.Info("err", patch.PatchId, patch.Namespace, patch.Comment, err) - return patch.Error(err) - } - if (newId == patch.PatchId) && (newHash == patch.CommitHash) { - log.Info(patch.PatchId, "patch made here", patch.Comment) - continue + return "isPatchIdApplied() error", patch.Error(err) } - if newId == patch.PatchId { - log.Info(patch.PatchId, "patch already applied", patch.Comment) - continue - } - if newId != patch.PatchId { - log.Info(patch.PatchId, "probably duplicate subject", patch.Comment) - // try this. it should compute every patch id in the repo - // os.Chdir(repo.FullPath) - // newNewId, err := searchAllCommits(targetPatchID string) (string, error) { + if newId == "" { + // new patch ! + // log.Info(patch.PatchId, "newId==''", patch.Comment) + } else { + if (newId == patch.PatchId) && (newHash == patch.CommitHash) { + log.Info(patch.PatchId, newId, "patch made here", patch.Comment) + patch.NewHash = "author" + continue + } + if newId == patch.PatchId { + patch.NewHash = patch.CommitHash + log.Info(patch.PatchId, newId, "patch already applied", patch.Comment) + continue + } + if newId != patch.PatchId { + log.Info(patch.PatchId, newId, "probably duplicate subject? (mismatch)", patch.Comment) + // try this. it should compute every patch id in the repo + // os.Chdir(repo.FullPath) + // newNewId, err := searchAllCommits(targetPatchID string) (string, error) { + } } - log.Info("new patch", patch.PatchId, patch.Comment) + log.Info(patch.PatchId, newId, "new patch", patch.Comment) if !argv.Fix { - log.Info("use --fix to attempt to apply new patches") + needfix += 1 } else { log.Info(string(patch.Data)) log.Info("repo:", repo.FullPath, "patch header:", patch.Comment, patch.CommitHash) - if fhelp.QuestionUser("apply this patch?") { + if fhelp.QuestionUser("apply this patch? (--force to autoapply)") { newhash, err := applyPatch(repo, patch) - log.Info("apply results:", newhash, err) if err != nil { - return err + log.Info("apply results:", newhash, err) + } + if err != nil { + return "git am problem. manually investigate or purge everything and start over", err } } } } - return nil + var s string + if needfix == 0 { + s = "no new patches" + } else { + s = log.Sprintf("There are %d new patches. Use --fix to apply them", needfix) + curpatches.Save() + } + return s, nil } func applyPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) { |
