git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 11 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 asks git about the work tree a folder is in: its top, its common git folder, its remotes, the work trees and other repos it holds, the folders it doesn't track or ignores, and the files that differ between commits.

Index

Constants

This section is empty.

Variables

View Source
var ErrAmbiguous = errors.New("a name git reads as more than one ref")

ErrAmbiguous is returned, wrapped, for a question naming a ref that names more than one, which git answers for one while a command may take another.

View Source
var ErrNoFolder = errors.New("no such folder")

ErrNoFolder is returned, wrapped, for a folder that doesn't exist, where git can't run.

View Source
var ErrNotInstalled = errors.New("git isn't on the PATH; install git")

ErrNotInstalled is returned, wrapped, when git isn't on the PATH.

View Source
var ErrNotRepository = errors.New("not in a git work tree")

ErrNotRepository is returned, wrapped, for a folder in no git work tree.

Functions

This section is empty.

Types

type Client

type Client struct {
	Runner Runner
	// Environ is terrace's own environment, as os.Environ gives it. git
	// sees only what it needs of it: nothing that could point it at another
	// repo, as GIT_DIR or GIT_CEILING_DIRECTORIES would.
	Environ []string
}

Client runs git through Runner.

func (Client) Applies

func (c Client) Applies(ctx context.Context, dir, patch string) ([]string, error)

Applies are the files the patch file patch touches, as git apply reads them, by their paths from the top of the work tree. git names a file by the name the patch leaves it, so a rename's source is the name its reverse leaves.

func (Client) Changed

func (c Client) Changed(ctx context.Context, dir, rev string, specs []string) ([]string, error)

Changed are the files of specs whose content the work tree changes from the commit rev, which a move that discards its changes, or a restore from rev, writes.

func (Client) CommonDir

func (c Client) CommonDir(ctx context.Context, dir string) (string, error)

CommonDir is the git folder every worktree of dir's repo shares, as an absolute path.

func (Client) Differs

func (c Client) Differs(ctx context.Context, dir, rng string, specs []string) ([]string, error)

Differs are the files of specs that differ across rng, a revision range, which a move across it writes.

func (c Client) Gitlinks(ctx context.Context, dir string) ([]string, error)

Gitlinks are the other repos dir's work tree holds, by their absolute paths, as its index records them: each submodule, checked out or not, and a checkout added with no .gitmodules entry. dir is the top of the work tree, which git names them from.

func (Client) IgnoredFolders

func (c Client) IgnoredFolders(ctx context.Context, dir string) ([]string, error)

IgnoredFolders are the folders of dir's work tree git lists ignored, by their absolute paths: a folder wholly ignored, or holding only what's ignored, is one, which git doesn't look inside, so a repo inside it isn't listed apart. dir is the top of the work tree, which git names them from.

func (Client) IsCommit

func (c Client) IsCommit(ctx context.Context, dir, rev string) (bool, error)

IsCommit reports whether rev names a commit. It's peeled with ^0, not ^{commit}: git reads stash@{0}^3^{commit}, where stash@{0} has no third parent, as stash@{0} at a date its reflog gives, a commit.

func (Client) Others

func (c Client) Others(ctx context.Context, dir string, specs []string) ([]string, error)

Others are the files of specs git doesn't track, those it ignores too.

func (Client) Rebases

func (c Client) Rebases(ctx context.Context, dir, rev string) (bool, error)

Rebases reports whether a pull onto the branch rev names rebases, as git's config says: the branch's own rebase setting, else pull.rebase, anything but false; false where neither is set. A rev that names no branch takes pull.rebase alone.

func (Client) Remotes

func (c Client) Remotes(ctx context.Context, dir string) ([]Remote, error)

Remotes are dir's repo's remotes, in the order git lists them.

func (Client) TopLevel

func (c Client) TopLevel(ctx context.Context, dir string) (string, error)

TopLevel is the top of the work tree holding dir. A dir in no work tree is ErrNotRepository.

func (Client) Tops

func (c Client) Tops(ctx context.Context, dir string) (top, common string, err error)

Tops are the top of the work tree holding dir, and the git folder every worktree of its repo shares, as an absolute path, both from one call. A dir in no work tree is ErrNotRepository.

func (Client) Tracks

func (c Client) Tracks(ctx context.Context, dir, spec string) (bool, error)

Tracks reports whether git tracks a file the pathspec spec names.

func (Client) Tree

func (c Client) Tree(ctx context.Context, dir, rev string, specs []string) ([]string, error)

Tree are the files of specs the commit rev holds, compared with no commit at all, as a commit with no parent is: a stash's untracked files.

func (Client) Unstaged

func (c Client) Unstaged(ctx context.Context, dir string, specs []string) ([]string, error)

Unstaged are the files of specs whose content the work tree changes from the index, which a restore from the index writes.

func (Client) Untracked

func (c Client) Untracked(ctx context.Context, dir string, specs []string) ([]string, error)

Untracked are the files of specs git neither tracks nor ignores.

func (Client) UntrackedFolders

func (c Client) UntrackedFolders(ctx context.Context, dir string) ([]string, error)

UntrackedFolders are the folders of dir's work tree git lists untracked, by their absolute paths: git lists each untracked file, but stops at a repo of its own, which it lists as a folder, however deep in untracked folders it lies. dir is the top of the work tree, which git names them from.

func (Client) WorkTrees

func (c Client) WorkTrees(ctx context.Context, dir string) ([]string, error)

WorkTrees are the work trees of dir's repo, by their absolute paths, as git lists them: the main one, then each linked one.

type Error

type Error struct {
	Dir    string
	Args   []string
	Stderr string
	Err    error
	// contains filtered or unexported fields
}

Error is a git call that failed: where it ran, what git said, and the run's error.

func (*Error) Error

func (e *Error) Error() string

Error names the call, the folder it ran in, and what git said, then each error joined in the run's error, a line apiece, but the runner's exit where git exited by itself, which its words explain: a signal's end is kept. Where git said nothing, the run's error is given whole.

func (*Error) Exited

func (e *Error) Exited() bool

Exited reports whether git ran and exited with a status other than 0, as against never starting.

func (*Error) Unwrap

func (e *Error) Unwrap() []error

Unwrap gives the class git's stderr was read as, where there is one, and the run's own error.

type Remote

type Remote struct {
	Name string
	URL  string
}

Remote is one of a repo's remotes, with the URL git fetches from, after any url.<base>.insteadOf rewriting.

type Runner

type Runner interface {
	Run(ctx context.Context, cmd runner.Command) (runner.Result, error)
}

Runner runs a command, as runner.Exec does.

Directories

Path Synopsis
Package gittest runs real git for tests, in an environment of the test's own, so the person's git config can't reach it, and gives the folders git names, by their physical paths.
Package gittest runs real git for tests, in an environment of the test's own, so the person's git config can't reach it, and gives the folders git names, by their physical paths.

Jump to

Keyboard shortcuts

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