gitutil

package
v0.0.0-...-2e562c1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const RepoCacheDirEnv = "KPT_CACHE_DIR"

RepoCacheDirEnv is the name of the environment variable that controls the cache directory for remote repos. Defaults to UserHomeDir/.kpt/repos if unspecified.

Variables

This section is empty.

Functions

func AmendGitExecError

func AmendGitExecError(err error, f func(e *GitExecError))

AmendGitExecError provides a way to amend the GitExecError returned by the GitLocalRunner.run command.

Types

type GitExecError

type GitExecError struct {
	Type    GitExecErrorType
	Args    []string
	Err     error
	Command string
	Repo    string
	Ref     string
	StdErr  string
	StdOut  string
}

GitExecError is an error type returned if kpt encounters an error while executing a git command. It includes information about the command that was executed and the output from git.

func (*GitExecError) Error

func (e *GitExecError) Error() string

type GitExecErrorType

type GitExecErrorType int

GitExecErrorType is used to enumerate git errors.

const (
	// Unknown is used when we can't classify an error into any of the other
	// categories.
	Unknown GitExecErrorType = iota
	// GitExecutableNotFound means the git executable wasn't available.
	GitExecutableNotFound
	// UnknownReference means that provided reference (tag, branch) wasn't
	// found
	UnknownReference
	// HTTPSAuthRequired means we try to access the repo using the https
	// protocol, but the repo required authentication.
	HTTPSAuthRequired
	// RepositoryNotFound means the provided repo uri doesn't seem to point
	// to a valid git repo.
	RepositoryNotFound
	// RepositoryUnavailable means we weren't able to connect to the provided
	// uri.
	RepositoryUnavailable
)

type GitLocalRunner

type GitLocalRunner struct {

	// Dir is the directory the commands are run in.
	Dir string

	// Debug enables output of debug information to stderr.
	Debug bool
	// contains filtered or unexported fields
}

GitLocalRunner runs git commands in a local git repo.

func NewLocalGitRunner

func NewLocalGitRunner(pkg string) (*GitLocalRunner, error)

NewLocalGitRunner returns a new GitLocalRunner for a local package.

func (*GitLocalRunner) Run

func (g *GitLocalRunner) Run(ctx context.Context, command string, args ...string) (RunResult, error)

Run runs a git command. Omit the 'git' part of the command. The first return value contains the output to Stdout and Stderr when running the command.

func (*GitLocalRunner) RunVerbose

func (g *GitLocalRunner) RunVerbose(ctx context.Context, command string, args ...string) (RunResult, error)

RunVerbose runs a git command. Omit the 'git' part of the command. The first return value contains the output to Stdout and Stderr when running the command.

type GitUpstreamRepo

type GitUpstreamRepo struct {
	URI string

	// Heads contains all head refs in the upstream repo as well as the
	// each of the are referencing.
	Heads map[string]string

	// Tags contains all tag refs in the upstream repo as well as the
	// each of the are referencing.
	Tags map[string]string
	// contains filtered or unexported fields
}

GitUpstreamRepo runs git commands in a local git repo.

func NewGitUpstreamRepo

func NewGitUpstreamRepo(ctx context.Context, uri string, opts ...NewGitUpstreamRepoOption) (*GitUpstreamRepo, error)

NewGitUpstreamRepo returns a new GitUpstreamRepo for an upstream package.

func (*GitUpstreamRepo) GetDefaultBranch

func (gur *GitUpstreamRepo) GetDefaultBranch(ctx context.Context) (string, error)

GetDefaultBranch returns the name of the branch pointed to by the HEAD symref. This is the default branch of the repository.

func (*GitUpstreamRepo) GetFetchedRefs

func (gur *GitUpstreamRepo) GetFetchedRefs() []string

func (*GitUpstreamRepo) GetRepo

func (gur *GitUpstreamRepo) GetRepo(ctx context.Context, refs []string) (string, error)

GetRepo fetches all the provided refs and the objects. It will fetch it to the cache repo and returns the path to the local git clone in the cache directory.

func (*GitUpstreamRepo) ResolveBranch

func (gur *GitUpstreamRepo) ResolveBranch(branch string) (string, bool)

ResolveBranch resolves the branch to a commit SHA. This happens based on the cached information about refs in the upstream repo. If the branch doesn't exist in the upstream repo, the last return value will be false.

func (*GitUpstreamRepo) ResolveRef

func (gur *GitUpstreamRepo) ResolveRef(ref string) (string, bool)

ResolveRef resolves the ref (either tag or branch) to a commit SHA. If the ref doesn't exist in the upstream repo, the last return value will be false.

func (*GitUpstreamRepo) ResolveTag

func (gur *GitUpstreamRepo) ResolveTag(tag string) (string, bool)

ResolveTag resolves the tag to a commit SHA. This happens based on the cached information about refs in the upstream repo. If the tag doesn't exist in the upstream repo, the last return value will be false.

type NewGitUpstreamRepoOption

type NewGitUpstreamRepoOption func(*GitUpstreamRepo)

func WithFetchedRefs

func WithFetchedRefs(a map[string]bool) NewGitUpstreamRepoOption

type RunResult

type RunResult struct {
	Stdout string
	Stderr string
}

Jump to

Keyboard shortcuts

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