diff --git a/Makefile b/Makefile index ac11b12..6d2f9fc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ # go install -all: gitTag.pb.go goDep.pb.go repo.pb.go vet +all: goimports gitTag.pb.go goDep.pb.go repo.pb.go vet vet: @GO111MODULE=off go vet diff --git a/checkDirty.go b/checkDirty.go index 0db0ff4..83b049d 100644 --- a/checkDirty.go +++ b/checkDirty.go @@ -35,11 +35,22 @@ func (repo *Repo) CheckDirty() bool { return true } - if len(r.Stdout) == 0 { - repo.Dirty = false - return false + // 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 + } } - repo.Dirty = true - return true + + return bad } diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go index 7e56989..6aeb298 100644 --- a/goDep.redoGoMod.go +++ b/goDep.redoGoMod.go @@ -5,7 +5,6 @@ package gitpb import ( "errors" "os" - "strings" "go.wit.com/log" ) @@ -67,41 +66,6 @@ func (repo *Repo) RedoGoMod() (bool, error) { return false, errors.New("MakeRedomod() logic failed") } -func (repo *Repo) RepoType() string { - if repo == nil { - return "nil" - } - if repo.GetGoPlugin() { - return "plugin" - } - if repo.GetGoBinary() { - return "binary" - } - if ok, _, _ := repo.IsProtobuf(); ok { - return "protobuf" - } - if repo.GetGoLibrary() { - return "library" - } - return "" -} - -func (repo *Repo) goListRepoType() string { - os.Setenv("GO111MODULE", "off") - cmd := []string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"} - // cmd := []string{"go", "list", "-f", "'{{.Name}}'"} // probably use this. this just prints out the package name - // cmd := []string{"go", "list", "-f", "'{{.ImportPath}}'"} // returns go.wit.com/lib/protobuf/gitpb - - result := repo.RunQuiet(cmd) - if result.Error != nil { - log.Warn("go list binary detect failed", result.Error) - return "" - } - output := strings.TrimSpace(strings.Join(result.Stdout, "\n")) - output = strings.Trim(output, "'") - return output -} - // returns true if the last published func (repo *Repo) GoDepsLen() int { if repo.GoDeps == nil { diff --git a/repoType.go b/repoType.go new file mode 100644 index 0000000..52846d2 --- /dev/null +++ b/repoType.go @@ -0,0 +1,48 @@ +package gitpb + +// does processing on the go.mod and go.sum files + +import ( + "os" + "strings" + + "go.wit.com/log" +) + +func (repo *Repo) RepoType() string { + if repo == nil { + return "nil" + } + if repo.GetGoPlugin() { + return "plugin" + } + if repo.GetGoBinary() { + if repo.Exists(".plugin") { + return "plugin" + } + return "binary" + } + if ok, _, _ := repo.IsProtobuf(); ok { + return "protobuf" + } + if repo.GetGoLibrary() { + return "library" + } + return "" +} + +func (repo *Repo) goListRepoType() string { + os.Setenv("GO111MODULE", "off") + cmd := []string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"} + // cmd := []string{"go", "list", "-f", "'{{.Name}}'"} // probably use this. this just prints out the package name + // cmd := []string{"go", "list", "-f", "'{{.ImportPath}}'"} // returns go.wit.com/lib/protobuf/gitpb + + result := repo.RunQuiet(cmd) + if result.Error != nil { + log.Warn("go list binary detect failed", result.Error) + return "" + } + output := strings.TrimSpace(strings.Join(result.Stdout, "\n")) + output = strings.Trim(output, "'") + return output +} diff --git a/shell.go b/shell.go index ae741e3..ca9d6b1 100644 --- a/shell.go +++ b/shell.go @@ -54,13 +54,11 @@ func (repo *Repo) strictRun(cmd []string) (bool, error) { func (repo *Repo) Exists(filename string) bool { if repo == nil { - log.Warn("repo == nil for Exists()") return false } testf := filepath.Join(repo.FullPath, filename) _, err := os.Stat(testf) if err != nil { - log.Warn("gitpb: Exists() failed for", testf) return false } return true