summaryrefslogtreecommitdiff
path: root/doPull.go
blob: 160480024eadd805ae341d6e5d7a53b865d07211 (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
package main

import (
	"time"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func rillPull(repo *gitpb.Repo) error {
	if repo.IsDirty() {
		// never do dirty repos
		return nil
	}
	t, _ := repo.LastGitPull()
	if time.Since(t) < time.Hour {
		if argv.Verbose {
			log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t)))
		}
		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
}

// is every repo on the devel branch?

func doGitPullNew() {
	now := time.Now()
	me.forge.RillFuncError(rillPull)
	count := me.forge.RillReload()
	if count != 0 {
		me.forge.ConfigSave()
	}

	total, count, nope, _ := IsEverythingOnMaster()
	log.Printf("Master branch check. %d total repos. (%d git pulled) (%d not on master branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now)))
}

/*
func doGitPull() {
	allerr := me.found.RillGitPull(40, 5)

	all := me.found.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		result := allerr[repo]
		if result.Error == gitpb.ErrorGitPullOnDirty {
			log.Info("skip git pull. repo is dirty", repo.GetGoPath())
			continue
		}
		if result.Error == gitpb.ErrorGitPullOnLocal {
			log.Info("skip git pull. local branch ", repo.GetGoPath())
			continue
		}
		if result.Exit == 0 {
			continue
		}

		log.Info("git pull error:", repo.GetGoPath(), result.Error)
		log.Info("git pull error:", repo.GetGoPath(), result.Stdout)
	}

}
*/

// 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()
	}
}