summaryrefslogtreecommitdiff
path: root/checkDirty.go
blob: 0db0ff462ef0a887b572cefbba2cf31a19e25927 (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
package gitpb

// runs git, parses output
// types faster than you can

import (
	"fmt"
	"strings"

	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

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
	}

	if len(r.Stdout) == 0 {
		repo.Dirty = false
		return false
	}
	repo.Dirty = true
	return true

}