Documentation
¶
Index ¶
- Constants
- Variables
- func GetBranchNameForPR(ref string) string
- func GetDefaultExtraEnv(strictHostKeyChecking bool) []string
- func GetIDForPR(ref string) string
- func InstallBinary(ctx context.Context) error
- func InstallLFS(ctx context.Context) error
- func PingRepository(str string, extraEnv []string) bool
- type CloneStrategy
- type CommandError
- type Config
- func (c *Config) Add(ctx context.Context, key, value string, scope ConfigScope) error
- func (c *Config) Get(ctx context.Context, key string, scope ConfigScope) (string, error)
- func (c *Config) GetAll(ctx context.Context, key string, scope ConfigScope) ([]string, error)
- func (c *Config) Set(ctx context.Context, key, value string, scope ConfigScope) error
- func (c *Config) Unset(ctx context.Context, key string, scope ConfigScope) error
- func (c *Config) UnsetAll(ctx context.Context, key string, scope ConfigScope) error
- type ConfigScope
- type GitInfo
- type Host
- type Installer
- type LFSMode
- type Option
- type Repo
- func (r *Repo) CheckoutPR(ctx context.Context, repoURL, prRef string) error
- func (r *Repo) Clone(ctx context.Context, repository string, options ...Option) error
- func (r *Repo) CloneFromInfo(ctx context.Context, gitInfo *GitInfo, helper string, options ...Option) error
- func (r *Repo) Config() *Config
- func (r *Repo) CredentialFill(ctx context.Context, request string) (string, error)
- func (r *Repo) Fetch(ctx context.Context, refspec string) error
- func (r *Repo) LsRemote(ctx context.Context, repository string) error
- func (r *Repo) LsTree(ctx context.Context, ref string) ([]string, error)
- func (r *Repo) Path() string
- func (r *Repo) Reset(ctx context.Context, commit string, mode ResetMode) error
- func (r *Repo) SetupLFS(ctx context.Context, mode LFSMode)
- func (r *Repo) Switch(ctx context.Context, branch string) error
- type RepoOption
- type ResetMode
- type RunOptions
- type RunResult
- type Runner
Constants ¶
const ( CommitDelimiter string = "@sha256:" PullRequestReference string = "(?:pull|merge-requests)/([0-9]+)/head" SubPathDelimiter string = "@subpath:" )
Variables ¶
var ( ScopeDefault = ConfigScope{} ScopeLocal = ConfigScope{/* contains filtered or unexported fields */} ScopeGlobal = ConfigScope{/* contains filtered or unexported fields */} ScopeSystem = ConfigScope{/* contains filtered or unexported fields */} )
var ( HostGitHub = Host{ Name: hostNameGitHub, // contains filtered or unexported fields } HostGitLab = Host{ Name: hostNameGitLab, // contains filtered or unexported fields } )
var ErrGitNotFound = errors.New("git binary not found in PATH")
ErrGitNotFound is returned when the git binary is not available on PATH.
Functions ¶
func GetBranchNameForPR ¶
GetBranchNameForPR returns the local branch name for a request ref, using the provider convention encoded in the ref (PR<n> for GitHub, MR<n> for GitLab).
func GetDefaultExtraEnv ¶
func GetIDForPR ¶
GetIDForPR returns the lowercased request identifier used in workspace IDs.
func InstallBinary ¶
InstallBinary installs the git binary if it is not already available, using a system package manager.
func InstallLFS ¶ added in v1.4.1
InstallLFS installs the git-lfs binary if it is not already available.
func PingRepository ¶
Types ¶
type CloneStrategy ¶
type CloneStrategy string
CloneStrategy selects how much history and object data a clone fetches.
const ( FullCloneStrategy CloneStrategy = "" BloblessCloneStrategy CloneStrategy = "blobless" TreelessCloneStrategy CloneStrategy = "treeless" ShallowCloneStrategy CloneStrategy = "shallow" BareCloneStrategy CloneStrategy = "bare" )
func (*CloneStrategy) Set ¶
func (s *CloneStrategy) Set(v string) error
func (*CloneStrategy) String ¶
func (s *CloneStrategy) String() string
func (*CloneStrategy) Type ¶
func (s *CloneStrategy) Type() string
type CommandError ¶ added in v1.4.1
CommandError describes a failed git invocation.
func (*CommandError) Error ¶ added in v1.4.1
func (e *CommandError) Error() string
func (*CommandError) Unwrap ¶ added in v1.4.1
func (e *CommandError) Unwrap() error
type Config ¶ added in v1.4.1
type Config struct {
// contains filtered or unexported fields
}
Config exposes `git config` operations scoped to a repository. Obtain one via Repo.Config.
func (*Config) Get ¶ added in v1.4.1
Get retrieves the value of a config key in the given scope. An absent key is not an error: it returns ("", nil).
func (*Config) GetAll ¶ added in v1.4.1
GetAll retrieves all values of a multi-valued config key in the given scope. An absent key is not an error: it returns (nil, nil).
func (*Config) Set ¶ added in v1.4.1
Set sets a config key to value in the given scope, replacing any existing value.
type ConfigScope ¶ added in v1.4.1
type ConfigScope struct {
// contains filtered or unexported fields
}
ConfigScope selects which git configuration file an operation targets.
func ScopeFile ¶ added in v1.4.1
func ScopeFile(path string) ConfigScope
ScopeFile targets a specific config file.
type GitInfo ¶
GitInfo is the parsed form of a repository reference. Branch, Commit, PR, and SubPath are independent: a reference can carry zero or more of them. PR is exclusive with Branch and Commit.
func NormalizeRepository ¶
NormalizeRepository parses a repository reference into its structured parts. Accepts plain URLs, the "git:<url>" workspace-source scheme, and references suffixed with @branch, @subpath:<path>, @sha256:<commit>, or a pull/merge request ref (@pull/N/head or @merge-requests/N/head). Bare host[/path] inputs are upgraded to https://.
type Host ¶
type Host struct {
Name string
// contains filtered or unexported fields
}
Host is a git provider's convention for referencing pull/merge requests: GitHub exposes them at pull/N/head, GitLab at merge-requests/N/head.
func DetectHost ¶
DetectHost picks the provider from a repository URL, defaulting to GitHub.
func (Host) BranchName ¶
type Installer ¶ added in v1.4.1
type Installer struct {
// contains filtered or unexported fields
}
Installer installs git-related tools using an ordered list of strategies.
type LFSMode ¶ added in v1.4.1
type LFSMode int
LFSMode controls how Git LFS is handled after a clone.
const ( // LFSFull registers the LFS filters and downloads LFS content. This matches // git's default clone behavior and is the zero value. LFSFull LFSMode = iota // LFSSetupOnly registers the LFS filters but does not download content, // leaving pointer stubs. Future checkouts/pulls will hydrate on demand. LFSSetupOnly // LFSSkip does nothing: no filters, no download. LFSSkip )
type Option ¶
type Option func(*cloneConfig)
Option configures a clone performed by Repo.Clone or Repo.CloneFromInfo.
func WithBranch ¶ added in v1.4.1
WithBranch clones only the named branch.
func WithCloneStrategy ¶
func WithCloneStrategy(strategy CloneStrategy) Option
WithCloneStrategy selects the clone strategy. An empty strategy is treated as FullCloneStrategy.
func WithCredentialHelper ¶ added in v1.4.1
WithCredentialHelper configures a git credential helper for the clone.
func WithLFSMode ¶ added in v1.4.1
WithLFSMode selects how Git LFS is handled after the clone. The default is LFSFull.
func WithRecursiveSubmodules ¶
func WithRecursiveSubmodules() Option
WithRecursiveSubmodules clones submodules recursively.
func WithSkipLFS ¶
func WithSkipLFS() Option
WithSkipLFS disables Git LFS smudge and hydration for the clone. Equivalent to WithLFSMode(LFSSkip).
type Repo ¶ added in v1.4.1
type Repo struct {
// contains filtered or unexported fields
}
Repo is a handle to a git repository at a filesystem path.
func At ¶ added in v1.4.1
func At(path string, opts ...RepoOption) *Repo
At returns a Repo rooted at path.
func (*Repo) CheckoutPR ¶ added in v1.4.1
CheckoutPR fetches a pull/merge request into a local branch and switches to it. The request number is taken from prRef; the remote refspec is resolved against repoURL's hosting provider, falling back to the other known conventions when the detected one has no such ref (e.g. self-hosted GitLab on a custom domain that URL detection can't recognize).
func (*Repo) Clone ¶ added in v1.4.1
Clone clones repository into the repo's path using the given options.
func (*Repo) CloneFromInfo ¶ added in v1.4.1
func (r *Repo) CloneFromInfo( ctx context.Context, gitInfo *GitInfo, helper string, options ...Option, ) error
CloneFromInfo clones the repository described by gitInfo into the repo's path, using the given credential helper and options.
func (*Repo) Config ¶ added in v1.4.1
Config returns a handle for `git config` operations on the repository.
func (*Repo) CredentialFill ¶ added in v1.4.1
CredentialFill runs `git credential fill`, feeding request on stdin and returning git's response. Used to resolve credentials via configured helpers.
func (*Repo) LsRemote ¶ added in v1.4.1
LsRemote reports whether the remote repository is reachable.
func (*Repo) LsTree ¶ added in v1.4.1
LsTree lists the files tracked at ref, recursively, as repo-relative paths.
type RepoOption ¶ added in v1.4.1
type RepoOption func(*Repo)
RepoOption configures a Repo.
func WithEnv ¶ added in v1.4.1
func WithEnv(env []string) RepoOption
WithEnv appends extra environment entries applied to every operation.
func WithRunner ¶ added in v1.4.1
func WithRunner(runner Runner) RepoOption
WithRunner injects a command Runner, primarily for testing.
func WithStrictHostKeyChecking ¶ added in v1.4.1
func WithStrictHostKeyChecking(strict bool) RepoOption
WithStrictHostKeyChecking appends the default SSH/terminal environment honoring the given policy.
type ResetMode ¶ added in v1.4.1
type ResetMode string
ResetMode selects how Reset updates the index and working tree.
type RunOptions ¶ added in v1.4.1
type RunOptions struct {
Binary string
Dir string
Env []string
Args []string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
RunOptions describes one command invocation.