git

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProviderFromRemoteURL

func ProviderFromRemoteURL(remoteURL string) string

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

Types

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

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

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

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

MergeBase returns the best common ancestor of two refs.

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