This commit is contained in:
Oliver Davies 2025-07-31 21:23:06 +01:00
parent 74e7ef4451
commit 89955975bf
2 changed files with 36 additions and 28 deletions

View file

@ -0,0 +1,33 @@
package repositories
import (
"fmt"
"log"
"os/exec"
"git-repo-updater/internal/utils"
)
func FindInDirectory(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
}