Documentation
¶
Overview ¶
Package gitcmd contains utilities for common Git operations in a local repository, including authentication with a remote repository.
Index ¶
- func AttemptDelete(gitDir string)
- func CombinedOutput(dir string, args ...string) (string, error)
- func FetchRefCommit(dir, remote, ref string) (string, error)
- func NewTempCloneRepo(src string) (string, error)
- func NewTempGitRepo() (string, error)
- func Poll(checker PollChecker, delay time.Duration) string
- func RevParse(dir, rev string) (string, error)
- func Run(dir string, args ...string) error
- func Show(dir, rev string) (string, error)
- func ShowQuietPretty(dir, format, rev string) (string, error)
- type AzDOPATAuther
- type GitHubPATAuther
- type GitHubSSHAuther
- type MultiAuther
- type NoAuther
- type PollChecker
- type URLAuther
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttemptDelete ¶
func AttemptDelete(gitDir string)
AttemptDelete tries to delete the git dir. If an error occurs, log it, but this is not fatal. gitDir is expected to be in a temp dir, so it will be cleaned up later by the OS anyway.
func CombinedOutput ¶
CombinedOutput runs "git <args...>" in the given directory and returns the result.
func FetchRefCommit ¶ added in v0.0.6
FetchRefCommit effectively runs "git fetch <remote> <ref>" and returns the commit hash.
func NewTempCloneRepo ¶
func NewTempGitRepo ¶
NewTempGitRepo creates a gitRepo in temp storage. If desired, clean it up with AttemptDelete.
func Poll ¶
func Poll(checker PollChecker, delay time.Duration) string
Poll repeatedly checks using the given checker until it returns a successful result.
func Run ¶
Run runs "git <args>" in the given directory, showing the command to the user in logs for diagnosability. Using this func helps make one-line Git commands readable.
func ShowQuietPretty ¶ added in v0.0.6
ShowQuietPretty runs "git show" with the given format and revision and returns the result. See https://git-scm.com/docs/git-show#_pretty_formats
Types ¶
type AzDOPATAuther ¶
type AzDOPATAuther struct {
PAT string
}
AzDOPATAuther adds a PAT into the https-style Azure DevOps repository URL.
func (AzDOPATAuther) InsertAuth ¶
func (a AzDOPATAuther) InsertAuth(url string) string
type GitHubPATAuther ¶
type GitHubPATAuther struct {
User, PAT string
}
GitHubPATAuther adds a username and password into the https-style GitHub URL.
func (GitHubPATAuther) InsertAuth ¶
func (a GitHubPATAuther) InsertAuth(url string) string
type GitHubSSHAuther ¶
type GitHubSSHAuther struct{}
GitHubSSHAuther turns an https-style GitHub URL into an SSH-style GitHub URL.
func (GitHubSSHAuther) InsertAuth ¶
func (GitHubSSHAuther) InsertAuth(url string) string
type MultiAuther ¶
type MultiAuther struct {
Authers []URLAuther
}
MultiAuther tries multiple authers in sequence. Stops and returns the result when any auther makes a change to the URL.
func (MultiAuther) InsertAuth ¶
func (m MultiAuther) InsertAuth(url string) string
type PollChecker ¶
type PollChecker interface { // Check finds the string result associated with the check, or returns an error describing why // the result couldn't be found yet. Check() (string, error) }
PollChecker runs a check that returns a result. This is normally used to check an upstream repository for a release, or for go-images dependency flow status.
type URLAuther ¶
type URLAuther interface { // InsertAuth inserts authentication into the URL and returns it, or if the auther doesn't // apply, returns the url without any modifications. InsertAuth(url string) string }
URLAuther manipulates a Git repository URL (GitHub, AzDO, ...) such that Git commands taking a remote will work with the URL. This is intentionally vague: it could add an access token into the URL, or it could simply make the URL compatible with environmental auth on the machine (SSH).