gitutil

package
v0.13.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: Apache-2.0 Imports: 12 Imported by: 20

Documentation

Index

Constants

View Source
const (
	HTTPProtocol  string = "http"
	HTTPSProtocol string = "https"
	SSHProtocol   string = "ssh"
	GitProtocol   string = "git"
)

Variables

View Source
var (
	ErrUnknownProtocol = errors.New("unknown protocol")
	ErrInvalidProtocol = errors.New("invalid protocol")
)

Functions

func ParseURL added in v0.13.0

func ParseURL(remote string) (*url.URL, error)

ParseURL parses a git URL and returns a parsed URL object.

ParseURL understands implicit ssh URLs such as "git@host:repo", and returns the same response as if the URL were "ssh://git@host/repo".

func SplitGitFragment

func SplitGitFragment(fragment string) (ref string, subdir string)

SplitGitFragments splits a git URL fragment into its respective git reference and subdirectory components.

Types

type GitCLI added in v0.13.0

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

GitCLI carries config to pass to the git cli to make running multiple commands less repetitive.

func NewGitCLI added in v0.13.0

func NewGitCLI(opts ...Option) *GitCLI

New initializes a new git client

func (*GitCLI) Dir added in v0.13.0

func (cli *GitCLI) Dir() string

func (*GitCLI) GitDir added in v0.13.0

func (cli *GitCLI) GitDir(ctx context.Context) (string, error)

func (*GitCLI) New added in v0.13.0

func (cli *GitCLI) New(opts ...Option) *GitCLI

New returns a new git client with the same config as the current one, but with the given options applied on top.

func (*GitCLI) Run added in v0.13.0

func (cli *GitCLI) Run(ctx context.Context, args ...string) (_ []byte, err error)

Run executes a git command with the given args.

func (*GitCLI) WorkTree added in v0.13.0

func (cli *GitCLI) WorkTree(ctx context.Context) (string, error)

type GitRef added in v0.11.0

type GitRef struct {
	// Remote is the remote repository path.
	Remote string

	// ShortName is the directory name of the repo.
	// e.g., "bar" for "https://github.com/foo/bar.git"
	ShortName string

	// Commit is a commit hash, a tag, or branch name.
	// Commit is optional.
	Commit string

	// SubDir is a directory path inside the repo.
	// SubDir is optional.
	SubDir string

	// IndistinguishableFromLocal is true for a ref that is indistinguishable from a local file path,
	// e.g., "github.com/foo/bar".
	//
	// Deprecated.
	// Instead, use a distinguishable form such as "https://github.com/foo/bar.git".
	//
	// The dockerfile frontend still accepts this form only for build contexts.
	IndistinguishableFromLocal bool

	// UnencryptedTCP is true for a ref that needs an unencrypted TCP connection,
	// e.g., "git://..." and "http://..." .
	//
	// Discouraged, although not deprecated.
	// Instead, consider using an encrypted TCP connection such as "git@github.com/foo/bar.git" or "https://github.com/foo/bar.git".
	UnencryptedTCP bool
}

GitRef represents a git ref.

Examples:

func ParseGitRef added in v0.11.0

func ParseGitRef(ref string) (*GitRef, error)

ParseGitRef parses a git ref.

type Option added in v0.13.0

type Option func(b *GitCLI)

Option provides a variadic option for configuring the git client.

func WithArgs added in v0.13.0

func WithArgs(args ...string) Option

WithArgs sets extra args.

func WithDir added in v0.13.0

func WithDir(dir string) Option

WithDir sets working directory.

This should be a path to any directory within a standard git repository.

func WithExec added in v0.13.0

func WithExec(exec func(context.Context, *exec.Cmd) error) Option

WithExec sets the command exec function.

func WithGitBinary added in v0.13.0

func WithGitBinary(path string) Option

WithGitBinary sets the git binary path.

func WithGitDir added in v0.13.0

func WithGitDir(gitDir string) Option

WithGitDir sets the --git-dir arg.

This should be the path to the .git directory. When setting this, you may also need to set WithWorkTree, unless you are working with a bare repository.

func WithSSHAuthSock added in v0.13.0

func WithSSHAuthSock(sshAuthSock string) Option

WithSSHAuthSock sets the ssh auth sock.

func WithSSHKnownHosts added in v0.13.0

func WithSSHKnownHosts(sshKnownHosts string) Option

WithSSHKnownHosts sets the known hosts file.

func WithStreams added in v0.13.0

func WithStreams(streams StreamFunc) Option

WithStreams configures a callback for getting the streams for a command. The stream callback will be called once for each command, and both writers will be closed after the command has finished.

func WithWorkTree added in v0.13.0

func WithWorkTree(workTree string) Option

WithWorkTree sets the --work-tree arg.

This should be the path to the top-level directory of the checkout. When setting this, you also likely need to set WithGitDir.

type StreamFunc added in v0.13.0

type StreamFunc func(context.Context) (io.WriteCloser, io.WriteCloser, func())

Jump to

Keyboard shortcuts

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