Documentation
¶
Overview ¶
Package git provides low-level git helpers used by the plan executor and worktree manager. All operations run via os/exec directly (not through the sandbox shell tool) because the sandbox's only writable root is the session worktree, while branch creation, commits, and pushes write to the shared .git directory which is an ancestor the sandbox grants only read-only access.
Index ¶
- func BranchExists(dir, branch string) (bool, error)
- func Checkout(dir, branch string) error
- func CheckoutNewBranch(dir, branch, baseRef string) error
- func CheckoutWithFetch(dir, branch string) error
- func CommitAll(dir, message string) (sha string, committed bool, err error)
- func CommitSubject(dir, ref string) (string, error)
- func CurrentBranch(dir string) (string, error)
- func DefaultBranchName(repoRoot string) string
- func Fetch(dir, branch string) error
- func MergeBase(dir, ref1, ref2 string) (string, error)
- func Output(dir string, args ...string) (string, error)
- func Push(dir, branch string) error
- func RemoteBranchExists(dir, branch string) (bool, error)
- func RevParse(dir, ref string) (string, error)
- func StatusPorcelain(dir string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists reports whether a local branch of the given name exists in the repo at dir. `rev-parse --verify --quiet` exits 1 (no output) when the ref is absent and 0 when it resolves.
func Checkout ¶
Checkout switches the worktree at dir to an existing branch.
func CheckoutNewBranch ¶
CheckoutNewBranch cuts and checks out branch from baseRef in the worktree at dir (git checkout -b branch baseRef).
func CheckoutWithFetch ¶
CheckoutWithFetch checks out branch in the worktree at dir, fetching it from origin first when no local branch of that name exists yet. This lets callers check out a ticket branch that was cut and pushed by a different session/worktree without ever creating a remote-tracking ref: git fetch updates FETCH_HEAD, and the local branch is cut from that tip.
func CommitAll ¶
CommitAll stages every change in the worktree and creates one commit with the given message. It returns committed=false (and no error) when there is nothing to commit, so a no-op phase does not abort execution.
func CommitSubject ¶
CommitSubject returns the subject line of the commit at ref.
func CurrentBranch ¶
CurrentBranch returns the short symbolic name of the worktree's HEAD.
func DefaultBranchName ¶
DefaultBranchName makes a best-effort guess at the branch the first ticket should merge into. It prefers the remote's default branch (origin/HEAD), falls back to the main checkout's current branch, then to "main".
func Fetch ¶
Fetch fetches branch from origin into the repo at dir (git fetch origin <branch>), updating FETCH_HEAD without creating a remote-tracking ref.
func MergeBase ¶
MergeBase returns the best common ancestor commit SHA of ref1 and ref2 in the repository at dir. It is the git equivalent of "fork point": the commit where the two histories diverged.
func Output ¶
Output runs `git -C dir <args...>` and returns trimmed stdout. Any failure is wrapped with the command's stderr so the caller can surface the real git error (e.g. "a branch named X already exists").
func Push ¶
Push pushes branch to origin and sets it as the upstream, so any later pushes are simple and the branch is ready for a forge review request (opened externally via the ticket.completed lifecycle hook).
func RemoteBranchExists ¶
RemoteBranchExists reports whether branch exists on the "origin" remote, via `git ls-remote --heads origin <branch>`. A non-empty result means the branch is present; an empty result (exit 0, no output) means it is absent. Errors (e.g. no network, no "origin" remote configured) are surfaced to the caller rather than treated as "absent", since a connectivity failure is not evidence the branch was deleted.
func RevParse ¶
RevParse resolves a ref to a commit SHA in the worktree at dir.
Types ¶
This section is empty.
Source Files
¶
- git.go