cmd

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cmd facilitates execution of git and git-lfs commands.

Index

Constants

View Source
const BundleSuffix = ".bundle"

BundleSuffix is the git bundle file extension.

View Source
const HeadRefPrefix = "refs/heads/"

HeadRefPrefix is the git prefex for head references.

View Source
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.

View Source
const TagRefPrefix = "refs/tags/"

TagRefPrefix is the git prefex for tag references.

Variables

View Source
var ErrEmptyBundle = errors.New("refusing to create empty bundle")

ErrEmptyBundle indicates the set of commits resolved by git-rev-list-args is empty.

View Source
var ErrLFSCmdNotFound = errors.New("git-lfs command not found")

ErrLFSCmdNotFound indicates that the git-lfs command is not installed.

View Source
var ErrLFSNotEnabled = errors.New("repository does not contain git LFS files")

ErrLFSNotEnabled indicates that no LFS files were found.

View Source
var ErrNotAncestor = errors.New("parent is not an ancestor of child")

ErrNotAncestor indicates a target commit is not an ancestor (parent) of another.

View Source
var ErrRepoNotExistOrPermDenied = errors.New("repository does not exist or insufficient permissions")

ErrRepoNotExistOrPermDenied indicates a remote repository may not exist or user has insufficient permissions.

View Source
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

func CheckGitLFSVersion(ctx context.Context, altExec string) (string, error)

CheckGitLFSVersion gets and validates a user's git lfs version.

func CheckGitVersion

func CheckGitVersion(ctx context.Context, altExec string) (string, error)

CheckGitVersion gets and validates a user's git version.

func CreateFakeLFSFiles

func CreateFakeLFSFiles(gitDir string, oids map[string]int64) error

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

func ResolveLFSOIDPath(oid string) string

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 Commit

type Commit string

Commit represents a git commit OID.

type Git

type Git interface {
	Init(ctx context.Context, args ...string) error
	CloneWithShared(ctx context.Context, gitRemote, reference 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

type GitOptions struct {
	Force      bool
	AltGitExec string
}

GitOptions modify the execution of git commands.

type Helper

type Helper struct {
	Options
	Git
	LFS
	// contains filtered or unexported fields
}

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

func NewHelper(ctx context.Context, gitDir string, opts *Options) (*Helper, error)

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

func (c *Helper) ConfigureLFS(ctx context.Context) error

ConfigureLFS configures the git repository lfs options.

func (*Helper) Dir

func (c *Helper) Dir() string

Dir returns the path of the git directory.

func (*Helper) InitializeRepo

func (c *Helper) InitializeRepo(ctx context.Context) error

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

func (c *Helper) IsAncestor(ctx context.Context, parent, child Commit) error

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

func (c *Helper) ListReachableLFSFiles(ctx context.Context, argRevList []string) ([]string, error)

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.

func (*Helper) ValidateVersions

func (c *Helper) ValidateVersions(ctx context.Context) error

ValidateVersions checks if installed git and git-lfs versions meet minimum requirements.

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.

Jump to

Keyboard shortcuts

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