Documentation
¶
Index ¶
- Constants
- Variables
- func RelPath(candidate string) (string, error)
- func ValidateRef(ref string) error
- type Service
- func (s *Service) DiffFile(ctx context.Context, root, ref, filePath string) (string, error)
- func (s *Service) DiffHunks(ctx context.Context, root, fromRef, toRef, filePath string) (string, error)
- func (s *Service) Head(ctx context.Context, root string) (string, error)
- func (s *Service) LanguageForPath(filePath string) string
- func (s *Service) ListFiles(ctx context.Context, root, ref string) ([]string, error)
- func (s *Service) ReadFile(ctx context.Context, root, ref, filePath string) ([]byte, error)
- func (s *Service) ResolveCommit(ctx context.Context, root, ref string) (string, error)
Constants ¶
const RefWorktree = "WORKTREE"
RefWorktree selects the on-disk working tree rather than a committed ref.
Variables ¶
var ( // ErrPathOutsideRepo guards every filesystem read against paths supplied by // HTTP, MCP, and CLI callers, none of which are trusted to stay in the repo. ErrPathOutsideRepo = errors.New("path escapes repository root") ErrInvalidRef = errors.New("invalid git ref") ErrFileNotFound = errors.New("file not found") )
Functions ¶
func RelPath ¶
RelPath normalises a caller-supplied path and rejects anything that would leave the repository, including absolute paths, ".." traversal, and the .git directory. Symlinks that point outside the repo are handled separately by reading through os.Root.
func ValidateRef ¶
ValidateRef rejects refs that git would parse as command-line options. A ref such as "--output=/path" turns `git show` into an arbitrary file write, so this check runs before any ref reaches a git invocation.
Types ¶
type Service ¶
type Service struct{}
func NewService ¶
func NewService() *Service
func (*Service) DiffHunks ¶
func (s *Service) DiffHunks(ctx context.Context, root, fromRef, toRef, filePath string) (string, error)
DiffHunks returns a zero-context unified diff for one path between fromRef and toRef. An empty or WORKTREE toRef diffs against the working tree.
-U0 is deliberate: with no context lines every hunk is purely added and removed lines, which is what makes the resulting line mapping unambiguous.