gitutil

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

gitutil and its contents is originally forked from github.com/moby/buildkit/util/gitutil

Index

Constants

View Source
const (
	HTTPProtocol  string = "http"
	HTTPSProtocol string = "https"
	SSHProtocol   string = "ssh"
	GitProtocol   string = "git"
)
View Source
const InstrumentationLibrary = "dagger.io/gitutil"

Variables

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

Functions

func IsCommitSHA

func IsCommitSHA(str string) bool

func IsGitTransport

func IsGitTransport(remote string) bool

func Tracer

func Tracer(ctx context.Context) trace.Tracer

Types

type GitCLI

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

func NewGitCLI(opts ...Option) *GitCLI

New initializes a new git client

func (*GitCLI) Dir

func (cli *GitCLI) Dir() string

func (*GitCLI) GitDir

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

func (*GitCLI) New

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

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

Run executes a git command with the given args.

func (*GitCLI) WorkTree

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

type GitURL

type GitURL struct {
	// Scheme is the protocol over which the git repo can be accessed
	Scheme string

	// Host is the remote host that hosts the git repo
	Host string
	// Path is the path on the host to access the repo
	Path string
	// User is the username/password to access the host
	User *url.Userinfo
	// Fragment can contain additional metadata
	Fragment *GitURLFragment
	// contains filtered or unexported fields
}

URL is a custom URL type that points to a remote Git repository.

URLs can be parsed from both standard URLs (e.g. "https://github.com/moby/buildkit.git"), as well as SCP-like URLs (e.g. "[email protected]:moby/buildkit.git").

See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols

func ParseURL

func ParseURL(remote string) (*GitURL, error)

ParseURL parses a BuildKit-style Git URL (that may contain additional fragment metadata) and returns a parsed GitURL object.

func (*GitURL) Remote

func (gitURL *GitURL) Remote() string

Remote is a valid URL remote to pass into the Git CLI tooling (i.e. without the fragment metadata)

func (*GitURL) String

func (gitURL *GitURL) String() string

type GitURLFragment

type GitURLFragment struct {
	// Ref is the git reference
	Ref string
	// Subdir is the sub-directory inside the git repository to use
	Subdir string
}

GitURLFragment is the buildkit-specific metadata extracted from the fragment of a remote URL.

func (*GitURLFragment) String

func (fragment *GitURLFragment) String() string

type Option

type Option func(b *GitCLI)

Option provides a variadic option for configuring the git client.

func WithArgs

func WithArgs(args ...string) Option

WithArgs sets extra args.

func WithDir

func WithDir(dir string) Option

WithDir sets working directory.

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

func WithExec

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

WithExec sets the command exec function.

func WithGitBinary

func WithGitBinary(path string) Option

WithGitBinary sets the git binary path.

func WithGitDir

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

func WithSSHAuthSock(sshAuthSock string) Option

WithSSHAuthSock sets the ssh auth sock.

func WithSSHKnownHosts

func WithSSHKnownHosts(sshKnownHosts string) Option

WithSSHKnownHosts sets the known hosts file.

func WithStreams

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

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

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
JackTT - Gopher 🇻🇳