repository

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

View Source
const (
	DefaultRemote            = "origin"
	DefaultBranch            = "master"
	DefaultPublicKeyAuthUser = "git"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckoutStrategy

type CheckoutStrategy struct {
	// Branch to checkout. If supported by the client, it can be combined
	// with Commit.
	Branch string

	// Tag to checkout, takes precedence over Branch.
	Tag string

	// SemVer tag expression to checkout, takes precedence over Branch and Tag.
	SemVer string `json:"semver,omitempty"`

	// RefName is the reference to checkout to. It must conform to the
	// Git reference format: https://git-scm.com/book/en/v2/Git-Internals-Git-References
	// Examples: "refs/heads/main", "refs/pull/420/head", "refs/tags/v0.1.0"
	// It takes precedence over Branch, Tag and SemVer.
	RefName string

	// Commit SHA1 to checkout, takes precedence over all the other options.
	// If supported by the client, it can be combined with Branch.
	Commit string
}

CheckoutStrategy provides options to checkout a repository to a target.

type Client

type Client interface {
	Reader
	Writer
}

Client knows how to perform local and remote operations on a Git repository.

type CloneConfig added in v0.12.0

type CloneConfig struct {
	// CheckoutStrategy defines a strategy to use while checking out
	// the cloned repository to a specific target.
	CheckoutStrategy

	// RecurseSubmodules defines if submodules should be checked out,
	// not supported by all Implementations.
	RecurseSubmodules bool

	// LastObservedCommit holds the last observed commit hash of a
	// Git repository.
	// If provided, the clone operation will compare it with the HEAD commit
	// of the branch or tag (as configured via CheckoutStrategy) in the remote
	// repository. If they match, cloning will be skipped and a "non-concrete"
	// commit will be returned, which can be verified using `IsConcreteCommit()`.
	// This functionality is not supported when using a semver range or a commit
	// to checkout.
	LastObservedCommit string

	// ShallowClone defines if the repository should be shallow cloned,
	// not supported by all implementations
	ShallowClone bool

	// SparseCheckoutDirectories defines a list of directories to sparse-checkout
	// when cloning the repository. If provided, only listed directories are checked out.
	SparseCheckoutDirectories []string
}

CloneConfig provides configuration options for a Git clone.

type Closer

type Closer interface {
	// Close closes any resources that need to be closed at the end of
	// a Git repository client's lifecycle.
	Close()
}

Closer knows how to perform any operations that need to happen at the end of the lifecycle of a Writer/Reader. When this is not required by the implementation, it can simply embed an anonymous pointer to DiscardCloser.

type CommitOption

type CommitOption func(*CommitOptions)

CommitOption defines an option for a commit operation.

func WithFiles

func WithFiles(files map[string]io.Reader) CommitOption

WithFiles instructs the Git client to write the provided files and include them in the commit. files contains file names as its key and the content of the file as the value. If the file already exists, its overwritten.

func WithSigner

func WithSigner(signer *openpgp.Entity) CommitOption

WithSigner allows for the commit to be signed using the provided OpenPGP signer.

type CommitOptions

type CommitOptions struct {
	// Signer can be used to sign a commit using OpenPGP.
	Signer *openpgp.Entity
	// Files contains file names mapped to the file's content.
	// Its used to write files which are then included in the commit.
	Files map[string]io.Reader
}

CommitOptions provides options to configure a Git commit operation.

type DiscardCloser

type DiscardCloser struct{}

DiscardCloser is a Closer which discards calls to Close().

func (*DiscardCloser) Close

func (c *DiscardCloser) Close()

type PushConfig added in v0.12.0

type PushConfig struct {
	// Refspecs is a list of refspecs to use for the push operation.
	// For details about Git Refspecs, please see:
	// https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
	Refspecs []string

	// Force, if set to true, will result in a force push.
	Force bool

	// Options is a map specifying the push options that are sent
	// to the Git server when performing a push option. For details, see:
	// https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt
	Options map[string]string
}

PushConfig provides configuration options for a Git push.

type Reader

type Reader interface {
	// Clone clones a repository from the provided url using the config provided.
	// It returns a Commit object describing the Git commit that the repository
	// HEAD points to. If the repository is empty, it returns a nil Commit.
	Clone(ctx context.Context, url string, cfg CloneConfig) (*git.Commit, error)
	// IsClean returns whether the working tree is clean.
	IsClean() (bool, error)
	// Head returns the hash of the current HEAD of the repo.
	Head() (string, error)
	// Path returns the path of the repository.
	Path() string
	Closer
}

Reader knows how to perform local and remote read operations on a Git repository.

type Writer

type Writer interface {
	// Init initializes a repository at the configured path with the remote
	// origin set to url on the provided branch.
	Init(ctx context.Context, url, branch string) error
	// Push performs a Git push to origin. By default, it pushes the
	// reference pointed to by the HEAD, to its equivalent destination at
	// the origin, but this is configurable via PushConfig.
	Push(ctx context.Context, cfg PushConfig) error
	// SwitchBranch switches from the current branch of the repository to the
	// provided branch. If the branch doesn't exist, it is created.
	SwitchBranch(ctx context.Context, branch string) error
	// Commit commits any changes made to the repository. commitOpts is an
	// optional argument which can be provided to configure the commit.
	Commit(info git.Commit, commitOpts ...CommitOption) (string, error)
	Closer
}

Writer knows how to perform local and remote write operations on a Git repository.

Jump to

Keyboard shortcuts

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