git-repo-updater/main.go
2025-07-31 21:20:12 +01:00

62 lines
1.1 KiB
Go

package main
import (
"fmt"
"log"
"os/exec"
"strings"
"git-repo-updater/internal/config"
"git-repo-updater/internal/utils"
)
func main() {
cfg, err := config.Load()
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
dirs := cfg.Directories
for _, dir := range dirs {
repositories, err := findRepositoriesInDirectory(dir)
if err != nil {
}
lines := strings.SplitSeq(repositories, "\n")
for repositoryPath := range lines {
if (repositoryPath == "") {
continue
}
fmt.Println(repositoryPath)
}
}
}
func findRepositoriesInDirectory(dir string) (string, error) {
expanded, err := utils.ExpandPath(dir)
if err != nil {
log.Fatal(err)
}
cmd := exec.Command("find", expanded, "-type", "d", "-name", ".git", "-mindepth", "1", "-maxdepth", "2")
output, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
exitCode := exitErr.ExitCode()
return "", fmt.Errorf("Command failed with exit code %d\n", exitCode)
}
return "", fmt.Errorf("find failed on %s: %w\nOutput: %s", dir, err, string(output))
}
return string(output), nil
}