Documentation
¶
Overview ¶
gitutil and its contents is originally forked from github.com/moby/buildkit/util/gitutil
Index ¶
- Constants
- Variables
- func IsCommitSHA(str string) bool
- func IsGitTransport(remote string) bool
- func MergeGitConfigEnv(env []string, entries map[string]string) []string
- func Tracer(ctx context.Context) trace.Tracer
- type GitCLI
- func (cli *GitCLI) Dir() string
- func (cli *GitCLI) GitDir(ctx context.Context) (string, error)
- func (cli *GitCLI) New(opts ...Option) *GitCLI
- func (cli *GitCLI) Run(ctx context.Context, args ...string) (_ []byte, rerr error)
- func (cli *GitCLI) URL(ctx context.Context) (string, error)
- func (cli *GitCLI) WorkTree(ctx context.Context) (string, error)
- type GitURL
- type GitURLFragment
- type Option
- func WithArgs(args ...string) Option
- func WithConfig(entries map[string]string) Option
- func WithDir(dir string) Option
- func WithExec(exec func(context.Context, *exec.Cmd) error) Option
- func WithGitBinary(path string) Option
- func WithGitDir(gitDir string) Option
- func WithHTTPAuthorizationHeader(remote *GitURL, header string) Option
- func WithHTTPTokenAuth(remote *GitURL, token, username string) Option
- func WithIgnoreError() Option
- func WithSSHAuthSock(sshAuthSock string) Option
- func WithSSHKnownHosts(sshKnownHosts string) Option
- func WithStreams(streams StreamFunc) Option
- func WithWorkTree(workTree string) Option
- type StreamFunc
Constants ¶
const ( HTTPProtocol string = "http" HTTPSProtocol string = "https" SSHProtocol string = "ssh" GitProtocol string = "git" )
const InstrumentationLibrary = "dagger.io/gitutil"
Variables ¶
var ( ErrGitAuthFailed = errors.New("git authentication failed") ErrGitNoRepo = errors.New("not a git repository") ErrShallowNotSupported = errors.New("shallow clone not supported") )
var ( ErrUnknownProtocol = errors.New("unknown protocol") ErrInvalidProtocol = errors.New("invalid protocol") )
Functions ¶
func IsCommitSHA ¶
func IsGitTransport ¶
func MergeGitConfigEnv ¶ added in v0.18.17
MergeGitConfigEnv appends git config entries to the environment using GIT_CONFIG_COUNT/KEY_i/VALUE_i. It preserves existing env vars (except it drops any prior COUNT lines), appends new pairs in sorted key order for determinism, and writes exactly one final COUNT.
It defensively scans both the current COUNT and the highest existing KEY_/VALUE_ index, then appends after max(COUNT, maxIndex+1).
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 (*GitCLI) New ¶
New returns a new git client with the same config as the current one, but with the given options applied on top.
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. "git@github.com:moby/buildkit.git").
See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols
func ParseURL ¶
ParseURL parses a BuildKit-style Git URL (that may contain additional fragment metadata) and returns a parsed GitURL object.
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 WithConfig ¶ added in v0.18.17
WithConfig merges git config key-value pairs into the environment using GIT_CONFIG_COUNT/KEY_i/VALUE_i so they propagate to all child processes.
func WithDir ¶
WithDir sets working directory.
This should be a path to any directory within a standard git repository.
func WithGitDir ¶
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 WithHTTPAuthorizationHeader ¶ added in v0.18.17
WithHTTPAuthorizationHeader scopes a prebuilt Authorization header (e.g., "Basic ...") to http.<base>/.extraheader for the given remote.
func WithHTTPTokenAuth ¶ added in v0.18.17
WithHTTPTokenAuth scopes an Authorization header built from a token to the given remote's host using http.<base>/.extraheader so sub-commands inherit it
func WithIgnoreError ¶ added in v0.18.6
func WithIgnoreError() Option
WithIgnoreError ignores all errors from the command.
func WithSSHAuthSock ¶
WithSSHAuthSock sets the ssh auth sock.
func WithSSHKnownHosts ¶
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 ¶
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())