summaryrefslogtreecommitdiff
path: root/common.go
blob: 371a47f84b32f6c2a9025022331f2f00f09c6d52 (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
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
package repolist

import (
	"go.wit.com/lib/gui/repostatus"
	"go.wit.com/log"
)

func (r *RepoList) Hidden() bool {
	return r.reposbox.Hidden()
}

func (r *RepoList) Show() {
	r.reposbox.Show()
}

func (r *RepoList) Hide() {
	r.reposbox.Hide()
}

func (r *RepoList) FindRepo(path string) *Repo {
	repo, _ := me.allrepos[path]
	return repo
}

func (r *RepoList) AllRepos() []*Repo {
	var all []*Repo
	for _, repo := range me.allrepos {
		all = append(all, repo)
	}
	return all
}

// deprecate this
func AllRepos() []*Repo {
	var all []*Repo
	for _, repo := range me.allrepos {
		all = append(all, repo)
	}
	return all
}

// a human readable state of the current repo
func (r *Repo) State() string {
	return r.gitState.String()
}

func (r *Repo) Scan() bool {
	return r.NewScan()
}

// returns a name for human consuption only
// todo: implement nicknames
func (rs *Repo) Name() string {
	if rs.Status.IsGoLang() {
		return rs.Status.GoPath()
	}
	return rs.Status.Path()
}

func (r *Repo) Exists(s string) bool {
	return false
}

func (r *Repo) GoPath() string {
	return r.Status.GoPath()
}

func (r *Repo) CheckDirty() bool {
	return r.Status.CheckDirty()
}

func (r *Repo) IsDirty() bool {
	return r.Status.IsDirty()
}

func (r *Repo) ReadOnly() bool {
	return r.Status.ReadOnly()
}

func (r *Repo) LastTag() string {
	return r.Status.GetLastTagVersion()
}

// returns the state of the GO go.mod and go.sum files
// this is used to tell if they are valid and correctly reflect
// the versions of the other GUI packages
// at this point in time, there is _NO_ way to be check our
// be sure that anything will run with older versions
// because this are changing too often at this point
// TODO: revisit this in 2025 or 2026
func (r *Repo) GoState() string {
	if r == nil {
		log.Info("GoState() r == nil")
		return "goState == nil"
	}
	if r.goState == nil {
		log.Info("GoState() r.goState == nil")
		return "goState == nil"
	}
	return r.goState.String()
}

func (r *Repo) SetGoState(s string) {
	if r == nil {
		log.Info("SetGoState() r == nil")
		return
	}
	if r.goState == nil {
		log.Info("goState == nil")
		return
	}
	r.goState.SetText(s)
}

func (r *Repo) IsPerfect() bool {
	if r.gitState.String() == "PERFECT" {
		return true
	}
	if r.gitState.String() == "unchanged" {
		return true
	}
	return false
}

func (r *Repo) RunCmd(cmd []string) (error, string) {
	return r.Status.RunCmd(cmd)
}

func (r *Repo) AllTags() []*repostatus.Tag {
	return r.Status.Tags.ListAll()
}

func (r *Repo) TagsBox() *repostatus.GitTagBox {
	return r.Status.Tags
}

// todo, fix bool return for deletetag()
func (r *Repo) DeleteTag(t *repostatus.Tag) bool {
	r.Status.DeleteTag(t)
	return true
}