Documentation
¶
Overview ¶
Package git is a typed wrapper around the git command line. It shells out through pkg/exec; go-git is deliberately not used so behaviour matches the user's git exactly (hooks, config, worktrees, signing).
Index ¶
- Constants
- Variables
- type AddMode
- type Branch
- type Client
- func (c *Client) Add(ctx context.Context, repo Repo, mode AddMode) error
- func (c *Client) BranchExists(ctx context.Context, repo Repo, name string) (bool, error)
- func (c *Client) Branches(ctx context.Context, repo Repo) ([]Branch, error)
- func (c *Client) CheckRefFormat(ctx context.Context, name string) error
- func (c *Client) Commit(ctx context.Context, repo Repo, o CommitOptions) (string, error)
- func (c *Client) ConfigAdd(ctx context.Context, repo Repo, scope Scope, key, value string) error
- func (c *Client) ConfigGet(ctx context.Context, repo Repo, scope Scope, key string) (string, bool, error)
- func (c *Client) ConfigGetAll(ctx context.Context, repo Repo, scope Scope, key string) ([]string, error)
- func (c *Client) ConfigGetRegexp(ctx context.Context, repo Repo, scope Scope, re string) ([]ConfigEntry, error)
- func (c *Client) ConfigSet(ctx context.Context, repo Repo, scope Scope, key, value string) error
- func (c *Client) ConfigUnset(ctx context.Context, repo Repo, scope Scope, key string) error
- func (c *Client) ConfigUnsetValue(ctx context.Context, repo Repo, scope Scope, key, value string) error
- func (c *Client) ConflictedFiles(ctx context.Context, repo Repo) ([]string, error)
- func (c *Client) CountCommits(ctx context.Context, repo Repo, from, to string) (int, error)
- func (c *Client) CreateBranch(ctx context.Context, repo Repo, name, start string) error
- func (c *Client) CurrentBranch(ctx context.Context, repo Repo) (string, error)
- func (c *Client) DefaultBranch(ctx context.Context, repo Repo) (string, bool, error)
- func (c *Client) DiffRange(ctx context.Context, repo Repo, base, head string) (string, error)
- func (c *Client) Discover(ctx context.Context, dir string) (Repo, error)
- func (c *Client) HasStagedChanges(ctx context.Context, repo Repo) (bool, error)
- func (c *Client) HasUnstagedChanges(ctx context.Context, repo Repo) (bool, error)
- func (c *Client) HasUntrackedFiles(ctx context.Context, repo Repo) (bool, error)
- func (c *Client) IsAncestor(ctx context.Context, repo Repo, ancestor, descendant string) (bool, error)
- func (c *Client) ListCmds(ctx context.Context, spec string) ([]string, error)
- func (c *Client) Messages(ctx context.Context, repo Repo, from, to string) ([]string, error)
- func (c *Client) Passthrough(ctx context.Context, repo Repo, args ...string) error
- func (c *Client) RebaseInProgress(ctx context.Context, repo Repo) (bool, error)
- func (c *Client) RevParse(ctx context.Context, repo Repo, rev string) (string, error)
- func (c *Client) Runner() exec.Runner
- func (c *Client) StagedDiff(ctx context.Context, repo Repo) (string, error)
- func (c *Client) Subject(ctx context.Context, repo Repo, rev string) (string, error)
- func (c *Client) Subjects(ctx context.Context, repo Repo, rev string, n int) ([]string, error)
- func (c *Client) Switch(ctx context.Context, repo Repo, name string) error
- func (c *Client) SwitchDetached(ctx context.Context, repo Repo, rev string) error
- func (c *Client) Worktrees(ctx context.Context, repo Repo) ([]Worktree, error)
- type CommitOptions
- type ConfigEntry
- type Option
- type Repo
- type Scope
- type Worktree
Constants ¶
const DefaultLockRetryBudget = 2 * time.Second
DefaultLockRetryBudget is how long git commands wait for a held index lock before giving up. IDEs and agents take the lock for milliseconds at a time while refreshing status, which is plenty to make a bare `git add` fail.
Variables ¶
var ErrDetached = errors.New("HEAD is detached")
ErrDetached is returned when HEAD is not on a branch.
var ErrNotRepo = errors.New("not a git repository")
ErrNotRepo is returned by Discover outside a git repository.
Functions ¶
This section is empty.
Types ¶
type Branch ¶
type Branch struct {
Name string
// Head is the tip commit id.
Head string
// CommitTime is the committer date of the tip.
CommitTime time.Time
// Worktree is the path of the worktree the branch is checked out in, or
// empty.
Worktree string
// Upstream is the tracking branch (e.g. origin/feat), or empty.
Upstream string
}
Branch describes a local branch.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs git commands.
func (*Client) BranchExists ¶
BranchExists reports whether a local branch exists.
func (*Client) CheckRefFormat ¶
CheckRefFormat validates name as a branch name.
func (*Client) Commit ¶
Commit creates or amends a commit and returns the new HEAD id. When the editor must open (no message and not NoEdit, or Edit), the command runs in passthrough mode.
func (*Client) ConfigGet ¶
func (c *Client) ConfigGet(ctx context.Context, repo Repo, scope Scope, key string) (string, bool, error)
ConfigGet returns the value of key. The boolean reports whether it was set.
func (*Client) ConfigGetAll ¶
func (c *Client) ConfigGetAll(ctx context.Context, repo Repo, scope Scope, key string) ([]string, error)
ConfigGetAll returns every value of a multi-valued key.
func (*Client) ConfigGetRegexp ¶
func (c *Client) ConfigGetRegexp(ctx context.Context, repo Repo, scope Scope, re string) ([]ConfigEntry, error)
ConfigGetRegexp returns every entry whose key matches the regexp.
func (*Client) ConfigUnset ¶
ConfigUnset removes every value of key. A missing key is not an error.
func (*Client) ConfigUnsetValue ¶
func (c *Client) ConfigUnsetValue(ctx context.Context, repo Repo, scope Scope, key, value string) error
ConfigUnsetValue removes the values of key that match the given value (exact match). A missing key or value is not an error.
func (*Client) ConflictedFiles ¶
ConflictedFiles lists paths with unresolved merge conflicts.
func (*Client) CountCommits ¶
CountCommits returns the number of commits in from..to.
func (*Client) CreateBranch ¶
CreateBranch creates name at start without checking it out.
func (*Client) CurrentBranch ¶
CurrentBranch returns the checked-out branch name.
func (*Client) DefaultBranch ¶
DefaultBranch guesses the repository's trunk the way gh-stack does: the branch origin/HEAD points at, else a local main or master. The boolean is false when nothing matches.
func (*Client) DiffRange ¶
DiffRange returns the diff between base and head (base...head semantics are not used: this is the exact tree difference, which is what a rebased branch shows against its parent).
func (*Client) HasStagedChanges ¶
HasStagedChanges reports whether the index differs from HEAD.
func (*Client) HasUnstagedChanges ¶
HasUnstagedChanges reports whether the working tree has unstaged changes to tracked files.
func (*Client) HasUntrackedFiles ¶
HasUntrackedFiles reports whether untracked, non-ignored files exist.
func (*Client) IsAncestor ¶
func (c *Client) IsAncestor(ctx context.Context, repo Repo, ancestor, descendant string) (bool, error)
IsAncestor reports whether ancestor is reachable from descendant.
func (*Client) ListCmds ¶
ListCmds returns `git --list-cmds=<spec>` (e.g. "builtins" or "main,others").
func (*Client) Passthrough ¶
Passthrough runs git with the terminal attached (editors, `add -p`).
func (*Client) RebaseInProgress ¶
RebaseInProgress reports whether git has a rebase in progress.
func (*Client) Runner ¶
Runner exposes the underlying runner (used by adapters that run other tools with the same debug/TTY settings).
func (*Client) StagedDiff ¶
StagedDiff returns the diff of the index against HEAD.
func (*Client) Subjects ¶
Subjects returns the commit subjects of rev's history, newest first, at most n.
func (*Client) SwitchDetached ¶ added in v0.1.1
SwitchDetached checks out rev with a detached HEAD.
type CommitOptions ¶
type CommitOptions struct {
// Message paragraphs; each becomes a -m argument. Empty opens the editor
// unless NoEdit is set.
Message []string
Amend bool
NoEdit bool
// Edit forces the editor even with a message (or when amending).
Edit bool
ResetAuthor bool
NoVerify bool
// AllowEmpty permits a commit with no changes.
AllowEmpty bool
}
CommitOptions controls Commit.
type ConfigEntry ¶
ConfigEntry is one key/value pair.
type Repo ¶
type Repo struct {
// TopLevel is the working tree root.
TopLevel string
// GitDir is the repository directory for this worktree
// (e.g. .git or .git/worktrees/<name>).
GitDir string
// CommonDir is the shared repository directory (.git of the main worktree).
CommonDir string
}
Repo locates a repository. All paths are absolute.
func (Repo) IsLinkedWorktree ¶
IsLinkedWorktree reports whether the repo is a linked worktree.