git

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git defines types used in the Git remote helpers protocol.

Contrary to the git-remote-helpers documentation, this package refers to commands sent by Git as "Requests" for code readability.

See https://git-scm.com/docs/gitremote-helpers#_commands.

Index

Constants

View Source
const (
	// OptionSupported is a response to an [OptionRequest] indicating
	// the option is supported.
	OptionSupported string = "ok"
	// OptionNotSupported is a response to an [OptionRequest] indicating
	// the option is not supported.
	OptionNotSupported string = "unsupported"
)

Variables

View Source
var (
	// ErrBadRequest indicates a request does not contain sufficient information
	// to handle.
	ErrBadRequest = errors.New("request is invalid")
	// ErrUnexpectedRequest indicates a request was not the expected type.
	ErrUnexpectedRequest = errors.New("unexpected request")
	// ErrUnsupportedRequest indicates a request is not supported by this package.
	ErrUnsupportedRequest = errors.New("unsupported request")
	// ErrEmptyRequest is an indicator that Git is either breaking up a batch of
	// requests or has finished sending requests.
	ErrEmptyRequest = errors.New("empty request")
	// ErrEndOfInput marks the end of input from Git.
	ErrEndOfInput = errors.New("end of input")
)

Functions

func SupportedCommand

func SupportedCommand(name Command) bool

SupportedCommand returns true if a Command is supported.

Types

type CapabilitiesRequest

type CapabilitiesRequest struct {
	Cmd Command
}

CapabilitiesRequest is a command received from Git requesting a list of supported capabilities

https://git-scm.com/docs/gitremote-helpers#Documentation/gitremote-helpers.txt-capabilities.

func (*CapabilitiesRequest) Parse

func (r *CapabilitiesRequest) Parse(fields []string) error

Parse decodes request fields ensuring the CapabilitiesRequest is of the correct type and contains sufficient information to handle the request.

Implements Parsable.

func (*CapabilitiesRequest) String

func (r *CapabilitiesRequest) String() string

String condenses CapabilitiesRequest into a string, the raw request received from Git.

type Capability

type Capability = string

Capability defines a git-remote-helper capability.

See https://git-scm.com/docs/gitremote-helpers#_capabilities.

const (
	// CapabilityOption indicates a git remote helper is capable
	// of handling option commands.
	CapabilityOption Capability = "option"
	// CapabilityOption indicates a git remote helper is capable
	// of handling fetch commands.
	CapabilityFetch Capability = "fetch"
	// CapabilityOption indicates a git remote helper is capable
	// of handling push commands.
	CapabilityPush Capability = "push"
)

Capabilities with a '*' prefix marks them as mandatory.

type Command

type Command string

Command is an implemented git-remote-helper command provided by Git.

https://git-scm.com/docs/gitremote-helpers#_commands.

const (
	// Git conventions.
	Capabilities Command = "capabilities"
	Options      Command = "option"
	List         Command = "list"
	Push         Command = "push"
	Fetch        Command = "fetch"
)

Supported Git commands.

type FetchRequest

type FetchRequest struct {
	Cmd Command
	Ref *plumbing.Reference
}

FetchRequest is a command received from Git requesting a fetch operation.

https://git-scm.com/docs/gitremote-helpers#Documentation/gitremote-helpers.txt-fetchsha1name.

func (*FetchRequest) Parse

func (r *FetchRequest) Parse(fields []string) error

Parse decodes request fields ensuring the FetchRequest is of the correct type, is supported, and has a valid value.

Implements Parsable.

func (*FetchRequest) String

func (r *FetchRequest) String() string

String condenses FetchRequest into a string, the raw request received from Git.

type ListRequest

type ListRequest struct {
	Cmd     Command
	ForPush bool
}

ListRequest is a command received from Git requesting a list of references.

https://git-scm.com/docs/gitremote-helpers#Documentation/gitremote-helpers.txt-list.

func (*ListRequest) Parse

func (r *ListRequest) Parse(fields []string) error

Parse decodes request fields ensuring the ListRequest is of the correct type, is supported, and has a valid value.

Implements Parsable.

func (*ListRequest) String

func (r *ListRequest) String() string

String condenses ListRequest into a string, the raw request received from Git.

type ListResponse

type ListResponse struct {
	Reference plumbing.ReferenceName
	Commit    string
}

ListResponse is a reference and it's commit.

func (*ListResponse) String

func (r *ListResponse) String() string

String condenses the response into a format readable by Git.

type Option

type Option string

Option is an implemented git-remote-helper option sub command provided by Git.

https://git-scm.com/docs/gitremote-helpers#_options.

const (
	Verbosity Option = "verbosity"
)

Supported Git options.

type OptionRequest

type OptionRequest struct {
	Cmd   Command
	Opt   Option
	Value string
}

OptionRequest is a command received from Git requesting an option to be set.

https://git-scm.com/docs/gitremote-helpers#Documentation/gitremote-helpers.txt-optionnamevalue.

func (*OptionRequest) Parse

func (r *OptionRequest) Parse(fields []string) error

Parse decodes request fields ensuring the OptionRequest is of the correct type, is supported, and has a valid value.

Implements Parsable.

func (*OptionRequest) String

func (r *OptionRequest) String() string

String condenses OptionRequest into a string, the raw request received from Git.

type Parsable

type Parsable interface {
	Parse([]string) error
}

Parsable is a parsable command received from Git.

type PushRequest

type PushRequest struct {
	Cmd    Command
	Force  bool
	Src    plumbing.ReferenceName
	Remote plumbing.ReferenceName
}

PushRequest is a command received from Git requesting a push operation.

https://git-scm.com/docs/gitremote-helpers#Documentation/gitremote-helpers.txt-pushsrcdst.

func (*PushRequest) Parse

func (r *PushRequest) Parse(fields []string) error

Parse decodes request fields ensuring the PushRequest is of the correct type, is supported, and has a valid value.

Implements Parsable.

func (*PushRequest) String

func (r *PushRequest) String() string

String condenses PushRequest into a string, the raw request received from Git.

type PushResponse

type PushResponse struct {
	// remote reference
	Remote plumbing.ReferenceName
	// nil if successful
	Error error
}

PushResponse is a status indicating if a push request was handled successfully.

func (*PushResponse) String

func (r *PushResponse) String() string

String condenses the response into a format readable by Git.

Directories

Path Synopsis
Package comms facilitates receiving requests from and writing responses to Git via the remote helpers protocol.
Package comms facilitates receiving requests from and writing responses to Git via the remote helpers protocol.

Jump to

Keyboard shortcuts

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