summaryrefslogtreecommitdiff
path: root/doNormal.go
blob: 4c773d0178b704a02edd2cbdd86a37f16a247c84 (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

// checks that repos are in a "normal" state

import (
	"time"

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

func doNormal() bool {
	me.forge.CheckDirtyQuiet()

	var count int
	stats := me.forge.RillRepos(checkNormalRepoState)
	for path, stat := range stats {
		dur := stat.End.Sub(stat.Start)
		if dur > 10*time.Second {
			log.Infof("%s checkNormalRepoState() took a long time (%s)\n", path, shell.FormatDuration(dur))
		}
		if stat.Err == nil {
			continue
		}
		// log.Infof("%-60s, %-60s %v %s\n", stat.Start, stat.End.String(), dur, path)
		// log.Infof("%-30v %s %v\n", dur, path, stat.Err)
		// log.Info("got path", path, stat.Err)
		count += 1
	}
	if count > 0 {
		log.Info("Some repos are not in a 'normal' state. error count =", count)
		log.Info("TODO: list the repos here. forge patch repos?")
		dumpWorkRepos()
		configSave = true
		return false
	}
	return true
}

// 99% of the time, the repos during development should be on your user branch.
// error out if it's not
// this checks to see if a devel and user branch exist
// this needs to run each time in case repos were added manually by the user
// this also verifies that
func checkNormalRepoState(repo *gitpb.Repo) error {
	if repo.GetMasterBranchName() == "" {
		me.forge.VerifyBranchNames(repo)
		configSave = true
		log.Info("ABNORMAL: master branch name was blank in", repo.GetFullPath())
	}
	if repo.GetMasterBranchName() == "" {
		return log.Errorf("master branch name blank")
	}
	if repo.GetDevelBranchName() == "" {
		return log.Errorf("devel branch name blank")
	}
	if repo.GetUserBranchName() == "" {
		return log.Errorf("user branch name blank")
	}
	if repo.GetGoPath() == repo.GetNamespace() {
		// log.Info(repo.FullPath, "gopath == namespace", repo.GetGoPath(), repo.GetNamespace())
	} else {
		log.Info(repo.FullPath, "gopath != namespace", repo.GetGoPath(), repo.GetNamespace())
	}
	repo.MakeLocalDevelBranch()

	repo.VerifyRemoteAndLocalBranches(repo.GetDevelBranchName())
	repo.VerifyRemoteAndLocalBranches(repo.GetMasterBranchName())

	if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
		configSave = true
		log.Info("changing to user branch", repo.FullPath)
		repo.CheckoutUser()
		repo.ReloadCheck()
		return log.Errorf("now on user branch")
	}
	return nil
}