git

package
v2.0.4-main.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 26 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 is icebath's own runs of git: environments that never prompt, page, open an editor, run hooks or filter drivers, or read the user's config beyond the directories it says are safe; the checkout a folder lies in; and the upkeep of a clone many processes share: what a killed git leaves behind, and maintenance one process at a time claims

Index

Constants

View Source
const StaleAge = 10 * time.Minute

Age past which a lock or a temp file git writes is taken as left by a git that died: a healthy fetch is done in minutes

Variables

This section is empty.

Functions

func BranchName

func BranchName(name string) bool

Whether git takes the name for a branch, by the rules of git check-ref-format --branch: no part that starts with a dot or ends with .lock, no two dots in a row, no space, control character or any of ~^:?*[\, no @{, not @ or HEAD alone, not starting with a dash or ending with a dot, and no slash at either end or two in a row

func CommonDir

func CommonDir(ctx context.Context, dir string, env map[string]string) string

Folder holding the objects of the checkout the folder lies in, as git in the environment finds it, the one a worktree or submodule .git file leads to; empty outside one

func Configure

func Configure(env map[string]string, settings ...[2]string)

Adds settings to an environment Env made, after those it holds

func Env

func Env(ctx context.Context, base map[string]string) map[string]string

Environment of a git run that never prompts or runs the user's hooks, pager or editor: base, such as the profile's or a session's, else this machine's variables alone, with git's config replaced by the overrides and the user's safe directories

func Installed

func Installed(env map[string]string) bool

Whether git is on the search path of the environment, this machine's when nil, else on this process's, which a run then finds it on

func Lines

func Lines(text string) []string

Lines of text with the empty ones left out, each trimmed

func Maintain

func Maintain(ctx context.Context, repo string, base map[string]string)

Keeps a clone many processes share fast, with git run in the environment base, such as the profile's: a background repack once its packs sprawl, and a fresh commit graph, each claimed by one process per interval; every failure logged, none returned

func MarkPromisor

func MarkPromisor(repo string) int

Gives every pack of a partial clone without a promisor marker one, so git fetches the objects it lacks rather than failing; how many were marked

func Output

func Output(ctx context.Context, dir string, env map[string]string, timeout time.Duration, args ...string) (string, bool)

Trimmed output of a run of git in the folder with the environment that succeeded, false for any failure

func Remembering

func Remembering(ctx context.Context) context.Context

Context under which Env and RepoEnv ask git for the user's safe directories, and for the filter drivers of each repository, once for all the work done under it, such as the reads of one request: a change of git's config meanwhile reaches the next request rather than this one. A context that remembers already is given back as it is

func RepoEnv

func RepoEnv(ctx context.Context, base map[string]string, dir string) map[string]string

Environment of a git run in one repository from base, as Env makes it, that also turns off every filter driver its config names, following its included files; nil when what it includes cannot be followed with certainty. Each call is given a map of its own

func Root

func Root(ctx context.Context, dir string, env map[string]string) string

Top of the checkout the folder lies in, as git in the environment finds it, in the form of this system; empty outside one

func Running

func Running() bool

Whether any git may be running on this machine, true whenever the look cannot tell

func SweepObjectLocks

func SweepObjectLocks(gitDir string) []string

Removes the stale index locks of the object store under a git folder while no git runs; the paths removed

func SweepTemp

func SweepTemp(repo string, age time.Duration) []string

Removes the temp packs of aborted transfers and the temps of killed commit graph writes, older than the age, of a checkout or a bare repository while no git runs; the paths removed

Types

type Result

type Result struct {
	Code   int
	Stdout string
	Stderr string
}

What one run of git gave: its exit status and its output, invalid text replaced

func Capped

func Capped(ctx context.Context, dir string, env map[string]string, timeout time.Duration, most int, args ...string) (*Result, bool, error)

Runs git as Run does with no input, its output read up to the bytes given: a run that writes more is stopped with every process it started, its result holding what came before, and cut says so; an error when it could not start or timed out first

func Fetch

func Fetch(ctx context.Context, dir string, timeout time.Duration, address string, base map[string]string, lookup func(name string) string,
	args ...string) (*Result, error)

Runs a network verb of git in the environment base, such as a clone in the profile's, anonymously first, then with each credential the user has for the address's host while the remote keeps asking for one: a GitHub token of the environment lookup reads, the gh command's account, then what the credential helpers keep. A non zero exit is a Result, as Run's is

func Run

func Run(ctx context.Context, dir string, env map[string]string, timeout time.Duration, input []byte, args ...string) (*Result, error)

Runs git in the folder with the environment, such as the profile's or a session's, this machine's variables alone when nil, input on its stdin, stopped with every process it started once the timeout passes; an error when it could not start or timed out, a non zero exit being a Result

type TimeoutError

type TimeoutError struct {
	Args    []string
	Timeout time.Duration
}

Run of git stopped once it outlasted its time

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Jump to

Keyboard shortcuts

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