gitcmd

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitcmd contains utilities for common Git operations in a local repository, including authentication with a remote repository.

Index

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

func CombinedOutput(dir string, args ...string) (string, error)

CombinedOutput runs "git <args...>" in the given directory and returns the result.

func NewTempCloneRepo

func NewTempCloneRepo(src string) (string, error)

func NewTempGitRepo

func NewTempGitRepo() (string, error)

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 RevParse

func RevParse(dir, rev string) (string, error)

RevParse runs "git rev-parse <rev>" and returns the result with whitespace trimmed.

func Run

func Run(dir string, args ...string) error

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 Show

func Show(dir, rev string) (string, error)

Show runs "git show <spec>" and returns the content.

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 NoAuther

type NoAuther struct{}

NoAuther does nothing to URLs.

func (NoAuther) InsertAuth

func (NoAuther) 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).

Jump to

Keyboard shortcuts

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