// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "time" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "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 { submit := me.forge.PrepareCheckRepos() updatepb, regPB, err := submit.HttpPost(myServer(), "check") if err != nil { log.Info("err =", err) } if regPB == nil { log.Info("regPB==nil") } if updatepb == nil { 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 { found := gitpb.NewRepos() var count int for { if count > 10 { break } count += 1 found.Append(me.forge.Repos.Repos[count]) } me.forge.PrintPullTable(found) return nil } // below this, you must not be in 'normal' mode if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL { log.Info("you must check out the devel or master branches") return nil } if argv.Pull.Force || argv.Force { now := time.Now() stats := me.forge.RillFuncError(rillPull) count := me.forge.RillReload() if count != 0 { me.forge.ConfigSave() } total, count, nope, _ := me.forge.IsEverythingOnMaster() log.Printf("Master branch check. %d total repos. (%d git pulled) (%d not on master branch) (%s) git pull total=FIXME%d\n", total, count, nope, shell.FormatDuration(time.Since(now)), len(stats)) return nil } log.Info("do a pull check here?") return nil } func findGitTag(repo *gitpb.Repo, hash string) *gitpb.GitTag { for _, tag := range repo.Tags.GitTags { if tag.Hash == hash { return tag } // log.Info(i, tag.Hash, tag.Refname, tag) } for i, tag := range repo.Tags.GitTags { log.Info(hash, i, tag) } okExit("") return nil } func rillPull(repo *gitpb.Repo) error { if repo.IsDirty() { // never do dirty repos return nil } t, _ := repo.LastGitPull() if time.Since(t) < time.Minute*10 && !argv.Force { if argv.Verbose { log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t))) } 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 cmd = append(cmd, "git", "pull") err := repo.RunVerbose(cmd) if err != nil { log.Info(repo.GetFullPath(), "git pull err:", err) } return nil }