Documentation
¶
Overview ¶
Package git provides git utility functions for repository introspection, branch management, and pushing.
Index ¶
- func DiscoverCheckouts(root string, maxDepth int) ([]string, error)
- func GenerateCommitMsg(ctx context.Context, p genai.Provider, metadata, diff string, ...) (string, error)
- func RemoteToHTTPS(raw string) string
- type Checkout
- func (c *Checkout) CheckoutBranch(ctx context.Context, name string) error
- func (c *Checkout) CreateBranch(ctx context.Context, name, startPoint string, track bool) error
- func (c *Checkout) CurrentBranch(ctx context.Context) (string, error)
- func (c *Checkout) DefaultBranch(ctx context.Context, remote string) (string, error)
- func (c *Checkout) DefaultRemote(ctx context.Context) (string, error)
- func (c *Checkout) Fetch(ctx context.Context) error
- func (c *Checkout) FindModuleDirs(ctx context.Context) ([]string, error)
- func (c *Checkout) IsReachable(ctx context.Context, commit string) (bool, error)
- func (c *Checkout) ListBranches(ctx context.Context, remote string) ([][2]string, error)
- func (c *Checkout) ListSubmodules(ctx context.Context) ([]Submodule, error)
- func (c *Checkout) MergeBase(ctx context.Context, baseRef string) string
- func (c *Checkout) PushRef(ctx context.Context, ref, branch string, force bool) error
- func (c *Checkout) RefExists(ctx context.Context, ref string) (bool, error)
- func (c *Checkout) RemoteOriginURL(ctx context.Context) string
- func (c *Checkout) Remotes(ctx context.Context) ([]string, error)
- func (c *Checkout) RevParse(ctx context.Context, ref string) (string, error)
- func (c *Checkout) RunGit(ctx context.Context, args ...string) (string, error)
- func (c *Checkout) SquashOnto(ctx context.Context, sourceRef, targetBranch, message string) error
- type Logger
- type Submodule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiscoverCheckouts ¶
DiscoverCheckouts recursively walks root up to maxDepth levels, returning absolute paths of git repositories.
Both regular repos (containing a .git subdirectory) and bare repos (containing HEAD, objects/, and refs/ directly) are detected. Hidden directories (prefix ".") are skipped. Recursion stops once a repo is found, so submodules are not found.
func GenerateCommitMsg ¶
func GenerateCommitMsg(ctx context.Context, p genai.Provider, metadata, diff string, filters []func(string) bool) (string, error)
GenerateCommitMsg applies a progressive reduction pipeline to fit the diff under the LLM context limit, then calls the LLM to produce a commit message.
metadata should contain git context (branch name, file stats, recent commit messages). diff should be a unified diff of the changes to describe. filters is an ordered list of file predicates applied progressively to reduce the diff size. Pass nil to use defaultDiffFilters.
func RemoteToHTTPS ¶
RemoteToHTTPS converts a git remote URL to an HTTPS browse URL. SSH (git@host:owner/repo.git), ssh:// and https:// with .git suffix are normalised. Unrecognised formats are returned as-is.
Types ¶
type Checkout ¶
Checkout provides git operations scoped to the repository at Root, logging via Logger.
func RootDir ¶
RootDir discovers the git repository root for the given working directory and returns a Git scoped to it.
func (*Checkout) CheckoutBranch ¶
CheckoutBranch switches to an existing branch.
func (*Checkout) CreateBranch ¶
CreateBranch creates a new branch from startPoint without touching the working tree or index.
func (*Checkout) CurrentBranch ¶
CurrentBranch returns the current branch name for Root.
func (*Checkout) DefaultBranch ¶
DefaultBranch returns the default branch name (e.g. "main" or "master") for the given remote in Root.
func (*Checkout) DefaultRemote ¶
DefaultRemote returns the default remote for Root. If there is exactly one remote, it is returned. Otherwise "origin" is used.
func (*Checkout) FindModuleDirs ¶
FindModuleDirs returns relative paths (from <Root>/.git/modules/) for every bare module repository found under that directory.
Bare repos are detected by the presence of a HEAD file, an objects/ directory, and a refs/ directory. Nested module repos (submodules of submodules) stored under <module>/modules/ are included recursively. Returns nil if the modules directory does not exist.
func (*Checkout) IsReachable ¶
IsReachable reports whether commit is an ancestor of (or equal to) any ref in refs/heads/ or refs/remotes/origin/. Container remote-tracking refs (refs/remotes/<container>/*) are excluded by construction.
func (*Checkout) ListBranches ¶
ListBranches returns branches sorted alphabetically. It always runs git directly with no caching so the result is always fresh even when branches are created or deleted frequently.
If remote is empty, local branches (refs/heads/) are listed and each entry's first element is the short branch name. If remote is non-empty, remote tracking branches for that remote (refs/remotes/<remote>/) are listed and HEAD is excluded.
func (*Checkout) ListSubmodules ¶
ListSubmodules returns the submodules declared in .gitmodules for Root. Returns nil if no .gitmodules file exists or it has no entries.
func (*Checkout) MergeBase ¶
MergeBase returns the merge-base between HEAD and baseRef, falling back to baseRef itself if merge-base fails (e.g. unrelated histories).
func (*Checkout) PushRef ¶
PushRef pushes a local ref to the origin remote as the given branch. ref can be a remote-tracking ref (e.g. "container/branch"), a branch name, or any valid git ref. When force is true, --force is passed.
func (*Checkout) RefExists ¶ added in v0.17.0
RefExists reports whether the fully-qualified ref (e.g. "refs/heads/foo") exists in Root.
func (*Checkout) RemoteOriginURL ¶
RemoteOriginURL returns the URL of the "origin" remote, or "" if unavailable.
func (*Checkout) Remotes ¶ added in v0.17.0
Remotes returns the configured remote names sorted alphabetically.
func (*Checkout) SquashOnto ¶
SquashOnto creates a single squash commit of sourceRef's tree on top of origin/<targetBranch> and pushes it.
Uses plumbing commands only, no active branch checkout needed. The push is non-force so it fails with a non-fast-forward error if origin/<targetBranch> has advanced since fetch.