Documentation ¶
Overview ¶
Package gitoutput reads the output of calls to `git`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( LsTreeFields = []Field{ObjectMode, ObjectType, ObjectName, Path} LsFilesFields = []Field{ObjectMode, ObjectName, ObjectStage, Path} StatusFields = []Field{StatusX, StatusY, Path} )
These describe the structure of fields in the output of `git` commands.
var ( ErrInvalidObjectMode = errors.New("object mode is not valid") ErrInvalidObjectType = errors.New("object type is not valid") ErrInvalidObjectName = errors.New("object name is not valid") ErrInvalidObjectStage = errors.New("object stage is not valid") ErrInvalidObjectStatusX = errors.New("object status x is not valid") ErrInvalidObjectStatusY = errors.New("object status y is not valid") ErrInvalidPath = errors.New("path is not valid") ErrUnknownField = errors.New("unknown field") )
These are the errors that can be returned in ParseError.Err.
Functions ¶
func CheckObjectName ¶
CheckObjectName asserts that a byte slice looks like a SHA hash.
Types ¶
type Field ¶
type Field int
Field is the type for fields available in outputs to `git`. Used for naming and sensible call sites.
const ( // ObjectMode is the mode field from `git` outputs. e.g. 100644 ObjectMode Field = iota + 1 // ObjectType is the set of allowed types from `git` outputs: blob, tree, commit ObjectType // ObjectName is the 40-character SHA hash ObjectName // ObjectStage is a value 0-3. ObjectStage // StatusX is the first character of the two-character output from `git status`. StatusX // StatusY is the second character of the two-character output from `git status`. StatusY // Path is the file path under version control in `git`. Path )
type LsFilesEntry ¶
type LsFilesEntry []string
LsFilesEntry is the result from call `git ls-tree`
func (LsFilesEntry) GetField ¶
func (e LsFilesEntry) GetField(field Field) string
GetField returns the value of the specified field.
type LsTreeEntry ¶
type LsTreeEntry []string
LsTreeEntry is the result from call `git ls-files`
func (LsTreeEntry) GetField ¶
func (e LsTreeEntry) GetField(field Field) string
GetField returns the value of the specified field.
type ParseError ¶
type ParseError struct { Entry int // Entry where the error occurred Column int // Column where the error occurred Err error // The actual error }
A ParseError is returned for parsing errors. Entries and columns are both 1-indexed.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error creates a string for a parse error.
type Reader ¶
type Reader struct { // ReuseRecord controls whether calls to Read may return a slice sharing // the backing array of the previous call's returned slice for performance. // By default, each call to Read returns newly allocated memory owned by the caller. ReuseRecord bool // Fields specifies the type of each field. Fields []Field // contains filtered or unexported fields }
A Reader reads records from `git`'s output`.
func NewLSFilesReader ¶
NewLSFilesReader returns a new Reader that reads from reader.
func NewLSTreeReader ¶
NewLSTreeReader returns a new Reader that reads from reader.
func NewStatusReader ¶
NewStatusReader returns a new Reader that reads from reader.
func (*Reader) FieldPos ¶
FieldPos returns the entry and column corresponding to the start of the field with the given index in the slice most recently returned by Read. Numbering of entries and columns starts at 1; columns are counted in bytes, not runes.
If this is called with an out-of-bounds index, it panics.
type StatusEntry ¶
type StatusEntry []string
StatusEntry is the result from call `git status`
func (StatusEntry) GetField ¶
func (e StatusEntry) GetField(field Field) string
GetField returns the value of the specified field.