# internal/adapters/git

Package git inspects workspace state through Git-backed adapters.

Snapshot builds a commit-free fingerprint by writing the working tree through a temporary GIT\_INDEX\_FILE, seeded from HEAD when available, and then resolving a Git tree object. The real branch, index, HEAD, and stash are not mutated. Snapshot commands pin host core.autocrlf=false while preserving committed .gitattributes and filters as repository semantics.

Submodules are represented as gitlink entries: the snapshot records the opaque submodule commit pointer, not the nested submodule working tree.

## Adapter

```go
type Adapter struct {
	Root string
}
```

Adapter reads Git state from a workspace root.

- `Root: string`: 

## BaseDiffPaths

```go
func (a Adapter) BaseDiffPaths(ctx context.Context, baseRef string) ([]string, error)
```

BaseDiffPaths returns deterministic changed paths between baseRef's merge-base with HEAD and the current commit-free working tree. Deleted paths are included so deletion-only changes can still define a no-spec gate scope.

## CanonicalBytes

```go
func (a Adapter) CanonicalBytes(ctx context.Context, treeSHA string, path string) ([]byte, error)
```

CanonicalBytes returns the committed blob bytes for path at the snapshot tree. It is the reviewer-evidence source: bytes come from the content-addressed tree object, never the mutable working file, so the reviewer reads exactly what the receipt fingerprints.

## ChangedFiles

```go
func (a Adapter) ChangedFiles(ctx context.Context) ([]string, error)
```

ChangedFiles returns changed-file fingerprints for mutation guards.

## ExactStatus

```go
func (a Adapter) ExactStatus(ctx context.Context) (State, error)
```

ExactStatus returns every Git-visible difference in the worktree, including ignored files and scafld runtime paths. It is for execution roots where any byte on disk may be read by a command, so the narrower mutation-guard filters used by Status are intentionally not applied.

## IsAncestor

```go
func (a Adapter) IsAncestor(ctx context.Context, ancestor, descendant string) (bool, error)
```

IsAncestor reports whether ancestor is reachable from descendant.

## MaterialSeal

```go
func (a Adapter) MaterialSeal(ctx context.Context, scope []string) (reviewevidence.MaterialSeal, error)
```

MaterialSeal returns a content digest for the current working tree under scope, independent of whether the bytes are dirty or committed.

## ResolveCommit

```go
func (a Adapter) ResolveCommit(ctx context.Context, ref string) (string, error)
```

ResolveCommit returns the commit object identified by ref.

## ResolveHead

```go
func (a Adapter) ResolveHead(ctx context.Context) (string, bool, error)
```

ResolveHead returns the checked-out HEAD commit when the worktree has one. Repositories without an initial commit return ok=false instead of failing.

## Snapshot

```go
func (a Adapter) Snapshot(ctx context.Context, input SnapshotInput) (Snapshot, error)
```

Snapshot writes the working tree to a temporary Git index and returns a content-addressed fingerprint without mutating the real index, HEAD, or stash.

## Status

```go
func (a Adapter) Status(ctx context.Context) (State, error)
```

Status returns the current changed-file fingerprints.

## StatusMaterialSeal

```go
func (a Adapter) StatusMaterialSeal(ctx context.Context, scope []string) (reviewevidence.MaterialSeal, error)
```

StatusMaterialSeal returns the same material digest shape as MaterialSeal for read-only status projection without rebuilding a full-repository temporary tree. Review and completion still use MaterialSeal so authority evidence keeps the strongest snapshot path.

## TreeBlobs

```go
func (a Adapter) TreeBlobs(ctx context.Context, treeSHA string, paths []string) (map[string][]byte, error)
```

TreeBlobs reads the committed bytes of paths at the snapshot tree through one `git cat-file --batch` process. It is the batched form of CanonicalBytes: the bytes come from the content-addressed tree object, never the working files.

## TreeDigests

```go
func (a Adapter) TreeDigests(ctx context.Context, treeSHA string, scope []string) ([]FileDigest, error)
```

TreeDigests lists the in-scope file digests of an existing tree object, reading the immutable tree rather than the working directory. The gate reviewer uses it to read the exact bytes the receipt signs, regardless of any later working-tree mutation.

## TreeSHA

```go
func (a Adapter) TreeSHA(ctx context.Context, input SnapshotInput) (string, error)
```

TreeSHA computes only the commit-free snapshot tree fingerprint, skipping the per-file digest, diff, and ignored-path passes.

## DeletedPath

```go
type DeletedPath struct {
	Path   string
	Status string
}
```

DeletedPath records an in-scope path deleted from the base commit.

- `Path: string`: 
- `Status: string`: 

## EvidenceIntegrityError

```go
type EvidenceIntegrityError struct {
	Paths []string
}
```

EvidenceIntegrityError reports index flags that can hide working-tree edits.

- `Paths: []string`: 

## Error

```go
func (e EvidenceIntegrityError) Error() string
```

## FileDigest

```go
type FileDigest struct {
	Path   string
	Status string
	SHA256 string
}
```

FileDigest records a present path in the snapshot tree.

- `Path: string`: 
- `Status: string`: 
- `SHA256: string`: 

## IgnoredPath

```go
type IgnoredPath struct {
	Path   string
	Reason string
}
```

IgnoredPath records an ignored path that was intentionally excluded.

- `Path: string`: 
- `Reason: string`: 

## Snapshot

```go
type Snapshot struct {
	TreeSHA           string
	BaseCommit        string
	HeadCommit        string
	FileDigests       []FileDigest
	DeletedPaths      []DeletedPath
	IgnoredUnreviewed []IgnoredPath
}
```

Snapshot is a deterministic Git-backed workspace fingerprint.

- `TreeSHA: string`: 
- `BaseCommit: string`: 
- `HeadCommit: string`: 
- `FileDigests: []FileDigest`: 
- `DeletedPaths: []DeletedPath`: 
- `IgnoredUnreviewed: []IgnoredPath`: 

## SnapshotInput

```go
type SnapshotInput struct {
	Scope     []string
	BaseRef   string
	TargetRef string
}
```

SnapshotInput controls a commit-free Git tree snapshot.

- `Scope: []string`: 
- `BaseRef: string`: 
- `TargetRef: string`: 

## State

```go
type State struct {
	Changed []string
}
```

State is the fingerprinted set of Git-visible workspace changes.

- `Changed: []string`:
