summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-15 12:14:48 -0600
committerJeff Carr <[email protected]>2024-12-15 12:14:48 -0600
commit5006d718fd59a3ac964750bb7890c9e0e262811b (patch)
tree9cc8fdeff57fba97faf718fe413fccd99662366e
parent5c1bebb16c8056598e351565297ae6507902999d (diff)
tring to fix go-clonev0.0.30
-rw-r--r--goDep.redoGoMod.go47
-rw-r--r--isTracked.go63
2 files changed, 95 insertions, 15 deletions
diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go
index 82d5830..59845af 100644
--- a/goDep.redoGoMod.go
+++ b/goDep.redoGoMod.go
@@ -7,29 +7,46 @@ import (
"time"
)
-// checks to see if the go.sum and go.mod files
-// match the repo.pb information
+// checks to see if the go.sum and go.mod files exist
+// also check for a match with the repo.pb GoPrimitive bool
+// todo: check mtime
func (repo *Repo) ValidGoSum() error {
+ if !repo.Exists("go.mod") {
+ return errors.New("ValidGoSum() go.mod is missing")
+ }
if repo.GoPrimitive {
+ if !repo.Exists("go.mod") {
+ return errors.New("GoPrimitive == true, but go.mod is missing")
+ }
// repo thinks it is primitive but has a go.sum file
if repo.Exists("go.sum") {
return errors.New("GoPrimitive == true, but go.sum exists")
}
- mtime, err := repo.mtime("go.mod")
- if err == nil {
- return err
- }
- if mtime != repo.LastGoDep.AsTime() {
- return errors.New("go.mod mtime mis-match")
- }
- }
- mtime, err := repo.mtime("go.sum")
- if err == nil {
- return err
+ /*
+ // todo: fix this
+ mtime, err := repo.mtime("go.mod")
+ if err == nil {
+ return err
+ }
+ if mtime != repo.LastGoDep.AsTime() {
+ return errors.New("go.mod mtime mis-match")
+ }
+ */
+ return nil
}
- if mtime != repo.LastGoDep.AsTime() {
- return errors.New("go.sum mtime mis-match")
+ if !repo.Exists("go.sum") {
+ return errors.New("ValidGoSum() go.sum is missing")
}
+ /*
+ mtime, err := repo.mtime("go.sum")
+ // todo: fix this
+ if err == nil {
+ return err
+ }
+ if mtime != repo.LastGoDep.AsTime() {
+ return errors.New("go.sum mtime mis-match")
+ }
+ */
return nil
}
diff --git a/isTracked.go b/isTracked.go
new file mode 100644
index 0000000..2fc8ddf
--- /dev/null
+++ b/isTracked.go
@@ -0,0 +1,63 @@
+package gitpb
+
+import (
+ "fmt"
+)
+
+func (repo *Repo) isTracked(file string) (bool, error) {
+ cmd := []string{"git", "ls-files", "--error-unmatch", file}
+ result := repo.Run(cmd)
+ if result.Error != nil {
+ return false, result.Error
+ }
+ if result.Exit != 0 {
+ return false, nil
+ }
+ return true, nil
+}
+
+func (repo *Repo) isIgnored(file string) (bool, error) {
+ cmd := []string{"git", "check-ignore", "-q", file}
+ result := repo.Run(cmd)
+ if result.Error != nil {
+ return false, result.Error
+ }
+ if result.Exit == 0 {
+ // exit with 0 means the file is ignored
+ return true, nil
+ }
+ // non-zero exit means the file is not ignored
+ return false, nil
+}
+
+func (repo *Repo) RepoIgnoresGoMod() (bool, error) {
+ file := "go.mod"
+ if tracked, err := repo.isTracked(file); err != nil {
+ fmt.Printf("%s Error checking if %s tracked: %v\n", repo.GoPath, file, err)
+ return false, err
+ } else {
+ if tracked {
+ fmt.Printf("%s %s is tracked by Git.\n", repo.GoPath, file)
+ return false, nil
+ }
+ }
+
+ if ignored, err := repo.isIgnored(file); err != nil {
+ if err != nil {
+ fmt.Printf("%s Error checking if ignored: %v\n", repo.GoPath, err)
+ return false, err
+ }
+ } else {
+
+ if ignored {
+ fmt.Printf("%s %s is ignored by Git.\n", repo.GoPath, file)
+ return true, nil
+ }
+ }
+ fmt.Printf("%s %s is neither tracked nor ignored by Git.\n", repo.GoPath, file)
+ // this means, if you make a go.mod file, it'll add it to the repo to be tracked
+ // so you need to either add it to .gitignore (this is what should happen)
+ // or accept you want an auto-generated file to put endless garbage in your git repo
+ // this obviously exposes my opinion on this subject matter
+ return false, nil
+}