forge/doPull.go

91 lines
2.1 KiB
Go

// 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"
)
// is every repo on the devel branch?
func doPull() error {
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
log.Info("you must check out the devel or master branches")
return nil
}
if argv.Force == true {
log.Info("okay. you have forced the issue")
}
// stats := me.forge.RillFuncError(rillPull)
log.Info("TODO: actually git pull here? this is a bad idea. stopping.")
submit := gitpb.NewRepos()
for repo := range me.forge.Repos.IterByFullPath() {
newrepo := new(gitpb.Repo)
newrepo.MasterHash = repo.MasterHash
newrepo.DevelHash = repo.DevelHash
newrepo.Namespace = repo.Namespace
newrepo.URL = repo.URL
submit.Append(newrepo)
}
submit.HttpPost(myServer(), "check")
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
}
/*
// git fetch origin master:master
func rillFetchMaster(repo *gitpb.Repo) error {
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
// only fetch when branch is on the user branch
return nil
}
branch := repo.GetMasterBranchName()
cmd := []string{"git", "fetch", "origin", branch + ":" + branch}
err := repo.RunVerbose(cmd)
return err
}
func doGitFetch() {
me.forge.RillFuncError(rillFetchMaster)
count := me.forge.RillReload()
if count != 0 {
me.forge.ConfigSave()
}
}
*/