gitroot

package
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gitroot resolves the repository root that a sandbox should cover.

The distinction this package exists for: `git rev-parse --show-toplevel` run from inside a *linked worktree* returns the worktree directory, not the main checkout. pi-go spawns subagents whose working directory is a linked worktree (`.pi-go/tasks/<id>`, `.worktrees/<branch>`), and each spawned pi process derives its own PI_SANDBOX_ROOT. Using the toplevel there roots the sandbox at the worktree, so every read or edit of a path elsewhere in the repo is rejected as escaping the sandbox — which is what made /run workers fall back to shelling out instead of using the file tools.

Detect resolves the main checkout instead, so a worker in a worktree can still reach the whole repository.

Index

Constants

View Source
const CmdTimeout = 5 * time.Second

CmdTimeout bounds every git subprocess this package spawns so a stalled repository (blocked hook, lock contention, unreachable network mount) cannot hang initialization indefinitely.

Variables

This section is empty.

Functions

func Detect

func Detect(ctx context.Context, dir string) string

Detect returns the main checkout of the repository containing dir, or "" when dir is not inside a repository.

For an ordinary checkout this is the same as `git rev-parse --show-toplevel`. For a linked worktree it is the main checkout the worktree belongs to, resolved through the common git directory.

func Toplevel

func Toplevel(ctx context.Context, dir string) string

Toplevel returns the working tree containing dir — the linked worktree itself when dir is inside one. Callers that mean "the directory this checkout owns" rather than "the repository" want this.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL