summaryrefslogtreecommitdiff
path: root/isTracked.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-13 17:13:29 -0600
committerJeff Carr <[email protected]>2024-12-13 17:13:29 -0600
commit3a83cf030d6037790f1a57bb224f6bf55054a120 (patch)
treedd3e3d570df936caaa6d47b37571b034809101a6 /isTracked.go
parent8c68cff7624dd797533122509a7d86ed316090c5 (diff)
start skipping repos with tracked go.* files
Diffstat (limited to 'isTracked.go')
-rw-r--r--isTracked.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/isTracked.go b/isTracked.go
new file mode 100644
index 0000000..391ecd5
--- /dev/null
+++ b/isTracked.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+
+ "go.wit.com/lib/protobuf/gitpb"
+)
+
+func isTracked(file string) (bool, error) {
+ cmd := exec.Command("git", "ls-files", "--error-unmatch", file)
+ err := cmd.Run()
+ if err == nil {
+ return true, nil
+ }
+ if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 {
+ return false, nil // File not tracked
+ }
+ return false, fmt.Errorf("error checking tracked status: %v", err)
+}
+
+func isIgnored(file string) (bool, error) {
+ cmd := exec.Command("git", "check-ignore", "-q", file)
+ err := cmd.Run()
+ if err == nil {
+ return true, nil
+ }
+ if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 {
+ return false, nil // File not ignored
+ }
+ return false, fmt.Errorf("error checking ignored status: %v", err)
+}
+
+func repoOwnsGoMod(repo *gitpb.Repo) (bool, error) {
+ os.Chdir(repo.FullPath)
+ file := "go.mod"
+
+ tracked, err := isTracked(file)
+ if err != nil {
+ fmt.Printf("%s Error checking if tracked: %v\n", repo.GoPath, err)
+ return false, err
+ }
+
+ if tracked {
+ fmt.Printf("%s %s is tracked by Git.\n", repo.GoPath, file)
+ return true, nil
+ }
+
+ ignored, err := isIgnored(file)
+ if err != nil {
+ fmt.Printf("%s Error checking if ignored: %v\n", repo.GoPath, err)
+ return false, err
+ }
+
+ 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)
+ return false, nil
+}