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
|
package gitpb
// does processing on the go.mod and go.sum files
import (
"go.wit.com/log"
)
// count all objects only in branch1
func (repo *Repo) countDiffObjects(branch1, branch2 string) int {
cmd := repo.ConstructGitDiffLog(branch1, branch2)
r, err := repo.RunVerboseOnError(cmd)
if err != nil {
return -1
}
// log.Info("countDiffObjects()", cmd, len(r.Stdout), strings.Join(r.Stdout, " "))
return len(r.Stdout)
}
func (repo *Repo) setRepoState() {
if repo == nil {
return
}
if repo.IsDirty() {
repo.State = "dirty"
return
}
if repo.GetUserVersion() == "uerr" {
// user has not made user branches
} else {
if repo.GetUserVersion() != repo.GetDevelVersion() {
repo.State = "merge to devel"
return
}
}
if repo.GetDevelVersion() != repo.GetMasterVersion() {
if !repo.ExistsDevelBranch() {
// there is no devel branch. you are safe to proceed
repo.State = "no devel branch"
return
}
if !repo.IsLocalBranch(repo.GetDevelBranchName()) {
// the remote devel branch exists but is not checked out
repo.State = "devel not checked out"
return
}
b1 := repo.countDiffObjects(repo.GetMasterBranchName(), repo.GetDevelBranchName())
if b1 == 0 {
repo.State = "merge to main"
// log.Info("master vs devel count is normal b1 == 0", b1)
} else {
repo.State = "DEVEL < MASTER"
// log.Info("master vs devel count b1 != 0", b1)
log.Info("SERIOUS ERROR. DEVEL BRANCH NEEDS MERGE FROM MASTER b1 ==", b1, repo.GetGoPath())
}
return
}
// if IsGoTagVersionGreater(oldtag string, newtag string) bool {
if !IsGoTagVersionGreater(repo.GetLastTag(), repo.GetMasterVersion()) {
repo.State = "last tag greater error"
return
}
if repo.GetLastTag() != repo.GetMasterVersion() {
repo.State = "ready to release"
return
}
if repo.CheckBranches() {
repo.State = "PERFECT"
return
}
log.Info("Branches are not Perfect", repo.GetFullPath())
log.Info("Branches are not Perfect", repo.GetFullPath())
log.Info("Branches are not Perfect", repo.GetFullPath())
repo.State = "unknown branches"
}
// returns true if old="v0.2.4" and new="v0.3.3"
// returns true if equal
// todo: make all of this smarter someday
func IsGoTagVersionGreater(oldtag string, newtag string) bool {
olda, oldb, oldc := splitInts(oldtag)
newa, newb, newc := splitInts(newtag)
if newa < olda {
return false
}
if newb < oldb {
return false
}
if newc < oldc {
return false
}
return true
}
// returns true for "v0.2.4" and false for "v0.2.43-asdfj"
// actually returns false for anything not perfectly versioned
func IsGoTagPublished(oldtag string, newtag string) bool {
// todo
return true
}
|