Help us shape the future of Go! Take the 2026 Go Developer Survey

gitclone

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gitclone is the one place sift runs `git clone`. The CLI (`sift clone`) and the web server (`POST /api/clone`) both go through it, so URL validation, hardening, and git invocation have a single copy to audit.

Only remote repositories are accepted: https, http, ssh, git, and scp-like `user@host:path`. Local paths and file:// URLs are refused everywhere (there is no legitimate need to "clone" a directory that is already on disk, and a web endpoint must never be talked into reading one), as are git's `<helper>::<address>` remote-helper syntax (`ext::` runs commands) and anything that could be mistaken for a command-line option.

Authentication is left entirely to the system git: credential helpers, ~/.gitconfig, and the ssh agent all work as they do in a terminal.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoGit = errors.New("git is not installed or not on PATH")

ErrNoGit means the git executable is not on PATH.

Functions

func Args

func Args(o Options) []string

Args builds the git argument list. Exported for tests.

func Available

func Available() bool

Available reports whether a usable git executable exists. The web UI hides every clone entry point when it does not.

func Clone

func Clone(ctx context.Context, o Options) error

Clone validates o and runs git clone, honoring ctx cancellation.

func Redact

func Redact(raw string) string

Redact strips credentials from a URL for logs and UI. Anything that fails to parse is returned without its userinfo as best effort.

func RepoName

func RepoName(raw string) string

RepoName derives a short directory/display name from a repository URL ("https://host/owner/repo.git" → "repo"), falling back to "repo".

func ValidateRef

func ValidateRef(ref string) error

ValidateRef checks a branch or tag name before it is passed to --branch.

func ValidateURL

func ValidateURL(raw string) error

ValidateURL accepts only remote repository URLs. The returned message is safe to show to the user.

Types

type Failure

type Failure struct {
	Err error
	// Detail is the tail of git's non-progress output, for display.
	Detail string
}

Failure is a git exit failure carrying git's last messages.

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) Unwrap

func (f *Failure) Unwrap() error

type Options

type Options struct {
	URL    string
	Branch string
	// Depth is the history depth; values below 1 are rejected.
	Depth int
	// Dest is the checkout path; it must not exist (or be empty).
	Dest string
	// Interactive lets git use the caller's terminal for prompts (the CLI).
	// Otherwise git never prompts and runs without a controlling terminal, so
	// a repository that needs credentials fails fast instead of hanging.
	Interactive bool
	Stdin       io.Reader
	// Output receives git's raw stderr/stdout (the CLI passes the terminal).
	Output io.Writer
	// OnProgress receives parsed "Receiving objects: 42%" style updates.
	OnProgress func(Progress)
}

Options configures one clone.

type Progress

type Progress struct {
	Phase   string
	Percent int
}

Progress is one parsed git progress update.

type Temp

type Temp struct {
	// Dir is the private parent directory that Remove deletes.
	Dir string
	// Repo is the (not yet existing) checkout path inside Dir.
	Repo string
}

Temp is a throwaway checkout location, created like the CLI always has: a private sift-clone-* directory under the OS temp dir holding one repo dir. An OS temp cleaner (or reboot) reclaims anything a crash leaves behind.

func NewTemp

func NewTemp(name string) (*Temp, error)

NewTemp creates the private parent directory (mode 0700).

func (*Temp) Remove

func (t *Temp) Remove() error

Remove deletes the checkout and its parent. Safe to call more than once.

Jump to

Keyboard shortcuts

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