diff options
| -rw-r--r-- | doClean.go | 83 | ||||
| -rw-r--r-- | doPull.go | 53 |
2 files changed, 104 insertions, 32 deletions
@@ -14,10 +14,59 @@ import ( "go.wit.com/log" ) +func doResetRepo(repo *gitpb.Repo) error { + if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { + return log.Errorf("not on master branch") + } + if repo.IsDirty() { + return log.Errorf("repo is dirty") + } + + // when publishing, clean out the details of that if it's still there + if repo.GetTargetVersion() != "" { + repo.SetTargetVersion("") + } + + // try to delete user + if err := doRepoCleanUser(repo); err != nil { + if err == ErrorBranchUnique { + if argv.Clean.Fix != nil { + bname := repo.GetUserBranchName() + checkPatchIds(repo, repo.GetUserBranchName(), repo.GetMasterBranchName()) + s := fmt.Sprintf("delete this odd user (%s) branch %s?", bname, repo.FullPath) + if fhelp.QuestionUser(s) { + repo.RunVerbose([]string{"git", "branch", "-D", bname}) + // repo.RunVerbose([]string{"git", "checkout", bname}) + } + } + } else { + log.Info(repo.GetGoPath(), err) + } + } + + // try to delete devel + err := doRepoCleanDevel(repo) + return err +} + // reverts all repos back to the original master branches // automatically deletes local devel and user branches func doClean() error { - setForgeMode(forgepb.ForgeMode_CLEAN) + if argv.Clean.Repo != "" { + setForgeMode(forgepb.ForgeMode_CLEAN) + log.Info("only reset repo:", argv.Clean.Repo) + if found := me.forge.Repos.FindByNamespace(argv.Clean.Repo); found != nil { + return doResetRepo(found) + } + if found := me.forge.Repos.FindByFullPath(argv.Clean.Repo); found != nil { + return doResetRepo(found) + } + return log.Errorf("repo not found: %s", argv.Clean.Repo) + } + + s := fmt.Sprintf("Reset all (%d) git repos to the original state (non-destructive)?", me.forge.Repos.Len()) + if !fhelp.QuestionUser(s) { + } // fix this to work, then delete all the other options for "forge clean' if err := me.forge.DoAllCheckoutMaster(); err != nil { @@ -27,37 +76,7 @@ func doClean() error { all := me.forge.Repos.SortByFullPath() for all.Scan() { repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { - continue - } - if repo.IsDirty() { - continue - } - - // when publishing, clean out the details of that if it's still there - if repo.GetTargetVersion() != "" { - repo.SetTargetVersion("") - } - - // try to delete user - if err := doRepoCleanUser(repo); err != nil { - if err == ErrorBranchUnique { - if argv.Clean.Fix != nil { - bname := repo.GetUserBranchName() - checkPatchIds(repo, repo.GetUserBranchName(), repo.GetMasterBranchName()) - s := fmt.Sprintf("delete this odd user (%s) branch %s?", bname, repo.FullPath) - if fhelp.QuestionUser(s) { - repo.RunVerbose([]string{"git", "branch", "-D", bname}) - // repo.RunVerbose([]string{"git", "checkout", bname}) - } - } - } else { - log.Info(repo.GetGoPath(), err) - } - } - - // try to delete devel - doRepoCleanDevel(repo) + doResetRepo(repo) } found := gitpb.NewRepos() @@ -12,6 +12,42 @@ import ( "go.wit.com/log" ) +// returns true if 'git pull' should be run +func needToUpdateRepo(repo *gitpb.Repo) (*gitpb.Repo, error) { + if repo.Tags == nil { + return nil, nil + } + if repo.Tags.Master == nil { + return nil, nil + } + found := me.forge.Repos.FindByNamespace(repo.Namespace) + if found == nil { + return nil, nil + } + if found.Tags == nil { + return nil, nil + } + if found.Tags.Master == nil { + return nil, nil + } + + newtime := repo.Tags.Master.Creatordate.AsTime() + ourtime := found.Tags.Master.Creatordate.AsTime() + + dur := newtime.Sub(ourtime) + if dur < time.Minute { + return nil, nil + } + log.Infof("checking for updates %s %s\n", shell.FormatDuration(dur), found.Namespace) + /* + dur := time.Since(repo.Tags.Master.Authordate.AsTime()) + when := repo.Tags.Master.Creatordate.AsTime() + dur = time.Since(when) + log.Infof("stuff %s age=%s %v\n", repo.Namespace, shell.FormatDuration(dur), when) + */ + return found, nil +} + // is every repo on the devel branch? func doPull() error { if argv.Pull.Check != nil { @@ -27,8 +63,25 @@ func doPull() error { log.Info("server sent nil back") return err } + var count int // log.Infof("pull check %s pb.Len()=%d client.Len()=%d server.Len()=%d err=%v\n", regPB.URL, updatepb.Len(), regPB.ClientDataLen, regPB.ServerDataLen, err) log.Infof("pull check pb.Len()=%d\n", updatepb.Len()) + for repo := range updatepb.IterAll() { + found, _ := needToUpdateRepo(repo) + if found == nil { + continue + } + // found.RunVerbose([]string{"git", "pull", "origin", found.GetMasterBranchName()}) + found.CheckoutMaster() + found.GitPull() + found.ReloadCheck() + found.GitPull() + if count > 10 { + break + } + count += 1 + } + me.forge.SaveRepos() return nil } if argv.Pull.List != nil { |
