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 CheckoutRevToTargetDir(dir, rev, path, targetDir string) error
- func CombinedOutput(dir string, args ...string) (string, error)
- func FetchRefCommit(dir, remote, ref string) (string, error)
- func GetGlobalAuthor() (string, error)
- func GetSubmoduleCommitAtRev(dir, submoduleDir, rev 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 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 CheckoutRevToTargetDir ¶ added in v0.0.7
CheckoutRevToTargetDir checks out the given path/subdir of the repository at the given revision into the target directory.
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 GetGlobalAuthor ¶ added in v0.0.7
GetGlobalAuthor returns the author that a new Git commit would be written by, based (only!) on the current global Git settings.
func GetSubmoduleCommitAtRev ¶ added in v0.0.7
GetSubmoduleCommitAtRev returns the commit hash of the submodule at the given revision. submoduleDir may be absolute or relative to dir.
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 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). Other packages may implement this interface for various services and authentication types.