Documentation
¶
Overview ¶
Package gitx is the only package that runs the system git binary, with argument slices, validated refs and hardened flags and environment.
Index ¶
- Constants
- Variables
- func Available() bool
- type Config
- type Entry
- type Git
- func (g *Git) InRepo(ctx context.Context, dir string) (bool, error)
- func (g *Git) ListFiles(ctx context.Context, dir string) ([]string, error)
- func (g *Git) StreamLog(ctx context.Context, dir string, opt LogOptions, fn func(Entry) bool) error
- func (g *Git) StreamStaged(ctx context.Context, dir string, maxBytes int64, fn func(Entry) bool) error
- func (g *Git) ValidateRef(ctx context.Context, dir, ref string) (string, error)
- type LogOptions
Constants ¶
const DefaultMaxBytes = 10 << 20
DefaultMaxBytes is the per-file limit used when none is given (10 MiB).
Variables ¶
var ( // ErrNotFound: the git binary is not on PATH. ErrNotFound = errors.New("gitx: git not found") // ErrNotRepo: the directory is not inside a git work tree. ErrNotRepo = errors.New("gitx: not a git repository") // ErrBadRef: a ref is not acceptable or does not resolve to a commit. ErrBadRef = errors.New("gitx: invalid ref") // ErrGit: git ran and failed. ErrGit = errors.New("gitx: git failed") )
Errors returned by gitx. They carry no git output (AD-3).
Functions ¶
Types ¶
type Config ¶
type Config struct {
// HTTPSProxy becomes https_proxy.
HTTPSProxy string
// NoProxy becomes no_proxy.
NoProxy string
// CAFile is a PEM file path that becomes GIT_SSL_CAINFO.
CAFile string
}
Config is the network configuration handed to git, mapped from the public network options. Empty fields set nothing.
type Entry ¶
type Entry struct {
// Commit, Author and Date describe the commit; they are empty for staged entries.
// Author is the name only, never the email. Date is UTC.
Commit string
Author string
Date time.Time
// Path is the post-image path with forward slashes, relative to the scan directory.
Path string
// Data is the post-image of the file with every line that was not added replaced by
// an empty line, so line k of Data is line k of the file. Nil when TooLarge.
Data []byte
// TooLarge is set when Data would exceed the size limit.
TooLarge bool
}
Entry is the added lines of one file in one commit, or in the index.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git runs hardened git commands. The zero value is not usable; call New.
func (*Git) InRepo ¶
InRepo reports whether dir is inside a git work tree. A directory that is not, or that git refuses to read (for example because of its owner), reports false.
func (*Git) ListFiles ¶
ListFiles lists what git would commit from dir: tracked files plus untracked files that are not ignored, relative to dir with forward slashes, without duplicates. A path that is absolute or climbs out of dir is dropped.
func (*Git) StreamLog ¶
StreamLog streams the added lines of the whole history of dir, one Entry per file per commit, through fn, which returns false to stop. It reads git's output through a bufio.Reader and never holds more than one file of one commit.
func (*Git) StreamStaged ¶
func (g *Git) StreamStaged(ctx context.Context, dir string, maxBytes int64, fn func(Entry) bool) error
StreamStaged streams the added lines of the index against HEAD, one Entry per file, through fn, which returns false to stop. Deleted and binary files give no Entry.
func (*Git) ValidateRef ¶
ValidateRef checks ref for --since and resolves it to a full commit id. The ref must be non-empty, must not start with "-" or hold NUL, whitespace or control characters, and must be 4 to 64 hex characters or pass git check-ref-format --allow-onelevel. It then must resolve to a commit. Any failure is ErrBadRef.
type LogOptions ¶
type LogOptions struct {
// Since is a full commit id (from ValidateRef): history is limited to commits
// reachable from HEAD but not from it. Empty means every ref (--all).
Since string
// MaxBytes is the largest post-image one file of one commit may take; larger
// ones come back with TooLarge set. 0 or less means 10 MiB.
MaxBytes int64
// OnCommit, when set, is called once per commit the log walks, including commits
// that add no lines (and so give no Entry).
OnCommit func()
}
LogOptions configures StreamLog.