62 lines
1.1 KiB
Go
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()
|
|
|
|
fmt.Printf("Command failed with exit code %d\n", exitCode)
|
|
}
|
|
|
|
fmt.Printf("find failed on %s: %v\nOutput: %s\n", dir, err, string(output))
|
|
}
|
|
|
|
return string(output), nil
|
|
}
|