Documentation
¶
Overview ¶
Package cmd facilitates execution of git and git-lfs commands.
Index ¶
- Constants
- Variables
- func CheckGitLFSVersion(ctx context.Context, altExec string) (string, error)
- func CheckGitVersion(ctx context.Context, altExec string) (string, error)
- func CreateFakeLFSFiles(gitDir string, oids map[string]int64) error
- func ResolveLFSOIDPath(oid string) string
- type BadObjectError
- type Commit
- type Git
- type GitOptions
- type Helper
- func (c *Helper) ConfigureLFS(ctx context.Context) error
- func (c *Helper) Dir() string
- func (c *Helper) InitializeRepo(ctx context.Context) error
- func (c *Helper) IsAncestor(ctx context.Context, parent, child Commit) error
- func (c *Helper) ListReachableLFSFiles(ctx context.Context, argRevList []string) ([]string, error)
- func (c *Helper) LocalCommitsRefs(ctx context.Context, argRevList ...string) ([]string, []string, error)
- func (c *Helper) RemoteCommitsRefs(ctx context.Context, remote string, argRevList ...string) ([]string, []string, error)
- func (c *Helper) ValidateVersions(ctx context.Context) error
- type LFS
- type LFSOptions
- type Options
Constants ¶
const BundleSuffix = ".bundle"
BundleSuffix is the git bundle file extension.
const HeadRefPrefix = "refs/heads/"
HeadRefPrefix is the git prefex for head references.
const LFSObjsPath = "lfs/objects" // ignore '.git' dir as we clone with --bare
LFSObjsPath is the relative path to LFS objects.
In a bare repository this is the full path from the top-level directory to the LFS objects sub directory. In a normal repository the '.git' prefix must be added.
const TagRefPrefix = "refs/tags/"
TagRefPrefix is the git prefex for tag references.
Variables ¶
var ErrEmptyBundle = errors.New("refusing to create empty bundle")
ErrEmptyBundle indicates the set of commits resolved by git-rev-list-args is empty.
var ErrLFSCmdNotFound = errors.New("git-lfs command not found")
ErrLFSCmdNotFound indicates that the git-lfs command is not installed.
var ErrLFSNotEnabled = errors.New("repository does not contain git LFS files")
ErrLFSNotEnabled indicates that no LFS files were found.
var ErrNotAncestor = errors.New("parent is not an ancestor of child")
ErrNotAncestor indicates a target commit is not an ancestor (parent) of another.
var ErrRepoNotExistOrPermDenied = errors.New("repository does not exist or insufficient permissions")
ErrRepoNotExistOrPermDenied indicates a remote repository may not exist or user has insufficient permissions.
var ErrTagUpdate = errors.New("updates were rejected because the tag already exists in the remote")
ErrTagUpdate is the error returned when updating an existing git tag fails because it already exists.
Functions ¶
func CheckGitLFSVersion ¶
CheckGitLFSVersion gets and validates a user's git lfs version.
func CheckGitVersion ¶
CheckGitVersion gets and validates a user's git version.
func CreateFakeLFSFiles ¶
CreateFakeLFSFiles initializes placeholder LFS files with the same size as the original, tricking git-lfs to believe the files already exsits, causing git-lfs to skip the transfer of those files.
func ResolveLFSOIDPath ¶
ResolveLFSOIDPath resolves a relative path to an lfs object: `lfs/objects/ab/bc/abcdef...`
TODO: Do we need to support an alternative lfs objects path?
Types ¶
type BadObjectError ¶
type BadObjectError struct {
// contains filtered or unexported fields
}
BadObjectError indicates a git object does not exist.
func (*BadObjectError) Error ¶
func (e *BadObjectError) Error() string
Error returns the original error.
func (*BadObjectError) Object ¶
func (e *BadObjectError) Object() Commit
Object returns the bad object hash, as extracted from the original error.
type Git ¶
type Git interface {
Init(ctx context.Context, args ...string) error
Config(ctx context.Context, args ...string) error
Push(ctx context.Context, gitRemote string, refs ...string) error
Fetch(ctx context.Context, args ...string) error
BundleCreate(ctx context.Context, destFile string, revList []string) error
ShowRefs(ctx context.Context, refs ...string) ([]string, error)
UpdateRef(ctx context.Context, ref string, commit string) error
RemoteAdd(ctx context.Context, shortname, remoteTarget string) error
RemoteRemove(ctx context.Context, shortname string) error
LSRemote(ctx context.Context, args ...string) ([]string, error)
MergeBase(ctx context.Context, args ...string) ([]string, error)
CatFile(ctx context.Context, args ...string) error
Run(ctx context.Context, subCmd string, args ...string) ([]string, error)
Tag(ctx context.Context, args ...string) ([]string, error)
}
Git provides access to git commands.
type GitOptions ¶
GitOptions modify the execution of git commands.
type Helper ¶
Helper assists in running git and git-lfs commands. Its methods often combine and parse git or git-lfs commands to determine information about a repository's state.
func NewHelper ¶
NewHelper returns a cmdHelper object used for running git and git-lfs commands. It validates the compatibility of git and git-lfs. Displays a warning if git-lfs is not installed.
func (*Helper) ConfigureLFS ¶
ConfigureLFS configures the git repository lfs options.
func (*Helper) InitializeRepo ¶
InitializeRepo initializes the temporary directory as an empty bare git repository. This repository functions as an intermediate repo of which changes are collected/applied and then handled accordingly.
func (*Helper) IsAncestor ¶
IsAncestor returns nil if the parent commit is an ancestor of the child commit, ErrNotAncestor if not, and the original git error if one occurs.
func (*Helper) ListReachableLFSFiles ¶
ListReachableLFSFiles lists all git lfs tracked files reachable from argRevList, returning a slice of lfs OIDs.
TODO: This is a very expensive operation.
func (*Helper) LocalCommitsRefs ¶
func (c *Helper) LocalCommitsRefs(ctx context.Context, argRevList ...string) ([]string, []string, error)
LocalCommitsRefs returns the local references and the commits they reference split into two slices, with indicies matching the pairs. If argRevList is empty all references will be returned.
func (*Helper) RemoteCommitsRefs ¶
func (c *Helper) RemoteCommitsRefs(ctx context.Context, remote string, argRevList ...string) ([]string, []string, error)
RemoteCommitsRefs returns the remote references and the commits they reference split into two slices, with indicies matching the pairs. If argRevList is empty all references will be returned.
type LFS ¶
type LFS interface {
Version(ctx context.Context) (string, error)
Track(ctx context.Context, pattern string) error
Fetch(ctx context.Context, gitRemote string, argRevList ...string) error
Push(ctx context.Context, gitRemote string, argRevList ...string) error
LSFiles(ctx context.Context, args ...string) ([]string, error)
Run(ctx context.Context, subCmd string, args ...string) ([]string, error)
}
LFS provides access to git-lfs commands.
type LFSOptions ¶
type LFSOptions struct {
WithLFS bool // will be overridden if git-lfs command is not found.
AltLFSExec string
ServerURL string
}
LFSOptions modify the execution of git-lfs commands.
type Options ¶
type Options struct {
GitOptions
*LFSOptions
}
Options modifies the execution of git and git-lfs commands.