updateref

package
v15.11.13 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlreadyLockedError added in v15.11.0

type AlreadyLockedError struct {
	Ref string
}

AlreadyLockedError indicates a reference cannot be locked because another process has already locked it.

func (*AlreadyLockedError) Error added in v15.11.0

func (e *AlreadyLockedError) Error() string

type CustomHookError

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

CustomHookError contains an error message when executing a custom hook.

func (CustomHookError) Error

func (e CustomHookError) Error() string

Error returns an error message.

func (CustomHookError) Proto

Proto returns the Protobuf representation of this error.

func (CustomHookError) Unwrap

func (e CustomHookError) Unwrap() error

Unwrap will return the embedded error.

type Error

type Error struct {
	// Reference is the name of the reference that would have been updated.
	Reference git.ReferenceName
	// OldOID and NewOID are the expected object IDs previous to and after the update if it
	// would have succeeded.
	OldOID, NewOID git.ObjectID
}

Error reports an error in git update-ref

func (Error) Error

func (e Error) Error() string

type FileDirectoryConflictError added in v15.11.0

type FileDirectoryConflictError struct {
	// ConflictingReferenceName is the name of the reference that would have conflicted.
	ConflictingReferenceName string
	// ExistingReferenceName is the name of the already existing reference.
	ExistingReferenceName string
}

FileDirectoryConflictError is returned when an operation would causes a file-directory conflict in the reference store.

func (FileDirectoryConflictError) Error added in v15.11.0

type InTransactionConflictError added in v15.11.0

type InTransactionConflictError struct {
	// FirstReferenceName is the name of the first reference that was modified.
	FirstReferenceName string
	// SecondReferenceName is the name of the second reference that was modified.
	SecondReferenceName string
}

InTransactionConflictError is returned when attempting to modify two references in the same transaction in a manner that is not allowed. For example, modifying 'refs/heads/parent' and creating 'refs/heads/parent/child' is not allowed.

func (InTransactionConflictError) Error added in v15.11.0

type InvalidReferenceFormatError added in v15.11.0

type InvalidReferenceFormatError struct {
	// ReferenceName is the invalid reference name.
	ReferenceName string
}

InvalidReferenceFormatError indicates a reference name was invalid.

func (InvalidReferenceFormatError) Error added in v15.11.0

type NonCommitObjectError added in v15.7.0

type NonCommitObjectError struct {
	// ReferenceName is the name of the branch that was being updated.
	ReferenceName string
	// ObjectID is the object ID of the non-commit object.
	ObjectID string
}

NonCommitObjectError is returned when attempting to point a branch to an object that is not an object.

func (NonCommitObjectError) Error added in v15.7.0

func (e NonCommitObjectError) Error() string

type NonExistentObjectError added in v15.7.0

type NonExistentObjectError struct {
	// ReferenceName is the name of the reference that was being updated.
	ReferenceName string
	// ObjectID is the object ID of the non-existent object.
	ObjectID string
}

NonExistentObjectError is returned when attempting to point a reference to an object that does not exist in the object database.

func (NonExistentObjectError) Error added in v15.7.0

func (e NonExistentObjectError) Error() string

type Updater

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

Updater wraps a `git update-ref --stdin` process, presenting an interface that allows references to be easily updated in bulk. It is not suitable for concurrent use.

Correct usage of the Updater is as follows:

  1. Transaction must be started before anything else.
  2. Transaction can't be started if there is an active transaction.
  3. Updates can be staged only when there is an unprepared transaction.
  4. Prepare can be called only with an unprepared transaction.
  5. Commit can be called only with an active transaction. The transaction can be committed unprepared or prepared.
  6. Close can be called at any time. The active transaction is aborted.
  7. Any sort of error causes the updater to close.

func New

func New(ctx context.Context, repo git.RepositoryExecutor, opts ...UpdaterOpt) (*Updater, error)

New returns a new bulk updater, wrapping a `git update-ref` process. Call the various methods to enqueue updates, then call Commit() to attempt to apply all the updates at once.

It is important that ctx gets canceled somewhere. If it doesn't, the process spawned by New() may never terminate.

func (*Updater) Close added in v15.7.0

func (u *Updater) Close() error

Close closes the updater and aborts a possible open transaction. No changes will be written to disk, all lockfiles will be cleaned up and the process will exit.

func (*Updater) Commit

func (u *Updater) Commit() error

Commit applies the commands specified in other calls to the Updater. Commit finishes the reference transaction and another one must be started before further changes can be staged.

func (*Updater) Create

func (u *Updater) Create(reference git.ReferenceName, oid git.ObjectID) error

Create commands the reference to be created with the given object ID. The ref must not exist.

A reference transaction must be started before calling Create.

func (*Updater) Delete

func (u *Updater) Delete(reference git.ReferenceName) error

Delete commands the reference to be removed from the repository. This command will ignore any old state of the reference and just force-remove it.

A reference transaction must be started before calling Delete.

func (*Updater) Prepare

func (u *Updater) Prepare() error

Prepare prepares the reference transaction by locking all references and determining their current values. The updates are not yet committed and will be rolled back in case there is no call to `Commit()`. This call is optional.

func (*Updater) Start added in v15.7.0

func (u *Updater) Start() error

Start begins a new reference transaction. The reference changes are not perfromed until Commit is explicitly called.

func (*Updater) Update

func (u *Updater) Update(reference git.ReferenceName, newOID, oldOID git.ObjectID) error

Update commands the reference to be updated to point at the object ID specified in newOID. If newOID is the zero OID, then the branch will be deleted. If oldOID is a non-empty string, then the reference will only be updated if its current value matches the old value. If the old value is the zero OID, then the branch must not exist.

A reference transaction must be started before calling Update.

type UpdaterOpt

type UpdaterOpt func(*updaterConfig)

UpdaterOpt is a type representing options for the Updater.

func WithDisabledTransactions

func WithDisabledTransactions() UpdaterOpt

WithDisabledTransactions disables hooks such that no reference-transactions are used for the updater.

func WithNoDeref added in v15.7.0

func WithNoDeref() UpdaterOpt

WithNoDeref disables de-reference while updating ref. If this option is turned on, <ref> itself is overwritten, rather than the result of following the symbolic ref.

type UpdaterWithHooks

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

UpdaterWithHooks updates a ref with Git hooks.

func NewUpdaterWithHooks

func NewUpdaterWithHooks(
	cfg config.Cfg,
	locator storage.Locator,
	hookManager hook.Manager,
	gitCmdFactory git.CommandFactory,
	catfileCache catfile.Cache,
) *UpdaterWithHooks

NewUpdaterWithHooks creates a new instance of a struct that will update a Git reference.

func (*UpdaterWithHooks) UpdateReference

func (u *UpdaterWithHooks) UpdateReference(
	ctx context.Context,
	repoProto *gitalypb.Repository,
	user *gitalypb.User,
	quarantineDir *quarantine.Dir,
	reference git.ReferenceName,
	newrev, oldrev git.ObjectID,
	pushOptions ...string,
) error

UpdateReference updates a branch with a given commit ID using the Git hooks. If a quarantine directory is given, then the pre-receive, update and reference-transaction hook will be invoked with the quarantined repository as returned by the quarantine structure. If these hooks succeed, quarantined objects will be migrated and all subsequent hooks are executed via the unquarantined repository.

Jump to

Keyboard shortcuts

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