DirtyList()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-01 21:41:16 -05:00
parent bf2a42ec64
commit b451591006
2 changed files with 27 additions and 3 deletions

29
git.go
View File

@ -188,9 +188,29 @@ func (rs *RepoStatus) IsDirty() bool {
return true
}
// return the list of dirty files (but ignores go.mod & go.sum)
func (rs *RepoStatus) DirtyList() []string {
var all []string
for _, line := range strings.Split(rs.dirtyList, "\n") {
line = strings.TrimSpace(line)
parts := strings.Split(line, " ")
if len(parts) != 2 {
continue
}
if parts[1] == "go.mod" {
continue
}
if parts[1] == "go.sum" {
continue
}
all = append(all, parts[1])
}
return all
}
func (rs *RepoStatus) CheckDirty() bool {
var start string = rs.dirtyLabel.String()
cmd := []string{"git", "status"}
cmd := []string{"git", "status", "--porcelain"}
err, out := rs.RunCmd(cmd)
if err != nil {
log.Warn("CheckDirty() status cmd =", cmd)
@ -204,9 +224,12 @@ func (rs *RepoStatus) CheckDirty() bool {
return true
}
last := out[strings.LastIndex(out, "\n")+1:]
rs.dirtyList = out
if last == "nothing to commit, working tree clean" {
// last := out[strings.LastIndex(out, "\n")+1:]
// if last == "nothing to commit, working tree clean" {
if len(rs.DirtyList()) == 0 {
log.Log(REPO, "CheckDirty() no", rs.realPath.String())
rs.dirtyLabel.SetValue("no")
if start == "" {

View File

@ -15,6 +15,7 @@ type RepoStatus struct {
Tags *GitTagBox // a box of all the git tags
dirtyLabel *gadgets.OneLiner
dirtyList string // the output from git status --porcelain
readOnly *gadgets.OneLiner
gitState *gadgets.OneLiner
primitive *gadgets.OneLiner