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 ¶
var ErrNoGit = errors.New("git is not installed or not on PATH")
ErrNoGit means the git executable is not on PATH.
Functions ¶
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 Redact ¶
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 ¶
RepoName derives a short directory/display name from a repository URL ("https://host/owner/repo.git" → "repo"), falling back to "repo".
func ValidateRef ¶
ValidateRef checks a branch or tag name before it is passed to --branch.
func ValidateURL ¶
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.
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 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.