git

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package git contains functions for interacting with Git repositories using the Git CLI. As such, this package requires the Git CLI to be installed on the system.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHeadBranch is returned when a repository's HEAD (aka default) branch cannot
	// be determine
	ErrNoHeadBranch = errors.New("failed to find a head branch, does one exist?")

	// ErrNoRemoteHeadBranch is returned when a repository's remote  default/HEAD branch
	// cannot be determined.
	ErrNoRemoteHeadBranch = errors.New("failed to get head branch from remote origin")
)

This block contains errors and regexes

Functions

func Clone

func Clone(ctx context.Context, ref, url string, optss ...*CloneOptions) (string, error)

Clone clone a git repository to a temporary directory and returns the path to the repository. If ref is empty, the default branch will be used. A shallow clone is performed.

optss is a variadic argument only to avoid a breaking change. Only one option struct is allowed, an error will be returned if more than one is provided.

func GetDefaultBranch

func GetDefaultBranch(ctx context.Context, path string) (string, error)

GetDefaultBranch determines the default/HEAD branch for a given git repository.

func ListRemote

func ListRemote(ctx context.Context, remote string) ([][]string, error)

ListRemote returns a list of all remotes as shown from running 'git ls-remote'.

Types

type CloneOptions added in v0.3.0

type CloneOptions struct {
	// UseArchive fetches the references using a tarball from the
	// underlying VCS provider. This comes with the caveat that the
	// downloaded tarball will not contain the .git directory. However,
	// this can be much faster to download than a full clone.
	//
	// Currently, only Github URLs are supported.
	//
	// If this option fails, a normal clone will be performed without an
	// error.
	UseArchive bool
}

CloneOptions contains options accepted by Clone.

Jump to

Keyboard shortcuts

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