repos

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const RefWorktree = "WORKTREE"

RefWorktree selects the on-disk working tree rather than a committed ref.

Variables

View Source
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")
)

Functions

func RelPath

func RelPath(candidate string) (string, error)

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

func ValidateRef(ref string) error

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) DiffFile

func (s *Service) DiffFile(ctx context.Context, root, ref, filePath string) (string, error)

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.

func (*Service) Head

func (s *Service) Head(ctx context.Context, root string) (string, error)

func (*Service) LanguageForPath

func (s *Service) LanguageForPath(filePath string) string

func (*Service) ListFiles

func (s *Service) ListFiles(ctx context.Context, root, ref string) ([]string, error)

func (*Service) ReadFile

func (s *Service) ReadFile(ctx context.Context, root, ref, filePath string) ([]byte, error)

func (*Service) ResolveCommit

func (s *Service) ResolveCommit(ctx context.Context, root, ref string) (string, error)

ResolveCommit expands a ref into a full commit SHA, so a binding records an immutable point rather than a branch name that will move.

Jump to

Keyboard shortcuts

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