gitpb/reloadCheckDirty.go

62 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-12-01 00:49:25 -06:00
package gitpb
// runs git, parses output
// types faster than you can
import (
"fmt"
"strings"
2024-12-17 01:15:31 -06:00
"time"
2024-12-01 00:49:25 -06:00
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
2024-12-17 01:15:31 -06:00
"google.golang.org/protobuf/types/known/timestamppb"
2024-12-01 00:49:25 -06:00
)
func (repo *Repo) NoteChange(s string) {
log.Warn("NoteChange()", s)
}
// just return the current value
func (repo *Repo) IsDirty() bool {
return repo.Dirty
}
// actually os.Exec('git')
func (repo *Repo) CheckDirty() bool {
cmd := []string{"git", "status", "--porcelain"}
r := shell.PathRunLog(repo.FullPath, cmd, GITPB)
if r.Error != nil {
log.Warn("CheckDirty() status cmd =", cmd)
out := strings.Join(r.Stdout, "\n")
log.Warn("CheckDirty() status out =", out)
log.Warn("CheckDirty() status err =", r.Error)
log.Error(r.Error, "CheckDirty() git status error")
repo.NoteChange("git status is in error " + fmt.Sprint(r.Error))
repo.Dirty = true
return true
}
// dirty if anything but go.mod and go.sum
var bad bool = false
for _, line := range r.Stdout {
parts := strings.Fields(line)
if len(parts) == 2 {
switch parts[1] {
case "go.mod":
case "go.sum":
default:
bad = true
}
} else {
bad = true
}
2024-12-01 00:49:25 -06:00
}
2024-12-17 01:15:31 -06:00
pbnow := timestamppb.New(time.Now())
repo.Times.LastDirty = pbnow
2024-12-18 22:02:37 -06:00
repo.Dirty = bad
return bad
2024-12-01 00:49:25 -06:00
}