git

package
v14.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReferenceTransactionHook represents the reference-transaction git hook.
	ReferenceTransactionHook = Hook(1 << iota)
	// UpdateHook represents the update git hook.
	UpdateHook
	// PreReceiveHook represents the pre-receive git hook.
	PreReceiveHook
	// PostReceiveHook represents the post-receive git hook.
	PostReceiveHook
	// PackObjectsHook represents the pack-objects git hook.
	PackObjectsHook

	// AllHooks is the bitwise set of all hooks supported by Gitaly.
	AllHooks = ReferenceTransactionHook | UpdateHook | PreReceiveHook | PostReceiveHook | PackObjectsHook
	// ReceivePackHooks includes the set of hooks which shall be executed in
	// a typical "push" or an emulation thereof (e.g. `updateReferenceWithHooks()`).
	ReceivePackHooks = ReferenceTransactionHook | UpdateHook | PreReceiveHook | PostReceiveHook
)
View Source
const (
	// EmptyTreeOID is the Git tree object hash that corresponds to an empty tree (directory)
	EmptyTreeOID = ObjectID("4b825dc642cb6eb9a060e54bf8d69288fbee4904")

	// ZeroOID is the special value that Git uses to signal a ref or object does not exist
	ZeroOID = ObjectID("0000000000000000000000000000000000000000")
)
View Source
const DefaultBranch = "main"

DefaultBranch is the default reference written to HEAD when a repository is created

View Source
const (
	// EnvHooksPayload is the name of the environment variable used
	// to hold the hooks payload.
	EnvHooksPayload = "GITALY_HOOKS_PAYLOAD"
)
View Source
const (
	// ProtocolV2 is the special value used by Git clients to request protocol v2
	ProtocolV2 = "version=2"
)

Variables

View Source
var (
	// ErrInvalidArg represent family of errors to report about bad argument used to make a call.
	ErrInvalidArg = errors.New("invalid argument")
	// ErrHookPayloadRequired indicates a HookPayload is needed but
	// absent from the command.
	ErrHookPayloadRequired = errors.New("hook payload is required but not configured")
)
View Source
var (
	// ConfigTypeDefault is a default choice.
	ConfigTypeDefault = ConfigType("")
	// ConfigTypeInt is an integer type check.
	// https://git-scm.com/docs/git-config/2.6.7#Documentation/git-config.txt---int
	ConfigTypeInt = ConfigType("--int")
	// ConfigTypeBool is a bool type check.
	// https://git-scm.com/docs/git-config/2.6.7#Documentation/git-config.txt---bool
	ConfigTypeBool = ConfigType("--bool")
	// ConfigTypeBoolOrInt is a bool or int type check.
	// https://git-scm.com/docs/git-config/2.6.7#Documentation/git-config.txt---bool-or-int
	ConfigTypeBoolOrInt = ConfigType("--bool-or-int")
	// ConfigTypePath is a path type check.
	// https://git-scm.com/docs/git-config/2.6.7#Documentation/git-config.txt---path
	ConfigTypePath = ConfigType("--path")
)
View Source
var (
	// RemoteAddOptsMirrorDefault allows to use a default behaviour.
	RemoteAddOptsMirrorDefault = RemoteAddOptsMirror("")
	// RemoteAddOptsMirrorFetch configures everything in refs/ on the remote to be
	// directly mirrored into refs/ in the local repository.
	RemoteAddOptsMirrorFetch = RemoteAddOptsMirror("fetch")
	// RemoteAddOptsMirrorPush configures 'git push' to always behave as if --mirror was passed.
	RemoteAddOptsMirrorPush = RemoteAddOptsMirror("push")
)
View Source
var (
	// RemoteAddOptsTagsDefault enables importing of tags only on fetched branches.
	RemoteAddOptsTagsDefault = RemoteAddOptsTags("")
	// RemoteAddOptsTagsAll enables importing of every tag from the remote repository.
	RemoteAddOptsTagsAll = RemoteAddOptsTags("--tags")
	// RemoteAddOptsTagsNone disables importing of tags from the remote repository.
	RemoteAddOptsTagsNone = RemoteAddOptsTags("--no-tags")
)
View Source
var (
	// ErrReferenceNotFound represents an error when a reference was not
	// found.
	ErrReferenceNotFound = errors.New("reference not found")
	// ErrReferenceAmbiguous represents an error when a reference couldn't
	// unambiguously be resolved.
	ErrReferenceAmbiguous = errors.New("reference is ambiguous")

	// ErrAlreadyExists represents an error when the resource is already exists.
	ErrAlreadyExists = errors.New("already exists")
	// ErrNotFound represents an error when the resource can't be found.
	ErrNotFound = errors.New("not found")
)
View Source
var DefaultRef = []byte("refs/heads/" + DefaultBranch)

DefaultRef is the reference that GitLab will use if HEAD of the bare repository is not found, or other edge cases to detect the default branch.

View Source
var (
	// ErrInvalidObjectID is returned in case an object ID's string
	// representation is not a valid one.
	ErrInvalidObjectID = errors.New("invalid object ID")
)
View Source
var (
	// ErrPayloadNotFound is returned by HooksPayloadFromEnv if the given
	// environment variables don't have a hooks payload.
	ErrPayloadNotFound = errors.New("no hooks payload found in environment")
)
View Source
var FallbackTimeValue = time.Unix(1<<63-62135596801, 999999999)

FallbackTimeValue is the value returned by `SafeTimeParse` in case it encounters a parse error. It's the maximum time value possible in golang. See https://gitlab.com/gitlab-org/gitaly/issues/556#note_40289573

View Source
var InternalRefPrefixes = [...]string{
	"refs/environments/",
	"refs/keep-around/",
	"refs/merge-requests/",
	"refs/pipelines/",
}

InternalRefPrefixes is an array of all reference prefixes which are used internally by GitLab. These need special treatment in some cases, e.g. to restrict writing to them.

View Source
var LegacyDefaultRef = []byte("refs/heads/master")

LegacyDefaultRef is the reference that used to be the default HEAD of the bare repository. If the default reference is not found, Gitaly will still test the legacy default.

View Source
var (
	// OutputToStdout is used indicate the output should be sent to STDOUT
	// Seen in: git bundle create
	OutputToStdout = StaticOption{/* contains filtered or unexported fields */}
)

Functions

func AlternateObjectDirectories

func AlternateObjectDirectories(ctx context.Context, storageRoot, repoPath string) ([]string, error)

AlternateObjectDirectories reads the alternates file of the repository and returns absolute paths to its alternate object directories, if any. The returned directories are verified to exist and that they are within the storage root. The alternate directories are returned recursively, not only the immediate alternates.

func BuildSSHInvocation

func BuildSSHInvocation(ctx context.Context, sshKey, knownHosts string) (string, func(), error)

BuildSSHInvocation builds a command line to invoke SSH with the provided key and known hosts. Both are optional.

func CheckRefFormat

func CheckRefFormat(ctx context.Context, gitCmdFactory CommandFactory, refName string) (bool, error)

CheckRefFormat checks whether a fully-qualified refname is well well-formed using git-check-ref-format

func IsInvalidArgErr

func IsInvalidArgErr(err error) bool

IsInvalidArgErr relays if the error is due to an argument validation failure

func IsLFSPointer

func IsLFSPointer(b []byte) bool

IsLFSPointer checks to see if a blob is an LFS pointer. TODO: this is incomplete as it does not recognize pre-release version of LFS blobs with the "https://hawser.github.com/spec/v1" version. For compatibility with the Ruby RPC, we leave this as-is for now though.

func ObjectDirectories

func ObjectDirectories(ctx context.Context, storageRoot, repoPath string) ([]string, error)

ObjectDirectories looks for Git object directories, including alternates specified in objects/info/alternates.

CAVEAT Git supports quoted strings in here, but we do not. We should never need those on a Gitaly server.

func ValidateObjectID

func ValidateObjectID(id string) error

ValidateObjectID checks if id is a syntactically correct object ID. Abbreviated object IDs are not deemed to be valid. Returns an ErrInvalidObjectID if the id is not valid.

func ValidateRevision

func ValidateRevision(revision []byte) error

ValidateRevision checks if a revision looks valid

func ValidateRevisionAllowEmpty

func ValidateRevisionAllowEmpty(revision []byte) error

ValidateRevisionAllowEmpty checks if a revision looks valid, but allows empty strings

func WarnIfTooManyBitmaps

func WarnIfTooManyBitmaps(ctx context.Context, locator storage.Locator, storageName, repoPath string)

WarnIfTooManyBitmaps checks for too many (more than one) bitmaps in repoPath, and if it finds any, it logs a warning. This is to help us investigate https://gitlab.com/gitlab-org/gitaly/issues/1728.

Types

type CheckRefFormatError

type CheckRefFormatError struct{}

CheckRefFormatError is used by CheckRefFormat() below

func (CheckRefFormatError) Error

func (e CheckRefFormatError) Error() string

type Cmd

type Cmd interface {
	CommandArgs() ([]string, error)
	Subcommand() string
}

Cmd is an interface for safe git commands

type CmdOpt

type CmdOpt func(*cmdCfg) error

CmdOpt is an option for running a command

func ConvertGlobalOptions

func ConvertGlobalOptions(options *gitalypb.GlobalOptions) []CmdOpt

ConvertGlobalOptions converts a protobuf message to a CmdOpt.

func WithConfig

func WithConfig(configPairs ...ConfigPair) CmdOpt

WithConfig adds git configuration entries to the command.

func WithConfigEnv

func WithConfigEnv(configPairs ...ConfigPair) CmdOpt

WithConfigEnv adds git configuration entries to the command's environment. This should be used in place of `WithConfig()` in case config entries may contain secrets which shouldn't leak e.g. via the process's command line.

func WithDisabledHooks

func WithDisabledHooks() CmdOpt

WithDisabledHooks returns an option that satisfies the requirement to set up hooks, but won't in fact set up hook execution.

func WithEnv

func WithEnv(envs ...string) CmdOpt

WithEnv adds environment variables to the command.

func WithGitProtocol

func WithGitProtocol(ctx context.Context, req RequestWithGitProtocol) CmdOpt

WithGitProtocol checks whether the request has Git protocol v2 and sets this in the environment.

func WithGlobalOption

func WithGlobalOption(opts ...GlobalOption) CmdOpt

WithGlobalOption adds the global options to the command. These are universal options which work across all git commands.

func WithPackObjectsHookEnv

func WithPackObjectsHookEnv(ctx context.Context, repo *gitalypb.Repository, cfg config.Cfg) CmdOpt

WithPackObjectsHookEnv provides metadata for gitaly-hooks so it can act as a pack-objects hook.

func WithReceivePackHooks

func WithReceivePackHooks(ctx context.Context, cfg config.Cfg, req ReceivePackRequest, protocol string) CmdOpt

WithReceivePackHooks returns an option that populates the safe command with the environment variables necessary to properly execute the pre-receive, update and post-receive hooks for git-receive-pack(1).

func WithRefTxHook

func WithRefTxHook(ctx context.Context, repo repository.GitRepo, cfg config.Cfg) CmdOpt

WithRefTxHook returns an option that populates the safe command with the environment variables necessary to properly execute a reference hook for repository changes that may possibly update references

func WithStderr

func WithStderr(w io.Writer) CmdOpt

WithStderr sets the command's stderr.

func WithStdin

func WithStdin(r io.Reader) CmdOpt

WithStdin sets the command's stdin. Pass `command.SetupStdin` to make the command suitable for `Write()`ing to.

func WithStdout

func WithStdout(w io.Writer) CmdOpt

WithStdout sets the command's stdout.

type CommandFactory

type CommandFactory interface {
	// New creates a new command for the repo repository.
	New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error)
	// NewWithoutRepo creates a command without a target repository.
	NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error)
	// NewWithDir creates a command without a target repository that would be executed in dir directory.
	NewWithDir(ctx context.Context, dir string, sc Cmd, opts ...CmdOpt) (*command.Command, error)
}

CommandFactory is designed to create and run git commands in a protected and fully managed manner.

type Config

type Config interface {
	// Set will set a configuration value. Any preexisting values will be overwritten with the
	// new value.
	Set(ctx context.Context, name, value string) error

	// GetRegexp returns configurations matched to nameRegexp regular expression.
	// https://git-scm.com/docs/git-config#Documentation/git-config.txt---get-regexp
	GetRegexp(ctx context.Context, nameRegexp string, opts ConfigGetRegexpOpts) ([]ConfigPair, error)

	// Unset removes configuration associated with the name.
	// If All option is set all configurations associated with the name will be removed.
	// If multiple values associated with the name and called without All option will result in ErrNotFound error.
	// https://git-scm.com/docs/git-config#Documentation/git-config.txt---unset-all
	Unset(ctx context.Context, name string, opts ConfigUnsetOpts) error
}

Config represents 'config' sub-command. https://git-scm.com/docs/git-config

type ConfigGetRegexpOpts

type ConfigGetRegexpOpts struct {
	// Type allows to specify an expected type for the configuration.
	Type ConfigType
	// ShowOrigin controls if origin needs to be fetched.
	ShowOrigin bool
	// ShowScope controls if scope needs to be fetched.
	ShowScope bool
}

ConfigGetRegexpOpts is used to configure invocation of the 'git config --get-regexp' command.

type ConfigPair

type ConfigPair struct {
	Key   string
	Value string
	// Origin shows the origin type: file, standard input, blob, command line.
	// https://git-scm.com/docs/git-config#Documentation/git-config.txt---show-origin
	Origin string
	// Scope shows the scope of this config value: local, global, system, command.
	// https://git-scm.com/docs/git-config#Documentation/git-config.txt---show-scope
	Scope string
}

ConfigPair is a sub-command option for use with commands like "git config"

func ConvertConfigOptions

func ConvertConfigOptions(options []string) ([]ConfigPair, error)

ConvertConfigOptions converts `<key>=<value>` config entries into `ConfigPairs`.

func (ConfigPair) GlobalArgs

func (cp ConfigPair) GlobalArgs() ([]string, error)

GlobalArgs generates a git `-c <key>=<value>` flag. The key must pass validation by containing only alphanumeric sections separated by dots. No other characters are allowed for now as `git -c` may not correctly parse them, most importantly when they contain equals signs.

func (ConfigPair) OptionArgs

func (cp ConfigPair) OptionArgs() ([]string, error)

OptionArgs validates the config pair args

type ConfigType

type ConfigType string

ConfigType represents supported types of the config values.

func (ConfigType) String

func (t ConfigType) String() string

type ConfigUnsetOpts

type ConfigUnsetOpts struct {
	// All controls if all values associated with the key needs to be unset.
	All bool
	// NotStrict if set to true it won't return an error if the configuration was not found
	// or in case multiple values exist for a given key and All option is not set.
	NotStrict bool
}

ConfigUnsetOpts allows to configure fetching of the configurations using regexp.

type ExecCommandFactory

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

ExecCommandFactory knows how to properly construct different types of commands.

func NewExecCommandFactory

func NewExecCommandFactory(cfg config.Cfg) *ExecCommandFactory

NewExecCommandFactory returns a new instance of initialized ExecCommandFactory.

func (*ExecCommandFactory) Collect

func (cf *ExecCommandFactory) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*ExecCommandFactory) Describe

func (cf *ExecCommandFactory) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*ExecCommandFactory) New

func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error)

New creates a new command for the repo repository.

func (*ExecCommandFactory) NewWithDir

func (cf *ExecCommandFactory) NewWithDir(ctx context.Context, dir string, sc Cmd, opts ...CmdOpt) (*command.Command, error)

NewWithDir creates a new command.Command whose working directory is set to dir. Arguments are validated before the command is being run. It is invalid to use an empty directory.

func (*ExecCommandFactory) NewWithoutRepo

func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error)

NewWithoutRepo creates a command without a target repository.

type FetchScanner

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

FetchScanner scans the output of `git fetch`, allowing information about the updated refs to be gathered

func NewFetchScanner

func NewFetchScanner(r io.Reader) *FetchScanner

NewFetchScanner returns a new FetchScanner

func (*FetchScanner) Err

func (f *FetchScanner) Err() error

Err returns any error encountered while scanning the reader supplied to NewFetchScanner(). Note that lines not matching the expected format are not an error.

func (*FetchScanner) Scan

func (f *FetchScanner) Scan() bool

Scan looks for the next fetch status line in the reader supplied to NewFetchScanner(). Any lines that are not valid status lines are discarded without error. It returns true if you should call Scan() again, and false if scanning has come to an end.

func (*FetchScanner) StatusLine

func (f *FetchScanner) StatusLine() FetchStatusLine

StatusLine returns the most recent fetch status line encountered by the FetchScanner. It changes after each call to Scan(), unless there is an error.

type FetchStatusLine

type FetchStatusLine struct {
	// Type encodes the kind of change that git fetch has made
	Type RefUpdateType
	// Summary is a brief description of the change. This may be text such as
	// [new tag], or a compact-form SHA range showing the old and new values of
	// the updated reference, depending on the type of update
	Summary string
	// From is usually the name of the remote ref being fetched from, missing
	// the refs/<type>/ prefix. If a ref is being deleted, this will be "(none)"
	From string
	// To is the name of the local ref being updated, missing the refs/<type>/
	// prefix.
	To string
	// Reason optionally contains human-readable information about the change. It
	// is typically used to explain why making a given change failed (e.g., the
	// type will be RefUpdateTypeUpdateFailed). It may be empty.
	Reason string
}

FetchStatusLine represents a line of status output from `git fetch`, as documented here: https://git-scm.com/docs/git-fetch/2.30.0#_output. Each line is a change to a git reference in the local repository that was caused by the fetch

func (FetchStatusLine) IsTagAdded

func (f FetchStatusLine) IsTagAdded() bool

IsTagAdded returns true if this status line indicates a new tag was added

func (FetchStatusLine) IsTagUpdated

func (f FetchStatusLine) IsTagUpdated() bool

IsTagUpdated returns true if this status line indicates a tag was changed

type Flag

type Flag struct {
	Name string
}

Flag is a single token optional command line argument that enables or disables functionality (e.g. "-L")

func (Flag) GlobalArgs

func (f Flag) GlobalArgs() ([]string, error)

GlobalArgs returns the arguments for the given flag, which should typically only be the flag itself. It returns an error if the flag is not sanitary.

func (Flag) OptionArgs

func (f Flag) OptionArgs() ([]string, error)

OptionArgs returns an error if the flag is not sanitary

type GlobalOption

type GlobalOption interface {
	GlobalArgs() ([]string, error)
}

GlobalOption is an interface for all options which can be globally applied to git commands. This is the command-inspecific part before the actual command that's being run, e.g. the `-c` part in `git -c foo.bar=value command`.

type Hook

type Hook uint

Hook represents a git hook. See githooks(5) for more information about existing hooks.

type HooksPayload

type HooksPayload struct {
	// RequestedHooks is a bitfield of requested Hooks. Hooks which
	// were not requested will not get executed.
	RequestedHooks Hook `json:"requested_hooks"`
	// FeatureFlags contains feature flags with their values. They are set
	// into the outgoing context when calling HookService.
	FeatureFlags featureflag.Raw `json:"feature_flags,omitempty"`

	// Repo is the repository in which the hook is running.
	Repo *gitalypb.Repository `json:"-"`
	// BinDir is the binary directory of Gitaly.
	BinDir string `json:"binary_directory"`
	// GitPath is the path to the git executable.
	GitPath string `json:"git_path"`
	// InternalSocket is the path to Gitaly's internal socket.
	InternalSocket string `json:"internal_socket"`
	// InternalSocketToken is the token required to authenticate with
	// Gitaly's internal socket.
	InternalSocketToken string `json:"internal_socket_token"`

	// Transaction is used to identify a reference transaction. This is an optional field -- if
	// it's not set, no transactional voting will happen.
	Transaction *txinfo.Transaction `json:"transaction"`

	// ReceiveHooksPayload contains information required when executing
	// git-receive-pack.
	ReceiveHooksPayload *ReceiveHooksPayload `json:"receive_hooks_payload"`
}

HooksPayload holds parameters required for all hooks.

func HooksPayloadFromEnv

func HooksPayloadFromEnv(envs []string) (HooksPayload, error)

HooksPayloadFromEnv extracts the HooksPayload from the given environment variables. If no HooksPayload exists, it returns a ErrPayloadNotFound error.

func NewHooksPayload

func NewHooksPayload(
	cfg config.Cfg,
	repo *gitalypb.Repository,
	tx *txinfo.Transaction,
	receiveHooksPayload *ReceiveHooksPayload,
	requestedHooks Hook,
	featureFlags featureflag.Raw,
) HooksPayload

NewHooksPayload creates a new hooks payload which can then be encoded and passed to Git hooks.

func (HooksPayload) Env

func (p HooksPayload) Env() (string, error)

Env encodes the given HooksPayload into an environment variable.

func (HooksPayload) IsHookRequested

func (p HooksPayload) IsHookRequested(hook Hook) bool

IsHookRequested returns whether the HooksPayload is requesting execution of the given git hook.

type ObjectID

type ObjectID string

ObjectID represents an object ID.

func NewObjectIDFromHex

func NewObjectIDFromHex(hex string) (ObjectID, error)

NewObjectIDFromHex constructs a new ObjectID from the given hex representation of the object ID. Returns ErrInvalidObjectID if the given OID is not valid.

func (ObjectID) Bytes

func (oid ObjectID) Bytes() ([]byte, error)

Bytes returns the byte representation of the ObjectID.

func (ObjectID) IsZeroOID

func (oid ObjectID) IsZeroOID() bool

IsZeroOID is a shortcut for `something == git.ZeroOID.String()`

func (ObjectID) Revision

func (oid ObjectID) Revision() Revision

Revision returns a revision of the ObjectID. This directly returns the hex representation as every object ID is a valid revision.

func (ObjectID) String

func (oid ObjectID) String() string

String returns the hex representation of the ObjectID.

type Option

type Option interface {
	OptionArgs() ([]string, error)
}

Option is a git command line flag with validation logic

type ReceiveHooksPayload

type ReceiveHooksPayload struct {
	// Username contains the name of the user who has caused the hook to be executed.
	Username string `json:"username"`
	// UserID contains the ID of the user who has caused the hook to be executed.
	UserID string `json:"userid"`
	// Protocol contains the protocol via which the hook was executed. This
	// can be one of "web", "ssh" or "smarthttp".
	Protocol string `json:"protocol"`
}

ReceiveHooksPayload contains all information which is required for hooks executed by git-receive-pack, namely the pre-receive, update or post-receive hook.

type ReceivePackRequest

type ReceivePackRequest interface {
	GetGlId() string
	GetGlUsername() string
	GetGlRepository() string
	GetRepository() *gitalypb.Repository
}

ReceivePackRequest abstracts away the different requests that end up spawning git-receive-pack.

type RefUpdateType

type RefUpdateType byte

RefUpdateType represents the type of update a FetchStatusLine is. The valid types are documented here: https://git-scm.com/docs/git-fetch/2.30.0#Documentation/git-fetch.txt-flag

const (
	// RefUpdateTypeFastForwardUpdate represents a 'fast forward update' fetch status line
	RefUpdateTypeFastForwardUpdate RefUpdateType = ' '
	// RefUpdateTypeForcedUpdate represents a 'forced update' fetch status line
	RefUpdateTypeForcedUpdate RefUpdateType = '+'
	// RefUpdateTypePruned represents a 'pruned' fetch status line
	RefUpdateTypePruned RefUpdateType = '-'
	// RefUpdateTypeTagUpdate represents a 'tag update' fetch status line
	RefUpdateTypeTagUpdate RefUpdateType = 't'
	// RefUpdateTypeFetched represents a 'fetched' fetch status line. This
	// indicates that a new reference has been created in the local repository
	RefUpdateTypeFetched RefUpdateType = '*'
	// RefUpdateTypeUpdateFailed represents an 'update failed' fetch status line
	RefUpdateTypeUpdateFailed RefUpdateType = '!'
	// RefUpdateTypeUnchanged represents an 'unchanged' fetch status line
	RefUpdateTypeUnchanged RefUpdateType = '='
)

func (RefUpdateType) Valid

func (t RefUpdateType) Valid() bool

Valid checks whether the RefUpdateType is one of the seven valid types of update

type Reference

type Reference struct {
	// Name is the name of the reference
	Name ReferenceName
	// Target is the target of the reference. For direct references it
	// contains the object ID, for symbolic references it contains the
	// target branch name.
	Target string
	// IsSymbolic tells whether the reference is direct or symbolic
	IsSymbolic bool
}

Reference represents a Git reference.

func NewReference

func NewReference(name ReferenceName, target string) Reference

NewReference creates a direct reference to an object.

func NewSymbolicReference

func NewSymbolicReference(name ReferenceName, target string) Reference

NewSymbolicReference creates a symbolic reference to another reference.

type ReferenceName

type ReferenceName string

ReferenceName represents the name of a git reference, e.g. "refs/heads/master". It does not support extended revision notation like a Revision does and must always contain a fully qualified reference.

func NewReferenceNameFromBranchName

func NewReferenceNameFromBranchName(branch string) ReferenceName

NewReferenceNameFromBranchName returns a new ReferenceName from a given branch name. Note that branch is treated as an unqualified branch name. This function will thus always prepend "refs/heads/".

func (ReferenceName) Branch

func (r ReferenceName) Branch() (string, bool)

Branch returns `true` and the branch name if the reference is a branch. E.g. if ReferenceName is "refs/heads/master", it will return "master". If it is not a branch, `false` is returned.

func (ReferenceName) Revision

func (r ReferenceName) Revision() Revision

Revision converts the ReferenceName to a Revision. This is safe to do as a reference is always also a revision.

func (ReferenceName) String

func (r ReferenceName) String() string

String returns the string representation of the ReferenceName.

type Remote

type Remote interface {
	// Add creates a new remote repository if it doesn't exist.
	// If such a remote already exists it returns an ErrAlreadyExists error.
	// https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
	Add(ctx context.Context, name, url string, opts RemoteAddOpts) error
	// Remove removes the remote configured for the local repository and all configurations associated with it.
	// https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emremoveem
	Remove(ctx context.Context, name string) error
	// SetURL sets a new url value for an existing remote.
	// If remote doesn't exist it returns an ErrNotFound error.
	// https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem
	SetURL(ctx context.Context, name, url string, opts SetURLOpts) error
}

Remote represents 'remote' sub-command. https://git-scm.com/docs/git-remote

type RemoteAddOpts

type RemoteAddOpts struct {
	// RemoteTrackingBranches controls what branches should be tracked instead of
	// all branches which is a default refs/remotes/<name>.
	// For each entry the refspec '+refs/heads/<branch>:refs/remotes/<remote>/<branch>' would be created and added to the configuration.
	RemoteTrackingBranches []string
	// DefaultBranch sets the default branch (i.e. the target of the symbolic-ref refs/remotes/<name>/HEAD)
	// for the named remote.
	// If set to 'develop' then: 'git symbolic-ref refs/remotes/<remote>/HEAD' call will result to 'refs/remotes/<remote>/develop'.
	DefaultBranch string
	// Fetch controls if 'git fetch <name>' is run immediately after the remote information is set up.
	Fetch bool
	// Tags controls whether tags will be fetched as part of the remote or not.
	Tags RemoteAddOptsTags
	// Mirror controls value used for '--mirror' flag.
	Mirror RemoteAddOptsMirror
}

RemoteAddOpts is used to configure invocation of the 'git remote add' command. https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem

type RemoteAddOptsMirror

type RemoteAddOptsMirror string

RemoteAddOptsMirror represents possible values for the '--mirror' flag value

func (RemoteAddOptsMirror) String

func (m RemoteAddOptsMirror) String() string

type RemoteAddOptsTags

type RemoteAddOptsTags string

RemoteAddOptsTags controls whether tags will be fetched.

func (RemoteAddOptsTags) String

func (t RemoteAddOptsTags) String() string

type Repository

type Repository interface {
	// ResolveRevision tries to resolve the given revision to its object
	// ID. This uses the typical DWIM mechanism of git, see gitrevisions(1)
	// for accepted syntax. This will not verify whether the object ID
	// exists. To do so, you can peel the reference to a given object type,
	// e.g. by passing `refs/heads/master^{commit}`.
	ResolveRevision(ctx context.Context, revision Revision) (ObjectID, error)
	// HasBranches returns whether the repository has branches.
	HasBranches(ctx context.Context) (bool, error)
}

Repository is the common interface of different repository implementations.

type RepositoryExecutor

type RepositoryExecutor interface {
	repository.GitRepo
	Exec(ctx context.Context, cmd Cmd, opts ...CmdOpt) (*command.Command, error)
	ExecAndWait(ctx context.Context, cmd Cmd, opts ...CmdOpt) error
}

RepositoryExecutor is an interface which allows execution of Git commands in a specific repository.

type RequestWithGitProtocol

type RequestWithGitProtocol interface {
	GetGitProtocol() string
}

RequestWithGitProtocol holds requests that respond to GitProtocol

type Revision

type Revision string

Revision represents anything that resolves to either a commit, multiple commits or to an object different than a commit. This could be e.g. "master", "master^{commit}", an object hash or similar. See gitrevisions(1) for supported syntax.

func (Revision) String

func (r Revision) String() string

String returns the string representation of the Revision.

type SetURLOpts

type SetURLOpts struct {
	// Push URLs are manipulated instead of fetch URLs.
	Push bool
}

SetURLOpts are the options for SetURL.

type StaticOption

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

StaticOption are reusable trusted options

func (StaticOption) OptionArgs

func (sa StaticOption) OptionArgs() ([]string, error)

OptionArgs just passes through the already trusted value. This never returns an error.

type SubCmd

type SubCmd struct {
	Name        string   // e.g. "log", or "cat-file", or "worktree"
	Flags       []Option // optional flags before the positional args
	Args        []string // positional args after all flags
	PostSepArgs []string // post separator (i.e. "--") positional args
}

SubCmd represents a specific git command

func (SubCmd) CommandArgs

func (sc SubCmd) CommandArgs() ([]string, error)

CommandArgs checks all arguments in the sub command and validates them

func (SubCmd) Subcommand

func (sc SubCmd) Subcommand() string

Subcommand returns the subcommand name

type SubSubCmd

type SubSubCmd struct {
	// Name is the name of the subcommand, e.g. "remote" in `git remote set-url`
	Name string
	// Action is the action of the subcommand, e.g. "set-url" in `git remote set-url`
	Action string

	// Flags are optional flags before the positional args
	Flags []Option
	// Args are positional arguments after all flags
	Args []string
	// PostSepArgs are positional args after the "--" separator
	PostSepArgs []string
}

SubSubCmd is a positional argument that appears in the list of options for a subcommand.

func (SubSubCmd) CommandArgs

func (sc SubSubCmd) CommandArgs() ([]string, error)

CommandArgs checks all arguments in the SubSubCommand and validates them, returning the array of all arguments required to execute it.

func (SubSubCmd) Subcommand

func (sc SubSubCmd) Subcommand() string

Subcommand returns the name of the given git command which this SubSubCmd executes. E.g. for `git remote add`, it would return "remote".

type ValueFlag

type ValueFlag struct {
	Name  string
	Value string
}

ValueFlag is an optional command line argument that is comprised of pair of tokens (e.g. "-n 50")

func (ValueFlag) GlobalArgs

func (vf ValueFlag) GlobalArgs() ([]string, error)

GlobalArgs returns the arguments for the given value flag, which should typically be two arguments: the flag and its value. It returns an error if the value flag is not sanitary.

func (ValueFlag) OptionArgs

func (vf ValueFlag) OptionArgs() ([]string, error)

OptionArgs returns an error if the flag is not sanitary

type Version

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

Version represents the version of git itself.

func CurrentVersion

func CurrentVersion(ctx context.Context, gitCmdFactory CommandFactory) (Version, error)

CurrentVersion returns the used git version.

func (Version) IsSupported

func (v Version) IsSupported() bool

IsSupported checks if a version string corresponds to a Git version supported by Gitaly.

func (Version) LessThan

func (v Version) LessThan(other Version) bool

LessThan determines whether the version is older than another version.

func (Version) String

func (v Version) String() string

String returns the string representation of the version.

func (Version) SupportsObjectTypeFilter added in v14.1.0

func (v Version) SupportsObjectTypeFilter() bool

SupportsObjectTypeFilter checks if a version corresponds to a Git version which supports object type filters.

Jump to

Keyboard shortcuts

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