git

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(dir, branch string) (bool, error)

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

func Checkout(dir, branch string) error

Checkout switches the worktree at dir to an existing branch.

func CheckoutNewBranch

func CheckoutNewBranch(dir, branch, baseRef string) error

CheckoutNewBranch cuts and checks out branch from baseRef in the worktree at dir (git checkout -b branch baseRef).

func CheckoutWithFetch

func CheckoutWithFetch(dir, branch string) error

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

func CommitAll(dir, message string) (sha string, committed bool, err error)

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

func CommitSubject(dir, ref string) (string, error)

CommitSubject returns the subject line of the commit at ref.

func CurrentBranch

func CurrentBranch(dir string) (string, error)

CurrentBranch returns the short symbolic name of the worktree's HEAD.

func DefaultBranchName

func DefaultBranchName(repoRoot string) string

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

func Fetch(dir, branch string) error

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

func MergeBase(dir, ref1, ref2 string) (string, error)

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

func Output(dir string, args ...string) (string, error)

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

func Push(dir, branch string) error

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

func RemoteBranchExists(dir, branch string) (bool, error)

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

func RevParse(dir, ref string) (string, error)

RevParse resolves a ref to a commit SHA in the worktree at dir.

func StatusPorcelain

func StatusPorcelain(dir string) (string, error)

StatusPorcelain returns the porcelain status of the worktree; an empty result means the tree is clean.

Types

This section is empty.

Source Files

  • git.go

Jump to

Keyboard shortcuts

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