git2go

package
v14.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LegacyErrPrefixInvalidBranch        = "Invalid branch"
	LegacyErrPrefixInvalidSubmodulePath = "Invalid submodule path"
	LegacyErrPrefixFailedCommit         = "Failed to create commit"
)

Error strings present in the legacy Ruby implementation

View Source
const (
	// MergeRecursionLimit limits how many virtual merge bases are computed
	// in a recursive merge.
	MergeRecursionLimit = 20
)

Variables

View Source
var (
	// ErrInvalidArgument is returned in case the merge arguments are invalid.
	ErrInvalidArgument = errors.New("invalid parameters")

	// BinaryName is a binary name with version suffix .
	BinaryName = rawBinaryName + "-" + version.GetModuleVersion()
)
View Source
var ErrMergeConflict = wrapError{Message: "merge conflict"}

ErrMergeConflict is returned when there is a merge conflict.

Functions

func BinaryPath

func BinaryPath(binaryFolder string) string

BinaryPath returns path to the executable binary.

func SerializableError

func SerializableError(err error) error

SerializableError returns an error that is Gob serializable. Registered types are serialized directly. Unregistered types are transformed in to an opaque error using their error message. Wrapped errors remain unwrappable.

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

Action represents an action taken to build a commit.

type ApplyParams

type ApplyParams struct {
	// Repository is the path to the repository.
	Repository string
	// Committer is the committer applying the patch.
	Committer Signature
	// ParentCommit is the OID of the commit to apply the patches against.
	ParentCommit string
	// Patches iterates over all the patches to be applied.
	Patches PatchIterator
}

ApplyParams are the parameters for Apply.

type ChangeFileMode

type ChangeFileMode struct {

	// Path is the path of the whose mode to change.
	Path string
	// ExecutableMode indicates whether the file mode should be changed to executable or not.
	ExecutableMode bool
	// contains filtered or unexported fields
}

ChangeFileMode sets a file's mode to either regular or executable file. FileNotFoundError is returned when attempting to change a non-existent file's mode.

type CherryPickCommand

type CherryPickCommand struct {
	// Repository is the path where to execute the cherry pick.
	Repository string
	// CommitterName is the committer name for the resulting commit.
	CommitterName string
	// CommitterMail is the committer mail for the resulting commit.
	CommitterMail string
	// CommitterDate is the committer date of revert commit.
	CommitterDate time.Time
	// Message is the message to be used for the resulting commit.
	Message string
	// Ours is the commit that the revert is applied to.
	Ours string
	// Commit is the commit that is to be picked.
	Commit string
	// Mainline is the parent to be considered the mainline
	Mainline uint
}

CherryPickCommand contains parameters to perform a cherry pick.

func (CherryPickCommand) Run

Run performs a cherry pick via gitaly-git2go.

type CommitParams

type CommitParams struct {
	// Repository is the path of the repository to operate on.
	Repository string
	// Author is the author of the commit.
	Author Signature
	// Committer is the committer of the commit.
	Committer Signature
	// Message is message of the commit.
	Message string
	// Parent is the OID of the commit to use as the parent of this commit.
	Parent string
	// Actions are the steps to build the commit.
	Actions []Action
}

CommitParams contains the information and the steps to build a commit.

type Conflict

type Conflict struct {
	// Ancestor is the conflict entry of the merge-base.
	Ancestor ConflictEntry `json:"ancestor"`
	// Our is the conflict entry of ours.
	Our ConflictEntry `json:"our"`
	// Their is the conflict entry of theirs.
	Their ConflictEntry `json:"their"`
	// Content contains the conflicting merge results.
	Content []byte `json:"content"`
}

Conflict represents a merge conflict for a single file.

type ConflictEntry

type ConflictEntry struct {
	// Path is the path of the conflicting file.
	Path string `json:"path"`
	// Mode is the mode of the conflicting file.
	Mode int32 `json:"mode"`
}

ConflictEntry represents a conflict entry which is one of the sides of a conflict.

type ConflictError

type ConflictError struct {
	// Code is the GRPC error code
	Code codes.Code
	// Message is the error message
	Message string
}

type ConflictsCommand

type ConflictsCommand struct {
	// Repository is the path to execute merge in.
	Repository string `json:"repository"`
	// Ours is the commit that is to be merged into theirs.
	Ours string `json:"ours"`
	// Theirs is the commit into which ours is to be merged.
	Theirs string `json:"theirs"`
}

ConflictsCommand contains parameters to perform a merge and return its conflicts.

func ConflictsCommandFromSerialized

func ConflictsCommandFromSerialized(serialized string) (ConflictsCommand, error)

ConflictsCommandFromSerialized constructs a ConflictsCommand from its serialized representation.

func (ConflictsCommand) Run

Run performs a merge via gitaly-git2go and returns all resulting conflicts.

type ConflictsResult

type ConflictsResult struct {
	// Conflicts
	Conflicts []Conflict `json:"conflicts"`
	// Error is an optional conflict error
	Error ConflictError `json:"error"`
}

ConflictsResult contains all conflicts resulting from a merge.

func (ConflictsResult) SerializeTo

func (m ConflictsResult) SerializeTo(writer io.Writer) error

SerializeTo serializes the conflicts result and writes it into the writer.

type CreateDirectory

type CreateDirectory struct {

	// Path is the path of the directory to create.
	Path string
	// contains filtered or unexported fields
}

CreateDirectory creates a directory in the given path with a '.gitkeep' file inside. FileExistsError is returned if a file already exists at the provided path. DirectoryExistsError is returned if a directory already exists at the provided path.

type CreateFile

type CreateFile struct {

	// Path is the path of the file to create.
	Path string
	// ExecutableMode indicates whether the file mode should be executable or not.
	ExecutableMode bool
	// OID is the id of the object that contains the content of the file.
	OID string
	// contains filtered or unexported fields
}

CreateFile creates a file using the provided path, mode and oid as the blob. FileExistsError is returned if a file exists at the given path.

type DeleteFile

type DeleteFile struct {

	// Path is the path of the file to delete.
	Path string
	// contains filtered or unexported fields
}

DeleteFile deletes a file or a directory from the provided path. FileNotFoundError is returned if the file does not exist.

type DirectoryExistsError

type DirectoryExistsError string

DirectoryExistsError is returned when an action attempts to overwrite a directory.

func (DirectoryExistsError) Error

func (err DirectoryExistsError) Error() string

type EmptyError

type EmptyError struct{}

EmptyError indicates the command, for example cherry-pick, did result in no changes, so the result is empty.

func (EmptyError) Error

func (err EmptyError) Error() string

type Executor

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

Executor executes gitaly-git2go.

func New

func New(binaryDirectory, gitBinaryPath string) Executor

New returns a new gitaly-git2go executor using the provided binary.

func (Executor) Apply

func (b Executor) Apply(ctx context.Context, params ApplyParams) (git.ObjectID, error)

Apply applies the provided patches and returns the OID of the commit with the patches applied.

func (Executor) Commit

func (b Executor) Commit(ctx context.Context, params CommitParams) (git.ObjectID, error)

Commit builds a commit from the actions, writes it to the object database and returns its object id.

type FileExistsError

type FileExistsError string

FileExistsError is returned when an action attempts to overwrite an existing file.

func (FileExistsError) Error

func (err FileExistsError) Error() string

type FileNotFoundError

type FileNotFoundError string

FileNotFoundError is returned when an action attempts to operate on a non-existing file.

func (FileNotFoundError) Error

func (err FileNotFoundError) Error() string

type HasConflictsError

type HasConflictsError struct{}

HasConflictsError is used when a change, for example a revert, could not be applied due to a conflict.

func (HasConflictsError) Error

func (err HasConflictsError) Error() string

type IndexError

type IndexError string

IndexError is an error that was produced by performing an invalid operation on the index.

func (IndexError) Error

func (err IndexError) Error() string

Error returns the error message of the index error.

type InvalidArgumentError

type InvalidArgumentError string

InvalidArgumentError is returned when an invalid argument is provided.

func (InvalidArgumentError) Error

func (err InvalidArgumentError) Error() string

type MergeCommand

type MergeCommand struct {
	// Repository is the path to execute merge in.
	Repository string `json:"repository"`
	// AuthorName is the author name of merge commit.
	AuthorName string `json:"author_name"`
	// AuthorMail is the author mail of merge commit.
	AuthorMail string `json:"author_mail"`
	// AuthorDate is the auithor date of merge commit.
	AuthorDate time.Time `json:"author_date"`
	// Message is the message to be used for the merge commit.
	Message string `json:"message"`
	// Ours is the commit that is to be merged into theirs.
	Ours string `json:"ours"`
	// Theirs is the commit into which ours is to be merged.
	Theirs string `json:"theirs"`
	// AllowConflicts controls whether conflicts are allowed. If they are,
	// then conflicts will be committed as part of the result.
	AllowConflicts bool `json:"allow_conflicts"`
}

MergeCommand contains parameters to perform a merge.

func MergeCommandFromSerialized

func MergeCommandFromSerialized(serialized string) (MergeCommand, error)

MergeCommandFromSerialized deserializes the merge request from its JSON representation encoded with base64.

func (MergeCommand) Run

func (m MergeCommand) Run(ctx context.Context, cfg config.Cfg) (MergeResult, error)

Run performs a merge via gitaly-git2go.

type MergeResult

type MergeResult struct {
	// CommitID is the object ID of the generated merge commit.
	CommitID string `json:"commit_id"`
}

MergeResult contains results from a merge.

func (MergeResult) SerializeTo

func (m MergeResult) SerializeTo(w io.Writer) error

SerializeTo serializes the merge result and writes it into the writer.

type MoveFile

type MoveFile struct {

	// Path is the path of the file to move.
	Path string
	// NewPath is the new path of the file.
	NewPath string
	// OID is the id of the object that contains the content of the file. If set,
	// the file contents are updated to match the object, otherwise the file keeps
	// the existing content.
	OID string
	// contains filtered or unexported fields
}

MoveFile moves a file or a directory to the new path. FileNotFoundError is returned if the file does not exist.

type Patch

type Patch struct {
	// Author is the author of the patch.
	Author Signature
	// Message is used as the commit message when applying the patch.
	Message string
	// Diff contains the diff of the patch.
	Diff []byte
}

Patch represents a single patch.

type PatchIterator

type PatchIterator interface {
	// Next returns whether there is a next patch.
	Next() bool
	// Value returns the patch being currently iterated upon.
	Value() Patch
	// Err returns the iteration error. Err should
	// be always checked after Next returns false.
	Err() error
}

PatchIterator iterates over a stream of patches.

func NewSlicePatchIterator

func NewSlicePatchIterator(patches []Patch) PatchIterator

NewSlicePatchIterator returns a PatchIterator that iterates over the slice of patches.

type RebaseCommand

type RebaseCommand struct {
	// Repository is the path to execute rebase in.
	Repository string
	// Committer contains the the committer signature.
	Committer Signature
	// BranchName is the branch that is rebased.
	BranchName string
	// UpstreamRevision is the revision where the branch is rebased onto.
	UpstreamRevision string
}

RebaseCommand contains parameters to rebase a branch.

func (RebaseCommand) Run

func (r RebaseCommand) Run(ctx context.Context, cfg config.Cfg) (git.ObjectID, error)

Run performs the rebase via gitaly-git2go

type ResolveCommand

type ResolveCommand struct {
	MergeCommand
	Resolutions []conflict.Resolution
}

ResolveCommand contains arguments to perform a merge commit and resolve any conflicts produced from that merge commit

func (ResolveCommand) Run

Run will attempt merging and resolving conflicts for the provided request

type ResolveResult

type ResolveResult struct {
	MergeResult
}

ResolveResult returns information about the successful merge and resolution

type Result

type Result struct {
	// CommitID is the result of the call.
	CommitID string
	// Error is set if the call errord.
	Error error
}

Result is the serialized result.

type RevertCommand

type RevertCommand struct {
	// Repository is the path to execute the revert in.
	Repository string `json:"repository"`
	// AuthorName is the author name of revert commit.
	AuthorName string `json:"author_name"`
	// AuthorMail is the author mail of revert commit.
	AuthorMail string `json:"author_mail"`
	// AuthorDate is the author date of revert commit.
	AuthorDate time.Time `json:"author_date"`
	// Message is the message to be used for the revert commit.
	Message string `json:"message"`
	// Ours is the commit that the revert is applied to.
	Ours string `json:"ours"`
	// Revert is the commit to be reverted.
	Revert string `json:"revert"`
	// Mainline is the parent to be considered the mainline
	Mainline uint `json:"mainline"`
}

func (RevertCommand) Run

func (r RevertCommand) Run(ctx context.Context, cfg config.Cfg) (git.ObjectID, error)

type Signature

type Signature struct {
	// Name of the author or the committer.
	Name string
	// Email of the author or the committer.
	Email string
	// When is the time of the commit.
	When time.Time
}

Signature represents a commits signature.

func NewSignature

func NewSignature(name, email string, when time.Time) Signature

NewSignature creates a new sanitized signature.

type SubmoduleCommand

type SubmoduleCommand struct {
	// Repository is the path to commit the submodule change
	Repository string `json:"repository"`

	// AuthorName is the author name of submodule commit.
	AuthorName string `json:"author_name"`
	// AuthorMail is the author mail of submodule commit.
	AuthorMail string `json:"author_mail"`
	// AuthorDate is the auithor date of submodule commit.
	AuthorDate time.Time `json:"author_date"`
	// Message is the message to be used for the submodule commit.
	Message string `json:"message"`

	// CommitSHA is where the submodule should point
	CommitSHA string `json:"commit_sha"`
	// Submodule is the actual submodule string to commit to the tree
	Submodule string `json:"submodule"`
	// Branch where to commit submodule update
	Branch string `json:"branch"`
}

SubmoduleCommand instructs how to commit a submodule update to a repo

func SubmoduleCommandFromSerialized

func SubmoduleCommandFromSerialized(serialized string) (SubmoduleCommand, error)

SubmoduleCommandFromSerialized deserializes the submodule request from its JSON representation encoded with base64.

func (SubmoduleCommand) Run

Run attempts to commit the request submodule change

type SubmoduleResult

type SubmoduleResult struct {
	// CommitID is the object ID of the generated submodule commit.
	CommitID string `json:"commit_id"`
}

SubmoduleResult contains results from a committing a submodule update

func (SubmoduleResult) SerializeTo

func (s SubmoduleResult) SerializeTo(w io.Writer) error

SerializeTo serializes the submodule result and writes it into the writer.

type UpdateFile

type UpdateFile struct {

	// Path is the path of the file to update.
	Path string
	// OID is the id of the object that contains the new content of the file.
	OID string
	// contains filtered or unexported fields
}

UpdateFile updates a file at the given path to point to the provided OID. FileNotFoundError is returned if the file does not exist.

Jump to

Keyboard shortcuts

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