git

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package git contains routines for interacting with git over the CLI. Unlike go-git, this is not a pure go library for interacting with git, and relies on the git command line being available locally. This is meant to provide high level interfaces used throughout various Gruntwork CLIs.

NOTE: The tests for these packages are intentionally stored in a separate test folder, rather than the go converntional style of source_test.go files. This is done to ensure that the tests for the packages are run in a separate docker container, as many functions in this package pollute the global git configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checkout

func Checkout(logger *logrus.Entry, ref string, targetDir string) error

Checkout checks out the given ref for the repo cloned in the target directory.

func Clone

func Clone(logger *logrus.Entry, repo string, targetDir string) error

Clone runs git clone to clone the specified repository into the given target directory.

func ConfigureCacheCredentialsHelper added in v0.12.3

func ConfigureCacheCredentialsHelper(logger *logrus.Entry, options CacheCredentialOptions) error

ConfigureCacheCredentialsHelper configures git globally to use the cache credentials helper for authentication based on the provided options configuration.

func ConfigureForceHTTPS

func ConfigureForceHTTPS(logger *logrus.Entry) error

ConfigureForceHTTPS configures git to force usage of https endpoints instead of SSH based endpoints for the three primary VCS platforms (GitHub, GitLab, BitBucket).

func ConfigureHTTPSAuth

func ConfigureHTTPSAuth(
	logger *logrus.Entry,
	gitUsername string,
	gitOauthToken string,
	vcsHost string,
) error

ConfigureHTTPSAuth configures git with username and password to authenticate with the given VCS host when interacting with git over HTTPS. This uses the cache credentials store to configure the credentials. Refer to the git documentation on credentials storage for more information: https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage NOTE: this configures the cache credential helper globally, with a default timeout of 1 hour. If you want more control over the configuration, use the ConfigureCacheCredentialsHelper and StoreCacheCredentials functions directly.

func StoreCacheCredentials added in v0.12.3

func StoreCacheCredentials(
	logger *logrus.Entry,
	gitUsername string,
	gitOauthToken string,
	vcsHost string,
	vcsPath string,
	socketPath string,
) error

StoreCacheCredentials stores the given git credentials for the vcs host and path pair to the git credential-cache helper.

Types

type CacheCredentialOptions added in v0.12.3

type CacheCredentialOptions struct {
	// Host is the VCS host where the cache credential helper should be triggered.
	// Set to "" if you want to apply the credential cache helper to all hosts.
	Host string

	// DefaultUsername is the default username to use when authenticating to the VCS host.
	DefaultUsername string

	// IncludeHTTPPath indicates whether to path through the git http path to the credential helper, enabling matching
	// with the path (e.g., the org/repo.git component of https://github.com/org/repo.git.
	IncludeHTTPPath bool

	// SocketPath configures the path to the Unix socket file to use to interact with the cache credential daemon. When
	// blank, uses the default path baked into the command:
	// https://git-scm.com/docs/git-credential-cache#_options
	// This is useful when you are configuring the cache for the same host across multiple paths, as the cache
	// credential helper is known to break when you have an entry for a specific path and the generic all hosts.
	SocketPath string

	// Timeout is the timeout in seconds for credentials in the cache.
	Timeout int
}

CredentialOptions are the possible configurations options for configuring the git credential-cache helper.

type TargetDirectoryNotExistsErr

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

TargetDirectoryNotExistsErr is returned when the target directory of the git commands does not exist or is not a directory.

func (TargetDirectoryNotExistsErr) Error

func (err TargetDirectoryNotExistsErr) Error() string

Jump to

Keyboard shortcuts

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