Documentation
¶
Overview ¶
Package vcslocator offers functions and tools to parse SPDX VCS locator strings and access data referenced by them.
Index ¶
- Constants
- func CloneRepository[T ~string](locator T, funcs ...fnOpt) (fs.FS, error)
- func CopyFile[T ~string](locator T, w io.Writer, funcs ...fnOpt) error
- func CopyFileGroup[T ~string](locators []T, writers []io.Writer, funcs ...fnOpt) error
- func Download[T ~string](locator T, localDir string, funcs ...fnOpt) error
- func GetAuthMethod[T ~string](locator T, funcs ...fnOpt) (transport.AuthMethod, error)
- func GetGroup[T ~string](locators []T) ([][]byte, error)
- func WithClonePath(path string) fnOpt
- func WithHttpAuth(user, password string) fnOpt
- func WithRefAsBranch(sino bool) fnOpt
- func WithSystemCredentials(yesno bool) fnOpt
- func WithTopLevelPath(path string) fnOpt
- type Components
- type ErrorList
- type Locator
Constants ¶
const ( // Supported transport strings TransportSSH = "ssh" TransportHTTPS = "https" TransportFile = "file" ToolGit = "git" )
Variables ¶
This section is empty.
Functions ¶
func CloneRepository ¶
CloneRepository clones the repository defined by the locator to a path.
func CopyFile ¶
CopyFile downloads a file specified by the VCS locator and copies it to an io.Writer.
func CopyFileGroup ¶ added in v0.2.0
CopyFileGroup copies a group of locators to the specified writers
func GetAuthMethod ¶ added in v0.4.0
func GetAuthMethod[T ~string](locator T, funcs ...fnOpt) (transport.AuthMethod, error)
getAuthMethod returns an appropriate auth method based on the transport type and available credentials.
It mimics git's behavior by automatically detecting and using SSH keys, SSH agent, or configuring http credentials from the options.
func GetGroup ¶ added in v0.2.0
GetGroup gets the data of several vcs locators in an efficient manner
func WithClonePath ¶
func WithClonePath(path string) fnOpt
WithClonePath specifies the directory to clone the repository. When
func WithHttpAuth ¶ added in v0.4.0
func WithHttpAuth(user, password string) fnOpt
WithHttpAuth configures basic authentication for http operations
func WithRefAsBranch ¶
func WithRefAsBranch(sino bool) fnOpt
WithRefAsBranch instructs the parser to treat the ref as branch name instead of a tag name.
func WithSystemCredentials ¶ added in v0.4.0
func WithSystemCredentials(yesno bool) fnOpt
WithSystemCredentials controls if cloning uses the system credentials
func WithTopLevelPath ¶ added in v0.4.1
func WithTopLevelPath(path string) fnOpt
WithTopLevelPath sets the uppermost directory the repository search will walk up to. The path must be a parent of the starting directory.
Types ¶
type Components ¶
type Components struct {
Tool string
Transport string
Hostname string
RepoPath string
RefString string
Commit string
Tag string
Branch string
SubPath string
}
Components captures the parsed pieces of a VCS locator.
func (*Components) RepoURL ¶
func (c *Components) RepoURL() string
RepoURL forms the repository URL to clone based on the defined components
type Locator ¶
type Locator string
Locator is a type that wraps a VCS locator string to add functionality to it.
func NewFromPath ¶ added in v0.4.3
NewFromPath builds a file:// Locator from a native filesystem path. It is the inverse of Locator.LocalPath: backslashes are normalized to forward slashes, and Windows drive-letter paths (e.g. "C:\foo\bar") are prefixed with an extra slash so the drive letter isn't parsed as a URL scheme (file:///C:/foo/bar). The input is treated as a pure filesystem path; "@ref" or "#subpath" suffixes are not interpreted.
func ReadFromRepo ¶ added in v0.4.1
ReadFromRepo opens a git repository by walking up from startDir toward the filesystem root (or the directory set via WithTopLevelPath) and returns a VCS Locator built from the repository's origin remote URL and current HEAD.
func (Locator) LocalPath ¶ added in v0.4.3
LocalPath returns the native filesystem path for a file:// locator, suitable for passing to os.Open, go-git's PlainOpen, and other local-path APIs. On Windows the parsed path takes the URL form "/C:/foo/bar"; this returns "C:/foo/bar" so the path isn't misread as drive-relative. For locators whose transport is not "file" the return value is an empty string. Returns an error only if the locator fails to parse.
func (Locator) Parse ¶
func (l Locator) Parse(funcs ...fnOpt) (*Components, error)
Parse a VCS locator and returns its components