git

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package git reads the local branch state the pr command needs. It shells out to git rather than linking a git library: the CLI already assumes a checkout with a remote (that's how the repo is detected), and the two facts needed here are one command each.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotRepo added in v0.18.0

func IsNotRepo(err error) bool

IsNotRepo reports whether err is git saying the directory is not inside a repository, as opposed to git being missing or failing for another reason. Callers that treat "no checkout" as an ordinary answer use it to avoid also swallowing the failures that would make the answer wrong.

func LinkedWorktree added in v0.18.0

func LinkedWorktree(dir string) (string, error)

LinkedWorktree returns the root path of the checkout containing dir when it is a linked worktree, which is what tells concurrent agents in one repository apart. The full path rather than the directory name, because two worktrees can share a name under different parents. It is empty for the main checkout, so a lone user in the primary checkout keeps the bare login, and an error when dir is not in a git checkout at all.

func MainCheckout added in v0.18.0

func MainCheckout(dir string) (string, error)

MainCheckout returns the path of the repository's main working tree as seen from dir (the working directory when empty). In a linked worktree it is not the worktree itself but the checkout the worktrees hang off, which is where state shared by every worktree has to live. For a bare repository there is no working tree, so it is the repository directory.

func RemoteURL added in v0.19.0

func RemoteURL(dir string) (string, error)

RemoteURL returns the URL of the repository's origin remote as seen from dir (the working directory when empty). It is empty when there is no origin remote, and an error when git cannot answer for another reason.

Types

type State

type State struct {
	// Branch is the current branch name, empty on a detached HEAD.
	Branch string
	// Upstream is the branch name on the remote, empty when the branch
	// tracks nothing there. It is not always the local name: see Head.
	Upstream string
	// Pushed reports whether the branch has a remote-tracking counterpart.
	// GitHub can only open a pull request for a ref it can already see, so
	// this is a precondition, not a nicety.
	Pushed bool
}

State is the local branch state a pull request is opened from.

func Current

func Current() (State, error)

Current reads the state of the checkout in the working directory.

func CurrentFor added in v0.19.0

func CurrentFor(dir string) (State, error)

CurrentFor reads the state of the checkout at dir, never the process's working directory: the public `pr` workflow answers every checkout question from the worktree its caller named.

func (State) Head added in v0.8.0

func (s State) Head() string

Head is the branch a pull request is opened from — the upstream name when there is one, the local name otherwise. The two differ whenever a checkout is made under a generated local name: an agent harness working in a git worktree ends up on worktree-feat+x tracking origin/feat/x, and GitHub has never heard of the local name, so a PR opened from it is rejected outright.

Jump to

Keyboard shortcuts

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