feat: apply ignores from .gitignore/.ignore files
1 file changed, 35 insertions(+), 0 deletions(-)
changed files
A repository/git/git.go
@@ -0,0 +1,35 @@ +package git + +import ( + "bytes" + "context" + "errors" + "os/exec" +) + +func IsGitRepo(ctx context.Context, wd string) (bool, string, error) { + root, err := showRoot(ctx, wd) + if err != nil { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + if exitErr.ExitCode() == 128 { + return false, wd, nil + } + } + + return false, wd, err + } + + return root != "", root, nil +} + +func showRoot(ctx context.Context, wd string) (string, error) { + cmd := exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel") + cmd.Dir = wd + rr, err := cmd.Output() + if err != nil { + return "", err + } + + return string(bytes.TrimSpace(rr)), nil +}