Documentation
¶
Overview ¶
Package gitutil provides git utility functions for repository introspection, branch management, and pushing.
Index ¶
- func CheckoutBranch(ctx context.Context, dir, name string) error
- func CreateBranch(ctx context.Context, dir, name, startPoint string) error
- func CreateBranchAt(ctx context.Context, dir, name, commit string) error
- func CurrentBranch(ctx context.Context, wd string) (string, error)
- func DefaultBranch(ctx context.Context, wd, remote string) (string, error)
- func DefaultRemote(ctx context.Context, wd string) (string, error)
- func DiscoverRepos(root string, maxDepth int) ([]string, error)
- func Fetch(ctx context.Context, dir string) error
- func GenerateCommitMsg(ctx context.Context, p genai.Provider, metadata, diff string, ...) (string, error)
- func IsReachable(ctx context.Context, dir, commit string) (bool, error)
- func MergeBase(ctx context.Context, dir, baseRef string) string
- func PushRef(ctx context.Context, dir, ref, branch string, force bool) error
- func RemoteOriginURL(ctx context.Context, dir string) string
- func RemoteToHTTPS(raw string) string
- func RevParse(ctx context.Context, dir, ref string) (string, error)
- func RootDir(ctx context.Context, wd string) (string, error)
- func RunGit(ctx context.Context, dir string, args ...string) (string, error)
- func SquashOnto(ctx context.Context, dir, sourceRef, targetBranch, message string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckoutBranch ¶
CheckoutBranch switches to an existing branch.
func CreateBranch ¶
CreateBranch creates a new branch from startPoint and checks it out.
func CreateBranchAt ¶
CreateBranchAt creates a local branch pointing at commit without checking it out. This does not touch the working tree or index.
func CurrentBranch ¶
CurrentBranch returns the current branch name for the given working directory.
func DefaultBranch ¶
DefaultBranch returns the default branch name (e.g. "main" or "master") for the given remote in the given working directory.
func DefaultRemote ¶
DefaultRemote returns the default remote for the given working directory. If there is exactly one remote, it is returned. Otherwise "origin" is used.
func DiscoverRepos ¶
DiscoverRepos recursively walks root up to maxDepth levels, returning absolute paths of directories containing a .git subdirectory. Hidden directories (prefix ".") are skipped. Recursion stops once .git is 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 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 MergeBase ¶
MergeBase returns the merge-base between HEAD and baseRef, falling back to baseRef itself if merge-base fails (e.g. unrelated histories).
func 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 RemoteOriginURL ¶
RemoteOriginURL returns the URL of the "origin" remote, or "" if unavailable.
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.
func SquashOnto ¶
SquashOnto creates a single squash commit of sourceRef's tree on top of origin/<targetBranch> and pushes it. Uses plumbing commands only — no working-tree checkout needed. The push is non-force so it fails with a non-fast-forward error if origin/<targetBranch> has advanced since fetch.
Types ¶
This section is empty.