git

package
v0.0.0-...-d3b81e6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var Dir = "/var/tmp/grit"

Dir is the directory in which git checkouts are made.

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.

func (*Commit) ShipitID

func (c *Commit) ShipitID() (ids []string)

ShipitID returns the shipit ID, if any.

func (*Commit) String

func (c *Commit) String() string

String returns a "one-line" commit message.

func (*Commit) Title

func (c *Commit) Title() string

Title returns the commit's title -- the first line of its body.

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 Header struct{ K, V string }

Header is a commit header.

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

func (p Patch) MaybeContainsLFSPointer() bool

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) Patch

func (p Patch) Patch() string

Patch returns the serialized patch as a string.

func (Patch) Paths

func (p Patch) Paths() map[string]bool

Paths returns the paths touched by this Patch as a set.

func (Patch) String

func (p Patch) String() string

func (Patch) Write

func (p Patch) Write(w io.Writer) error

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

func Open(url, prefix, branch string) (*Repo, error)

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) Apply

func (r *Repo) Apply(patch Patch) error

Apply applies a patch to the repository.

func (*Repo) Close

func (r *Repo) Close() error

Close relinquishes the repo's lock. Repo operations may not be safely performed after the repository has been closed.

func (*Repo) Configure

func (r *Repo) Configure(key, value string)

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

func (r *Repo) CopyLFSObject(src *Repo, pointer string) error

CopyLFSObject copies the object referred to by the provided pointer from the given source repository.

func (*Repo) Linearize

func (r *Repo) Linearize() error

Linearize linearizes the repository's history.

func (*Repo) ListLFSPointers

func (r *Repo) ListLFSPointers() (pointers []string, err error)

ListLFSPointers returns paths to in the repository which are LFS pointers. The paths are relative to the repository's root.

func (*Repo) Log

func (r *Repo) Log(args ...string) (commits []*Commit, err error)

Log returns a set of commit objects representing the "git log" operation with the provided arguments.

func (*Repo) Patch

func (r *Repo) Patch(id digest.Digest, dstPrefix string) (Patch, error)

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.

func (*Repo) Prefix

func (r *Repo) Prefix() string

Prefix returns the prefix within the repository, as specified in Open.

func (*Repo) Push

func (r *Repo) Push(remote, remoteBranch string) error

Push pushes the current state of the repository to the provided branch on the provided remote.

func (*Repo) String

func (r *Repo) String() string

Jump to

Keyboard shortcuts

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