git

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindRoot added in v0.5.0

func FindRoot(start string) (string, error)

FindRoot resolves the given path to the enclosing git repository root, returning the canonical (symlink-resolved) path. Worktrees backed by a .git file are accepted. Returns an error if no .git is found up to the filesystem root.

Callers that need a full *Repo handle should use OpenRepo. FindRoot is the lightweight option for code that only cares about whether a path belongs to a repository and which one.

func IsFullCommitHash added in v0.6.0

func IsFullCommitHash(s string) bool

IsFullCommitHash reports whether s is a full lowercase SHA-1 or SHA-256 object ID.

func ProviderFromRemoteURL

func ProviderFromRemoteURL(remoteURL string) string

ProviderFromRemoteURL returns the hosting provider based on the remote URL hostname. Returns "github", "gitlab", or "unknown".

func SemanticaHookMarker added in v0.3.9

func SemanticaHookMarker() string

SemanticaHookMarker returns the marker written into Semantica-owned git hooks.

Types

type Commit added in v0.4.0

type Commit struct {
	// ShortHash is git's abbreviated hash (typically 7 chars).
	ShortHash string

	// Subject is the first line of the commit message.
	Subject string

	// Body is the trimmed remainder of the commit message; empty
	// when the commit has no body. Already newline-normalized.
	Body string
}

Commit is one entry in the result of LogSince. Used by the handoff bundle to render each commit's subject and (when non-empty) body separately, so a session-summary commit with substantive details doesn't get truncated to its first line.

type FileStat

type FileStat struct {
	Path    string
	Added   int
	Deleted int
}

FileStat holds per-file line counts from a diff.

type HookInstallOptions

type HookInstallOptions struct {
	Name       string // "pre-commit", "post-commit"
	Subcommand string // "pre-commit", "post-commit"
	PassArgs   bool   // if true, pass "$@" to semantica hook
}

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

func OpenRepo

func OpenRepo(repoPath string) (*Repo, error)

func (*Repo) ChangedFilesForCommit

func (r *Repo) ChangedFilesForCommit(ctx context.Context, hash string) ([]string, error)

ChangedFilesForCommit returns the repo-relative paths (forward slashes) of files changed by the given commit. Uses git diff-tree, the canonical plumbing command for listing files touched by a commit.

func (*Repo) ChangedPathsBetween added in v0.6.0

func (r *Repo) ChangedPathsBetween(ctx context.Context, fromCommit, toCommit string) ([]string, error)

ChangedPathsBetween returns paths that differ between two commit trees. Renames are reported as a deletion and an addition.

func (*Repo) ChangedPathsFromCommitToWorktree added in v0.6.0

func (r *Repo) ChangedPathsFromCommitToWorktree(ctx context.Context, commit string) ([]string, error)

ChangedPathsFromCommitToWorktree returns staged, unstaged, and deleted paths relative to commit. It overrides Git settings that weaken stat validation. On Unix, ctime and inode changes expose same-size rewrites with restored mtimes. Windows has no equivalent signal, so callers that require this guarantee must disable reuse there. Git still skips assume-unchanged and skip-worktree entries; use OrdinaryTrackedFiles to exclude them.

func (*Repo) CommitFormat added in v0.4.0

func (r *Repo) CommitFormat(ctx context.Context, commitHash, format string) (string, error)

CommitFormat runs `git show -s --format=<format> <commitHash>` and returns the trimmed output. Callers compose multi-field formats (e.g. "%H%n%an%n%ai%n%s") and parse the result by line. This is the single git-show entry point for callers that need more than just the subject.

func (*Repo) CommitSubject

func (r *Repo) CommitSubject(ctx context.Context, commitHash string) (string, error)

func (*Repo) CommitSubjects added in v0.6.0

func (r *Repo) CommitSubjects(ctx context.Context, commitHashes []string) (map[string]string, error)

CommitSubjects resolves subjects for many commits in a single git invocation. This keeps large lineage-record listings from spawning one git process per row.

Keys of the returned map are the full commit hashes as git prints them (%H); callers that look up by input should pass full hashes. Unknown or pruned hashes are skipped (--ignore-missing), not errors.

func (*Repo) CommitSubjectsBetween

func (r *Repo) CommitSubjectsBetween(ctx context.Context, base, head string, limit int) ([]string, error)

CommitSubjectsBetween returns commit subject lines (no hashes) for commits reachable from head but not from base, newest first, capped at limit.

func (*Repo) CountCommitsBetween added in v0.5.4

func (r *Repo) CountCommitsBetween(ctx context.Context, base, head string) (int, error)

CountCommitsBetween returns the exact number of commits reachable from head but not from base. Used by callers that need an honest "dropped N commits" report when truncating: a limit-clamped log query cannot reveal the real total.

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch(ctx context.Context) (string, error)

CurrentBranch returns the current branch name (e.g. "main", "feature-x"). Returns "HEAD" for detached HEAD state.

func (*Repo) DefaultBaseRef

func (r *Repo) DefaultBaseRef(ctx context.Context) (string, error)

DefaultBaseRef returns the best-guess default branch ref for the repository. Resolution order: refs/remotes/origin/HEAD, origin/main, origin/master, main, master.

func (*Repo) DiffAll

func (r *Repo) DiffAll(ctx context.Context) ([]byte, error)

DiffAll returns a unified diff of all uncommitted changes: staged, unstaged, and untracked files. Untracked files are represented as new-file diffs so the LLM sees their full content.

func (*Repo) DiffBetween

func (r *Repo) DiffBetween(ctx context.Context, base, head string) ([]byte, error)

DiffBetween returns the unified diff between two refs (three-dot: from merge-base of a and b to b). This shows only changes introduced on the feature branch, not upstream drift.

func (*Repo) DiffCached

func (r *Repo) DiffCached(ctx context.Context) ([]byte, error)

DiffCached returns the unified diff of staged changes against HEAD. Used by the commit-msg hook to compute AI attribution before the commit is finalized (the commit hash doesn't exist yet at that point).

func (*Repo) DiffForCommit

func (r *Repo) DiffForCommit(ctx context.Context, hash string) ([]byte, error)

func (*Repo) DiffStatForCommit

func (r *Repo) DiffStatForCommit(ctx context.Context, hash string) ([]FileStat, error)

DiffStatForCommit returns per-file added/deleted line counts for the given commit using git diff --numstat. Binary files are included with 0/0 counts.

func (*Repo) DiffWorkingTree added in v0.4.0

func (r *Repo) DiffWorkingTree(ctx context.Context) ([]byte, error)

DiffWorkingTree returns the combined unstaged + staged diff against HEAD. Used by the handoff bundle to surface uncommitted changes; callers redact the result before including it in any agent-visible payload.

func (*Repo) HeadCommitHash

func (r *Repo) HeadCommitHash(ctx context.Context) (string, error)

func (*Repo) HooksDir

func (r *Repo) HooksDir(ctx context.Context) (string, error)

func (*Repo) InstallSemanticaHook

func (r *Repo) InstallSemanticaHook(ctx context.Context, opts HookInstallOptions) error

func (*Repo) IsDirty

func (r *Repo) IsDirty(ctx context.Context) (bool, error)

IsDirty returns true if the working tree has any changes: -modified, staged, deleted, untracked

func (*Repo) ListFilesFromGit

func (r *Repo) ListFilesFromGit(ctx context.Context) ([]string, error)

func (*Repo) LogSince added in v0.4.0

func (r *Repo) LogSince(ctx context.Context, since time.Time, limit int) ([]Commit, error)

LogSince returns commits whose author-date is at or after the given time, capped at limit entries (default 20 when limit<=0). Each Commit carries the short hash, subject, and body so the handoff bundle can render them with their full context rather than collapsing each commit to a single line.

func (*Repo) MergeBase

func (r *Repo) MergeBase(ctx context.Context, a, b string) (string, error)

MergeBase returns the best common ancestor of two refs.

func (*Repo) OrdinaryTrackedFiles added in v0.6.0

func (r *Repo) OrdinaryTrackedFiles(ctx context.Context) ([]string, error)

OrdinaryTrackedFiles returns index paths tagged "H" by git ls-files -v. It excludes entries whose working-tree content Git does not verify, including assume-unchanged, skip-worktree, unmerged, and removed entries.

func (*Repo) ReadFile

func (r *Repo) ReadFile(relPath string) ([]byte, error)

func (*Repo) RemoteURL

func (r *Repo) RemoteURL(ctx context.Context) (string, error)

RemoteURL returns the URL of the "origin" remote.

func (*Repo) RemoveFile

func (r *Repo) RemoveFile(relPath string) error

func (*Repo) ResolveRef

func (r *Repo) ResolveRef(ctx context.Context, ref string) (string, error)

ResolveRef resolves a git ref (HEAD, branch name, tag, commit prefix) to a full commit hash. Returns an error if the ref is not valid.

func (*Repo) RestoreFile

func (r *Repo) RestoreFile(relPath string, content []byte, mode os.FileMode, isSymlink bool, linkTarget string) error

RestoreFile restores a file from a checkpoint manifest. It handles both regular files (with correct mode bits) and symlinks. For backward compatibility, if mode is 0 it defaults to 0644.

func (*Repo) Root

func (r *Repo) Root() string

func (*Repo) StatusShort added in v0.4.0

func (r *Repo) StatusShort(ctx context.Context) (string, error)

StatusShort returns `git status --short` output (one line per file, e.g. " M path/to/file"). Used by the handoff bundle to summarize uncommitted changes a fresh agent session needs to know about.

func (*Repo) TrackedFilesAtCommit added in v0.6.0

func (r *Repo) TrackedFilesAtCommit(ctx context.Context, commit string) ([]string, error)

TrackedFilesAtCommit returns the paths tracked in the given commit's tree. The id must be a full commit hash.

func (*Repo) WriteFile

func (r *Repo) WriteFile(relPath string, b []byte) error

Jump to

Keyboard shortcuts

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