git

package
v1.68.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmptyTreeID is the Git tree object hash that corresponds to an empty tree (directory)
	EmptyTreeID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"

	// NullSHA is the special value that Git uses to signal a ref or object does not exist
	NullSHA = "0000000000000000000000000000000000000000"
)
View Source
const (
	// ProtocolV2 is the special value used by Git clients to request protocol v2
	ProtocolV2 = "version=2"
)

Variables

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 (
	// 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 AddGitProtocolEnv added in v0.125.0

func AddGitProtocolEnv(ctx context.Context, req RequestWithGitProtocol, env []string) []string

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

func BareCommand deprecated added in v0.126.0

func BareCommand(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, env []string, args ...string) (*command.Command, error)

BareCommand creates a git.Command with the given args, stdin/stdout/stderr, and env

Deprecated: use git.SafeBareCmd

func BuildGitOptions added in v0.118.0

func BuildGitOptions(gitOpts []string, otherOpts ...string) []string

BuildGitOptions helps to generate options to the git command. If gitOpts is not empty then its values are passed as part of the "-c" option of the git command, the other values are passed along with the subcommand.

func Command deprecated added in v0.41.0

func Command(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error)

Command creates a git.Command with the given args and Repository

Deprecated: use git.SafeCmd instead

func CommandWithoutRepo added in v0.92.0

func CommandWithoutRepo(ctx context.Context, args ...string) (*command.Command, error)

CommandWithoutRepo works like Command but without a git repository

func HookEnv added in v1.50.0

func HookEnv(req ReceivePackRequest) []string

HookEnv is information we pass down to the Git hooks during git-receive-pack.

func InfoAlternatesPath added in v1.31.0

func InfoAlternatesPath(repo repository.GitRepo) (string, error)

InfoAlternatesPath finds the fully qualified path for the alternates file.

func IsInvalidArgErr added in v1.65.0

func IsInvalidArgErr(err error) bool

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

func IsLFSPointer added in v1.60.0

func IsLFSPointer(b []byte) bool

IsLFSPointer checks to see if a blob is an LFS pointer. It returns the raw data of the pointer if it is

func IsValidRef added in v0.41.0

func IsValidRef(ctx context.Context, repo *gitalypb.Repository, ref string) bool

IsValidRef checks if a ref in a repo is valid

func NoMissingWantErrMessage added in v1.55.0

func NoMissingWantErrMessage() bool

NoMissingWantErrMessage checks if the git version is before Git 2.22, in which versions the missing objects in the wants didn't yield an explicit error message, but no ouput at all.

func ObjectDirectories added in v1.67.0

func ObjectDirectories(ctx context.Context, 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 ReceivePackConfig added in v1.50.0

func ReceivePackConfig() []string

ReceivePackConfig contains config options we want to enforce when receiving a push with git-receive-pack.

func SafeBareCmd added in v1.65.0

func SafeBareCmd(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, env []string, globals []Option, sc SubCmd) (*command.Command, error)

SafeBareCmd creates a git.Command with the given args, stdin/stdout/stderr, and env. It validates the arguments in the command before executing.

func SafeCmd added in v1.65.0

func SafeCmd(ctx context.Context, repo repository.GitRepo, globals []Option, sc SubCmd) (*command.Command, error)

SafeCmd creates a git.Command with the given args and Repository. It validates the arguments in the command before executing.

func SafeCmdWithoutRepo added in v1.65.0

func SafeCmdWithoutRepo(ctx context.Context, globals []Option, sc SubCmd) (*command.Command, error)

SafeCmdWithoutRepo works like Command but without a git repository. It validates the arugments in the command before executing.

func SafeStdinCmd added in v1.65.0

func SafeStdinCmd(ctx context.Context, repo repository.GitRepo, globals []Option, sc SubCmd) (*command.Command, error)

SafeStdinCmd creates a git.Command with the given args and Repository that is suitable for Write()ing to. It validates the arguments in the command before executing.

func StdinCommand deprecated added in v1.7.0

func StdinCommand(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error)

StdinCommand creates a git.Command with the given args and Repository that is suitable for Write()ing to

Deprecated: Use git.SafeStdinCmd instead

func SupportsDeltaIslands added in v1.30.0

func SupportsDeltaIslands(versionStr string) (bool, error)

SupportsDeltaIslands checks if a version string (e.g. "2.20.0") corresponds to a Git version that supports delta islands.

func ValidateCommitID added in v1.13.0

func ValidateCommitID(id string) error

ValidateCommitID checks if id could be a Git commit ID, syntactically.

func ValidateRevision added in v0.31.0

func ValidateRevision(revision []byte) error

ValidateRevision checks if a revision looks valid

func ValidateRevisionAllowEmpty added in v1.42.7

func ValidateRevisionAllowEmpty(revision []byte) error

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

func Version added in v0.46.0

func Version() (string, error)

Version returns the used git version.

func VersionLessThan added in v1.34.0

func VersionLessThan(v1Str, v2Str string) (bool, error)

VersionLessThan returns true if the parsed version value of v1Str is less than the parsed version value of v2Str. An error can be returned if the strings cannot be parsed. Note: this is an extremely simplified semver comparison algorithm

func WarnIfTooManyBitmaps added in v1.67.0

func WarnIfTooManyBitmaps(ctx context.Context, 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 ConfigPair added in v1.66.0

type ConfigPair struct {
	Key   string
	Value string
}

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

func (ConfigPair) IsOption added in v1.66.0

func (ConfigPair) IsOption()

IsOption is a method present on all Flag interface implementations

func (ConfigPair) ValidateArgs added in v1.66.0

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

ValidateArgs validates the config pair args

type Flag added in v1.65.0

type Flag struct {
	Name string
}

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

func (Flag) IsOption added in v1.65.0

func (Flag) IsOption()

IsOption is a method present on all Flag interface implementations

func (Flag) ValidateArgs added in v1.65.0

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

ValidateArgs returns an error if the flag is not sanitary

type Option added in v1.65.0

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

Option is a git command line flag with validation logic

type ReceivePackRequest added in v1.50.0

type ReceivePackRequest interface {
	GetGlId() string
	GetGlUsername() string
	GetGlRepository() string
}

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

type RequestWithGitProtocol added in v0.125.0

type RequestWithGitProtocol interface {
	GetGitProtocol() string
}

RequestWithGitProtocol holds requests that respond to GitProtocol

type StaticOption added in v1.66.0

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

StaticOption are reusable trusted options

func (StaticOption) IsOption added in v1.66.0

func (sa StaticOption) IsOption()

IsOption is a method present on all Flag interface implementations

func (StaticOption) ValidateArgs added in v1.66.0

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

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

type SubCmd added in v1.65.0

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) ValidateArgs added in v1.65.0

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

ValidateArgs checks all arguments in the sub command and validates them

type SubSubCmd added in v1.66.0

type SubSubCmd struct {
	Name string
}

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

func (SubSubCmd) IsOption added in v1.66.0

func (SubSubCmd) IsOption()

IsOption is a method present on all Flag interface implementations

func (SubSubCmd) ValidateArgs added in v1.66.0

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

ValidateArgs returns an error if the command name or options are not sanitary

type ValueFlag added in v1.65.0

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) IsOption added in v1.65.0

func (ValueFlag) IsOption()

IsOption is a method present on all Flag interface implementations

func (ValueFlag) ValidateArgs added in v1.65.0

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

ValidateArgs returns an error if the flag is not sanitary

Jump to

Keyboard shortcuts

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