Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractNamedPointerFromRevision(rev string) string
- func IsAnnotatedTag(t Tag) bool
- func IsConcreteCommit(c Commit) bool
- func IsSignedTag(t Tag) bool
- func SecurePath(path string) (string, error)
- func TransformRevision(rev string) string
- type AuthOptions
- type Commit
- type Credentials
- type ErrRepositoryNotFound
- type Hash
- type ProviderOptions
- type Signature
- type Tag
- type TransportType
Constants ¶
const ( ProviderAzure = "azure" ProviderGitHub = "github" GitHubAccessTokenUsername = "x-access-token" )
const ( // HashTypeSHA1 is the SHA1 hash algorithm. HashTypeSHA1 = "sha1" // HashTypeUnknown is an unknown hash algorithm. HashTypeUnknown = "<unknown>" )
const ( DefaultRemote = "origin" DefaultBranch = "master" DefaultPublicKeyAuthUser = "git" )
Variables ¶
var ( ErrNoGitRepository = errors.New("no git repository") ErrNoStagedFiles = errors.New("no staged files") )
var HostKeyAlgos []string
HostKeyAlgos holds the HostKey algorithms that the SSH client will advertise to the server. If empty, Go's default is used instead.
var KexAlgos []string
KexAlgos hosts the key exchange algorithms to be used for SSH connections. If empty, Go's default is used instead.
Functions ¶
func ExtractNamedPointerFromRevision ¶ added in v0.9.0
ExtractNamedPointerFromRevision extracts the named pointer from a revision string. It accepts the following formats:
- main@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- main/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
If the revision string does not contain a named pointer, the returned string is empty.
func IsAnnotatedTag ¶ added in v0.13.0
IsAnnotatedTag returns true if the provided tag is annotated.
func IsConcreteCommit ¶ added in v0.5.0
IsConcreteCommit returns if a given commit is a concrete commit. Concrete commits have most of the commit metadata and content. In contrast, a partial commit may only have some metadata and no commit content.
func IsSignedTag ¶ added in v0.13.0
IsSignedTag returns true if the provided tag has a signature.
func SecurePath ¶ added in v0.6.0
SecurePath accepts an absolute or relative path and returns a path that is safe for use. If the path is absolute, it's `filepath.Clean`ed and returned. If the path is relative, it's securely joined against the working directory to ensure that the resultant path is a child of the working directory.
func TransformRevision ¶ added in v0.9.0
TransformRevision transforms a "legacy" revision string into a "new" revision string. It accepts the following formats:
- main/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- HEAD/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
Which are transformed into the following formats respectively:
- main@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738 - feature/branch@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738 - sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
NOTE: This function is only intended to be used for backwards compatibility with the old revision format. It may be removed in a future release.
Types ¶
type AuthOptions ¶ added in v0.5.0
type AuthOptions struct { Transport TransportType Host string Username string Password string BearerToken string Identity []byte KnownHosts []byte CAFile []byte ProviderOpts *ProviderOptions }
AuthOptions are the authentication options for the Transport of communication with a remote origin.
func NewAuthOptions ¶ added in v0.5.0
NewAuthOptions constructs an AuthOptions object from the given map and URL. If the map is empty, it returns a minimal AuthOptions object after validating the result.
func (AuthOptions) Validate ¶ added in v0.5.0
func (o AuthOptions) Validate() error
Validate the AuthOptions against the defined Transport.
type Commit ¶ added in v0.5.0
type Commit struct { // Hash is the hash of the commit. Hash Hash // Reference is the original reference of the commit, for example: // 'refs/tags/foo'. Reference string // Author is the original author of the commit. Author Signature // Committer is the one performing the commit, might be different from // Author. Committer Signature // Signature is the PGP signature of the commit. Signature string // Encoded is the encoded commit, without any signature. Encoded []byte // Message is the commit message, containing arbitrary text. Message string // ReferencingTag is the tag that points to this commit. ReferencingTag *Tag }
Commit contains all possible information about a Git commit.
func (*Commit) AbsoluteReference ¶ added in v0.11.0
AbsoluteReference returns a string representation of the Commit, composed out of the Reference element (if not empty) and Hash. For example: 'refs/tags/tag-1@sha1:a0c14dc8580a23f79bc654faa79c4f62b46c2c22' for a "refs/tags/tag-1" Reference.
func (*Commit) ShortMessage ¶ added in v0.5.0
ShortMessage returns the first 50 characters of a commit subject.
func (*Commit) String ¶ added in v0.5.0
String returns a string representation of the Commit, composed out of the last part of the Reference element (if not empty) and Hash. For example: 'tag-1@sha1:a0c14dc8580a23f79bc654faa79c4f62b46c2c22', for a "refs/tags/tag-1" Reference.
func (*Commit) Verify ¶ added in v0.5.0
Verify the Signature of the commit with the given key rings. It returns the fingerprint of the key the signature was verified with, or an error. It does not verify the signature of the referencing tag (if present). Users are expected to explicitly verify the referencing tag's signature using `c.ReferencingTag.Verify()`
type Credentials ¶ added in v0.21.0
Credentials contains authentication data needed in order to access a Git repository.
func GetCredentials ¶ added in v0.21.0
func GetCredentials(ctx context.Context, providerOpts *ProviderOptions) (*Credentials, time.Time, error)
GetCredentials returns authentication credentials for accessing the provided Git repository.
type ErrRepositoryNotFound ¶ added in v0.5.0
ErrRepositoryNotFound indicates that the repository (or the ref in question) does not exist at the given URL.
func (ErrRepositoryNotFound) Error ¶ added in v0.5.0
func (e ErrRepositoryNotFound) Error() string
type Hash ¶ added in v0.5.0
type Hash []byte
Hash is the (non-truncated) SHA-1 or SHA-256 hash of a Git commit.
func ExtractHashFromRevision ¶ added in v0.9.0
ExtractHashFromRevision extracts the hash from a revision string. It accepts the following formats:
- main@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- main/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- HEAD/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- 5394cb7f48332b2de7c17dd8b8384bbc84b7e738
func SplitRevision ¶ added in v0.9.0
SplitRevision splits a revision string into it's named pointer and hash components. It accepts the following formats:
- main@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch@sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- sha1:5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- main/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- feature/branch/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- HEAD/5394cb7f48332b2de7c17dd8b8384bbc84b7e738
- 5394cb7f48332b2de7c17dd8b8384bbc84b7e738
If the revision string does not contain a named pointer, the returned string will be empty.
func (Hash) Algorithm ¶ added in v0.9.0
Algorithm returns the algorithm of the hash based on its length. This is heuristic, and may not be accurate for truncated user constructed hashes. The library itself does not produce truncated hashes.
type ProviderOptions ¶ added in v0.21.0
ProviderOptions contains options to configure various authentication providers.
type Signature ¶ added in v0.5.0
Signature represents an entity which associates a person and a time with a commit.
type Tag ¶ added in v0.13.0
type Tag struct { // Hash is the hash of the tag. Hash Hash // Name is the name of the tag. Name string // Author is the original author of the tag. Author Signature // Signature is the PGP signature of the tag. Signature string // Encoded is the encoded tag, without any signature. Encoded []byte // Message is the tag message, containing arbitrary text. Message string }
Tag represents a Git tag.
type TransportType ¶ added in v0.5.0
type TransportType string
const ( SSH TransportType = "ssh" HTTPS TransportType = "https" HTTP TransportType = "http" )