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
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
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
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.
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 CurrentFor ¶ added in v0.19.0
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
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.