githelper

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package githelper implements the git-remote-helper protocol: the "capabilities / list / option / connect / stateless-connect / push" command loop that canonical Git speaks to any helper binary on stdin/stdout, plus the bodies of those commands (ref listing, fetch negotiation, push relay).

The protocol layer is decoupled from the wire layer via the Transport interface so callers can plug a different backend in without dragging Entire-specific concerns into this package.

Index

Constants

This section is empty.

Variables

View Source
var Agent = "git-remote-entire/dev"

Agent is the git agent identifier the helper appends to upload-pack, receive-pack, and v2 requests so the server can attribute traffic to the remote helper. The CLI entrypoint overwrites it at startup with a build-stamped value (see cmd/entire); the default keeps tests and standalone use working without that wiring.

Functions

func Run

func Run(ctx context.Context, t Transport, mode Mode, stdin io.Reader, stdout io.Writer) error

Run drives the git-remote-helper protocol loop against the given Transport. It reads commands from stdin one line at a time and writes responses to stdout until git closes the pipe or sends an unsupported command (which terminates the loop with an error).

The Transport interface decouples this loop from any specific HTTP implementation — see the entire/transport package for the production wiring.

Types

type Mode

type Mode int

Mode selects the helper's capability advertisement.

const (
	// ModeConnect (the default) advertises `connect`: git speaks the
	// raw smart-HTTP protocol and the helper relays request/response
	// bodies. Works against any receive-pack endpoint without
	// depending on send-pack's stateless-rpc behaviour.
	ModeConnect Mode = iota
	// ModeStateless advertises `stateless-connect` + `push`: v2 fetch
	// over framed HTTP RPC, push via send-pack subprocess.
	ModeStateless
)

type Options

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

Options accumulates `option <name> <value>` commands from git and translates the ones we can act on into `git send-pack` flags. The fields mirror what upstream's transport-helper.c:set_common_push_options forwards before a push: dry-run, atomic, signed (push-cert), force-with-lease (cas), force-if-includes, push-option, plus the per-list object-format option. Unknown options are answered with "unsupported", which transport-helper treats as "ignore me".

func (*Options) SendPackArgs

func (o *Options) SendPackArgs() []string

SendPackArgs returns the `git send-pack` flag set corresponding to the accumulated options. Returned slice is fresh; callers can mutate it.

func (*Options) Set

func (o *Options) Set(name, value string) string

Set applies one option and returns the helper-protocol reply line. The value is taken verbatim — booleans use the literal "true"/"false" upstream emits (transport-helper.c:357-361); string options use quote_c_style output, which our consumers (send-pack) accept on input in the same form. We intentionally do not attempt to unquote, so values containing spaces or backslashes round-trip correctly.

type Transport

type Transport interface {
	// InfoRefs fetches the v0/v1 ref advertisement.
	InfoRefs(ctx context.Context, service string) (io.ReadCloser, error)
	// InfoRefsV2 fetches the v2 capability advertisement.
	InfoRefsV2(ctx context.Context) (io.ReadCloser, error)
	// ServiceRPC sends a request to /<service> and returns the
	// response. extraHeaders runs on each request before send.
	ServiceRPC(ctx context.Context, service string, body io.ReadSeeker, extraHeaders ...func(*http.Request)) (io.ReadCloser, error)
	// ErrorBaseURL is embedded into helper-status error messages and
	// passed to send-pack as the remote URL.
	ErrorBaseURL() string
}

Transport is the wire layer the helper protocol speaks against. In production it's *entire/transport.Proxy; tests can supply a fake.

Jump to

Keyboard shortcuts

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