summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git.go29
-rw-r--r--structs.go1
2 files changed, 27 insertions, 3 deletions
diff --git a/git.go b/git.go
index 6e05316..e712e4d 100644
--- a/git.go
+++ b/git.go
@@ -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
+
+ // last := out[strings.LastIndex(out, "\n")+1:]
+ // if last == "nothing to commit, working tree clean" {
- 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 == "" {
diff --git a/structs.go b/structs.go
index 5234e7e..7f02488 100644
--- a/structs.go
+++ b/structs.go
@@ -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