git

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 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 git runs the official git binary, and is the only thing in gitd that does.

Every process gets an environment built here rather than gitd's own: inheriting it once made a private repository look public, because the editor's `GIT_ASKPASS` answered for it. Killing a call kills git's whole process group (a job object on Windows), because git starts children of its own that would otherwise outlive it.

Index

Constants

Variables

This section is empty.

Functions

func About

func About(err error, repository string) error

About names the repository a failure is about, when it does not say yet.

func Redacted

func Redacted(address string) string

Redacted is an address fit to log and to answer with: a user and password written in it, as `https://user:token@host/…`, are left out.

Types

type Cmd

type Cmd struct {
	Dir         string
	Args        []string
	Env         []string
	Local       bool
	Progress    progress.Report
	Differences bool
	Input       string
}

Cmd is one git invocation. Args starts with the subcommand; Env is added to the closed environment, as a request's credentials are; Local lets git read a repository on this disk, which only a pool is.

Differences says that git ending with status 1 found differences — as diff and merge-tree do — and answered, rather than failed. Input, when set, is what git reads on its standard input.

type ConfigEntry

type ConfigEntry struct {
	Key, Value string
}

ConfigEntry is one key of a git configuration file and its value. Key is as git lists it: section and name lowercased, a subsection as written.

type Failure

type Failure struct {
	Reason     Reason
	GitSaid    string
	Repository string
	ExitCode   int
}

Failure is an operation that did not go through: why, what git said about it, and the repository it was about. ExitCode is git's, or -1 when git never said.

func AsFailure

func AsFailure(err error) (*Failure, bool)

AsFailure returns the failure inside err, if there is one.

func Fail

func Fail(reason Reason, format string, arguments ...any) *Failure

Fail builds a failure git did not report, such as a path that is refused.

func Unnamed

func Unnamed(address string) *Failure

Unnamed is the failure for an address that names no repository.

func (*Failure) AboutAccess

func (failure *Failure) AboutAccess() bool

AboutAccess is whether another credential could change the answer.

func (*Failure) AccessRefused

func (failure *Failure) AccessRefused(offered bool) *Failure

AccessRefused is what a failure about access means once it is known whether a credential was offered: asked for one when one was offered means that one was refused.

func (*Failure) Error

func (failure *Failure) Error() string

func (*Failure) Proto

func (failure *Failure) Proto() *gitdv1.GitFailure

Proto is the failure as it travels in an error's detail.

type Reason

type Reason = gitdv1.GitFailure_Reason

Reason is why an operation failed, as the contract names it.

type Runner

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

Runner starts git processes.

func NewRunner

func NewRunner(binary string) *Runner

NewRunner returns a runner for the git at binary.

func (*Runner) Branch

func (runner *Runner) Branch(ctx context.Context, dir string) (string, bool)

Branch is the branch the repository at dir is on, and false when it is on none.

func (*Runner) Config

func (runner *Runner) Config(ctx context.Context, path, key string) (string, error)

Config reads one key from the git config file at path, and "" when it is not set.

func (*Runner) ConfigEntries

func (runner *Runner) ConfigEntries(ctx context.Context, path string) ([]ConfigEntry, error)

ConfigEntries lists every key of the configuration file at path, without following its includes. Listing runs nothing the file names.

func (*Runner) HTTPBackend

func (runner *Runner) HTTPBackend(root string, settings []string) *cgi.Handler

HTTPBackend is git's own smart HTTP server, `git http-backend`, over the repositories under root, run as gitd runs every git: its closed environment, no hooks and no global configuration. settings are `name=value` pairs set on its command line, where nothing in a repository can turn them back: which services it offers and their limits. The caller decides who may reach it and which repository; this only answers.

func (*Runner) Resolve

func (runner *Runner) Resolve(ctx context.Context, dir, revision string) (string, bool, error)

Resolve returns the commit a revision names in the repository at dir, and false when there is none. The revision comes from outside, so it goes after `--end-of-options`.

func (*Runner) ResolveObject

func (runner *Runner) ResolveObject(ctx context.Context, dir, revision string) (string, bool, error)

ResolveObject is the object a revision names in the repository at dir — a blob as `<commit>:<path>` — and false when it names none.

func (*Runner) Run

func (runner *Runner) Run(ctx context.Context, command Cmd) (string, error)

Run runs git and returns its stdout, or a failure with what git said.

func (*Runner) Running

func (runner *Runner) Running() int64

Running is how many git processes are alive right now.

func (*Runner) SetConfig

func (runner *Runner) SetConfig(ctx context.Context, dir string, keysAndValues ...string) error

SetConfig writes keys and their values into the repository at dir, in order.

func (*Runner) Version

func (runner *Runner) Version(ctx context.Context) (string, error)

Version is what `git version` says.

Jump to

Keyboard shortcuts

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