Documentation ¶
Overview ¶
Package git provides an abstraction over github.com/go-git/go-git/v5 to make it easy to mock out remote git operations in tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrRepositoryAlreadyExists = git.ErrRepositoryAlreadyExists ErrRepositoryNotExists = git.ErrRepositoryNotExists NoErrAlreadyUpToDate = git.NoErrAlreadyUpToDate )
Errors are aliased from go-git to avoid importing it just for error checks.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Clone a repository at url into localPath. The clone is performed // non-bare, so the repository will have a worktree. If the local path is // not empty ErrRepositoryAlreadyExists is returned. Clone(ctx context.Context, url, localPath string) (Repository, error) // Open opens a repository from the given path. It detects if the // repository is bare or a normal one. If the path doesn't contain a valid // repository ErrRepositoryNotExists is returned. Open(path string) (Repository, error) // Init creates an empty non-bare git repository at the given path. // Non-bare means that the repository will have worktree. If the path is // not empty ErrRepositoryAlreadyExists is returned. Init(path string) (Repository, error) }
Client is the interface for a client that can perform actions on git repositories.
type FakeClient ¶
FakeClient is a fake git client with can be used in tests.
func (*FakeClient) Clone ¶
func (c *FakeClient) Clone(ctx context.Context, url, localPath string) (Repository, error)
Clone implements Client.
func (*FakeClient) Init ¶
func (c *FakeClient) Init(path string) (Repository, error)
Init implements Client.
func (*FakeClient) Open ¶
func (c *FakeClient) Open(path string) (Repository, error)
Open implements Client.
type FakeRepository ¶
FakeRepository is a fake git repository which can be used in tests.
func (*FakeRepository) Checkout ¶
func (r *FakeRepository) Checkout(hash plumbing.Hash) error
Checkout implements Repository.
func (*FakeRepository) ResolveRevision ¶
ResolveRevision implements Repository.
type Repository ¶
type Repository interface { // Fetch fetches references along with the objects necessary to complete // their histories, from the remote named origin. // // Returns nil if the operation is successful, NoErrAlreadyUpToDate if // there are no changes to be fetched, or an error. Fetch(ctx context.Context, refSpecs ...config.RefSpec) error // ResolveRevision resolves revision to corresponding hash. It will always // resolve to a commit hash, not a tree or annotated tag. ResolveRevision(revision plumbing.Revision) (*plumbing.Hash, error) // Checkout checks out the commit referenced by the provided hash. The // checkout is performed in force mode to throw away local changes. Checkout(hash plumbing.Hash) error }
Repository is the interface for a git repository.
func NewRepository ¶
func NewRepository(repo *git.Repository) Repository
NewRepository creates a new Repository from given go-git repository.