gitrepo

package
v0.0.0-...-95517ba Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gitrepo implements the coder's git port by shelling out to the git binary — always argv, never a shell string. Author and committer identity are left alone: attribution is a single sanitized "Assisted-by: <model> via Strument" trailer on auto-commits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Trailer

func Trailer(modelName string) string

Trailer renders the attribution trailer for a model name, stripping newlines and control characters so it stays one well-formed trailer.

Types

type Commit

type Commit struct {
	SHA     string
	Short   string
	Subject string
}

Commit describes one commit for the /squash gates.

type Repo

type Repo struct {

	// Trailer is appended to attributed commits via `git commit
	// --trailer`; build it with Trailer() so the model name is sanitized.
	CommitTrailer string

	// Message generates a commit message from staged diffs and chat
	// context (the side-model call); nil or an empty result falls
	// back to aider's "(no commit message provided)".
	Message func(diffs, context string) string

	// Sign, when non-empty, is the `git commit` signing flag passed
	// through as its own argv: "-S" to sign with the default key, or
	// "-S<keyid>" to pick one (git_sign = true / "keyid"). Empty means
	// unsigned.
	Sign string
	// contains filtered or unexported fields
}

Repo is a discovered git repository.

func Discover

func Discover(dir string) (*Repo, error)

Discover finds the repository containing dir, or returns an error when dir is not inside a git worktree (or git is not installed).

func (*Repo) ChangedInHead

func (r *Repo) ChangedInHead() ([]string, error)

ChangedInHead lists the files HEAD changed relative to its first parent.

func (*Repo) ChangedInRange

func (r *Repo) ChangedInRange(rev string) ([]string, error)

ChangedInRange lists the files changed between rev and HEAD — what /squash needs to re-stage after folding several commits back into the index.

func (*Repo) CheckoutFileFrom

func (r *Repo) CheckoutFileFrom(rev, rel string) error

CheckoutFileFrom restores rel from the given revision into the worktree and index.

func (*Repo) Commit

func (r *Repo) Commit(fnames []string, context, want string, attributed bool) (hash, message string, ok bool, err error)

Commit stages fnames and commits them. attributed adds the trailer (auto-commits of model edits); dirty commits stay unattributed. ok=false means there was nothing to commit. GIT_AUTHOR_* and GIT_COMMITTER_* are never overridden; hooks run normally.

want is the message to use. Empty means generate one from the staged diff through the Message hook, which is the automatic path; a non-empty one is used verbatim, for the commit tool where the model writes its own.

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch() string

CurrentBranch returns the checked-out branch name ("" when detached).

func (*Repo) DiffWorktree

func (r *Repo) DiffWorktree(base string) (string, error)

DiffWorktree returns `git diff <base>`: the changes from base to the current worktree (the /diff view).

func (*Repo) GitIgnored

func (r *Repo) GitIgnored(rel string) bool

GitIgnored reports whether rel matches the ignore rules.

func (*Repo) HeadInfo

func (r *Repo) HeadInfo() (sha, short, subject string, parents int, err error)

HeadInfo describes HEAD for /undo: full and short hashes, the subject line, and the parent count.

func (*Repo) HeadSHA

func (r *Repo) HeadSHA() string

HeadSHA returns the full HEAD hash, or "" on an unborn branch.

func (*Repo) InCommit

func (r *Repo) InCommit(commitish, rel string) bool

InCommit reports whether rel exists in the given commit's tree.

func (*Repo) IsDirty

func (r *Repo) IsDirty(rel string) bool

IsDirty reports whether rel has staged or unstaged changes against HEAD (untracked files are not dirty, matching GitPython's is_dirty).

func (*Repo) LastCommits

func (r *Repo) LastCommits(n int) ([]Commit, error)

LastCommits returns the n most recent commits, newest first. It returns fewer than n only when the branch is shorter than that.

func (*Repo) PathInRepo

func (r *Repo) PathInRepo(rel string) bool

PathInRepo reports whether rel is tracked.

func (*Repo) ResetSoft

func (r *Repo) ResetSoft(rev string) error

ResetSoft moves HEAD to rev, keeping the index and worktree.

func (*Repo) RevParse

func (r *Repo) RevParse(rev string) (string, error)

RevParse resolves a revision to a hash.

func (*Repo) Root

func (r *Repo) Root() string

Root returns the worktree root.

func (*Repo) TrackedFiles

func (r *Repo) TrackedFiles() []string

TrackedFiles returns the tracked files, repo-root-relative.

Jump to

Keyboard shortcuts

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