33 lines
669 B
Go
33 lines
669 B
Go
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
|
|
}
|