gitx

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 16 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 gitx runs the few git commands the loop needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Binary added in v0.2.0

func Binary() string

Binary is the git to spawn: the one PATH names, except that the macOS xcrun shim is replaced by the git it would run.

func DefaultBranch

func DefaultBranch(dir string) string

DefaultBranch is the branch origin/HEAD of the checkout at dir names, read from the repository files so a sweep spawns no git process per repository. It is empty when origin/HEAD is not set and for a reftable repository, which keeps no ref files.

func NeedsPrompt

func NeedsPrompt(msg string) bool

NeedsPrompt reports whether a git or ssh error means the access needs a credential, a key or a host key the process could not get without asking.

func PRRef

func PRRef(number int) string

func ParseRemote

func ParseRemote(remote string) (host, repo string)

ParseRemote is the host and the repository path, without ".git", of a remote URL: scp-like (git@github.com:acme/widget.git), ssh:// or https://. Both are empty for a local path.

func ReadHead

func ReadHead(dir string) (oid, branch string, ok bool)

ReadHead reads the branch and the commit HEAD of the checkout at dir names from the repository files. branch is empty for a detached HEAD. ok is false when the files do not answer: a reftable repository, a symbolic ref or any unexpected content, so the caller asks git.

func ReadUpstream

func ReadUpstream(dir string) (branch string, ok bool)

ReadUpstream reads the remote branch the current branch of the checkout at dir tracks from the repository files; branch is empty when it tracks none. ok is false whenever the files cannot answer with certainty, so the caller asks git: includes, worktree config, any syntax the parser does not fully understand (comments, continuations, quotes, unusual headers), a remote without exactly the standard fetch refspec, or a layout other than loose and packed refs. Only the repository's own config is read: branch settings in the user or system config are not seen.

func RemoteURL

func RemoteURL(dir, remote string) string

RemoteURL is the url of remote in the repository at dir, read from its config file so recording a fetch spawns no git process; "" when unset.

Types

type Access

type Access struct {
	Host string
	At   time.Time
	// Op names the operation and its subject, such as "fetch of acme/widget#7".
	Op  string
	Err string
}

Access is the outcome of one git operation that talked to a remote host.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache remembers ancestry answers, which never change for a pair of commits git knows, across the sweeps of one process.

type Error

type Error struct {
	Args []string
	Msg  string
	Code int
}

func (*Error) Error

func (e *Error) Error() string

type Exec

type Exec struct{}

func (Exec) Run

func (Exec) Run(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)

type Git

type Git struct {
	R Runner
	C *Cache
}

Git runs git through R; C, when set, remembers ancestry answers.

func New

func New() Git

func (Git) Changed

func (g Git) Changed(ctx context.Context, dir string) (int, error)

Changed counts modified and untracked files, whatever status.showUntrackedFiles says.

func (Git) CheckedOutAt

func (g Git) CheckedOutAt(ctx context.Context, dir, branch string) (string, error)

CheckedOutAt is the path of the worktree that has branch checked out, empty when none has.

func (Git) DirtyTracked

func (g Git) DirtyTracked(ctx context.Context, dir string) (bool, error)

DirtyTracked reports modified tracked files; untracked files do not block a reset.

func (Git) FetchPR

func (g Git) FetchPR(ctx context.Context, dir string, number int, heads ...string) error

FetchPR fetches the pull request's head into PRRef and, in the same fetch, each of heads, branches of origin, into its remote-tracking ref. A head origin lacks fails the whole fetch, so then it fetches the pull request alone.

func (Git) FetchTracking

func (g Git) FetchTracking(ctx context.Context, dir string) (remote, branch string, err error)

FetchTracking fetches the remote the current branch tracks, origin when it tracks none, and returns that remote and the tracked branch, "" for none. It does not prune: the pull request refs under refs/remotes are shared by every worktree of the repository.

func (Git) HasCommit

func (g Git) HasCommit(ctx context.Context, dir, oid string) (bool, error)

HasCommit reports whether the object database holds the commit.

func (Git) Head

func (g Git) Head(ctx context.Context, dir string) (string, error)

func (Git) Ignored

func (g Git) Ignored(ctx context.Context, dir string) ([]string, error)

Ignored lists the paths git ignores in the checkout; a wholly ignored directory is one entry ending in "/".

func (Git) IsAncestor

func (g Git) IsAncestor(ctx context.Context, dir, ancestor, commit string) (bool, error)

IsAncestor reports whether ancestor is reachable from commit. An unknown object counts as not an ancestor.

func (Git) LocalBranchTip

func (g Git) LocalBranchTip(ctx context.Context, dir, branch string) (string, error)

LocalBranchTip is the commit of a local branch, empty when there is none.

func (Git) LsRemote

func (g Git) LsRemote(ctx context.Context, dir string) error

LsRemote checks that the remote is reachable without prompting, the way launchd would run it.

func (Git) RemoteHasBranch

func (g Git) RemoteHasBranch(ctx context.Context, dir, remote, branch string) (bool, error)

RemoteHasBranch asks the remote whether branch still exists there.

func (Git) ResetHard

func (g Git) ResetHard(ctx context.Context, dir, ref string) error

func (Git) TrackBranch

func (g Git) TrackBranch(ctx context.Context, dir, branch string) (renamed bool, err error)

TrackBranch renames the checkout's current branch to the PR's head branch and tracks it, so tools that find a pull request by branch name find this one. It does nothing when another local branch already has that name.

func (Git) TrackFetchedBranch

func (g Git) TrackFetchedBranch(ctx context.Context, dir, branch string) (renamed bool, err error)

TrackFetchedBranch is TrackBranch for a branch FetchPR just fetched as a head.

func (Git) Unpushed

func (g Git) Unpushed(ctx context.Context, dir string) (int, error)

Unpushed counts the commits of HEAD that no remote branch holds.

func (Git) UpdateRef

func (g Git) UpdateRef(ctx context.Context, dir, ref, newOid, oldOid string) error

UpdateRef moves ref to newOid only if it still points at oldOid.

func (Git) UpstreamBranch

func (g Git) UpstreamBranch(ctx context.Context, dir string) (string, error)

UpstreamBranch returns the remote branch the current branch tracks, or "" when it tracks none.

func (Git) WorktreeAddDetached

func (g Git) WorktreeAddDetached(ctx context.Context, dir, path, commit string) error

WorktreeAddDetached checks out commit in a new worktree at path, on no branch.

func (Git) WorktreeRemove

func (g Git) WorktreeRemove(ctx context.Context, dir, path string) error

type Metered

type Metered struct{ Next Runner }

Metered records one meter.Git sample, a spawn, per command of Next. A run that ends because ctx was canceled is not an error.

func (Metered) Run

func (m Metered) Run(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)

type Observed

type Observed struct {
	R       Runner
	Observe func(Access)
	Now     func() time.Time
}

Observed runs git through R and reports every network operation's outcome to Observe; a run its context cancelled reports nothing.

func (Observed) Run

func (o Observed) Run(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)

type Runner

type Runner interface {
	Run(ctx context.Context, dir string, env []string, args ...string) ([]byte, error)
}

Jump to

Keyboard shortcuts

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