summaryrefslogtreecommitdiff
path: root/doCommon.go
blob: 5c377399ad94f245849011f75c3cb967ec9aabac (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
package main

import (
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func doScan() {
	me.forge.ScanGoSrc()
}

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

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

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

}
func doGitReset() {
	if !argv.DoGitReset {
		return
	}
	all := me.found.SortByGoPath()
	for all.Scan() {
		repo := all.Next()
		if me.forge.Config.IsReadOnly(repo.GoPath) {
			// log.Info("is readonly", repo.GoPath)
			if repo.CheckDirty() {
				log.Info("is readonly and dirty", repo.GoPath)
				cmd := []string{"git", "reset", "--hard"}
				repo.RunRealtime(cmd)
			}
		} else {
			// log.Info("is not readonly", repo.GoPath)
		}
	}
}

func checkoutBranches(repo *gitpb.Repo) error {
	dname := repo.GetDevelBranchName()
	if dname == "" {
		if err := me.forge.MakeDevelBranch(repo); err != nil {
			log.Info("verify() no devel branch name", repo.GoPath)
			return err
		}
		configSave = true
	}
	if repo.GetUserBranchName() == "" {
		if err := me.forge.MakeUserBranch(repo); err != nil {
			log.Info("verify() no devel branch name", repo.GoPath)
			return err
		}
		configSave = true
	}
	return nil
}