git

package
v3.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 57 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinGitConfigEnv []string

BuiltinGitConfigEnv contains builtin git configuration in the format acceptable by Git.

View Source
var ErrInvalidRepoURL = errors.New("repo URL is invalid")
View Source
var SupportedFIPSCompliantSSHKeyExchangeAlgorithms = []string{
	"ecdh-sha2-nistp256",
	"ecdh-sha2-nistp384",
	"ecdh-sha2-nistp521",
	"diffie-hellman-group-exchange-sha256",
	"diffie-hellman-group14-sha256",
}

SupportedFIPSCompliantSSHKeyExchangeAlgorithms is a list of all currently supported algorithms for SSH key exchange that are FIPS compliant

View Source
var SupportedSSHKeyExchangeAlgorithms = []string{
	"curve25519-sha256",
	"curve25519-sha256@libssh.org",
	"ecdh-sha2-nistp256",
	"ecdh-sha2-nistp384",
	"ecdh-sha2-nistp521",
	"diffie-hellman-group-exchange-sha256",
	"diffie-hellman-group14-sha256",
	"diffie-hellman-group14-sha1",
}

SupportedSSHKeyExchangeAlgorithms is a list of all currently supported algorithms for SSH key exchange Unfortunately, crypto/ssh does not offer public constants or list for this.

Functions

func GetRepoHTTPClient

func GetRepoHTTPClient(repoURL string, insecure bool, creds Creds, proxyURL string, noProxy string) *http.Client

Returns a HTTP client object suitable for go-git to use using the following pattern:

  • If insecure is true, always returns a client with certificate verification turned off.
  • If one or more custom certificates are stored for the repository, returns a client with those certificates in the list of root CAs used to verify the server's certificate.
  • Otherwise (and on non-fatal errors), a default HTTP client is returned.

func IsCommitSHA

func IsCommitSHA(sha string) bool

IsCommitSHA returns whether or not a string is a 40 character SHA-1

func IsHTTPSURL

func IsHTTPSURL(url string) bool

IsHTTPSURL returns true if supplied URL is HTTPS URL

func IsHTTPURL

func IsHTTPURL(url string) bool

IsHTTPURL returns true if supplied URL is HTTP URL

func IsSSHURL

func IsSSHURL(url string) (bool, string)

IsSSHURL returns true if supplied URL is SSH URL

func IsTruncatedCommitSHA

func IsTruncatedCommitSHA(sha string) bool

IsTruncatedCommitSHA returns whether or not a string is a truncated SHA-1

func NormalizeGitURL

func NormalizeGitURL(repo string) string

NormalizeGitURL normalizes a git URL for purposes of comparison, as well as preventing redundant local clones (by normalizing various forms of a URL to a consistent location). Prefer using SameURL() over this function when possible. This algorithm may change over time and should not be considered stable from release to release

func NormalizeGitURLAllowInvalid

func NormalizeGitURLAllowInvalid(repo string) string

NormalizeGitURLAllowInvalid is similar to NormalizeGitURL, except returning an original url if the url is invalid. Needed to allow a deletion of repos with invalid urls. See https://github.com/argoproj/argo-cd/issues/20921.

func SameURL

func SameURL(leftRepo, rightRepo string) bool

SameURL returns whether or not the two repository URLs are equivalent in location

func TestRepo

func TestRepo(repo string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string) error

TestRepo tests if a repo exists and is accessible with the given credentials

Types

type AzureWorkloadIdentityCreds

type AzureWorkloadIdentityCreds struct {
	// contains filtered or unexported fields
}

func NewAzureWorkloadIdentityCreds

func NewAzureWorkloadIdentityCreds(store CredsStore, tokenProvider workloadidentity.TokenProvider) AzureWorkloadIdentityCreds

func (AzureWorkloadIdentityCreds) Environ

func (creds AzureWorkloadIdentityCreds) Environ() (io.Closer, []string, error)

func (AzureWorkloadIdentityCreds) GetAzureDevOpsAccessToken

func (creds AzureWorkloadIdentityCreds) GetAzureDevOpsAccessToken() (string, error)

func (AzureWorkloadIdentityCreds) GetUserInfo

func (creds AzureWorkloadIdentityCreds) GetUserInfo(_ context.Context) (string, string, error)

GetUserInfo returns the username and email address for the credentials, if they're available.

type Client

type Client interface {
	Root() string
	Init() error
	Fetch(revision string) error
	Submodule() error
	Checkout(revision string, submoduleEnabled bool) (string, error)
	LsRefs() (*Refs, error)
	LsRemote(revision string) (string, error)
	LsFiles(path string, enableNewGitFileGlobbing bool) ([]string, error)
	LsLargeFiles() ([]string, error)
	CommitSHA() (string, error)
	RevisionMetadata(revision string) (*RevisionMetadata, error)
	VerifyCommitSignature(string) (string, error)
	IsAnnotatedTag(string) bool
	ChangedFiles(revision string, targetRevision string) ([]string, error)
	IsRevisionPresent(revision string) bool
	// SetAuthor sets the author name and email in the git configuration.
	SetAuthor(name, email string) (string, error)
	// CheckoutOrOrphan checks out the branch. If the branch does not exist, it creates an orphan branch.
	CheckoutOrOrphan(branch string, submoduleEnabled bool) (string, error)
	// CheckoutOrNew checks out the given branch. If the branch does not exist, it creates an empty branch based on
	// the base branch.
	CheckoutOrNew(branch, base string, submoduleEnabled bool) (string, error)
	// RemoveContents removes all files from the given paths in the git repository.
	RemoveContents(paths []string) (string, error)
	// CommitAndPush commits and pushes changes to the target branch.
	CommitAndPush(branch, message string) (string, error)
}

Client is a generic git client interface

func NewClient

func NewClient(rawRepoURL string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string, opts ...ClientOpts) (Client, error)

func NewClientExt

func NewClientExt(rawRepoURL string, root string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string, opts ...ClientOpts) (Client, error)

type ClientOpts

type ClientOpts func(c *nativeGitClient)

func WithBuiltinGitConfig added in v3.2.1

func WithBuiltinGitConfig(enable bool) ClientOpts

func WithCache

func WithCache(cache gitRefCache, loadRefFromCache bool) ClientOpts

WithCache sets git revisions cacher as well as specifies if client should tries to use cached resolved revision

func WithEventHandlers

func WithEventHandlers(handlers EventHandlers) ClientOpts

WithEventHandlers sets the git client event handlers

type CommitMetadata added in v3.1.0

type CommitMetadata struct {
	// Author is the author of the commit.
	// Comes from the Argocd-reference-commit-author trailer.
	Author mail.Address
	// Date is the date of the commit, formatted as by `git show -s --format=%aI`.
	// May be an empty string if the date is unknown.
	// Comes from the Argocd-reference-commit-date trailer.
	Date string
	// Subject is the commit message subject, i.e. `git show -s --format=%s`.
	// Comes from the Argocd-reference-commit-subject trailer.
	Subject string
	// Body is the commit message body, excluding the subject, i.e. `git show -s --format=%b`.
	// Comes from the Argocd-reference-commit-body trailer.
	Body string
	// SHA is the commit hash.
	// Comes from the Argocd-reference-commit-sha trailer.
	SHA string
	// RepoURL is the URL of the repository where the commit is located.
	// Comes from the Argocd-reference-commit-repourl trailer.
	// This value is not validated beyond confirming that it's a URL, and it should not be used to construct UI links
	// unless it is properly validated and/or sanitized first.
	RepoURL string
}

CommitMetadata contains metadata about a commit that is related in some way to another commit.

type Creds

type Creds interface {
	Environ() (io.Closer, []string, error)
	// GetUserInfo gets the username and email address for the credentials, if they're available.
	GetUserInfo(ctx context.Context) (string, string, error)
}

type CredsStore

type CredsStore interface {
	Add(username string, password string) string
	Remove(id string)
	// Environ returns the environment variables that should be set to use the credentials for the given credential ID.
	Environ(id string) []string
}

type EventHandlers

type EventHandlers struct {
	OnLsRemote func(repo string) func()
	OnFetch    func(repo string) func()
	OnPush     func(repo string) func()
}

type GenericHTTPSCreds

type GenericHTTPSCreds interface {
	HasClientCert() bool
	GetClientCertData() string
	GetClientCertKey() string
	Creds
}

func NewGitHubAppCreds

func NewGitHubAppCreds(appID int64, appInstallId int64, privateKey string, baseURL string, clientCertData string, clientCertKey string, insecure bool, proxy string, noProxy string, store CredsStore) GenericHTTPSCreds

NewGitHubAppCreds provide github app credentials

func NewHTTPSCreds

func NewHTTPSCreds(username string, password string, bearerToken string, clientCertData string, clientCertKey string, insecure bool, store CredsStore, forceBasicAuth bool) GenericHTTPSCreds

type GitHubAppCreds

type GitHubAppCreds struct {
	// contains filtered or unexported fields
}

GitHubAppCreds to authenticate as GitHub application

func (GitHubAppCreds) Environ

func (g GitHubAppCreds) Environ() (io.Closer, []string, error)

func (GitHubAppCreds) GetClientCertData

func (g GitHubAppCreds) GetClientCertData() string

func (GitHubAppCreds) GetClientCertKey

func (g GitHubAppCreds) GetClientCertKey() string

func (GitHubAppCreds) GetUserInfo

func (g GitHubAppCreds) GetUserInfo(ctx context.Context) (string, string, error)

GetUserInfo returns the username and email address for the credentials, if they're available.

func (GitHubAppCreds) HasClientCert

func (g GitHubAppCreds) HasClientCert() bool

type GoogleCloudCreds

type GoogleCloudCreds struct {
	// contains filtered or unexported fields
}

GoogleCloudCreds to authenticate to Google Cloud Source repositories

func NewGoogleCloudCreds

func NewGoogleCloudCreds(jsonData string, store CredsStore) GoogleCloudCreds

func (GoogleCloudCreds) Environ

func (c GoogleCloudCreds) Environ() (io.Closer, []string, error)

func (GoogleCloudCreds) GetUserInfo

func (c GoogleCloudCreds) GetUserInfo(_ context.Context) (string, string, error)

GetUserInfo returns the username and email address for the credentials, if they're available. TODO: implement getting email instead of just username.

type HTTPSCreds

type HTTPSCreds struct {
	// contains filtered or unexported fields
}

HTTPS creds implementation

func (HTTPSCreds) BasicAuthHeader

func (creds HTTPSCreds) BasicAuthHeader() string

func (HTTPSCreds) BearerAuthHeader

func (creds HTTPSCreds) BearerAuthHeader() string

func (HTTPSCreds) Environ

func (creds HTTPSCreds) Environ() (io.Closer, []string, error)

Get additional required environment variables for executing git client to access specific repository via HTTPS.

func (HTTPSCreds) GetClientCertData

func (creds HTTPSCreds) GetClientCertData() string

func (HTTPSCreds) GetClientCertKey

func (creds HTTPSCreds) GetClientCertKey() string

func (HTTPSCreds) GetUserInfo

func (creds HTTPSCreds) GetUserInfo(_ context.Context) (string, string, error)

GetUserInfo returns the username and email address for the credentials, if they're available.

func (HTTPSCreds) HasClientCert

func (creds HTTPSCreds) HasClientCert() bool

type NoopCredsStore

type NoopCredsStore struct{}

func (NoopCredsStore) Add

func (d NoopCredsStore) Add(_ string, _ string) string

func (NoopCredsStore) Environ

func (d NoopCredsStore) Environ(_ string) []string

func (NoopCredsStore) Remove

func (d NoopCredsStore) Remove(_ string)

type NopCloser

type NopCloser struct{}

nop implementation

func (NopCloser) Close

func (c NopCloser) Close() error

type NopCreds

type NopCreds struct{}

func (NopCreds) Environ

func (c NopCreds) Environ() (io.Closer, []string, error)

func (NopCreds) GetUserInfo

func (c NopCreds) GetUserInfo(_ context.Context) (name string, email string, err error)

GetUserInfo returns empty strings for user info

type PublicKeysWithOptions

type PublicKeysWithOptions struct {
	KexAlgorithms []string
	gitssh.PublicKeys
}

PublicKeysWithOptions is an auth method for go-git's SSH client that inherits from PublicKeys, but provides the possibility to override some client options.

func (*PublicKeysWithOptions) ClientConfig

func (a *PublicKeysWithOptions) ClientConfig() (*ssh.ClientConfig, error)

ClientConfig returns a custom SSH client configuration

func (*PublicKeysWithOptions) Name

func (a *PublicKeysWithOptions) Name() string

Name returns the name of the auth method

func (*PublicKeysWithOptions) String

func (a *PublicKeysWithOptions) String() string

String returns the configured user and auth method name as string

type Refs

type Refs struct {
	Branches []string
	Tags     []string
}

this should match reposerver/repository/repository.proto/RefsList

type RevisionMetadata

type RevisionMetadata struct {
	// Author is the author of the commit. Corresponds to the output of `git log -n 1 --pretty='format:%an <%ae>'`.
	Author string
	// Date is the date of the commit. Corresponds to the output of `git log -n 1 --pretty='format:%ad'`.
	Date time.Time
	Tags []string
	// Message is the commit message.
	Message string
	// References contains metadata about information that is related in some way to this commit. This data comes from
	// git commit trailers starting with "Argocd-reference-". We currently only support a single reference to a commit,
	// but we return an array to allow for future expansion.
	References []RevisionReference
}

type RevisionReference added in v3.1.0

type RevisionReference struct {
	// Commit contains metadata about the commit that is related in some way to another commit.
	Commit *CommitMetadata
}

RevisionReference contains a reference to a some information that is related in some way to another commit. For now, it supports only references to a commit. In the future, it may support other types of references.

func GetReferences added in v3.1.0

func GetReferences(logCtx *log.Entry, commitMessageBody string) ([]RevisionReference, string)

GetReferences extracts related commit metadata from the commit message trailers. If referenced commit metadata is present, we return a slice containing a single metadata object. If no related commit metadata is found, we return a nil slice.

If a trailer fails validation, we log an error and skip that trailer. We truncate the trailer values to 100 characters to avoid excessively long log messages.

We also return the commit message body with all valid Argocd-reference-commit-* trailers removed.

type SSHCreds

type SSHCreds struct {
	// contains filtered or unexported fields
}

SSH implementation

func NewSSHCreds

func NewSSHCreds(sshPrivateKey string, caPath string, insecureIgnoreHostKey bool, proxy string) SSHCreds

func (SSHCreds) Environ

func (c SSHCreds) Environ() (io.Closer, []string, error)

func (SSHCreds) GetUserInfo

func (c SSHCreds) GetUserInfo(_ context.Context) (string, string, error)

GetUserInfo returns empty strings for user info. TODO: Implement this method to return the username and email address for the credentials, if they're available.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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