repoRoot returns the worktree root of the git repository containing dir, or [ErrNotGitRepository] when dir is not inside one.
(ctx context.Context, dir string)
| 336 | // repoRoot returns the worktree root of the git repository containing dir, |
| 337 | // or [ErrNotGitRepository] when dir is not inside one. |
| 338 | func repoRoot(ctx context.Context, dir string) (string, error) { |
| 339 | out, err := gitOutput(ctx, dir, "rev-parse", "--show-toplevel") |
| 340 | if err != nil { |
| 341 | var exitErr *exec.ExitError |
| 342 | if errors.As(err, &exitErr) { |
| 343 | return "", ErrNotGitRepository |
| 344 | } |
| 345 | return "", err |
| 346 | } |
| 347 | return filepath.Clean(out), nil |
| 348 | } |
| 349 | |
| 350 | // fetchBase updates the local copy of a remote-tracking base ref (e.g. |
| 351 | // "origin/main") so the worktree branches from the latest remote state. Refs |