Documentation ¶
Index ¶
- Constants
- Variables
- func AlternateObjectDirectories(ctx context.Context, storageRoot, repoPath string) ([]string, error)
- func BuildSSHInvocation(ctx context.Context, sshKey, knownHosts string) (string, func(), error)
- func CheckRefFormat(ctx context.Context, gitCmdFactory CommandFactory, refName string) (bool, error)
- func ConfigPairsToGitEnvironment(configPairs []ConfigPair) []string
- func IsInvalidArgErr(err error) bool
- func IsLFSPointer(b []byte) bool
- func NewTreeEntry(commitOid, rootOid, rootPath string, filename, oidBytes, modeBytes []byte) (*gitalypb.TreeEntry, error)
- func ObjectDirectories(ctx context.Context, storageRoot, repoPath string) ([]string, error)
- func ValidateRevision(revision []byte) error
- func ValidateRevisionAllowEmpty(revision []byte) error
- func WarnIfTooManyBitmaps(ctx context.Context, locator storage.Locator, storageName, repoPath string)
- type BundledGitEnvironmentConstructor
- type Checksum
- type CmdOpt
- func ConvertGlobalOptions(options *gitalypb.GlobalOptions) []CmdOpt
- func WithConfig(configPairs ...ConfigPair) CmdOpt
- func WithConfigEnv(configPairs ...ConfigPair) CmdOpt
- func WithDisabledHooks() CmdOpt
- func WithEnv(envs ...string) CmdOpt
- func WithFinalizer(finalizer func(*command.Command)) CmdOpt
- func WithGitProtocol(req RequestWithGitProtocol) CmdOpt
- func WithGlobalOption(opts ...GlobalOption) CmdOpt
- func WithInternalFetch(req *gitalypb.SSHUploadPackRequest) CmdOpt
- func WithInternalFetchWithSidechannel(req *gitalypb.SSHUploadPackWithSidechannelRequest) CmdOpt
- func WithPackObjectsHookEnv(repo *gitalypb.Repository, protocol string) CmdOpt
- func WithReceivePackHooks(req ReceivePackRequest, protocol string) CmdOpt
- func WithRefTxHook(repo repository.GitRepo) CmdOpt
- func WithSetupStdin() CmdOpt
- func WithStderr(w io.Writer) CmdOpt
- func WithStdin(r io.Reader) CmdOpt
- func WithStdout(w io.Writer) CmdOpt
- func WithWorktree(worktreePath string) CmdOpt
- type Command
- type CommandFactory
- type ConfigPair
- type DistributedGitEnvironmentConstructor
- type ExecCommandFactory
- func (cf *ExecCommandFactory) Collect(metrics chan<- prometheus.Metric)
- func (cf *ExecCommandFactory) Describe(descs chan<- *prometheus.Desc)
- func (cf *ExecCommandFactory) GetExecutionEnvironment(ctx context.Context) ExecutionEnvironment
- func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error)
- func (cf *ExecCommandFactory) GlobalConfiguration(ctx context.Context) ([]ConfigPair, error)
- func (cf *ExecCommandFactory) HooksPath(ctx context.Context) string
- func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Command, opts ...CmdOpt) (*command.Command, error)
- func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Command, opts ...CmdOpt) (*command.Command, error)
- func (cf *ExecCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]ConfigPair, error)
- type ExecCommandFactoryOption
- type ExecutionEnvironment
- type ExecutionEnvironmentConstructor
- type FallbackGitEnvironmentConstructor
- type FeatureFlagWithValue
- type FetchScanner
- type FetchStatusLine
- type Flag
- type GlobalOption
- type Hook
- type HooksPayload
- type InternalReferenceType
- type Object
- type ObjectHash
- type ObjectID
- type ObjectInfo
- type Option
- type ReceivePackRequest
- type RefUpdateType
- type Reference
- type ReferenceName
- type Repository
- type RepositoryExecutor
- type RequestWithGitProtocol
- type Revision
- type ShowRefDecoder
- type StaticOption
- type UserDetails
- type ValueFlag
- type Version
Constants ¶
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 )
const ( // InternalReferenceTypeHidden indicates that a reference should never be advertised or // writeable. InternalReferenceTypeHidden = InternalReferenceType(iota + 1) // InternalReferenceTypeReadonly indicates that a reference should be advertised, but not // writeable. InternalReferenceTypeReadonly )
const DefaultBranch = "main"
DefaultBranch is the default reference written to HEAD when a repository is created
const DefaultRef = ReferenceName("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.
const ( // EnvHooksPayload is the name of the environment variable used // to hold the hooks payload. EnvHooksPayload = "GITALY_HOOKS_PAYLOAD" )
const ( // InternalGitalyURL is a special URL that indicates Gitaly wants to push to or fetch from // another internal Gitaly instance. InternalGitalyURL = "ssh://gitaly/internal.git" )
const LegacyDefaultRef = ReferenceName("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.
const ObjectPoolRefNamespace = "refs/remotes/origin"
ObjectPoolRefNamespace is the namespace used for the references of the primary pool member part of an object pool.
const (
// ProtocolV2 is the special value used by Git clients to request protocol v2
ProtocolV2 = "version=2"
)
const ZeroChecksum = "0000000000000000000000000000000000000000"
ZeroChecksum is the hex representation of a checksum with no references added.
Variables ¶
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") )
var ( // ErrNotConfigured may be returned by an ExecutionEnvironmentConstructor in case an // environment was not configured. ErrNotConfigured = errors.New("execution environment is not configured") // ExecutionEnvironmentConstructors is the list of Git environments supported by the Git // command factory. The order is important and signifies the priority in which the // environments will be used: the environment created by the first constructor is the one // that will be preferred when executing Git commands. Later environments may be used in // case `IsEnabled()` returns `false` though. ExecutionEnvironmentConstructors = []ExecutionEnvironmentConstructor{ BundledGitEnvironmentConstructor{ Suffix: "-v2.38", }, DistributedGitEnvironmentConstructor{}, } )
var ( // ObjectHashSHA1 is the implementation of an object ID via SHA1. ObjectHashSHA1 = ObjectHash{ Hash: sha1.New, EmptyTreeOID: ObjectID("4b825dc642cb6eb9a060e54bf8d69288fbee4904"), ZeroOID: ObjectID("0000000000000000000000000000000000000000"), Format: "sha1", ProtoFormat: gitalypb.ObjectFormat_OBJECT_FORMAT_SHA1, // contains filtered or unexported fields } // ObjectHashSHA256 is the implementation of an object ID via SHA256. ObjectHashSHA256 = ObjectHash{ Hash: sha256.New, EmptyTreeOID: ObjectID("6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321"), ZeroOID: ObjectID("0000000000000000000000000000000000000000000000000000000000000000"), Format: "sha256", ProtoFormat: gitalypb.ObjectFormat_OBJECT_FORMAT_SHA256, // contains filtered or unexported fields } // ErrInvalidObjectID is returned in case an object ID's string // representation is not a valid one. ErrInvalidObjectID = errors.New("invalid object ID") )
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") )
var ErrPayloadNotFound = errors.New("no hooks payload found in environment")
ErrPayloadNotFound is returned by HooksPayloadFromEnv if the given environment variables don't have a hooks payload.
var InternalRefPrefixes = map[string]InternalReferenceType{ "refs/environments/": InternalReferenceTypeReadonly, "refs/keep-around/": InternalReferenceTypeHidden, "refs/merge-requests/": InternalReferenceTypeReadonly, "refs/pipelines/": InternalReferenceTypeReadonly, "refs/remotes/": InternalReferenceTypeHidden, "refs/tmp/": InternalReferenceTypeHidden, }
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.
var OutputToStdout = StaticOption{/* contains filtered or unexported fields */}
OutputToStdout is used indicate the output should be sent to STDOUT Seen in: git bundle create
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 ¶
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 ConfigPairsToGitEnvironment ¶
func ConfigPairsToGitEnvironment(configPairs []ConfigPair) []string
ConfigPairsToGitEnvironment converts the given config pairs into a set of environment variables that can be injected into a Git executable.
func IsInvalidArgErr ¶
IsInvalidArgErr relays if the error is due to an argument validation failure
func IsLFSPointer ¶
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 NewTreeEntry ¶
func NewTreeEntry(commitOid, rootOid, rootPath string, filename, oidBytes, modeBytes []byte) (*gitalypb.TreeEntry, error)
NewTreeEntry is a helper to construct a gitalypb.TreeEntry from the provided parameters.
func ObjectDirectories ¶
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 ValidateRevision ¶
ValidateRevision checks if a revision looks valid
func ValidateRevisionAllowEmpty ¶
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 BundledGitEnvironmentConstructor ¶
type BundledGitEnvironmentConstructor struct { // Suffix is the version suffix used for this specific bundled Git environment. In case // multiple sets of bundled Git versions are installed it is possible to also have multiple // of these bundled Git environments with different suffixes. Suffix string // FeatureFlags is the set of feature flags which must be enabled in order for the bundled // Git environment to be enabled. Note that _all_ feature flags must be set to `true` in the // context. FeatureFlags []featureflag.FeatureFlag }
BundledGitEnvironmentConstructor sets up an ExecutionEnvironment for a bundled Git installation. Bundled Git is a partial Git installation, where only a subset of Git binaries are installed into Gitaly's binary directory. The binaries must have a `gitaly-` prefix like e.g. `gitaly-git`. Bundled Git installations can be installed with Gitaly's Makefile via `make install WITH_BUNDLED_GIT=YesPlease`.
func (BundledGitEnvironmentConstructor) Construct ¶
func (c BundledGitEnvironmentConstructor) Construct(cfg config.Cfg) (_ ExecutionEnvironment, returnedErr error)
Construct sets up an ExecutionEnvironment for a bundled Git installation. Because bundled Git installations are not complete Git installations we need to set up a usable environment at runtime. This is done by creating a temporary directory into which we symlink the bundled binaries with their usual names as expected by Git. Furthermore, we configure the GIT_EXEC_PATH environment variable to point to that directory such that Git is able to locate its auxiliary binaries.
For testing purposes, this function will automatically enable use of bundled Git in case the `GITALY_TESTING_BUNDLED_GIT_PATH` environment variable is set.
type Checksum ¶
type Checksum struct {
// contains filtered or unexported fields
}
Checksum is a hash representation of all references in a repository. Checksum must not be copied after first use.
func (*Checksum) AddBytes ¶
AddBytes adds a reference to the checksum that is a line in the output format of `git-show-ref`.
type CmdOpt ¶
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 WithFinalizer ¶ added in v15.2.0
WithFinalizer sets up the finalizer to be run when the command is being wrapped up. It will be called after `Wait()` has returned.
func WithGitProtocol ¶
func WithGitProtocol(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 WithInternalFetch ¶
func WithInternalFetch(req *gitalypb.SSHUploadPackRequest) CmdOpt
WithInternalFetch returns an option which sets up git-fetch(1) to fetch from another internal Gitaly node.
func WithInternalFetchWithSidechannel ¶
func WithInternalFetchWithSidechannel(req *gitalypb.SSHUploadPackWithSidechannelRequest) CmdOpt
WithInternalFetchWithSidechannel returns an option which sets up git-fetch(1) to fetch from another internal Gitaly node. In contrast to WithInternalFetch, this will call SSHUploadPackWithSidechannel instead of SSHUploadPack.
func WithPackObjectsHookEnv ¶
func WithPackObjectsHookEnv(repo *gitalypb.Repository, protocol string) CmdOpt
WithPackObjectsHookEnv provides metadata for gitaly-hooks so it can act as a pack-objects hook.
func WithReceivePackHooks ¶
func WithReceivePackHooks(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(repo repository.GitRepo) 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 WithSetupStdin ¶ added in v15.2.0
func WithSetupStdin() CmdOpt
WithSetupStdin sets up the command so that it can be `Write()`en to.
func WithStdin ¶
WithStdin sets the command's stdin. Pass `command.SetupStdin` to make the command suitable for `Write()`ing to.
func WithWorktree ¶ added in v15.6.0
WithWorktree sets up the Git command to run in the given worktree path by using the `-C` switch.
type Command ¶ added in v15.7.0
type Command struct { // Name is the name of the Git command to run, e.g. "log", "cat-flie" or "worktree". Name string // Action is the action of the Git command, e.g. "set-url" in `git remote set-url` Action string // Flags is the number of optional flags to pass before positional arguments, e.g. // `--oneline` or `--format=fuller`. Flags []Option // Args is the arguments that shall be passed after all flags. These arguments must not be // flags and thus cannot start with `-`. Note that it may be unsafe to use this field in the // case where arguments are directly user-controlled. In that case it is advisable to use // `PostSepArgs` instead. Args []string // PostSepArgs is the arguments that shall be passed as positional arguments after the `--` // separator. Git recognizes that separator as the point where it should stop expecting any // options and treat the remaining arguments as positionals. This should be used when // passing user-controlled input of arbitrary form like for example paths, which may start // with a `-`. PostSepArgs []string }
Command represent a Git command.
func (Command) CommandArgs ¶ added in v15.7.0
CommandArgs checks all arguments in the sub command and validates them
type CommandFactory ¶
type CommandFactory interface { // New creates a new command for the repo repository. New(ctx context.Context, repo repository.GitRepo, sc Command, opts ...CmdOpt) (*command.Command, error) // NewWithoutRepo creates a command without a target repository. NewWithoutRepo(ctx context.Context, sc Command, opts ...CmdOpt) (*command.Command, error) // GetExecutionEnvironment returns parameters required to execute Git commands. GetExecutionEnvironment(context.Context) ExecutionEnvironment // HooksPath returns the path where Gitaly's Git hooks reside. HooksPath(context.Context) string // GitVersion returns the Git version used by the command factory. GitVersion(context.Context) (Version, error) // SidecarGitConfiguration returns the Git configuration is it should be used by the Ruby // sidecar. This is a design wart and shouldn't ever be used outside of the context of the // sidecar. SidecarGitConfiguration(context.Context) ([]ConfigPair, error) }
CommandFactory is designed to create and run git commands in a protected and fully managed manner.
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 GetURLAndResolveConfig ¶ added in v15.3.5
func GetURLAndResolveConfig(remoteURL string, resolvedAddress string) (string, []ConfigPair, error)
GetURLAndResolveConfig parses the given repository's URL and resolved address to generate the modified URL and configuration to avoid DNS rebinding.
In Git v2.37.0 we added the functionality for `http.curloptResolve` which like its curl counterpart when provided with a `HOST:PORT:ADDRESS` value, uses the IP Address provided directly for the given HOST:PORT combination for HTTP/HTTPS protocols, without requiring DNS resolution.
This functions currently does the following operations:
- Git Protocol: Replaces the hostname with the resolved IP address. - SSH Protocol: Replaces the hostname with the resolved IP address (supports both the regular syntax `ssh://[user@]server/project.git` and scp-like syntax `[user@]server:project.git`). - HTTP/HTTPS Protocol: Keeps the URL as is, but adds the `http.curloptResolve` flag.
SideNote: We cannot replace the hostname with IP in HTTPS protocol because the protocol demands the hostname to be present, as it is required for the SSL verification.
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 DistributedGitEnvironmentConstructor ¶
type DistributedGitEnvironmentConstructor struct{}
DistributedGitEnvironmentConstructor creates ExecutionEnvironments via the Git binary path configured in the Gitaly configuration. This expects a complete Git installation with all its components. The installed distribution must either have its prefix compiled into the binaries or alternatively be compiled with runtime-detection of the prefix such that Git is able to locate its auxiliary helper binaries correctly.
func (DistributedGitEnvironmentConstructor) Construct ¶
func (c DistributedGitEnvironmentConstructor) Construct(cfg config.Cfg) (ExecutionEnvironment, error)
Construct sets up an ExecutionEnvironment for a complete Git distribution. No setup needs to be performed given that the Git environment is expected to be self-contained.
For testing purposes, this function overrides the configured Git binary path if the `GITALY_TESTING_GIT_BINARY` environment variable is set.
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, opts ...ExecCommandFactoryOption) (_ *ExecCommandFactory, _ func(), returnedErr error)
NewExecCommandFactory returns a new instance of initialized ExecCommandFactory. The returned cleanup function shall be executed when the server shuts down.
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) GetExecutionEnvironment ¶
func (cf *ExecCommandFactory) GetExecutionEnvironment(ctx context.Context) ExecutionEnvironment
GetExecutionEnvironment returns parameters required to execute Git commands.
func (*ExecCommandFactory) GitVersion ¶
func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error)
GitVersion returns the Git version in use. The version is cached as long as the binary remains unchanged as determined by stat(3P).
func (*ExecCommandFactory) GlobalConfiguration ¶ added in v15.7.0
func (cf *ExecCommandFactory) GlobalConfiguration(ctx context.Context) ([]ConfigPair, error)
GlobalConfiguration returns the global Git configuration that should be applied to every Git command.
func (*ExecCommandFactory) HooksPath ¶
func (cf *ExecCommandFactory) HooksPath(ctx context.Context) string
HooksPath returns the path where Gitaly's Git hooks reside.
func (*ExecCommandFactory) New ¶
func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Command, opts ...CmdOpt) (*command.Command, error)
New creates a new command for the repo repository.
func (*ExecCommandFactory) NewWithoutRepo ¶
func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Command, opts ...CmdOpt) (*command.Command, error)
NewWithoutRepo creates a command without a target repository.
func (*ExecCommandFactory) SidecarGitConfiguration ¶
func (cf *ExecCommandFactory) SidecarGitConfiguration(ctx context.Context) ([]ConfigPair, error)
SidecarGitConfiguration assembles the Git configuration as required by the Ruby sidecar. This includes global configuration, command-specific configuration for all commands executed in the sidecar, as well as configuration that was configured by the administrator in Gitaly's config.
This function should not be used for anything else but the Ruby sidecar.
type ExecCommandFactoryOption ¶
type ExecCommandFactoryOption func(*execCommandFactoryConfig)
ExecCommandFactoryOption is an option that can be passed to NewExecCommandFactory.
func WithCgroupsManager ¶ added in v15.6.0
func WithCgroupsManager(cgroupsManager cgroups.Manager) ExecCommandFactoryOption
WithCgroupsManager overrides the Cgroups manager used by the command factory.
func WithGitBinaryPath ¶
func WithGitBinaryPath(path string) ExecCommandFactoryOption
WithGitBinaryPath overrides the path to the Git binary that shall be executed.
func WithHooksPath ¶
func WithHooksPath(hooksPath string) ExecCommandFactoryOption
WithHooksPath will override the path where hooks are to be found.
func WithSkipHooks ¶
func WithSkipHooks() ExecCommandFactoryOption
WithSkipHooks will skip any use of hooks in this command factory.
type ExecutionEnvironment ¶
type ExecutionEnvironment struct { // BinaryPath is the path to the Git binary. BinaryPath string // EnvironmentVariables are variables which must be set when running the Git binary. EnvironmentVariables []string // contains filtered or unexported fields }
ExecutionEnvironment describes the environment required to execute a Git command
func (ExecutionEnvironment) Cleanup ¶
func (e ExecutionEnvironment) Cleanup()
Cleanup cleans up any state set up by this ExecutionEnvironment.
type ExecutionEnvironmentConstructor ¶
type ExecutionEnvironmentConstructor interface {
Construct(config.Cfg) (ExecutionEnvironment, error)
}
ExecutionEnvironmentConstructor is an interface for constructors of Git execution environments. A constructor should be able to set up an environment in which it is possible to run Git executables.
type FallbackGitEnvironmentConstructor ¶
type FallbackGitEnvironmentConstructor struct{}
FallbackGitEnvironmentConstructor sets up a fallback execution environment where Git is resolved via the `PATH` environment variable. This is only intended as a last resort in case no other environments have been set up.
func (FallbackGitEnvironmentConstructor) Construct ¶
func (c FallbackGitEnvironmentConstructor) Construct(config.Cfg) (ExecutionEnvironment, error)
Construct sets up an execution environment by searching `PATH` for a `git` executable.
type FeatureFlagWithValue ¶ added in v15.2.0
type FeatureFlagWithValue struct { // Flag is the feature flag. Flag featureflag.FeatureFlag `json:"flag"` // Enabled indicates whether the flag is enabled or not. Enabled bool `json:"enabled"` }
FeatureFlagWithValue is used as part of the HooksPayload to pass on feature flags with their values to gitaly-hooks.
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 ¶
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 ¶
OptionArgs returns an error if the flag is not sanitary
type GlobalOption ¶
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"` // FeatureFlagsWithValue contains feature flags with their values. They are set into the // outgoing context when calling HookService. FeatureFlagsWithValue []FeatureFlagWithValue `json:"feature_flags_with_value,omitempty"` // Repo is the repository in which the hook is running. Repo *gitalypb.Repository `json:"-"` // RuntimeDir is the path to Gitaly's runtime directory. RuntimeDir string `json:"runtime_dir"` // 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"` // UserDetails contains information required when executing // git-receive-pack or git-upload-pack UserDetails *UserDetails `json:"user_details"` // ReceiveHooksPayload should be identical to UserDetails. // Since the git2go binary is replaced before the gitaly binary, there // is a period of time during an upgrade when the gitaly binary is older // than the corresponding git2go binary. So, we need to keep the // receive_hooks_payload key for one release before we can remove it. ReceiveHooksPayload *UserDetails `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, userDetails *UserDetails, requestedHooks Hook, featureFlagsWithValue map[featureflag.FeatureFlag]bool, ) 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 InternalReferenceType ¶ added in v15.3.0
type InternalReferenceType int
InternalReferenceType is the type of an internal reference.
type Object ¶
type Object interface { // ObjectInfo provides information about the object. ObjectInfo // Reader reads object data. io.Reader // WriterTo writes object data into a reader. io.WriterTo }
Object is an interface encapsulating an object with contents.
type ObjectHash ¶ added in v15.3.0
type ObjectHash struct { // Hash is the hashing function used to hash objects. Hash func() hash.Hash // EmptyTreeOID is the object ID of the tree object that has no directory entries. EmptyTreeOID ObjectID // ZeroOID is the special value that Git uses to signal a ref or object does not exist ZeroOID ObjectID // Format is the name of the object hash. Format string // ProtoFormat is the Protobuf representation of the object format. ProtoFormat gitalypb.ObjectFormat // contains filtered or unexported fields }
ObjectHash is a hash-function specific implementation of an object ID.
func DetectObjectHash ¶ added in v15.3.0
func DetectObjectHash(ctx context.Context, repoExecutor RepositoryExecutor) (ObjectHash, error)
DetectObjectHash detects the object-hash used by the given repository.
func ObjectHashByFormat ¶ added in v15.6.0
func ObjectHashByFormat(format string) (ObjectHash, error)
ObjectHashByFormat looks up the ObjectHash by its format name.
func ObjectHashByProto ¶ added in v15.7.0
func ObjectHashByProto(format gitalypb.ObjectFormat) (ObjectHash, error)
ObjectHashByProto looks up the ObjectHash by its Protobuf representation `gitalypb.ObjectFormat`. Returns an error in case the object format is not known.
func (ObjectHash) EncodedLen ¶ added in v15.3.0
func (h ObjectHash) EncodedLen() int
EncodedLen returns the length of the hex-encoded string of a full object ID.
func (ObjectHash) FromHex ¶ added in v15.3.0
func (h ObjectHash) FromHex(hex string) (ObjectID, error)
FromHex constructs a new ObjectID from the given hex representation of the object ID. Returns ErrInvalidObjectID if the given object ID is not valid.
func (ObjectHash) IsZeroOID ¶ added in v15.3.0
func (h ObjectHash) IsZeroOID(oid ObjectID) bool
IsZeroOID checks whether the given object ID is the all-zeroes object ID for the given hash.
func (ObjectHash) ValidateHex ¶ added in v15.3.0
func (h ObjectHash) ValidateHex(hex string) error
ValidateHex checks if `hex` is a syntactically correct object ID for the given hash. Abbreviated object IDs are not deemed to be valid. Returns an `ErrInvalidObjectID` if the `hex` is not valid.
type ObjectID ¶
type ObjectID string
ObjectID represents an object ID.
type ObjectInfo ¶
ObjectInfo is an interface encapsulating information about objects.
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 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) // GetDefaultBranch returns the default branch of the repository. GetDefaultBranch(ctx context.Context) (ReferenceName, error) }
Repository is the common interface of different repository implementations.
type RepositoryExecutor ¶
type RepositoryExecutor interface { repository.GitRepo Exec(ctx context.Context, cmd Command, opts ...CmdOpt) (*command.Command, error) ExecAndWait(ctx context.Context, cmd Command, opts ...CmdOpt) error GitVersion(ctx context.Context) (Version, error) ObjectHash(ctx context.Context) (ObjectHash, 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.
type ShowRefDecoder ¶
type ShowRefDecoder struct {
// contains filtered or unexported fields
}
ShowRefDecoder parses the output format of git-show-ref
func NewShowRefDecoder ¶
func NewShowRefDecoder(r io.Reader) *ShowRefDecoder
NewShowRefDecoder returns a new ShowRefDecoder
func (*ShowRefDecoder) Decode ¶
func (d *ShowRefDecoder) Decode(ref *Reference) error
Decode reads and parses the next reference. Returns io.EOF when the end of the reader has been reached.
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 UserDetails ¶ added in v15.2.0
type UserDetails 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"` }
UserDetails contains all information which is required for hooks executed by git-receive-pack, namely the pre-receive, update or post-receive hook.
type ValueFlag ¶
ValueFlag is an optional command line argument that is comprised of pair of tokens (e.g. "-n 50")
func (ValueFlag) GlobalArgs ¶
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 ¶
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 (Version) IsSupported ¶
IsSupported checks if a version string corresponds to a Git version supported by Gitaly.
func (Version) MidxDeletesRedundantBitmaps ¶ added in v15.9.0
MidxDeletesRedundantBitmaps detects whether the given Git version deletes redundant pack-based bitmaps when writing multi-pack-indices. This feature has been added via 55d902cd61 (builtin/repack.c: remove redundant pack-based bitmaps, 2022-10-17), which is part of Git v2.39.0 and newer.
func (Version) PatchIDRespectsBinaries ¶ added in v15.8.0
PatchIDRespectsBinaries detects whether the given Git version correctly handles binary diffs when computing a patch ID. Previous to Git v2.39.0, git-patch-id(1) just completely ignored any binary diffs and thus would consider two diffs the same even if a binary changed.
Source Files ¶
- bitmap.go
- checksum.go
- command.go
- command_description.go
- command_factory.go
- command_options.go
- command_resolve.go
- decoder.go
- dirs.go
- execution_environment.go
- fetch_scanner.go
- hooks_options.go
- hooks_payload.go
- lfs.go
- object.go
- object_id.go
- protocol.go
- reference.go
- repository.go
- revision.go
- ssh.go
- staticargs.go
- tree_entry.go
- version.go
Directories ¶
Path | Synopsis |
---|---|
Package pktline implements utility functions for working with the Git pkt-line format.
|
Package pktline implements utility functions for working with the Git pkt-line format. |