updateref

package
v16.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlreadyLockedError

type AlreadyLockedError struct {
	// ReferenceName is the name of the reference that is already locked.
	ReferenceName string
}

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

func (AlreadyLockedError) Error

func (e AlreadyLockedError) Error() string

func (AlreadyLockedError) ErrorMetadata added in v16.2.0

func (e AlreadyLockedError) ErrorMetadata() []structerr.MetadataItem

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the name of the reference that was locked already.

type FileDirectoryConflictError

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

func (FileDirectoryConflictError) ErrorMetadata added in v16.2.0

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the name of preexisting and conflicting reference names.

type InTransactionConflictError

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

func (InTransactionConflictError) ErrorMetadata added in v16.2.0

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the name of the first and second conflicting reference names.

type InvalidReferenceFormatError

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

InvalidReferenceFormatError indicates a reference name was invalid.

func (InvalidReferenceFormatError) Error

func (InvalidReferenceFormatError) ErrorMetadata added in v16.2.0

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the name of the reference that was invalid.

type MismatchingStateError added in v16.2.0

type MismatchingStateError struct {
	// ReferenceName is the name of the reference that was being updated.
	ReferenceName string
	// ExpectedObjectID is the expected object ID as specified by the caller.
	ExpectedObjectID string
	// ActualObjectID is the actual object ID that the reference was pointing to.
	ActualObjectID string
}

MismatchingStateError is returned when attempting to update a reference where the expected object ID does not match the actual object ID that the reference currently points to.

func (MismatchingStateError) Error added in v16.2.0

func (e MismatchingStateError) Error() string

func (MismatchingStateError) ErrorMetadata added in v16.2.0

func (e MismatchingStateError) ErrorMetadata() []structerr.MetadataItem

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides error metadata about the expected and actual object ID of the failed reference update.

type NonCommitObjectError

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

func (e NonCommitObjectError) Error() string

func (NonCommitObjectError) ErrorMetadata added in v16.2.0

func (e NonCommitObjectError) ErrorMetadata() []structerr.MetadataItem

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the object that is not a commit as well as the reference that should have been updated to point to it.

type NonExistentObjectError

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

func (e NonExistentObjectError) Error() string

func (NonExistentObjectError) ErrorMetadata added in v16.2.0

func (e NonExistentObjectError) ErrorMetadata() []structerr.MetadataItem

ErrorMetadata implements the `structerr.ErrorMetadater` interface and provides the missing object as well as the reference that should have been updated to point to it.

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

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

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

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.

Jump to

Keyboard shortcuts

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