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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
package gitpb
import (
"path/filepath"
"strings"
"go.wit.com/log"
)
func (repo *Repo) ActualDevelHash() string {
brname := repo.GetDevelBranchName()
refname := "refs/heads/" + brname
for tag := range repo.Tags.IterAll() {
// log.Info("repo tag", tag.GetHash(), tag.GetName())
if tag.GetName() == refname {
return tag.GetHash()
}
}
return ""
}
func (repo *Repo) ActualGetDevelHash() string {
s := repo.GetDevelBranchName()
return repo.GetLocalHash(s)
}
func (repo *Repo) ActualGetUserHash() string {
s := repo.GetUserBranchName()
return repo.GetLocalHash(s)
}
func (repo *Repo) ActualGetMasterHash() (string, string) {
s := repo.GetMasterBranchName()
return repo.GetLocalHash(s), repo.GetRemoteHash(s)
}
func (repo *Repo) GetLocalHash(brname string) string {
refname := "refs/heads/" + brname
for tag := range repo.Tags.IterAll() {
// log.Info("repo tag", tag.GetHash(), tag.GetName())
if tag.GetName() == refname {
return strings.TrimSpace(tag.GetHash())
}
}
return ""
}
func (repo *Repo) GetRemoteHash(brname string) string {
refname := "refs/remotes/origin/" + brname
for tag := range repo.Tags.IterAll() {
// log.Info("repo tag", tag.GetHash(), tag.GetName())
if tag.GetName() == refname {
return strings.TrimSpace(tag.GetHash())
}
}
return ""
}
func (repo *Repo) GetRemoteTag(brname string) *Stat {
refname := "refs/remotes/origin/" + brname
for tag := range repo.Tags.IterAll() {
// log.Info("repo tag", tag.GetHash(), tag.GetName())
if tag.GetName() == refname {
return tag
}
}
return nil
}
// this is the correct way. uses 'git show-ref'
func (repo *Repo) IsBranchRemote(brname string) bool {
if repo.Tags == nil {
return false
}
brname = "refs/remotes/origin/" + brname
ref := repo.Tags.FindByName(brname)
if ref == nil {
// log.Info("did not found refname!!!!!!!!", brname)
return false
}
// log.Info("found refname!!!!!!!!")
return true
}
// this is the correct way. uses 'git show-ref'
func (repo *Repo) IsDevelRemote() bool {
devname := repo.GetDevelBranchName()
return repo.IsBranchRemote(devname)
}
// find a branch namm
// will find "master" or "devel"
// will also find "v0.1.1"
// or will find "patches-from-foo"
// will return *any* match on any git branch because it doesn't
// matter much here yet
// eventually this will be worked out by forge in some future code that hasn't been made yet
func (repo *Repo) IsBranch(findname string) bool {
for t := range repo.Tags.IterAll() {
tagname := t.Name
if strings.HasPrefix(tagname, "refs/remotes") {
continue
}
path, filename := filepath.Split(tagname)
log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true
}
}
log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false
}
func (repo *Repo) IsBranchLocal(findname string) *Stat {
for t := range repo.Tags.IterAll() {
if !strings.HasPrefix(t.Name, "refs/heads") {
continue
}
_, filename := filepath.Split(t.Name)
// log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
// log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return t
}
}
return nil
}
func (repo *Repo) IsLocalBranch(findname string) bool {
for t := range repo.Tags.IterAll() {
if !strings.HasPrefix(t.Name, "refs/heads") {
continue
}
path, filename := filepath.Split(t.Name)
log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true
}
}
log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false
}
func (repo *Repo) IsLocalBranchVerbose(findname string) bool {
for t := range repo.Tags.IterAll() {
if !strings.HasPrefix(t.Name, "refs/heads") {
continue
}
path, filename := filepath.Split(t.Name)
log.Info("gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
log.Info("gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true
}
}
log.Info("did not find tag:", findname, "in", repo.GetGoPath())
return false
}
func (repo *Repo) IsRemoteBranch(findname string) bool {
for t := range repo.Tags.IterAll() {
if !strings.HasPrefix(t.Name, "refs/remotes/origin") {
continue
}
path, filename := filepath.Split(t.Name)
log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname {
log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true
}
}
log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false
}
func (repo *Repo) IfRefExists(refname string) *Stat {
for t := range repo.Tags.IterAll() {
if _, filename := filepath.Split(t.Name); filename == refname {
return t
}
}
return nil
}
// finds the newest tag. used for deciding if master needs to be published
func (repo *Repo) FindLastTag() string {
var newest *Stat
for tag := range repo.Tags.IterAll() {
if !strings.HasPrefix(tag.GetName(), "refs/tags/") {
continue
}
if newest == nil {
newest = tag
continue
}
cur := newest.CommitTime.AsTime()
if cur.Before(tag.CommitTime.AsTime()) {
newest = tag
}
// newtag := strings.TrimPrefix(tag.GetName(), "refs/tags/")
// log.Info("repo tag", tag.GetHash(), tag.CommitTime.AsTime(), tag.GetName(), newtag)
}
if newest == nil {
return ""
}
// log.Info("repo newest tag", newest.GetHash(), newest.CommitTime.AsTime(), newest.GetName())
newtag := strings.TrimPrefix(newest.GetName(), "refs/tags/")
return newtag
}
|