Make depth configurable per path

This commit is contained in:
Oliver Davies 2025-07-31 21:59:07 +01:00
parent f91b6e4cbd
commit 6644029a77
2 changed files with 22 additions and 3 deletions

View file

@ -4,21 +4,26 @@ import (
"fmt" "fmt"
"log" "log"
"os/exec" "os/exec"
"strings"
"git-repo-updater/internal/utils" "git-repo-updater/internal/utils"
) )
func FindInDirectory(dir string) (string, error) { func FindInDirectory(dir string) (string, error) {
expanded, err := utils.ExpandPath(dir) repoPath, err := utils.ExpandPath(dir)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
cmd := exec.Command("find", expanded, "-type", "d", "-name", ".git", "-mindepth", "1", "-maxdepth", "2") repoPath, depth := splitPath(repoPath)
cmd := exec.Command("find", repoPath, "-type", "d", "-name", ".git", "-mindepth", "1", "-maxdepth", depth)
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
fmt.Println(string(output))
if err != nil { if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok { if exitErr, ok := err.(*exec.ExitError); ok {
exitCode := exitErr.ExitCode() exitCode := exitErr.ExitCode()
@ -31,3 +36,16 @@ func FindInDirectory(dir string) (string, error) {
return string(output), nil return string(output), nil
} }
func splitPath(repoPath string) (string, string) {
parts := strings.SplitN(repoPath, ":", 2)
repoPath = parts[0]
depth := "2"
if len(parts) == 2 {
return parts[0], parts[1]
}
return repoPath, depth
}

View file

@ -1,4 +1,5 @@
* Load directories from a configuration file * Load directories from a configuration file
* Update the repositories within each directory. * Update the repositories within each directory.
* Make depth configurable per directory.
Make depth configurable per directory. Set a default depth in config.yaml.