gitbundle

package
v0.54.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 18 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 gitbundle inspects a run's git bundle outside the sandbox and pushes it on the run's behalf (HR24 to HR26). A bundle is hostile input: every git call runs in a bare, blobless mirror with fsck on, no hooks, no worktree, an allow-list of transports, a timeout and an output cap, and the token reaches git only through GIT_CONFIG_* environment variables.

Index

Constants

View Source
const DefaultMaxBytes = 1 << 30

DefaultMaxBytes is a mirror's size limit on disk when Cache.MaxBytes is zero.

View Source
const MaxBlob = 1 << 20

MaxBlob is the largest blob a push may change, compressed or not: larger is push_size, read by its header alone, never inflated (core.bigFileThreshold matches it).

Variables

View Source
var ErrLeaseLost = errors.New("gitbundle: the branch moved since it was read")

ErrLeaseLost is a push whose lease the remote refused: the branch moved since OldHead was read.

View Source
var ErrPushRejected = errors.New("gitbundle: the remote refused the push")

ErrPushRejected is a push the remote refused for good, not for the lease: a "[remote rejected]" ref (a pre-receive hook, a missing workflows permission) or a 403 / permission denied.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Root string
	// Remote is a repository's URL; nil means "https://github.com/" + repo + ".git".
	Remote func(repo string) string
	// Token is the token git sends for repo (the publisher's), only through GIT_CONFIG_COUNT/KEY/VALUE
	// env as http.extraHeader; never in argv. nil sends none (tests on file://).
	Token func(ctx context.Context, repo string) (string, error)
	// Git is the git binary, "git" (from PATH) when empty.
	Git string
	// Protocols are the allowed transport protocols, ["https"] when empty.
	Protocols []string
	// Timeout bounds each git call, 60s when zero.
	Timeout time.Duration
	// MaxBytes bounds one mirror on disk, DefaultMaxBytes when zero: a mirror past it is re-created
	// before the next inspection, so pushed objects never accumulate past the cache's emptyDir.
	MaxBytes int64
	// contains filtered or unexported fields
}

Cache holds one bare, blobless mirror per repository under Root (an emptyDir, MAKU_GIT_CACHE in the factory).

func (*Cache) Mirror

func (c *Cache) Mirror(repo string) *Mirror

Mirror is cache's mirror of repo (one per lower-cased repo, created lazily on disk by the first operation; its dir is Root/<owner>/<name>.git, sanitised).

type File

type File struct{ Path, Status, Mode string }

File is one changed entry: Status is git's raw letter (A, M, D, T), Mode is the new mode ("100644", "100755", "120000", "160000"), the old mode for a deletion.

type Inspection

type Inspection struct {
	Ref      string // the one ref, refs/heads/<branch>
	Head     string // the bundle's head SHA (40 or 64 hex)
	OldHead  string // the branch's head on the remote when read, "" when absent: the lease
	BaseHead string // the base branch's head on the remote when read
	Kind     Kind
	// Files is the union of OldHead..Head (FastForward) or merge-base(BaseHead, Head)..Head
	// (Rebase) and every intermediate commit in that range, deletions included.
	Files []File
	// Added is every commit's added lines in Files' range (no "+" prefix), then each new commit's
	// author/committer headers and message.
	Added []string
	// Cumulative is merge-base(BaseHead, Head)..Head, always.
	Cumulative Stats
	// contains filtered or unexported fields
}

Inspection is what a bundle would change on the remote.

type Kind

type Kind string

Kind is how a push lands (HR25).

const (
	// FastForward: the new head descends from the branch's current head.
	FastForward Kind = "fast_forward"
	// Rebase: the branch is absent, or the new head descends from the base's current head (and not
	// the branch's).
	Rebase Kind = "rebase"
)

The kinds of push.

type Mirror

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

Mirror is one repository's bare, blobless mirror. Inspect and Push hold its lock.

func (*Mirror) Discard

func (m *Mirror) Discard(ctx context.Context, in Inspection)

Discard deletes the ref in's bundle was fetched into, for a push the applier refuses or holds after the inspection (#505's review); Push and Inspect's own refusals delete it themselves. It holds the mirror's lock, and is a no-op for a ref already gone.

func (*Mirror) Inspect

func (m *Mirror) Inspect(ctx context.Context, bundle []byte, branch, base string) (Inspection, error)

Inspect checks bundle as a push of exactly refs/heads/<branch> onto base (e.g. "agent/t-1", "main"), and returns what it would change. A *Refused error is the bundle's fault; any other error is the factory's (retry later). It holds the mirror's lock for its whole run.

func (*Mirror) Push

func (m *Mirror) Push(ctx context.Context, in Inspection) error

Push pushes in.Head to in.Ref with --force-with-lease=<ref>:<in.OldHead> (an empty OldHead: the ref must be absent). A remote already at in.Head is success with nothing pushed only when the inspection read it there (HR26); one that moved there since, by another hand, is ErrLeaseLost, as is any other move. It holds the mirror's lock. The head's objects are the mirror's, from the Inspect that returned in.

func (*Mirror) Read added in v0.47.0

func (m *Mirror) Read(ctx context.Context, bundle []byte, branch, base string) (Inspection, error)

Read is the cumulative change bundle carries onto base, merge-base(base, head)..head, whatever the branch holds now: the drill runner reads an applied push with it after the fact (HR38), when the branch may have moved past the bundle's head. Files and Added are that range's, and Kind is Rebase. It pushes nothing and keeps no ref to the bundle's objects; its refusals are Inspect's.

type Refused

type Refused struct {
	Reason hardening.Refusal
	Detail string
}

Refused is a bundle the inspection refuses. Reason is one of hardening.RefusePushRef, RefusePushHistory, RefusePushTree, RefusePushSize. Detail is bounded, never bundle content (a ref name or a path may appear, cut at 200 bytes).

func (*Refused) Error

func (r *Refused) Error() string

type Stats

type Stats struct{ Files, Lines int }

Stats is a change's size: files changed, and lines added plus deleted (binary files count 0 lines).

Jump to

Keyboard shortcuts

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