| 192 | } |
| 193 | |
| 194 | func InferGitRepoRoot(path string) (string, error) { |
| 195 | cmd := exec.Command("git", "-C", path, "rev-parse", "--show-cdup") |
| 196 | data, err := cmd.Output() |
| 197 | if err != nil { |
| 198 | var execErr *exec.ExitError |
| 199 | if !errors.As(err, &execErr) { |
| 200 | return "", err |
| 201 | } |
| 202 | errStr := strings.TrimSpace(string(execErr.Stderr)) |
| 203 | if strings.Contains(errStr, "not a git repository") { |
| 204 | return "", ErrNotAGitRepository |
| 205 | } |
| 206 | return "", errors.New(string(execErr.Stderr)) |
| 207 | } |
| 208 | return filepath.Join(path, strings.TrimSpace(string(data))), nil |
| 209 | } |
| 210 | |
| 211 | func isGitIgnored(repoRoot, subpath string) (bool, error) { |
| 212 | cmd := exec.Command("git", "-C", repoRoot, "check-ignore", subpath) |