summaryrefslogtreecommitdiff
path: root/doPull.go
blob: e6e8525bb53875ece3ca51d6c7b7de3dafa4f2c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 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 argv.Pull.Check != nil {
			// 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)
			}
			updatepb, regPB, err := submit.HttpPost(myServer(), "check")
			if regPB == nil || err != nil {
				log.Info("regPB==nil or err:", err)
				return nil
			}
			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)
			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 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()
	}
}
*/