all repos — erl @ d29d0816680a343ee47c40fa9ace8d80862ac412

Execute Reload Loop

feat: apply ignores from .gitignore/.ignore files

Alan Pearce
commit

d29d0816680a343ee47c40fa9ace8d80862ac412

parent

a52be32962b55478c31d6f4e1139e4ab4b140100

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 +}