git

package module
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 21 Imported by: 223

README

Git Module

GitHub Workflow Status codecov GoDoc Sourcegraph

Package git-module is a Go module for Git access through shell commands.

Requirements

  • Go version must be at least 1.17.
  • Git version must be no less than 1.8.3.
  • For Windows users, try to use the latest version of both.

License

This project is under the MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	RefsHeads = "refs/heads/"
	RefsTags  = "refs/tags/"
)
View Source
const DefaultHooksDir = "hooks"

DefaultHooksDir is the default directory for Git hooks.

View Source
const DefaultTimeout = time.Minute

DefaultTimeout is the default timeout duration for all commands.

View Source
const EmptyID = "0000000000000000000000000000000000000000"

EmptyID is an ID with empty SHA-1 hash.

View Source
const LogFormatHashOnly = `format:%H`

Variables

View Source
var (
	ErrParentNotExist       = errors.New("parent does not exist")
	ErrSubmoduleNotExist    = errors.New("submodule does not exist")
	ErrRevisionNotExist     = errors.New("revision does not exist")
	ErrRemoteNotExist       = errors.New("remote does not exist")
	ErrURLNotExist          = errors.New("URL does not exist")
	ErrExecTimeout          = errors.New("execution was timed out")
	ErrNoMergeBase          = errors.New("no merge based was found")
	ErrNotBlob              = errors.New("the entry is not a blob")
	ErrNotDeleteNonPushURLs = errors.New("will not delete all non-push URLs")
)
View Source
var (
	// ServerSideHooks contains a list of Git hooks that are supported on the server
	// side.
	ServerSideHooks = []HookName{HookPreReceive, HookUpdate, HookPostReceive}
	// ServerSideHookSamples contains samples of Git hooks that are supported on the
	// server side.
	ServerSideHookSamples = map[HookName]string{
		HookPreReceive: `#!/bin/sh
#
# An example hook script to make use of push options.
# The example simply echoes all push options that start with 'echoback='
# and rejects all pushes when the "reject" push option is used.
#
# To enable this hook, rename this file to "pre-receive".

if test -n "$GIT_PUSH_OPTION_COUNT"
then
	i=0
	while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
	do
		eval "value=\$GIT_PUSH_OPTION_$i"
		case "$value" in
		echoback=*)
			echo "echo from the pre-receive-hook: ${value#*=}" >&2
			;;
		reject)
			exit 1
		esac
		i=$((i + 1))
	done
fi
`,
		HookUpdate: `#!/bin/sh
#
# An example hook script to block unannotated tags from entering.
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
#
# To enable this hook, rename this file to "update".
#
# Config
# ------
# hooks.allowunannotated
#   This boolean sets whether unannotated tags will be allowed into the
#   repository.  By default they won't be.
# hooks.allowdeletetag
#   This boolean sets whether deleting tags will be allowed in the
#   repository.  By default they won't be.
# hooks.allowmodifytag
#   This boolean sets whether a tag may be modified after creation. By default
#   it won't be.
# hooks.allowdeletebranch
#   This boolean sets whether deleting branches will be allowed in the
#   repository.  By default they won't be.
# hooks.denycreatebranch
#   This boolean sets whether remotely creating branches will be denied
#   in the repository.  By default this is allowed.
#

# --- Command line
refname="$1"
oldrev="$2"
newrev="$3"

# --- Safety check
if [ -z "$GIT_DIR" ]; then
	echo "Don't run this script from the command line." >&2
	echo " (if you want, you could supply GIT_DIR then run" >&2
	echo "  $0 <ref> <oldrev> <newrev>)" >&2
	exit 1
fi

if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
	echo "usage: $0 <ref> <oldrev> <newrev>" >&2
	exit 1
fi

# --- Config
allowunannotated=$(git config --bool hooks.allowunannotated)
allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
denycreatebranch=$(git config --bool hooks.denycreatebranch)
allowdeletetag=$(git config --bool hooks.allowdeletetag)
allowmodifytag=$(git config --bool hooks.allowmodifytag)

# check for no description
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
case "$projectdesc" in
"Unnamed repository"* | "")
	echo "*** Project description file hasn't been set" >&2
	exit 1
	;;
esac

# --- Check types
# if $newrev is 0000...0000, it's a commit to delete a ref.
zero="0000000000000000000000000000000000000000"
if [ "$newrev" = "$zero" ]; then
	newrev_type=delete
else
	newrev_type=$(git cat-file -t $newrev)
fi

case "$refname","$newrev_type" in
	refs/tags/*,commit)
		# un-annotated tag
		short_refname=${refname##refs/tags/}
		if [ "$allowunannotated" != "true" ]; then
			echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
			echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
			exit 1
		fi
		;;
	refs/tags/*,delete)
		# delete tag
		if [ "$allowdeletetag" != "true" ]; then
			echo "*** Deleting a tag is not allowed in this repository" >&2
			exit 1
		fi
		;;
	refs/tags/*,tag)
		# annotated tag
		if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
		then
			echo "*** Tag '$refname' already exists." >&2
			echo "*** Modifying a tag is not allowed in this repository." >&2
			exit 1
		fi
		;;
	refs/heads/*,commit)
		# branch
		if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
			echo "*** Creating a branch is not allowed in this repository" >&2
			exit 1
		fi
		;;
	refs/heads/*,delete)
		# delete branch
		if [ "$allowdeletebranch" != "true" ]; then
			echo "*** Deleting a branch is not allowed in this repository" >&2
			exit 1
		fi
		;;
	refs/remotes/*,commit)
		# tracking branch
		;;
	refs/remotes/*,delete)
		# delete tracking branch
		if [ "$allowdeletebranch" != "true" ]; then
			echo "*** Deleting a tracking branch is not allowed in this repository" >&2
			exit 1
		fi
		;;
	*)
		# Anything else (is there anything else?)
		echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
		exit 1
		;;
esac

# --- Finished
exit 0
`,
		HookPostReceive: `#!/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master

while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" = "$branch" ]; then
        # Do something
    fi
done`,
	}
)
View Source
var ErrReferenceNotExist = errors.New("reference does not exist")

Functions

func Add added in v1.3.0

func Add(repoPath string, opts ...AddOptions) error

Add adds local changes to index for the repository in given path.

func BinVersion

func BinVersion() (string, error)

BinVersion returns current Git binary version that is used by this module.

func Checkout

func Checkout(repoPath, branch string, opts ...CheckoutOptions) error

Checkout checks out to given branch for the repository in given path.

func Clone

func Clone(url, dst string, opts ...CloneOptions) error

Clone clones the repository from remote URL to the destination.

func CreateCommit added in v1.3.0

func CreateCommit(repoPath string, committer *Signature, message string, opts ...CommitOptions) error

CreateCommit commits local changes with given author, committer and message for the repository in given path.

func DeleteBranch

func DeleteBranch(repoPath, name string, opts ...DeleteBranchOptions) error

DeleteBranch deletes the branch from the repository in given path.

func DiffNameOnly added in v1.3.0

func DiffNameOnly(repoPath, base, head string, opts ...DiffNameOnlyOptions) ([]string, error)

DiffNameOnly returns a list of changed files between base and head revisions of the repository in given path.

func Fsck

func Fsck(repoPath string, opts ...FsckOptions) error

Fsck verifies the connectivity and validity of the objects in the database for the repository in given path.

func HasTag added in v1.3.0

func HasTag(repoPath, tag string, opts ...ShowRefVerifyOptions) bool

HasTag returns true if given tag exists in the repository in given path. The tag must be given in short name e.g. "v1.0.0".

func Init added in v1.0.0

func Init(path string, opts ...InitOptions) error

Init initializes a new Git repository.

func IsURLAccessible added in v1.0.0

func IsURLAccessible(timeout time.Duration, url string) bool

IsURLAccessible returns true if given remote URL is accessible via Git within given timeout.

func MergeBase added in v1.3.0

func MergeBase(repoPath, base, head string, opts ...MergeBaseOptions) (string, error)

MergeBase returns merge base between base and head revisions of the repository in given path.

func Move added in v1.3.0

func Move(repoPath, src, dst string, opts ...MoveOptions) error

Move moves a file, a directory, or a symlink file or directory from source to destination for the repository in given path.

func Push

func Push(repoPath, remote, branch string, opts ...PushOptions) error

Push pushes local changes to given remote and branch for the repository in given path.

func ReceivePack added in v1.8.3

func ReceivePack(path string, opts ...ReceivePackOptions) ([]byte, error)

ReceivePack receives what is pushed into the repository in given path.

func RefShortName added in v1.0.0

func RefShortName(ref string) string

RefShortName returns short name of heads or tags. Other references will return original string.

func RemoteAdd added in v1.3.0

func RemoteAdd(repoPath, name, url string, opts ...RemoteAddOptions) error

RemoteAdd adds a new remote to the repository in given path.

func RemoteGetURL added in v1.2.0

func RemoteGetURL(repoPath, name string, opts ...RemoteGetURLOptions) ([]string, error)

RemoteGetURL retrieves URL(s) of a remote of the repository in given path.

func RemoteRemove added in v1.3.0

func RemoteRemove(repoPath, name string, opts ...RemoteRemoveOptions) error

RemoteRemove removes a remote from the repository in given path.

func RemoteSetURL added in v1.2.0

func RemoteSetURL(repoPath, name, newurl string, opts ...RemoteSetURLOptions) error

RemoteSetURL sets first URL of the remote with given name of the repository in given path.

func RemoteSetURLAdd added in v1.2.0

func RemoteSetURLAdd(repoPath, name, newurl string, opts ...RemoteSetURLAddOptions) error

RemoteSetURLAdd appends an URL to the remote with given name of the repository in given path. Use RemoteSetURL to overwrite the URL(s) instead.

func RemoteSetURLDelete added in v1.2.0

func RemoteSetURLDelete(repoPath, name, regex string, opts ...RemoteSetURLDeleteOptions) error

RemoteSetURLDelete deletes the remote with given name of the repository in given path.

func Remotes added in v1.2.0

func Remotes(repoPath string, opts ...RemotesOptions) ([]string, error)

Remotes lists remotes of the repository in given path.

func RepoAdd deprecated added in v1.0.0

func RepoAdd(repoPath string, opts ...AddOptions) error

Deprecated: Use Add instead.

func RepoAddRemote deprecated added in v1.0.0

func RepoAddRemote(repoPath, name, url string, opts ...RemoteAddOptions) error

Deprecated: Use RemoteAdd instead.

func RepoCheckout deprecated added in v1.0.0

func RepoCheckout(repoPath, branch string, opts ...CheckoutOptions) error

Deprecated: Use Checkout instead.

func RepoCommit deprecated added in v1.0.0

func RepoCommit(repoPath string, committer *Signature, message string, opts ...CommitOptions) error

Deprecated: Use CreateCommit instead.

func RepoDeleteBranch deprecated added in v1.0.0

func RepoDeleteBranch(repoPath, name string, opts ...DeleteBranchOptions) error

Deprecated: Use DeleteBranch instead.

func RepoDiffNameOnly deprecated added in v1.0.0

func RepoDiffNameOnly(repoPath, base, head string, opts ...DiffNameOnlyOptions) ([]string, error)

Deprecated: Use DiffNameOnly instead.

func RepoFsck deprecated added in v1.0.0

func RepoFsck(repoPath string, opts ...FsckOptions) error

Deprecated: Use Fsck instead.

func RepoHasBranch added in v1.0.0

func RepoHasBranch(repoPath, branch string, opts ...ShowRefVerifyOptions) bool

RepoHasBranch returns true if given branch exists in the repository in given path. The branch must be given in short name e.g. "master".

func RepoHasReference added in v1.0.0

func RepoHasReference(repoPath, ref string, opts ...ShowRefVerifyOptions) bool

RepoHasReference returns true if given reference exists in the repository in given path. The reference must be given in full refspec, e.g. "refs/heads/master".

func RepoHasTag deprecated added in v1.0.0

func RepoHasTag(repoPath, tag string, opts ...ShowRefVerifyOptions) bool

Deprecated: Use HasTag instead.

func RepoMergeBase deprecated added in v1.0.0

func RepoMergeBase(repoPath, base, head string, opts ...MergeBaseOptions) (string, error)

Deprecated: Use MergeBase instead.

func RepoMove deprecated added in v1.0.0

func RepoMove(repoPath, src, dst string, opts ...MoveOptions) error

Deprecated: Use Move instead.

func RepoPush deprecated added in v1.0.0

func RepoPush(repoPath, remote, branch string, opts ...PushOptions) error

Deprecated: Use Push instead.

func RepoRemoveRemote deprecated added in v1.0.0

func RepoRemoveRemote(repoPath, name string, opts ...RemoteRemoveOptions) error

Deprecated: Use RemoteRemove instead.

func RepoReset deprecated added in v1.0.0

func RepoReset(repoPath, rev string, opts ...ResetOptions) error

Deprecated: Use Reset instead.

func RepoShowRefVerify deprecated added in v1.0.0

func RepoShowRefVerify(repoPath, ref string, opts ...ShowRefVerifyOptions) (string, error)

Deprecated: Use ShowRefVerify instead.

func RepoTags added in v1.0.0

func RepoTags(repoPath string, opts ...TagsOptions) ([]string, error)

RepoTags returns a list of tags of the repository in given path.

func Reset added in v1.3.0

func Reset(repoPath, rev string, opts ...ResetOptions) error

Reset resets working tree to given revision for the repository in given path.

func SetOutput added in v1.0.0

func SetOutput(output io.Writer)

SetOutput sets the output writer for logs.

func SetPrefix added in v1.0.0

func SetPrefix(prefix string)

SetPrefix sets the prefix to be prepended to each log entry.

func ShowRefVerify added in v1.3.0

func ShowRefVerify(repoPath, ref string, opts ...ShowRefVerifyOptions) (string, error)

ShowRefVerify returns the commit ID of given reference if it exists in the repository in given path.

func StreamParseDiff added in v1.0.0

func StreamParseDiff(r io.Reader, done chan<- SteamParseDiffResult, maxFiles, maxFileLines, maxLineChars int)

StreamParseDiff parses the diff read from the given io.Reader. It does parse-on-read to minimize the time spent on huge diffs. It accepts a channel to notify and send error (if any) to the caller when the process is done. Therefore, this method should be called in a goroutine asynchronously.

func SymbolicRef added in v1.7.2

func SymbolicRef(repoPath string, opts ...SymbolicRefOptions) (string, error)

SymbolicRef returns the reference name (e.g. "refs/heads/master") pointed by the symbolic ref in the repository in given path. It returns an empty string and nil error when doing set operation.

func UnescapeChars

func UnescapeChars(in []byte) []byte

UnescapeChars reverses escaped characters.

func UpdateServerInfo added in v1.8.3

func UpdateServerInfo(path string, opts ...UpdateServerInfoOptions) error

UpdateServerInfo updates the auxiliary info file on the server side for the repository in given path.

func UploadPack added in v1.8.3

func UploadPack(path string, opts ...UploadPackOptions) ([]byte, error)

UploadPack sends the packfile to the client for the repository in given path.

Types

type AddOptions added in v1.0.0

type AddOptions struct {
	// Indicates whether to add all changes to index.
	All bool
	// The specific pathspecs to be added to index.
	Pathspecs []string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

AddOptions contains optional arguments for adding local changes.

Docs: https://git-scm.com/docs/git-add

type AddRemoteOptions deprecated added in v0.8.3

type AddRemoteOptions = RemoteAddOptions

Deprecated: Use RemoteAddOptions instead.

type ArchiveFormat added in v1.0.0

type ArchiveFormat string

ArchiveFormat is the format of an archive.

const (
	ArchiveZip   ArchiveFormat = "zip"
	ArchiveTarGz ArchiveFormat = "tar.gz"
)

A list of formats can be created by Git for an archive.

type Blame added in v1.1.4

type Blame struct {
	// contains filtered or unexported fields
}

Blame contains information of a Git file blame.

func (*Blame) Line added in v1.1.4

func (b *Blame) Line(i int) *Commit

Line returns the commit by given line number (1-based). It returns nil when no such line.

type BlameOptions added in v1.1.4

type BlameOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

BlameOptions contains optional arguments for blaming a file. Docs: https://git-scm.com/docs/git-blame

type Blob

type Blob struct {
	*TreeEntry
}

Blob is a blob object.

func (*Blob) Bytes added in v1.0.0

func (b *Blob) Bytes() ([]byte, error)

Bytes reads and returns the content of the blob all at once in bytes. This can be very slow and memory consuming for huge content.

func (*Blob) Pipeline added in v1.0.0

func (b *Blob) Pipeline(stdout, stderr io.Writer) error

Pipeline reads the content of the blob and pipes stdout and stderr to supplied io.Writer.

type CatFileBlobOptions added in v1.7.0

type CatFileBlobOptions struct {
	// The timeout duration before giving up for each shell command execution.
	// The default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CatFileBlobOptions contains optional arguments for verifying the objects.

Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt

type CatFileCommitOptions added in v1.0.0

type CatFileCommitOptions struct {
	// The timeout duration before giving up for each shell command execution.
	// The default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CatFileCommitOptions contains optional arguments for verifying the objects.

Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt-lttypegt

type CatFileTypeOptions added in v1.1.0

type CatFileTypeOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CatFileTypeOptions contains optional arguments for showing the object type.

Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt--t

type CheckoutOptions

type CheckoutOptions struct {
	// The base branch if checks out to a new branch.
	BaseBranch string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CheckoutOptions contains optional arguments for checking out to a branch.

Docs: https://git-scm.com/docs/git-checkout

type CloneOptions added in v1.0.0

type CloneOptions struct {
	// Indicates whether the repository should be cloned as a mirror.
	Mirror bool
	// Indicates whether the repository should be cloned in bare format.
	Bare bool
	// Indicates whether to suppress the log output.
	Quiet bool
	// The branch to checkout for the working tree when Bare=false.
	Branch string
	// The number of revisions to clone.
	Depth uint64
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CloneOptions contains optional arguments for cloning a repository.

Docs: https://git-scm.com/docs/git-clone

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command contains the name, arguments and environment variables of a command.

func NewCommand

func NewCommand(args ...string) *Command

NewCommand creates and returns a new Command with given arguments for "git".

func NewCommandWithContext added in v1.8.2

func NewCommandWithContext(ctx context.Context, args ...string) *Command

NewCommandWithContext creates and returns a new Command with given arguments and context for "git".

func (*Command) AddArgs added in v1.0.0

func (c *Command) AddArgs(args ...string) *Command

AddArgs appends given arguments to the command.

func (*Command) AddCommitter added in v1.4.0

func (c *Command) AddCommitter(committer *Signature) *Command

AddCommitter appends given committer to the command.

func (*Command) AddEnvs

func (c *Command) AddEnvs(envs ...string) *Command

AddEnvs appends given environment variables to the command.

func (*Command) AddOptions added in v1.6.0

func (c *Command) AddOptions(opts ...CommandOptions) *Command

AddOptions adds options to the command. Note: only the last option will take effect if there are duplicated options.

func (*Command) Run

func (c *Command) Run() ([]byte, error)

Run executes the command in working directory and default timeout duration. It returns stdout in string and error (combined with stderr).

func (*Command) RunInDir

func (c *Command) RunInDir(dir string) ([]byte, error)

RunInDir executes the command in given directory and default timeout duration. It returns stdout and error (combined with stderr).

func (*Command) RunInDirPipeline

func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error

RunInDirPipeline executes the command in given directory and default timeout duration. It pipes stdout and stderr to supplied io.Writer.

func (*Command) RunInDirPipelineWithTimeout deprecated added in v1.0.0

func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error)

RunInDirPipelineWithTimeout executes the command in given directory and timeout duration. It pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout duration is less than time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout if the execution was timed out.

Deprecated: Use RunInDirPipeline and CommandOptions instead. TODO: remove this in the next major version

func (*Command) RunInDirWithOptions added in v1.6.0

func (c *Command) RunInDirWithOptions(dir string, opts ...RunInDirOptions) (err error)

RunInDirWithOptions executes the command in given directory and options. It pipes stdin from supplied io.Reader, and pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout duration is less than time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout if the execution was timed out.

func (*Command) RunInDirWithTimeout deprecated added in v1.0.0

func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error)

RunInDirWithTimeout executes the command in given directory and timeout duration. It returns stdout in []byte and error (combined with stderr).

Deprecated: Use RunInDir and CommandOptions instead. TODO: remove this in the next major version

func (*Command) RunWithTimeout deprecated added in v1.0.0

func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error)

RunWithTimeout executes the command in working directory and given timeout duration. It returns stdout in string and error (combined with stderr).

Deprecated: Use RunInDir and CommandOptions instead. TODO: remove this in the next major version

func (*Command) SetTimeout added in v1.8.2

func (c *Command) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout for the command.

func (*Command) String

func (c *Command) String() string

String returns the string representation of the command.

func (Command) WithContext added in v1.8.2

func (c Command) WithContext(ctx context.Context) *Command

WithContext returns a new Command with the given context.

func (Command) WithTimeout added in v1.8.2

func (c Command) WithTimeout(timeout time.Duration) *Command

WithTimeout returns a new Command with given timeout.

type CommandOptions added in v1.6.0

type CommandOptions struct {
	Args    []string
	Envs    []string
	Timeout time.Duration
	Context context.Context
}

CommandOptions contains options for running a command. If timeout is zero, DefaultTimeout will be used. If timeout is less than zero, no timeout will be set. If context is nil, context.Background() will be used.

type Commit

type Commit struct {
	// The SHA-1 hash of the commit.
	ID *SHA1
	//  The author of the commit.
	Author *Signature
	// The committer of the commit.
	Committer *Signature
	// The full commit message.
	Message string

	*Tree
	// contains filtered or unexported fields
}

Commit contains information of a Git commit.

func Log added in v1.3.0

func Log(repoPath, rev string, opts ...LogOptions) ([]*Commit, error)

Log returns a list of commits in the state of given revision of the repository in given path. The returned list is in reverse chronological order.

func RepoLog deprecated added in v1.0.0

func RepoLog(repoPath, rev string, opts ...LogOptions) ([]*Commit, error)

Deprecated: Use Log instead.

func (*Commit) Ancestors added in v1.0.0

func (c *Commit) Ancestors(opts ...LogOptions) ([]*Commit, error)

Ancestors returns a list of ancestors of this commit in reverse chronological order.

func (*Commit) CommitByPath added in v1.0.0

func (c *Commit) CommitByPath(opts ...CommitByRevisionOptions) (*Commit, error)

CommitByPath returns the commit of the path in the state of this commit.

func (*Commit) CommitsAfter added in v1.0.0

func (c *Commit) CommitsAfter(after string, opts ...RevListOptions) ([]*Commit, error)

CommitsAfter returns a list of commits after given commit ID up to this commit. The returned list is in reverse chronological order.

func (*Commit) CommitsByPage added in v1.0.0

func (c *Commit) CommitsByPage(page, size int, opts ...CommitsByPageOptions) ([]*Commit, error)

CommitsByPage returns a paginated list of commits in the state of this commit. The returned list is in reverse chronological order.

func (*Commit) CommitsCount

func (c *Commit) CommitsCount(opts ...RevListCountOptions) (int64, error)

CommitsCount returns number of total commits up to this commit.

func (*Commit) CreateArchive

func (c *Commit) CreateArchive(format ArchiveFormat, dst string) error

CreateArchive creates given format of archive to the destination.

func (*Commit) FilesChangedAfter added in v1.0.0

func (c *Commit) FilesChangedAfter(after string, opts ...DiffNameOnlyOptions) ([]string, error)

FilesChangedAfter returns a list of files changed after given commit ID.

func (*Commit) IsImageFile

func (c *Commit) IsImageFile(subpath string) (bool, error)

IsImageFile returns true if the blob of the commit is an image by subpath.

func (*Commit) IsImageFileByIndex added in v1.1.0

func (c *Commit) IsImageFileByIndex(index string) (bool, error)

IsImageFileByIndex returns true if the blob of the commit is an image by index.

func (*Commit) Parent

func (c *Commit) Parent(n int, opts ...CatFileCommitOptions) (*Commit, error)

Parent returns the n-th parent commit (0-based) of this commit. It returns ErrRevisionNotExist if no such parent exists.

func (*Commit) ParentID

func (c *Commit) ParentID(n int) (*SHA1, error)

ParentID returns the SHA-1 hash of the n-th parent (0-based) of this commit. It returns an ErrParentNotExist if no such parent exists.

func (*Commit) ParentsCount added in v1.0.0

func (c *Commit) ParentsCount() int

ParentsCount returns number of parents of the commit. It returns 0 if this is the root commit, otherwise returns 1, 2, etc.

func (*Commit) SearchCommits

func (c *Commit) SearchCommits(pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)

SearchCommits searches commit message with given pattern. The returned list is in reverse chronological order.

func (*Commit) ShowNameStatus added in v1.0.0

func (c *Commit) ShowNameStatus(opts ...ShowNameStatusOptions) (*NameStatus, error)

ShowNameStatus returns name status of the commit.

func (*Commit) Submodule added in v1.0.0

func (c *Commit) Submodule(path string) (*Submodule, error)

Submodule returns submodule by given name. It returns an ErrSubmoduleNotExist if the path does not exist as a submodule.

func (*Commit) Submodules added in v1.0.0

func (c *Commit) Submodules() (Submodules, error)

Submodules returns submodules found in this commit.

func (*Commit) Summary

func (c *Commit) Summary() string

Summary returns first line of commit message.

type CommitByRevisionOptions added in v1.0.0

type CommitByRevisionOptions struct {
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CommitByRevisionOptions contains optional arguments for getting a commit.

Docs: https://git-scm.com/docs/git-log

type CommitOptions added in v1.0.0

type CommitOptions struct {
	// Author is the author of the changes if that's not the same as committer.
	Author *Signature
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CommitOptions contains optional arguments to commit changes.

Docs: https://git-scm.com/docs/git-commit

type CommitsByPageOptions added in v1.0.0

type CommitsByPageOptions struct {
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CommitsByPageOptions contains optional arguments for getting paginated commits.

Docs: https://git-scm.com/docs/git-log

type CommitsInfoOptions added in v1.0.0

type CommitsInfoOptions struct {
	// The relative path of the repository.
	Path string
	// The maximum number of goroutines to be used for getting commits information.
	// When not set (i.e. <=0), runtime.GOMAXPROCS is used to determine the value.
	MaxConcurrency int
	// The timeout duration before giving up for each shell command execution.
	// The default timeout duration will be used when not supplied.
	Timeout time.Duration
}

CommitsInfoOptions contains optional arguments for getting commits information.

type CommitsSinceOptions added in v1.0.0

type CommitsSinceOptions struct {
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CommitsSinceOptions contains optional arguments for listing commits since a time.

Docs: https://git-scm.com/docs/git-log

type CountObject

type CountObject struct {
	Count         int64
	Size          int64
	InPack        int64
	Packs         int64
	SizePack      int64
	PrunePackable int64
	Garbage       int64
	SizeGarbage   int64
}

CountObject contains disk usage report of a repository.

func CountObjects added in v1.3.0

func CountObjects(repoPath string, opts ...CountObjectsOptions) (*CountObject, error)

CountObjects returns disk usage report of the repository in given path.

func RepoCountObjects deprecated added in v1.0.0

func RepoCountObjects(repoPath string, opts ...CountObjectsOptions) (*CountObject, error)

Deprecated: Use CountObjects instead.

type CountObjectsOptions added in v1.0.0

type CountObjectsOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CountObjectsOptions contains optional arguments for counting objects.

Docs: https://git-scm.com/docs/git-count-objects

type CreateTagOptions added in v1.0.0

type CreateTagOptions struct {
	// Annotated marks a tag as annotated rather than lightweight.
	Annotated bool
	// Message specifies a tagging message for the annotated tag. It is ignored when tag is not annotated.
	Message string
	// Author is the author of the tag. It is ignored when tag is not annotated.
	Author *Signature
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

CreateTagOptions contains optional arguments for creating a tag.

Docs: https://git-scm.com/docs/git-tag

type DeleteBranchOptions

type DeleteBranchOptions struct {
	// Indicates whether to force delete the branch.
	Force bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

DeleteBranchOptions contains optional arguments for deleting a branch.

Docs: https://git-scm.com/docs/git-branch

type DeleteTagOptions added in v1.0.0

type DeleteTagOptions struct {
	// The timeout duration before giving up for each shell command execution.
	// The default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

DeleteTagOptions contains optional arguments for deleting a tag.

Docs: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---delete

type Diff

type Diff struct {
	Files []*DiffFile // The files in the diff
	// contains filtered or unexported fields
}

Diff represents a Git diff.

func (*Diff) IsIncomplete

func (d *Diff) IsIncomplete() bool

IsIncomplete returns true if the file is incomplete to the entire diff.

func (*Diff) NumFiles

func (d *Diff) NumFiles() int

NumFiles returns the number of files in the diff.

func (*Diff) TotalAdditions added in v1.0.0

func (d *Diff) TotalAdditions() int

TotalAdditions returns the total additions in the diff.

func (*Diff) TotalDeletions added in v1.0.0

func (d *Diff) TotalDeletions() int

TotalDeletions returns the total deletions in the diff.

type DiffBinaryOptions added in v1.0.0

type DiffBinaryOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

DiffBinaryOptions contains optional arguments for producing binary patch.

type DiffFile

type DiffFile struct {
	// The name of the file.
	Name string
	// The type of the file.
	Type DiffFileType
	// The index (SHA1 hash) of the file. For a changed/new file, it is the new SHA,
	// and for a deleted file it becomes "000000".
	Index string
	// OldIndex is the old index (SHA1 hash) of the file.
	OldIndex string
	// The sections in the file.
	Sections []*DiffSection
	// contains filtered or unexported fields
}

DiffFile represents a file in diff.

func (*DiffFile) IsBinary added in v1.0.0

func (f *DiffFile) IsBinary() bool

IsBinary returns true if the file is in binary format.

func (*DiffFile) IsCreated

func (f *DiffFile) IsCreated() bool

IsCreated returns true if the file is newly created.

func (*DiffFile) IsDeleted

func (f *DiffFile) IsDeleted() bool

IsDeleted returns true if the file has been deleted.

func (*DiffFile) IsIncomplete

func (f *DiffFile) IsIncomplete() bool

IsIncomplete returns true if the file is incomplete to the file diff.

func (*DiffFile) IsRenamed

func (f *DiffFile) IsRenamed() bool

IsRenamed returns true if the file has been renamed.

func (*DiffFile) IsSubmodule

func (f *DiffFile) IsSubmodule() bool

IsSubmodule returns true if the file contains information of a submodule.

func (*DiffFile) Mode added in v1.5.0

func (f *DiffFile) Mode() EntryMode

Mode returns the mode of the file.

func (*DiffFile) NumAdditions added in v1.0.0

func (f *DiffFile) NumAdditions() int

NumAdditions returns the number of additions in the file.

func (*DiffFile) NumDeletions added in v1.0.0

func (f *DiffFile) NumDeletions() int

NumDeletions returns the number of deletions in the file.

func (*DiffFile) NumSections

func (f *DiffFile) NumSections() int

NumSections returns the number of sections in the file.

func (*DiffFile) OldMode added in v1.5.0

func (f *DiffFile) OldMode() EntryMode

OldMode returns the old mode of the file if it's changed.

func (*DiffFile) OldName

func (f *DiffFile) OldName() string

OldName returns previous name before renaming.

type DiffFileType

type DiffFileType uint8

DiffFileType is the file status in diff.

const (
	DiffFileAdd DiffFileType = iota + 1
	DiffFileChange
	DiffFileDelete
	DiffFileRename
)

A list of different file statuses.

type DiffLine

type DiffLine struct {
	Type      DiffLineType // The type of the line
	Content   string       // The content of the line
	LeftLine  int          // The left line number
	RightLine int          // The right line number
}

DiffLine represents a line in diff.

type DiffLineType

type DiffLineType uint8

DiffLineType is the line type in diff.

const (
	DiffLinePlain DiffLineType = iota + 1
	DiffLineAdd
	DiffLineDelete
	DiffLineSection
)

A list of different line types.

type DiffNameOnlyOptions added in v1.0.0

type DiffNameOnlyOptions struct {
	// Indicates whether two commits should have a merge base.
	NeedsMergeBase bool
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

DiffNameOnlyOptions contains optional arguments for listing changed files.

Docs: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-only

type DiffOptions added in v1.0.0

type DiffOptions struct {
	// The commit ID to used for computing diff between a range of commits (base,
	// revision]. When not set, only computes diff for a single commit at revision.
	Base string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

DiffOptions contains optional arguments for parsing diff.

Docs: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---full-index

type DiffSection

type DiffSection struct {
	Lines []*DiffLine // lines in the section
	// contains filtered or unexported fields
}

DiffSection represents a section in diff.

func (*DiffSection) Line

func (s *DiffSection) Line(typ DiffLineType, line int) *DiffLine

Line returns a specific line by given type and line number in a section.

func (*DiffSection) NumLines added in v1.0.0

func (s *DiffSection) NumLines() int

NumLines returns the number of lines in the section.

type Entries

type Entries []*TreeEntry

Entries is a sortable list of tree entries.

func (Entries) CommitsInfo added in v1.0.0

func (es Entries) CommitsInfo(commit *Commit, opts ...CommitsInfoOptions) ([]*EntryCommitInfo, error)

CommitsInfo returns a list of commit information for these tree entries in the state of given commit and subpath. It takes advantages of concurrency to speed up the process. The returned list has the same number of items as tree entries, so the caller can access them via slice indices.

func (Entries) Len

func (es Entries) Len() int

func (Entries) Less

func (es Entries) Less(i, j int) bool

func (Entries) Sort

func (es Entries) Sort()

func (Entries) Swap

func (es Entries) Swap(i, j int)

type EntryCommitInfo added in v1.0.0

type EntryCommitInfo struct {
	Entry     *TreeEntry
	Index     int
	Commit    *Commit
	Submodule *Submodule
}

EntryCommitInfo contains a tree entry with its commit information.

type EntryMode

type EntryMode int

EntryMode is the unix file mode of a tree entry.

const (
	EntryTree    EntryMode = 0040000
	EntryBlob    EntryMode = 0100644
	EntryExec    EntryMode = 0100755
	EntrySymlink EntryMode = 0120000
	EntryCommit  EntryMode = 0160000
)

There are only a few file modes in Git. They look like unix file modes, but they can only be one of these.

type FetchOptions added in v1.0.0

type FetchOptions struct {
	// Indicates whether to prune during fetching.
	Prune bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

FetchOptions contains optional arguments for fetching repository updates.

Docs: https://git-scm.com/docs/git-fetch

type FsckOptions added in v1.0.0

type FsckOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

FsckOptions contains optional arguments for verifying the objects.

Docs: https://git-scm.com/docs/git-fsck

type GrepOptions added in v1.8.0

type GrepOptions struct {
	// The tree to run the search. Defaults to "HEAD".
	Tree string
	// Limits the search to files in the specified pathspec.
	Pathspec string
	// Whether to do case insensitive search.
	IgnoreCase bool
	// Whether to match the pattern only at word boundaries.
	WordRegexp bool
	// Whether use extended regular expressions.
	ExtendedRegexp bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

GrepOptions contains optional arguments for grep search over repository files.

Docs: https://git-scm.com/docs/git-grep

type GrepResult added in v1.8.0

type GrepResult struct {
	// The tree of the file that matched, e.g. "HEAD".
	Tree string
	// The path of the file that matched.
	Path string
	// The line number of the match.
	Line int
	// The 1-indexed column number of the match.
	Column int
	// The text of the line that matched.
	Text string
}

GrepResult represents a single result from a grep search.

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook contains information of a Git hook.

func (*Hook) Content

func (h *Hook) Content() string

Content returns the content of the Git hook.

func (*Hook) IsSample added in v1.0.0

func (h *Hook) IsSample() bool

IsSample returns true if the content is read from the sample hook.

func (*Hook) Name

func (h *Hook) Name() HookName

Name returns the name of the Git hook.

func (*Hook) Path added in v1.0.0

func (h *Hook) Path() string

Path returns the path of the Git hook.

func (*Hook) Update

func (h *Hook) Update(content string) error

Update writes the content of the Git hook on filesystem. It updates the memory copy of the content as well.

type HookName added in v1.0.0

type HookName string

HookName is the name of a Git hook.

const (
	HookPreReceive  HookName = "pre-receive"
	HookUpdate      HookName = "update"
	HookPostReceive HookName = "post-receive"
)

A list of Git server hooks' name that are supported.

type InitOptions added in v1.0.0

type InitOptions struct {
	// Indicates whether the repository should be initialized in bare format.
	Bare bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

InitOptions contains optional arguments for initializing a repository.

Docs: https://git-scm.com/docs/git-init

type LatestCommitTimeOptions added in v1.0.0

type LatestCommitTimeOptions struct {
	// To get the latest commit time of the branch. When not set, it checks all branches.
	Branch string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

LatestCommitTimeOptions contains optional arguments for getting the latest commit time.

type LogOptions added in v1.0.0

type LogOptions struct {
	// The maximum number of commits to output.
	MaxCount int
	// The number commits skipped before starting to show the commit output.
	Skip int
	// To only show commits since the time.
	Since time.Time
	// The regular expression to filter commits by their messages.
	GrepPattern string
	// Indicates whether to ignore letter case when match the regular expression.
	RegexpIgnoreCase bool
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

LogOptions contains optional arguments for listing commits.

Docs: https://git-scm.com/docs/git-log

type LsRemoteOptions added in v1.0.0

type LsRemoteOptions struct {
	// Indicates whether include heads.
	Heads bool
	// Indicates whether include tags.
	Tags bool
	// Indicates whether to not show peeled tags or pseudo refs.
	Refs bool
	// The list of patterns to filter results.
	Patterns []string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

LsRemoteOptions contains arguments for listing references in a remote repository.

Docs: https://git-scm.com/docs/git-ls-remote

type LsTreeOptions added in v1.0.0

type LsTreeOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

LsTreeOptions contains optional arguments for listing trees.

Docs: https://git-scm.com/docs/git-ls-tree

type MergeBaseOptions added in v1.0.0

type MergeBaseOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

MergeBaseOptions contains optional arguments for getting merge base.

Docs: https://git-scm.com/docs/git-merge-base

type MoveOptions added in v1.0.0

type MoveOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

MoveOptions contains optional arguments for moving a file, a directory, or a symlink.

Docs: https://git-scm.com/docs/git-mv

type NameStatus added in v1.0.0

type NameStatus struct {
	Added    []string
	Removed  []string
	Modified []string
}

NameStatus contains name status of a commit.

func RepoShowNameStatus deprecated added in v1.0.0

func RepoShowNameStatus(repoPath, rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)

Deprecated: Use ShowNameStatus instead.

func ShowNameStatus added in v1.3.0

func ShowNameStatus(repoPath, rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)

ShowNameStatus returns name status of given revision of the repository in given path.

type ObjectType

type ObjectType string

ObjectType is the type of a Git objet.

const (
	ObjectCommit ObjectType = "commit"
	ObjectTree   ObjectType = "tree"
	ObjectBlob   ObjectType = "blob"
	ObjectTag    ObjectType = "tag"
)

A list of object types.

type PullOptions added in v1.0.0

type PullOptions struct {
	// Indicates whether to rebased during pulling.
	Rebase bool
	// Indicates whether to pull from all remotes.
	All bool
	// The remote to pull updates from when All=false.
	Remote string
	// The branch to pull updates from when All=false and Remote is supplied.
	Branch string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

PullOptions contains optional arguments for pulling repository updates.

Docs: https://git-scm.com/docs/git-pull

type PushOptions added in v1.0.0

type PushOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

PushOptions contains optional arguments for pushing repository changes.

Docs: https://git-scm.com/docs/git-push

type RawDiffFormat added in v1.0.0

type RawDiffFormat string

RawDiffFormat is the format of a raw diff.

const (
	RawDiffNormal RawDiffFormat = "diff"
	RawDiffPatch  RawDiffFormat = "patch"
)

type RawDiffOptions added in v1.0.0

type RawDiffOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RawDiffOptions contains optional arguments for dumping a raw diff.

Docs: https://git-scm.com/docs/git-format-patch

type ReceivePackOptions added in v1.8.3

type ReceivePackOptions struct {
	// Indicates whether to suppress the log output.
	Quiet bool
	// Indicates whether to generate the "info/refs" used by the "git http-backend".
	HTTPBackendInfoRefs bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

ReceivePackOptions contains optional arguments for receiving the info pushed to the repository.

Docs: https://git-scm.com/docs/git-receive-pack

type Reference added in v1.0.0

type Reference struct {
	ID      string
	Refspec string
}

Reference contains information of a Git reference.

func LsRemote added in v1.0.0

func LsRemote(url string, opts ...LsRemoteOptions) ([]*Reference, error)

LsRemote returns a list references in the remote repository.

type RemoteAddOptions added in v1.3.0

type RemoteAddOptions struct {
	// Indicates whether to execute git fetch after the remote information is set
	// up.
	Fetch bool
	// Indicates whether to add remote as mirror with --mirror=fetch.
	MirrorFetch bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteAddOptions contains options to add a remote address.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem

type RemoteGetURLOptions added in v1.2.0

type RemoteGetURLOptions struct {
	// Indicates whether to get push URLs instead of fetch URLs.
	Push bool
	// Indicates whether to get all URLs, including lists that are not part of main
	// URLs. This option is independent of the Push option.
	All bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteGetURLOptions contains arguments for retrieving URL(s) of a remote of the repository.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emget-urlem

type RemoteRemoveOptions added in v1.3.0

type RemoteRemoveOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteRemoveOptions contains arguments for removing a remote from the repository.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emremoveem

type RemoteSetURLAddOptions added in v1.2.0

type RemoteSetURLAddOptions struct {
	// Indicates whether to get push URLs instead of fetch URLs.
	Push bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteSetURLAddOptions contains arguments for appending an URL to a remote of the repository.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem

type RemoteSetURLDeleteOptions added in v1.2.0

type RemoteSetURLDeleteOptions struct {
	// Indicates whether to get push URLs instead of fetch URLs.
	Push bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteSetURLDeleteOptions contains arguments for deleting an URL of a remote of the repository.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem

type RemoteSetURLOptions added in v1.2.0

type RemoteSetURLOptions struct {
	// Indicates whether to get push URLs instead of fetch URLs.
	Push bool
	// The regex to match existing URLs to replace (instead of first).
	Regex string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemoteSetURLOptions contains arguments for setting an URL of a remote of the repository.

Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem

type RemotesOptions added in v1.2.0

type RemotesOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RemotesOptions contains arguments for listing remotes of the repository. / Docs: https://git-scm.com/docs/git-remote#_commands

type RemoveRemoteOptions deprecated added in v1.0.0

type RemoveRemoteOptions = RemoteRemoveOptions

Deprecated: Use RemoteRemoveOptions instead.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository contains information of a Git repository.

func Open added in v1.0.0

func Open(repoPath string) (*Repository, error)

Open opens the repository at the given path. It returns an os.ErrNotExist if the path does not exist.

func (*Repository) Add added in v1.0.0

func (r *Repository) Add(opts ...AddOptions) error

Add adds local changes to index for the repository.

func (*Repository) AddRemote deprecated

func (r *Repository) AddRemote(name, url string, opts ...RemoteAddOptions) error

Deprecated: Use RemoteAdd instead.

func (*Repository) BlameFile added in v1.1.4

func (r *Repository) BlameFile(rev, file string, opts ...BlameOptions) (*Blame, error)

BlameFile returns blame results of the file with the given revision of the repository.

func (*Repository) BranchCommit added in v1.0.0

func (r *Repository) BranchCommit(branch string, opts ...CatFileCommitOptions) (*Commit, error)

BranchCommit returns the latest commit of given branch of the repository. The branch must be given in short name e.g. "master".

func (*Repository) BranchCommitID added in v1.0.0

func (r *Repository) BranchCommitID(branch string, opts ...ShowRefVerifyOptions) (string, error)

BranchCommitID returns the commit ID of given branch if it exists in the repository. The branch must be given in short name e.g. "master".

func (*Repository) Branches added in v1.0.0

func (r *Repository) Branches() ([]string, error)

Branches returns a list of all branches in the repository.

func (*Repository) CatFileBlob added in v1.7.0

func (r *Repository) CatFileBlob(rev string, opts ...CatFileBlobOptions) (*Blob, error)

CatFileBlob returns the blob corresponding to the given revision of the repository.

func (*Repository) CatFileCommit added in v1.0.0

func (r *Repository) CatFileCommit(rev string, opts ...CatFileCommitOptions) (*Commit, error)

CatFileCommit returns the commit corresponding to the given revision of the repository. The revision could be a commit ID or full refspec (e.g. "refs/heads/master").

func (*Repository) CatFileType added in v1.1.0

func (r *Repository) CatFileType(rev string, opts ...CatFileTypeOptions) (ObjectType, error)

CatFileType returns the object type of given revision of the repository.

func (*Repository) Checkout added in v1.0.0

func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error

Checkout checks out to given branch for the repository.

func (*Repository) Commit added in v1.0.0

func (r *Repository) Commit(committer *Signature, message string, opts ...CommitOptions) error

Commit commits local changes with given author, committer and message for the repository.

func (*Repository) CommitByRevision added in v1.0.0

func (r *Repository) CommitByRevision(rev string, opts ...CommitByRevisionOptions) (*Commit, error)

CommitByRevision returns a commit by given revision.

func (*Repository) CommitsByPage added in v1.0.0

func (r *Repository) CommitsByPage(rev string, page, size int, opts ...CommitsByPageOptions) ([]*Commit, error)

CommitsByPage returns a paginated list of commits in the state of given revision. The pagination starts from the newest to the oldest commit.

func (*Repository) CommitsSince added in v1.0.0

func (r *Repository) CommitsSince(rev string, since time.Time, opts ...CommitsSinceOptions) ([]*Commit, error)

CommitsSince returns a list of commits since given time. The returned list is in reverse chronological order.

func (*Repository) CountObjects added in v1.0.0

func (r *Repository) CountObjects(opts ...CountObjectsOptions) (*CountObject, error)

CountObjects returns disk usage report of the repository.

func (*Repository) CreateTag

func (r *Repository) CreateTag(name, rev string, opts ...CreateTagOptions) error

CreateTag creates a new tag on given revision.

func (*Repository) DeleteBranch

func (r *Repository) DeleteBranch(name string, opts ...DeleteBranchOptions) error

DeleteBranch deletes the branch from the repository.

func (*Repository) DeleteTag

func (r *Repository) DeleteTag(name string, opts ...DeleteTagOptions) error

DeleteTag deletes a tag from the repository.

func (*Repository) Diff added in v1.0.0

func (r *Repository) Diff(rev string, maxFiles, maxFileLines, maxLineChars int, opts ...DiffOptions) (*Diff, error)

Diff returns a parsed diff object between given commits of the repository.

func (*Repository) DiffBinary added in v1.0.0

func (r *Repository) DiffBinary(base, head string, opts ...DiffBinaryOptions) ([]byte, error)

DiffBinary returns binary patch between base and head revisions that could be used for git-apply.

func (*Repository) DiffNameOnly added in v1.0.0

func (r *Repository) DiffNameOnly(base, head string, opts ...DiffNameOnlyOptions) ([]string, error)

DiffNameOnly returns a list of changed files between base and head revisions of the repository.

func (*Repository) Fetch added in v1.0.0

func (r *Repository) Fetch(opts ...FetchOptions) error

Fetch fetches updates for the repository.

func (*Repository) Fsck added in v1.0.0

func (r *Repository) Fsck(opts ...FsckOptions) error

Fsck verifies the connectivity and validity of the objects in the database for the repository.

func (*Repository) Grep added in v1.8.0

func (r *Repository) Grep(pattern string, opts ...GrepOptions) []*GrepResult

Grep returns the results of a grep search in the repository.

func (*Repository) HasBranch added in v1.0.0

func (r *Repository) HasBranch(branch string, opts ...ShowRefVerifyOptions) bool

HasBranch returns true if given branch exists in the repository. The branch must be given in short name e.g. "master".

func (*Repository) HasReference added in v1.0.0

func (r *Repository) HasReference(ref string, opts ...ShowRefVerifyOptions) bool

HasReference returns true if given reference exists in the repository. The reference must be given in full refspec, e.g. "refs/heads/master".

func (*Repository) HasTag added in v1.0.0

func (r *Repository) HasTag(tag string, opts ...ShowRefVerifyOptions) bool

HasTag returns true if given tag exists in the repository. The tag must be given in short name e.g. "v1.0.0".

func (*Repository) Hook added in v1.0.0

func (r *Repository) Hook(dir string, name HookName) (*Hook, error)

Hook returns a Git hook by given name in the repository. Giving empty directory will use the default directory. It returns an os.ErrNotExist if both active and sample hook do not exist.

func (*Repository) Hooks

func (r *Repository) Hooks(dir string) ([]*Hook, error)

Hooks returns a list of Git hooks found in the repository. Giving empty directory will use the default directory. It may return an empty slice when no hooks found.

func (*Repository) LatestCommitTime added in v1.0.0

func (r *Repository) LatestCommitTime(opts ...LatestCommitTimeOptions) (time.Time, error)

LatestCommitTime returns the time of latest commit of the repository.

func (*Repository) Log added in v1.0.0

func (r *Repository) Log(rev string, opts ...LogOptions) ([]*Commit, error)

Log returns a list of commits in the state of given revision of the repository. The returned list is in reverse chronological order.

func (*Repository) LsTree added in v1.0.0

func (r *Repository) LsTree(treeID string, opts ...LsTreeOptions) (*Tree, error)

LsTree returns the tree object in the repository by given tree ID.

func (*Repository) MergeBase added in v1.0.0

func (r *Repository) MergeBase(base, head string, opts ...MergeBaseOptions) (string, error)

MergeBase returns merge base between base and head revisions of the repository.

func (*Repository) Move added in v1.0.0

func (r *Repository) Move(src, dst string, opts ...MoveOptions) error

Move moves a file, a directory, or a symlink file or directory from source to destination for the repository.

func (*Repository) NewHook added in v1.0.0

func (r *Repository) NewHook(dir string, name HookName) *Hook

NewHook creates and returns a new hook with given name. Update method must be called to actually save the hook to disk.

func (*Repository) Path

func (r *Repository) Path() string

Path returns the path of the repository.

func (*Repository) Pull added in v1.0.0

func (r *Repository) Pull(opts ...PullOptions) error

Pull pulls updates for the repository.

func (*Repository) Push added in v1.0.0

func (r *Repository) Push(remote, branch string, opts ...PushOptions) error

Push pushes local changes to given remote and branch for the repository.

func (*Repository) RawDiff added in v1.0.0

func (r *Repository) RawDiff(rev string, diffType RawDiffFormat, w io.Writer, opts ...RawDiffOptions) error

RawDiff dumps diff of repository in given revision directly to given io.Writer.

func (*Repository) RemoteAdd added in v1.3.0

func (r *Repository) RemoteAdd(name, url string, opts ...RemoteAddOptions) error

RemoteAdd adds a new remote to the repository.

func (*Repository) RemoteGetURL added in v1.2.0

func (r *Repository) RemoteGetURL(name string, opts ...RemoteGetURLOptions) ([]string, error)

RemoteGetURL retrieves URL(s) of a remote of the repository in given path.

func (*Repository) RemoteRemove added in v1.3.0

func (r *Repository) RemoteRemove(name string, opts ...RemoteRemoveOptions) error

RemoteRemove removes a remote from the repository.

func (*Repository) RemoteSetURL added in v1.2.0

func (r *Repository) RemoteSetURL(name, newurl string, opts ...RemoteSetURLOptions) error

RemoteSetURL sets the first URL of the remote with given name of the repository.

func (*Repository) RemoteSetURLAdd added in v1.2.0

func (r *Repository) RemoteSetURLAdd(name, newurl string, opts ...RemoteSetURLAddOptions) error

RemoteSetURLAdd appends an URL to the remote with given name of the repository. Use RemoteSetURL to overwrite the URL(s) instead.

func (*Repository) RemoteSetURLDelete added in v1.2.0

func (r *Repository) RemoteSetURLDelete(name, regex string, opts ...RemoteSetURLDeleteOptions) error

RemoteSetURLDelete deletes all URLs matching regex of the remote with given name of the repository.

func (*Repository) Remotes added in v1.2.0

func (r *Repository) Remotes(opts ...RemotesOptions) ([]string, error)

Remotes lists remotes of the repository.

func (*Repository) RemoveRemote deprecated

func (r *Repository) RemoveRemote(name string, opts ...RemoteRemoveOptions) error

Deprecated: Use RemoteRemove instead.

func (*Repository) Reset added in v1.0.0

func (r *Repository) Reset(rev string, opts ...ResetOptions) error

Reset resets working tree to given revision for the repository.

func (*Repository) RevList added in v1.0.0

func (r *Repository) RevList(refspecs []string, opts ...RevListOptions) ([]*Commit, error)

RevList returns a list of commits based on given refspecs in reverse chronological order.

func (*Repository) RevListCount added in v1.0.0

func (r *Repository) RevListCount(refspecs []string, opts ...RevListCountOptions) (int64, error)

RevListCount returns number of total commits up to given refspec of the repository.

func (*Repository) RevParse added in v1.0.0

func (r *Repository) RevParse(rev string, opts ...RevParseOptions) (string, error)

RevParse returns full length (40) commit ID by given revision in the repository.

func (*Repository) SearchCommits added in v1.0.0

func (r *Repository) SearchCommits(rev, pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)

SearchCommits searches commit message with given pattern in the state of given revision. The returned list is in reverse chronological order.

func (*Repository) ShowNameStatus added in v1.0.0

func (r *Repository) ShowNameStatus(rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)

ShowNameStatus returns name status of given revision of the repository.

func (*Repository) ShowRef added in v1.0.0

func (r *Repository) ShowRef(opts ...ShowRefOptions) ([]*Reference, error)

ShowRef returns a list of references in the repository.

func (*Repository) ShowRefVerify added in v1.0.0

func (r *Repository) ShowRefVerify(ref string, opts ...ShowRefVerifyOptions) (string, error)

ShowRefVerify returns the commit ID of given reference (e.g. "refs/heads/master") if it exists in the repository.

func (*Repository) SymbolicRef added in v1.0.0

func (r *Repository) SymbolicRef(opts ...SymbolicRefOptions) (string, error)

SymbolicRef returns the reference name (e.g. "refs/heads/master") pointed by the symbolic ref. It returns an empty string and nil error when doing set operation.

func (*Repository) Tag added in v1.0.0

func (r *Repository) Tag(name string, opts ...TagOptions) (*Tag, error)

Tag returns a Git tag by given name, e.g. "v1.0.0".

func (*Repository) TagCommit added in v1.0.0

func (r *Repository) TagCommit(tag string, opts ...CatFileCommitOptions) (*Commit, error)

TagCommit returns the latest commit of given tag of the repository. The tag must be given in short name e.g. "v1.0.0".

func (*Repository) TagCommitID added in v1.0.0

func (r *Repository) TagCommitID(tag string, opts ...ShowRefVerifyOptions) (string, error)

TagCommitID returns the commit ID of given tag if it exists in the repository. The tag must be given in short name e.g. "v1.0.0".

func (*Repository) Tags added in v1.0.0

func (r *Repository) Tags(opts ...TagsOptions) ([]string, error)

Tags returns a list of tags of the repository.

type ResetOptions added in v1.0.0

type ResetOptions struct {
	// Indicates whether to perform a hard reset.
	Hard bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

ResetOptions contains optional arguments for resetting a branch.

Docs: https://git-scm.com/docs/git-reset

type RevListCountOptions added in v1.0.0

type RevListCountOptions struct {
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RevListCountOptions contains optional arguments for counting commits.

Docs: https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---count

type RevListOptions added in v1.0.0

type RevListOptions struct {
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RevListOptions contains optional arguments for listing commits.

Docs: https://git-scm.com/docs/git-rev-list

type RevParseOptions added in v1.0.0

type RevParseOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

RevParseOptions contains optional arguments for parsing revision.

Docs: https://git-scm.com/docs/git-rev-parse

type RunInDirOptions added in v1.6.0

type RunInDirOptions struct {
	// Stdin is the input to the command.
	Stdin io.Reader
	// Stdout is the outputs from the command.
	Stdout io.Writer
	// Stderr is the error output from the command.
	Stderr io.Writer
	// Timeout is the duration to wait before timing out.
	//
	// Deprecated: Use CommandOptions.Timeout or *Command.WithTimeout instead.
	Timeout time.Duration
}

RunInDirOptions contains options for running a command in a directory.

type SHA1 added in v1.0.0

type SHA1 struct {
	// contains filtered or unexported fields
}

SHA1 is the SHA-1 hash of a Git object.

func MustID

func MustID(b []byte) *SHA1

MustID always returns a new SHA1 from a [20]byte array with no validation of input.

func MustIDFromString

func MustIDFromString(s string) *SHA1

MustIDFromString always returns a new sha from a ID with no validation of input.

func NewID

func NewID(b []byte) (*SHA1, error)

NewID returns a new SHA1 from a [20]byte array.

func NewIDFromString

func NewIDFromString(s string) (*SHA1, error)

NewIDFromString returns a new SHA1 from a ID string of length 40.

func (*SHA1) Equal added in v1.0.0

func (s *SHA1) Equal(s2 interface{}) bool

Equal returns true if s2 has the same SHA1 as s. It supports 40-length-string, []byte, and SHA1.

func (*SHA1) String added in v1.0.0

func (s *SHA1) String() string

String returns string (hex) representation of the SHA1.

type SearchCommitsOptions added in v1.0.0

type SearchCommitsOptions struct {
	// The maximum number of commits to output.
	MaxCount int
	// The relative path of the repository.
	Path string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

SearchCommitsOptions contains optional arguments for searching commits.

Docs: https://git-scm.com/docs/git-log

type ShowNameStatusOptions added in v1.0.0

type ShowNameStatusOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

ShowNameStatusOptions contains optional arguments for showing name status.

Docs: https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-status

type ShowRefOptions added in v1.0.0

type ShowRefOptions struct {
	// Indicates whether to include heads.
	Heads bool
	// Indicates whether to include tags.
	Tags bool
	// The list of patterns to filter results.
	Patterns []string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

ShowRefOptions contains optional arguments for listing references.

Docs: https://git-scm.com/docs/git-show-ref

type ShowRefVerifyOptions added in v1.0.0

type ShowRefVerifyOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

ShowRefVerifyOptions contains optional arguments for verifying a reference.

Docs: https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt---verify

type Signature

type Signature struct {
	// The name of the person.
	Name string
	// The email address.
	Email string
	// The time of the signature.
	When time.Time
}

Signature represents a author or committer.

type SteamParseDiffResult added in v1.0.0

type SteamParseDiffResult struct {
	Diff *Diff
	Err  error
}

SteamParseDiffResult contains results of streaming parsing a diff.

type Submodule added in v1.0.0

type Submodule struct {
	// The name of the submodule.
	Name string
	// The URL of the submodule.
	URL string
	// The commit ID of the subproject.
	Commit string
}

Submodule contains information of a Git submodule.

type Submodules added in v1.0.0

type Submodules = *objectCache

Submodules contains information of submodules.

type SymbolicRefOptions added in v1.0.0

type SymbolicRefOptions struct {
	// The name of the symbolic ref. When not set, default ref "HEAD" is used.
	Name string
	// The name of the reference, e.g. "refs/heads/master". When set, it will be
	// used to update the symbolic ref.
	Ref string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

SymbolicRefOptions contains optional arguments for get and set symbolic ref.

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag contains information of a Git tag.

func (*Tag) Commit

func (t *Tag) Commit(opts ...CatFileCommitOptions) (*Commit, error)

Commit returns the underlying commit of the tag.

func (*Tag) CommitID added in v1.0.0

func (t *Tag) CommitID() *SHA1

CommitID returns the commit ID of the tag.

func (*Tag) ID

func (t *Tag) ID() *SHA1

ID returns the SHA-1 hash of the tag.

func (*Tag) Message

func (t *Tag) Message() string

Message returns the message of the tag.

func (*Tag) Refspec added in v1.0.0

func (t *Tag) Refspec() string

Refspec returns the refspec of the tag.

func (*Tag) Tagger

func (t *Tag) Tagger() *Signature

Tagger returns the tagger of the tag.

func (*Tag) Type

func (t *Tag) Type() ObjectType

Type returns the type of the tag.

type TagOptions added in v1.0.0

type TagOptions struct {
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

TagOptions contains optional arguments for getting a tag.

Docs: https://git-scm.com/docs/git-cat-file

type TagsOptions added in v1.0.0

type TagsOptions struct {
	// SortKet sorts tags with provided tag key, optionally prefixed with '-' to sort tags in descending order.
	SortKey string
	// Pattern filters tags matching the specified pattern.
	Pattern string
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	//
	// Deprecated: Use CommandOptions.Timeout instead.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

TagsOptions contains optional arguments for listing tags.

Docs: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---list

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree represents a flat directory listing in Git.

func (*Tree) Blob added in v1.0.0

func (t *Tree) Blob(subpath string, opts ...LsTreeOptions) (*Blob, error)

Blob returns the blob object by given subpath of the tree.

func (*Tree) BlobByIndex added in v1.1.0

func (t *Tree) BlobByIndex(index string) (*Blob, error)

BlobByIndex returns blob object by given index.

func (*Tree) Entries added in v1.0.0

func (t *Tree) Entries(opts ...LsTreeOptions) (Entries, error)

Entries returns all entries of the tree.

func (*Tree) Subtree added in v1.0.0

func (t *Tree) Subtree(subpath string, opts ...LsTreeOptions) (*Tree, error)

Subtree returns a subtree by given subpath of the tree.

func (*Tree) TreeEntry added in v1.0.0

func (t *Tree) TreeEntry(subpath string, opts ...LsTreeOptions) (*TreeEntry, error)

TreeEntry returns the TreeEntry by given subpath of the tree.

type TreeEntry

type TreeEntry struct {
	// contains filtered or unexported fields
}

func (*TreeEntry) Blob

func (e *TreeEntry) Blob() *Blob

Blob returns a blob object from the entry.

func (*TreeEntry) ID

func (e *TreeEntry) ID() *SHA1

ID returns the SHA-1 hash of the entry.

func (*TreeEntry) IsBlob added in v1.0.0

func (e *TreeEntry) IsBlob() bool

IsBlob returns true if the entry is a blob.

func (*TreeEntry) IsCommit added in v1.0.0

func (e *TreeEntry) IsCommit() bool

IsCommit returns true if the entry is a commit (i.e. a submodule).

func (*TreeEntry) IsExec added in v1.0.0

func (e *TreeEntry) IsExec() bool

IsExec returns tree if the entry is an executable.

func (e *TreeEntry) IsSymlink() bool

IsSymlink returns true if the entry is a symbolic link.

func (*TreeEntry) IsTree added in v1.0.0

func (e *TreeEntry) IsTree() bool

IsTree returns tree if the entry itself is another tree (i.e. a directory).

func (*TreeEntry) Mode added in v1.0.0

func (e *TreeEntry) Mode() EntryMode

Mode returns the entry mode if the tree entry.

func (*TreeEntry) Name

func (e *TreeEntry) Name() string

Name returns name of the entry.

func (*TreeEntry) Size

func (e *TreeEntry) Size() int64

Size returns the size of thr entry.

func (*TreeEntry) Type

func (e *TreeEntry) Type() ObjectType

Type returns the object type of the entry.

type UpdateServerInfoOptions added in v1.8.3

type UpdateServerInfoOptions struct {
	// Indicates whether to overwrite the existing server info.
	Force bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

UpdateServerInfoOptions contains optional arguments for updating auxiliary info file on the server side.

Docs: https://git-scm.com/docs/git-update-server-info

type UploadPackOptions added in v1.8.3

type UploadPackOptions struct {
	// Indicates whether to quit after a single request/response exchange.
	StatelessRPC bool
	// Indicates whether to not try "<directory>/.git/" if "<directory>" is not a
	// Git directory.
	Strict bool
	// Indicates whether to generate the "info/refs" used by the "git http-backend".
	HTTPBackendInfoRefs bool
	// The timeout duration before giving up for each shell command execution. The
	// default timeout duration will be used when not supplied.
	Timeout time.Duration
	// The additional options to be passed to the underlying git.
	CommandOptions
}

UploadPackOptions contains optional arguments for sending the packfile to the client.

Docs: https://git-scm.com/docs/git-upload-pack

Jump to

Keyboard shortcuts

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