Documentation ¶
Overview ¶
Package git implements support for querying and patching git repositories. Operations in this package are intended to be used in command line tooling and are therefore generally fatal on error.
Index ¶
- Variables
- type Commit
- type Diff
- type Header
- type Patch
- type Repo
- func (r *Repo) Apply(patch Patch) error
- func (r *Repo) Close() error
- func (r *Repo) Configure(key, value string)
- func (r *Repo) CopyLFSObject(src *Repo, pointer string) error
- func (r *Repo) Linearize() error
- func (r *Repo) ListLFSPointers() (pointers []string, err error)
- func (r *Repo) Log(args ...string) (commits []*Commit, err error)
- func (r *Repo) Patch(id digest.Digest, dstPrefix string) (Patch, error)
- func (r *Repo) Prefix() string
- func (r *Repo) Push(remote, remoteBranch string) error
- func (r *Repo) String() string
Constants ¶
This section is empty.
Variables ¶
var Dir = "/var/tmp/grit"
Dir is the directory in which git checkouts are made.
var SHA1 = digest.Digester(crypto.SHA1)
SHA1 is the digester used to represent Git hashes.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
type Commit struct { // Digest is the git hash for the commit. Digest digest.Digest // Headers is the set of headers present in the commit. Headers []Header // Body is the commit message. Body string // contains filtered or unexported fields }
Commit represents a single commit.
type Diff ¶
type Diff struct { // Path holds the path of the file to be changed. Path string // Meta holds the diff's metadata, treated opaquely. Meta []byte // Body is the actual diff contents. It is interpreted by // git when applying a patch. Body []byte }
A Diff represents a set of changes to a single file.
type Patch ¶
type Patch struct { // ID is the commit ID from which the patch was derived. ID digest.Digest // Author is the patch's author. Author string // Time is the commit time of the patch's underlying commit. Time time.Time // Subject is the patch's subject line. Subject string // Body is the patch's description. Body string // Diffs contains a set of diffs that represent the patch's // change. Diffs []Diff }
A Patch is a single, atomic change, originating in a Repo. Patches comprise one or more diffs, representing file changes in a repository. Patches may be derived from commits and applied to a repo in order to recreate that commit elsewhere, possibly by way of rewriting.
func (Patch) MaybeContainsLFSPointer ¶
MaybeContainsLFSPointer uses (coarse) heuristics to determine whether the patch could possibly contain an LFS pointer. If it returns false, then there is definitely not an LFS pointer in the patch.
func (Patch) Write ¶
Write serializes the patch to the standard git patch format and writes it to the provided writer. Write escapes diff-like content in the patch body. Specifically, lines beginning with "diff", "---", and "+++" are prefixed with a unicode zero width space. This is to avoid ambiguity in git's patch parsing. This appears to be an issue with git itself: patches that contain other patches embedded in the patch description fail to apply properly using standard git tooling.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
A Repo is a cached git repository against which supported git operations are issued.
func Open ¶
Open returns a repo representing the provided git remote url, branch, and prefix within the repository. The prefix is interpreted to provide a "view" into the git repository: all operations apply only to this prefix. Repositories are safe for concurrent operations across multiple uses on the same machine.
func (*Repo) Close ¶
Close relinquishes the repo's lock. Repo operations may not be safely performed after the repository has been closed.
func (*Repo) Configure ¶
Configure sets the configuration parameter named by key to the value value. Properties configured this way overrides the Git's defaults (e.g., sourced through a user's .gitconfig) for repo Git invocations.
func (*Repo) CopyLFSObject ¶
CopyLFSObject copies the object referred to by the provided pointer from the given source repository.
func (*Repo) ListLFSPointers ¶
ListLFSPointers returns paths to in the repository which are LFS pointers. The paths are relative to the repository's root.
func (*Repo) Log ¶
Log returns a set of commit objects representing the "git log" operation with the provided arguments.
func (*Repo) Patch ¶
Patch returns a patch representing the commit named by the provided ID. Arg dstPrefix is the prefix of the destination repository. If dstPrefix!="", it it is prepended to the pathnames in the patch.