localrepo

package
v14.9.0-rc42 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FetchOptsTagsDefault enables importing of tags only on fetched branches.
	FetchOptsTagsDefault = FetchOptsTags("")
	// FetchOptsTagsAll enables importing of every tag from the remote repository.
	FetchOptsTagsAll = FetchOptsTags("--tags")
	// FetchOptsTagsNone disables importing of tags from the remote repository.
	FetchOptsTagsNone = FetchOptsTags("--no-tags")
)
View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound is returned in case an object could not be found.

Functions

func FormatTag

func FormatTag(
	objectID git.ObjectID,
	objectType string,
	tagName, tagBody []byte,
	committer *gitalypb.User,
	committerDate time.Time,
) (string, error)

FormatTag is used by WriteTag (or for testing) to make the tag signature to feed to git-mktag, i.e. the plain-text mktag format. This does not create an object, just crafts input for "git mktag" to consume.

We are not being paranoid about exhaustive input validation here because we're just about to run git's own "fsck" check on this.

However, if someone injected parameters with extra newlines they could cause subsequent values to be ignore via a crafted message. This someone could also locally craft a tag locally and "git push" it. But allowing e.g. someone to provide their own timestamp here would at best be annoying, and at worst run up against some other assumption (e.g. that some hook check isn't as strict on locally generated data).

Types

type ErrFetchFailed added in v14.2.0

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

ErrFetchFailed indicates that the fetch has failed.

func (ErrFetchFailed) Error added in v14.2.0

func (e ErrFetchFailed) Error() string

Error returns the error message.

type FetchOpts

type FetchOpts struct {
	// Env is a list of env vars to pass to the cmd.
	Env []string
	// CommandOptions is a list of options to use with 'git' command.
	CommandOptions []git.CmdOpt
	// Prune if set fetch removes any remote-tracking references that no longer exist on the remote.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---prune
	Prune bool
	// Force if set fetch overrides local references with values from remote that's
	// doesn't have the previous commit as an ancestor.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---force
	Force bool
	// Verbose controls how much information is written to stderr. The list of
	// refs updated by the fetch will only be listed if verbose is true.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---quiet
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---verbose
	Verbose bool
	// Tags controls whether tags will be fetched as part of the remote or not.
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---tags
	// https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---no-tags
	Tags FetchOptsTags
	// Stderr if set it would be used to redirect stderr stream into it.
	Stderr io.Writer
	// DisableTransactions will disable the reference-transaction hook and atomic transactions.
	DisableTransactions bool
}

FetchOpts is used to configure invocation of the 'FetchRemote' command.

type FetchOptsTags

type FetchOptsTags string

FetchOptsTags controls what tags needs to be imported on fetch.

func (FetchOptsTags) String

func (t FetchOptsTags) String() string

type FormatTagError

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

FormatTagError is used by FormatTag() below

func (FormatTagError) Error

func (e FormatTagError) Error() string

type GetRemoteReferencesOption

type GetRemoteReferencesOption func(*getRemoteReferenceConfig)

GetRemoteReferencesOption is an option which can be passed to GetRemoteReferences.

func WithConfig

func WithConfig(config ...git.ConfigPair) GetRemoteReferencesOption

WithConfig sets up Git configuration for the git-ls-remote(1) invocation. The config pairs are set up via `WithConfigEnv()` and are thus not exposed via the command line.

func WithPatterns

func WithPatterns(patterns ...string) GetRemoteReferencesOption

WithPatterns sets up a set of patterns which are then used to filter the list of returned references.

func WithSSHCommand

func WithSSHCommand(cmd string) GetRemoteReferencesOption

WithSSHCommand sets the SSH invocation to use when communicating with the remote.

type InvalidCommitError

type InvalidCommitError git.Revision

InvalidCommitError is returned when the revision does not point to a valid commit object.

func (InvalidCommitError) Error

func (err InvalidCommitError) Error() string

type InvalidObjectError

type InvalidObjectError string

InvalidObjectError is returned when trying to get an object id that is invalid or does not exist.

func (InvalidObjectError) Error

func (err InvalidObjectError) Error() string

type MktagError

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

MktagError is used by WriteTag() below

func (MktagError) Error

func (e MktagError) Error() string

type PushOptions

type PushOptions struct {
	// SSHCommand is the command line to use for git's SSH invocation. The command line is used
	// as is and must be verified by the caller to be safe.
	SSHCommand string
	// Force decides whether to force push all of the refspecs.
	Force bool
	// Config is the Git configuration which gets passed to the git-push(1) invocation.
	// Configuration is set up via `WithConfigEnv()`, so potential credentials won't be leaked
	// via the command line.
	Config []git.ConfigPair
}

PushOptions are options that can be configured for a push.

type ReadCommitOpt

type ReadCommitOpt func(*readCommitConfig)

ReadCommitOpt is an option for ReadCommit.

func WithTrailers

func WithTrailers() ReadCommitOpt

WithTrailers will cause ReadCommit to parse commit trailers.

type Repo

type Repo struct {
	repository.GitRepo
	// contains filtered or unexported fields
}

Repo represents a local Git repository.

func New

func New(locator storage.Locator, gitCmdFactory git.CommandFactory, catfileCache catfile.Cache, repo repository.GitRepo) *Repo

New creates a new Repo from its protobuf representation.

func NewTestRepo

func NewTestRepo(t testing.TB, cfg config.Cfg, repo repository.GitRepo, factoryOpts ...git.ExecCommandFactoryOption) *Repo

NewTestRepo constructs a Repo. It is intended as a helper function for tests which assembles dependencies ad-hoc from the given config.

func (*Repo) Exec

func (repo *Repo) Exec(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) (*command.Command, error)

Exec creates a git command with the given args and Repo, executed in the Repo. It validates the arguments in the command before executing.

func (*Repo) ExecAndWait

func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) error

ExecAndWait is similar to Exec, but waits for the command to exit before returning.

func (*Repo) FetchInternal added in v14.2.0

func (repo *Repo) FetchInternal(
	ctx context.Context,
	remoteRepo *gitalypb.Repository,
	refspecs []string,
	opts FetchOpts,
) error

FetchInternal performs a fetch from an internal Gitaly-hosted repository. Returns an ErrFetchFailed error in case git-fetch(1) failed.

func (*Repo) FetchRemote

func (repo *Repo) FetchRemote(ctx context.Context, remoteName string, opts FetchOpts) error

FetchRemote fetches changes from the specified remote. Returns an ErrFetchFailed error in case the fetch itself failed.

func (*Repo) GetBranches

func (repo *Repo) GetBranches(ctx context.Context) ([]git.Reference, error)

GetBranches returns all branches.

func (*Repo) GetDefaultBranch added in v14.4.0

func (repo *Repo) GetDefaultBranch(ctx context.Context) (git.ReferenceName, error)

GetDefaultBranch determines the default branch name

func (*Repo) GetReference

func (repo *Repo) GetReference(ctx context.Context, reference git.ReferenceName) (git.Reference, error)

GetReference looks up and returns the given reference. Returns a ReferenceNotFound error if the reference was not found.

func (*Repo) GetReferences

func (repo *Repo) GetReferences(ctx context.Context, patterns ...string) ([]git.Reference, error)

GetReferences returns references matching any of the given patterns. If no patterns are given, all references are returned.

func (*Repo) GetRemoteReferences

func (repo *Repo) GetRemoteReferences(ctx context.Context, remote string, opts ...GetRemoteReferencesOption) ([]git.Reference, error)

GetRemoteReferences lists references of the remote. Peeled tags are not returned.

func (*Repo) GitVersion added in v14.7.0

func (repo *Repo) GitVersion(ctx context.Context) (git.Version, error)

GitVersion returns the Git version in use.

func (*Repo) GuessHead added in v14.6.0

func (repo *Repo) GuessHead(ctx context.Context, head git.Reference) (git.ReferenceName, error)

GuessHead tries to guess what branch HEAD would be pointed at. If no reference is found git.ErrReferenceNotFound is returned.

This function should be roughly equivalent to the corresponding function in git: https://github.com/git/git/blob/2a97289ad8b103625d3a1a12f66c27f50df822ce/remote.c#L2198

func (*Repo) HasBranches

func (repo *Repo) HasBranches(ctx context.Context) (bool, error)

HasBranches determines whether there is at least one branch in the repository.

func (*Repo) HasRevision

func (repo *Repo) HasRevision(ctx context.Context, revision git.Revision) (bool, error)

HasRevision checks if a revision in the repository exists. This will not verify whether the target object exists. To do so, you can peel the revision to a given object type, e.g. by passing `refs/heads/master^{commit}`.

func (*Repo) InfoAlternatesPath added in v14.8.0

func (repo *Repo) InfoAlternatesPath() (string, error)

InfoAlternatesPath returns the full path of the alternates file.

func (*Repo) IsAncestor

func (repo *Repo) IsAncestor(ctx context.Context, parent, child git.Revision) (bool, error)

IsAncestor returns whether the parent is an ancestor of the child. InvalidCommitError is returned if either revision does not point to a commit in the repository.

func (*Repo) ObjectDirectoryPath added in v14.8.0

func (repo *Repo) ObjectDirectoryPath() (string, error)

ObjectDirectoryPath returns the full path of the object directory. The errors returned are gRPC errors with relevant error codes and should be passed back to gRPC without further decoration.

func (*Repo) Path

func (repo *Repo) Path() (string, error)

Path returns the on-disk path of the repository.

func (*Repo) Push

func (repo *Repo) Push(ctx context.Context, remote string, refspecs []string, options PushOptions) error

Push force pushes the refspecs to the remote.

func (*Repo) ReadCommit

func (repo *Repo) ReadCommit(ctx context.Context, revision git.Revision, opts ...ReadCommitOpt) (*gitalypb.GitCommit, error)

ReadCommit reads the commit specified by the given revision. If no such revision exists, it will return an ErrObjectNotFound error.

func (*Repo) ReadObject

func (repo *Repo) ReadObject(ctx context.Context, oid git.ObjectID) ([]byte, error)

ReadObject reads an object from the repository's object database. InvalidObjectError is returned if the oid does not refer to a valid object.

func (*Repo) ResolveRevision

func (repo *Repo) ResolveRevision(ctx context.Context, revision git.Revision) (git.ObjectID, error)

ResolveRevision resolves the given revision to its object ID. This will not verify whether the target object exists. To do so, you can peel the reference to a given object type, e.g. by passing `refs/heads/master^{commit}`. Returns an ErrReferenceNotFound error in case the revision does not exist.

func (*Repo) SetConfig added in v14.4.0

func (repo *Repo) SetConfig(ctx context.Context, key, value string, txManager transaction.Manager) (returnedErr error)

SetConfig will set a configuration value. Any preexisting values will be overwritten with the new value. The change will use transactional semantics.

func (*Repo) SetDefaultBranch added in v14.7.0

func (repo *Repo) SetDefaultBranch(ctx context.Context, txManager transaction.Manager, reference git.ReferenceName) error

SetDefaultBranch sets the repository's HEAD to point to the given reference. It will not verify the reference actually exists.

func (*Repo) UnsetMatchingConfig added in v14.4.0

func (repo *Repo) UnsetMatchingConfig(
	ctx context.Context,
	regex string,
	txManager transaction.Manager,
) (returnedErr error)

UnsetMatchingConfig removes all config entries whose key match the given regular expression. If no matching keys are found, then this function returns an `git.ErrNotFound` error. The change will use transactional semantics.

func (*Repo) UpdateRef

func (repo *Repo) UpdateRef(ctx context.Context, reference git.ReferenceName, newValue, oldValue git.ObjectID) error

UpdateRef updates reference from oldValue to newValue. If oldValue is a non-empty string, the update will fail it the reference is not currently at that revision. If newValue is the ZeroOID, the reference will be deleted. If oldValue is the ZeroOID, the reference will created.

func (*Repo) WriteBlob

func (repo *Repo) WriteBlob(ctx context.Context, path string, content io.Reader) (git.ObjectID, error)

WriteBlob writes a blob to the repository's object database and returns its object ID. Path is used by git to decide which filters to run on the content.

func (*Repo) WriteTag

func (repo *Repo) WriteTag(
	ctx context.Context,
	objectID git.ObjectID,
	objectType string,
	tagName, tagBody []byte,
	committer *gitalypb.User,
	committerDate time.Time,
) (git.ObjectID, error)

WriteTag writes a tag to the repository's object database with git-mktag and returns its object ID.

It's important that this be git-mktag and not git-hash-object due to its fsck sanity checking semantics.

Jump to

Keyboard shortcuts

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