git

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPullRequest = errors.New("no pull request found for branch")

ErrNoPullRequest reports that the current branch has no hosted pull request (GitHub PR or GitLab MR) yet.

Functions

func AheadBehind

func AheadBehind(ctx context.Context, dir, ref string) (ahead, behind int, err error)

AheadBehind counts commits in ref but not in HEAD (behind) and in HEAD but not in ref (ahead), so callers can show how a branch relates to a remote main line instead of its upstream.

func Checkout

func Checkout(ctx context.Context, dir, branch string, create bool) error

Checkout switches the workspace to branch, creating it first when create is true. Remote-only names (origin/...) create a local tracking branch.

func CommitAll

func CommitAll(ctx context.Context, dir, message string) (string, error)

Commit stages every change (tracked, staged, and untracked) and creates a commit with message, so a subsequent push always has something to upload.

func CurrentBranch

func CurrentBranch(ctx context.Context, dir string) (string, error)

CurrentBranch returns the checked-out branch name, or "HEAD" when detached. symbolic-ref works even on an unborn HEAD (a repository without commits).

func Fetch

func Fetch(ctx context.Context, dir string) error

Fetch downloads the latest refs from origin so panel comparisons against origin/main reflect what is actually on the remote. It never touches the working tree, so it is safe during rebases and merges.

func IsMerged

func IsMerged(ctx context.Context, dir, ref string) (bool, error)

IsMerged reports whether HEAD is an ancestor of ref, i.e. every commit on the current branch is already reachable from the main line.

func MainBranch

func MainBranch(ctx context.Context, dir string) string

MainBranch returns the remote ref of the repository's main line (origin/main, falling back to origin/master), or "" when the remote has neither.

func MainBranchShort

func MainBranchShort(ctx context.Context, dir string) string

MainBranchShort returns the short branch name of the repository's main line ("main" or "master"), or "" when the remote has neither.

func OperationState

func OperationState(ctx context.Context, dir string) string

OperationState reports an in-progress git operation by inspecting the per-worktree git directory, or "" when the workspace is idle.

func Pull

func Pull(ctx context.Context, dir string) (string, error)

Pull updates the workspace with a conservative fast-forward-only merge.

func Push

func Push(ctx context.Context, dir string) (string, error)

Push uploads the current branch, setting the upstream when the branch has none yet.

func RemoteURL

func RemoteURL(ctx context.Context, dir string) (string, error)

RemoteURL returns the origin remote URL, or an error when origin is not configured.

Types

type BranchList

type BranchList struct {
	Local  []string
	Remote []string
}

BranchList separates local and remote branch names for one workspace.

func Branches

func Branches(ctx context.Context, dir string) (BranchList, error)

Branches lists local and remote branch names for one workspace.

type Change

type Change struct {
	Path       string
	Status     string
	Staged     bool
	RenameFrom string
	Added      int
	Deleted    int
}

Change is one working-tree change of a workspace.

type Commit

type Commit struct {
	Hash    string
	Short   string
	Subject string
	Author  string
	Email   string
	Time    time.Time
	Files   []FileChange
}

Commit is one entry of a workspace's commit history.

func Log

func Log(ctx context.Context, dir string, limit int) ([]Commit, error)

func LogRange

func LogRange(ctx context.Context, dir, ref string) ([]Commit, error)

LogRange returns every commit reachable from HEAD but not from ref, i.e. the current branch's changes that are not yet merged into ref's line.

type Error

type Error struct {
	Output string
	Err    error
}

Error carries the trimmed command output so the UI can show why an operation failed instead of a bare exit status.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FileChange

type FileChange struct {
	Path       string
	Status     string
	RenameFrom string
	Added      int
	Deleted    int
}

FileChange is one file touched by a commit, as reported by --name-status, with added/deleted line counts merged from --numstat.

type FileView

type FileView struct {
	Content          string
	Diff             string
	ContentTruncated bool
	DiffTruncated    bool
}

FileView is one file's full content and its unified diff, both keyed to the same version: the working tree, the index, or a specific commit.

func Show

func Show(ctx context.Context, dir, path string, staged bool, commit string) (FileView, error)

Show returns the full content of path at the selected version together with its unified diff. When commit is non-empty both are keyed to that commit; staged selects the index; otherwise the working tree is shown. Untracked files have no reference version, so the whole file is shown as new content. Deleted files report an empty content with their diff.

type LineCount

type LineCount struct {
	Added   int
	Deleted int
}

LineCount is the added/deleted line total of one path in a diff.

type PullRequest

type PullRequest struct {
	Number int
	Title  string
	Body   string
	State  string
	Draft  bool
	URL    string
	Author string
	Base   string
	Head   string
}

PullRequest is a hosted pull request for one branch, backed by either the GitHub CLI or the GitLab CLI depending on the origin remote.

func CreatePullRequest

func CreatePullRequest(ctx context.Context, dir, title, body string) (*PullRequest, error)

CreatePullRequest pushes the current branch when needed and opens a pull request against the repository's main branch, returning the created request.

func PullRequestForBranch

func PullRequestForBranch(ctx context.Context, dir string) (*PullRequest, error)

PullRequestForBranch returns the pull request whose head is the current branch, or (nil, ErrNoPullRequest) when none exists yet.

type Status

type Status struct {
	Branch   string
	Upstream string
	Ahead    int
	Behind   int
	Stash    int
	Changes  []Change
}

Status summarizes one workspace working tree.

func StatusFor

func StatusFor(ctx context.Context, dir string) (Status, error)

StatusFor reports the working-tree status of the git repository at dir, including added/deleted line counts for staged and unstaged changes.

Jump to

Keyboard shortcuts

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