Documentation
¶
Overview ¶
Package git provides utilities for working with git repositories.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidRepo = errors.New("invalid git repository")
ErrInvalidRepo indicates that the provided string is not a valid git repository name or URL.
Functions ¶
func RegisterHostHandler ¶
func RegisterHostHandler(exactHost string, handler HostHandler)
RegisterHostHandler allows for the registration of a host handler that is triggered when the host of a URL exactly matches the given host, ignoring case.
This method is not thread-safe, and is expected to be called from init().
Types ¶
type HostHandler ¶
type HostHandler interface {
// Validate checks if the URL is valid for this host.
Validate(u *url.URL) error
// Canon canonicalizes the URL for this host.
Canon(u *url.URL) *url.URL
}
HostHandler defines the interface for host-specific validation and canonicalization of URLs.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo represents a parsed and canonicalized git repository.
func ParseRepo ¶
ParseRepo parses a git repository URL or SCP-like string and returns a Repo.
It validates the repository against registered host handlers and computes a canonical URL.
If the repository is not valid, an error is returned.
func (*Repo) ID ¶
ID returns a string that can be used to identify the repository.
The ID is based on the canonical URL, but is made up of the host and path only. The ID is unsuitable for interacting with the repository.
type StandardHostHandler ¶
type StandardHostHandler struct {
// ForceScheme will replace any URL scheme with its value when set.
ForceScheme string
// StripUser will remove the user from the URL when true.
StripUser bool
// HasTrailingSlash will add a trailing slash to the URL if it doesn't have
// one. If false any trailing slash will be removed.
HasTrailingSlash bool
// HasDotGitSuffix will add a .git suffix to the URL if it doesn't have one.
// If false any .git suffix will be removed.
HasDotGitSuffix bool
// PathPrefix is the prefix that is required to be set for a valid git
// repository for this host.
PathPrefix string
// MinPathSegments is the minimum number of path segments that are required for a
// valid git repository for this host. If 0 there is no restriction. If PathPrefix
// is not empty, then only segments after the prefix are considered.
MinPathSegments int
// MaxPathSegments is the maximum number of path segments that are required for a
// valid git repository for this host. If 0 there is no restriction. If PathPrefix
// is not empty, then only segments after the prefix are considered.
MaxPathSegments int
// LowerPathSegments is the number of path segments that should be lowercased
// following any PathPrefix, during the canonicalization process. This is to
// ensure that URLs for case-insensitive hosts are canonicalized correctly.
//
// A zero value means no path segements will be lowercased.
// A positive value of N means the first N path segments following the
// PathPrefix will be lowercased.
// A negative value of -N means all but the last N path segments following
// the PathPrefix will be lowercased.
LowerPathSegments int
}
StandardHostHandler implements HostHandler with common validation and canonicalization settings.