Documentation
¶
Index ¶
- Constants
- Variables
- func BinVersion(ctx context.Context) (string, error)
- func Clone(ctx context.Context, url, dst string, opts ...CloneOptions) error
- func Init(ctx context.Context, path string, opts ...InitOptions) error
- func IsURLAccessible(ctx context.Context, url string) bool
- func ReceivePack(ctx context.Context, path string, opts ...ReceivePackOptions) ([]byte, error)
- func RefShortName(ref string) string
- func SetOutput(output io.Writer)
- func SetPrefix(prefix string)
- func StreamParseDiff(r io.Reader, done chan<- SteamParseDiffResult, ...)
- func UnescapeChars(in []byte) []byte
- func UpdateServerInfo(ctx context.Context, path string, opts ...UpdateServerInfoOptions) error
- func UploadPack(ctx context.Context, path string, opts ...UploadPackOptions) ([]byte, error)
- type AddOptions
- type ArchiveFormat
- type Blame
- type BlameOptions
- type Blob
- type CatFileBlobOptions
- type CatFileCommitOptions
- type CatFileTypeOptions
- type CheckoutOptions
- type CloneOptions
- type CommandOptions
- type Commit
- func (c *Commit) Ancestors(ctx context.Context, opts ...LogOptions) ([]*Commit, error)
- func (c *Commit) Archive(ctx context.Context, format ArchiveFormat, dst string) error
- func (c *Commit) CommitByPath(ctx context.Context, opts ...CommitByRevisionOptions) (*Commit, error)
- func (c *Commit) CommitsAfter(ctx context.Context, after string, opts ...RevListOptions) ([]*Commit, error)
- func (c *Commit) CommitsByPage(ctx context.Context, page, size int, opts ...CommitsByPageOptions) ([]*Commit, error)
- func (c *Commit) CommitsCount(ctx context.Context, opts ...RevListCountOptions) (int64, error)
- func (c *Commit) FilesChangedAfter(ctx context.Context, after string, opts ...DiffNameOnlyOptions) ([]string, error)
- func (c *Commit) IsImageFile(ctx context.Context, subpath string) (bool, error)
- func (c *Commit) IsImageFileByIndex(ctx context.Context, index string) (bool, error)
- func (c *Commit) Parent(ctx context.Context, n int, opts ...CatFileCommitOptions) (*Commit, error)
- func (c *Commit) ParentID(n int) (*SHA1, error)
- func (c *Commit) ParentsCount() int
- func (c *Commit) SearchCommits(ctx context.Context, pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)
- func (c *Commit) ShowNameStatus(ctx context.Context, opts ...ShowNameStatusOptions) (*NameStatus, error)
- func (c *Commit) Submodule(ctx context.Context, path string) (*Submodule, error)
- func (c *Commit) Submodules(ctx context.Context) (Submodules, error)
- func (c *Commit) Summary() string
- type CommitByRevisionOptions
- type CommitOptions
- type CommitsByPageOptions
- type CommitsInfoOptions
- type CommitsSinceOptions
- type CountObject
- type CountObjectsOptions
- type CreateTagOptions
- type DeleteBranchOptions
- type DeleteTagOptions
- type Diff
- type DiffBinaryOptions
- type DiffFile
- func (f *DiffFile) IsBinary() bool
- func (f *DiffFile) IsCreated() bool
- func (f *DiffFile) IsDeleted() bool
- func (f *DiffFile) IsIncomplete() bool
- func (f *DiffFile) IsRenamed() bool
- func (f *DiffFile) IsSubmodule() bool
- func (f *DiffFile) Mode() EntryMode
- func (f *DiffFile) NumAdditions() int
- func (f *DiffFile) NumDeletions() int
- func (f *DiffFile) NumSections() int
- func (f *DiffFile) OldMode() EntryMode
- func (f *DiffFile) OldName() string
- type DiffFileType
- type DiffLine
- type DiffLineType
- type DiffNameOnlyOptions
- type DiffOptions
- type DiffSection
- type Entries
- type EntryCommitInfo
- type EntryMode
- type FetchOptions
- type FsckOptions
- type GrepOptions
- type GrepResult
- type Hook
- type HookName
- type InitOptions
- type LatestCommitTimeOptions
- type LogOptions
- type LsRemoteOptions
- type LsTreeOptions
- type MergeBaseOptions
- type MoveOptions
- type NameStatus
- type ObjectType
- type PullOptions
- type PushOptions
- type RawDiffFormat
- type RawDiffOptions
- type ReceivePackOptions
- type Reference
- type RemoteAddOptions
- type RemoteGetURLOptions
- type RemoteRemoveOptions
- type RemoteSetURLAddOptions
- type RemoteSetURLDeleteOptions
- type RemoteSetURLOptions
- type RemotesOptions
- type Repository
- func (r *Repository) Add(ctx context.Context, opts ...AddOptions) error
- func (r *Repository) Blame(ctx context.Context, rev, file string, opts ...BlameOptions) (*Blame, error)
- func (r *Repository) BranchCommit(ctx context.Context, branch string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) BranchCommitID(ctx context.Context, branch string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) Branches(ctx context.Context) ([]string, error)
- func (r *Repository) CatFileBlob(ctx context.Context, rev string, opts ...CatFileBlobOptions) (*Blob, error)
- func (r *Repository) CatFileCommit(ctx context.Context, rev string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) CatFileType(ctx context.Context, rev string, opts ...CatFileTypeOptions) (ObjectType, error)
- func (r *Repository) Checkout(ctx context.Context, branch string, opts ...CheckoutOptions) error
- func (r *Repository) Commit(ctx context.Context, committer *Signature, message string, ...) error
- func (r *Repository) CommitByRevision(ctx context.Context, rev string, opts ...CommitByRevisionOptions) (*Commit, error)
- func (r *Repository) CommitsByPage(ctx context.Context, rev string, page, size int, opts ...CommitsByPageOptions) ([]*Commit, error)
- func (r *Repository) CommitsSince(ctx context.Context, rev string, since time.Time, opts ...CommitsSinceOptions) ([]*Commit, error)
- func (r *Repository) CountObjects(ctx context.Context, opts ...CountObjectsOptions) (*CountObject, error)
- func (r *Repository) CreateTag(ctx context.Context, name, rev string, opts ...CreateTagOptions) error
- func (r *Repository) DeleteBranch(ctx context.Context, name string, opts ...DeleteBranchOptions) error
- func (r *Repository) DeleteTag(ctx context.Context, name string, opts ...DeleteTagOptions) error
- func (r *Repository) Diff(ctx context.Context, rev string, maxFiles, maxFileLines, maxLineChars int, ...) (*Diff, error)
- func (r *Repository) DiffBinary(ctx context.Context, base, head string, opts ...DiffBinaryOptions) ([]byte, error)
- func (r *Repository) DiffNameOnly(ctx context.Context, base, head string, opts ...DiffNameOnlyOptions) ([]string, error)
- func (r *Repository) Fetch(ctx context.Context, opts ...FetchOptions) error
- func (r *Repository) Fsck(ctx context.Context, opts ...FsckOptions) error
- func (r *Repository) Grep(ctx context.Context, pattern string, opts ...GrepOptions) []*GrepResult
- func (r *Repository) HasBranch(ctx context.Context, branch string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) HasReference(ctx context.Context, ref string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) HasTag(ctx context.Context, tag string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) Hook(dir string, name HookName) (*Hook, error)
- func (r *Repository) Hooks(dir string) ([]*Hook, error)
- func (r *Repository) LatestCommitTime(ctx context.Context, opts ...LatestCommitTimeOptions) (time.Time, error)
- func (r *Repository) Log(ctx context.Context, rev string, opts ...LogOptions) ([]*Commit, error)
- func (r *Repository) LsTree(ctx context.Context, treeID string, opts ...LsTreeOptions) (*Tree, error)
- func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...MergeBaseOptions) (string, error)
- func (r *Repository) Move(ctx context.Context, src, dst string, opts ...MoveOptions) error
- func (r *Repository) NewHook(dir string, name HookName) *Hook
- func (r *Repository) Path() string
- func (r *Repository) Pull(ctx context.Context, opts ...PullOptions) error
- func (r *Repository) Push(ctx context.Context, remote, branch string, opts ...PushOptions) error
- func (r *Repository) RawDiff(ctx context.Context, rev string, diffType RawDiffFormat, w io.Writer, ...) error
- func (r *Repository) RemoteAdd(ctx context.Context, name, url string, opts ...RemoteAddOptions) error
- func (r *Repository) RemoteGetURL(ctx context.Context, name string, opts ...RemoteGetURLOptions) ([]string, error)
- func (r *Repository) RemoteRemove(ctx context.Context, name string, opts ...RemoteRemoveOptions) error
- func (r *Repository) RemoteSetURL(ctx context.Context, name, newurl string, opts ...RemoteSetURLOptions) error
- func (r *Repository) RemoteSetURLAdd(ctx context.Context, name, newurl string, opts ...RemoteSetURLAddOptions) error
- func (r *Repository) RemoteSetURLDelete(ctx context.Context, name, regex string, opts ...RemoteSetURLDeleteOptions) error
- func (r *Repository) Remotes(ctx context.Context, opts ...RemotesOptions) ([]string, error)
- func (r *Repository) Reset(ctx context.Context, rev string, opts ...ResetOptions) error
- func (r *Repository) RevList(ctx context.Context, refspecs []string, opts ...RevListOptions) ([]*Commit, error)
- func (r *Repository) RevListCount(ctx context.Context, refspecs []string, opts ...RevListCountOptions) (int64, error)
- func (r *Repository) RevParse(ctx context.Context, rev string, opts ...RevParseOptions) (string, error)
- func (r *Repository) SearchCommits(ctx context.Context, rev, pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)
- func (r *Repository) ShowNameStatus(ctx context.Context, rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)
- func (r *Repository) ShowRef(ctx context.Context, opts ...ShowRefOptions) ([]*Reference, error)
- func (r *Repository) ShowRefVerify(ctx context.Context, ref string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) SymbolicRef(ctx context.Context, opts ...SymbolicRefOptions) (string, error)
- func (r *Repository) Tag(ctx context.Context, name string, opts ...TagOptions) (*Tag, error)
- func (r *Repository) TagCommit(ctx context.Context, tag string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) TagCommitID(ctx context.Context, tag string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) Tags(ctx context.Context, opts ...TagsOptions) ([]string, error)
- func (r *Repository) WorktreeAdd(ctx context.Context, path, commitIsh string, opts ...WorktreeAddOptions) error
- func (r *Repository) WorktreeRemove(ctx context.Context, path string, opts ...WorktreeRemoveOptions) error
- type ResetOptions
- type RevListCountOptions
- type RevListOptions
- type RevParseOptions
- type SHA1
- type SearchCommitsOptions
- type ShowNameStatusOptions
- type ShowRefOptions
- type ShowRefVerifyOptions
- type Signature
- type SteamParseDiffResult
- type Submodule
- type Submodules
- type SymbolicRefOptions
- type Tag
- type TagOptions
- type TagsOptions
- type Tree
- func (t *Tree) Blob(ctx context.Context, subpath string, opts ...LsTreeOptions) (*Blob, error)
- func (t *Tree) BlobByIndex(ctx context.Context, index string) (*Blob, error)
- func (t *Tree) Entries(ctx context.Context, opts ...LsTreeOptions) (Entries, error)
- func (t *Tree) Subtree(ctx context.Context, subpath string, opts ...LsTreeOptions) (*Tree, error)
- func (t *Tree) TreeEntry(ctx context.Context, subpath string, opts ...LsTreeOptions) (*TreeEntry, error)
- type TreeEntry
- func (e *TreeEntry) Blob() *Blob
- func (e *TreeEntry) ID() *SHA1
- func (e *TreeEntry) IsBlob() bool
- func (e *TreeEntry) IsCommit() bool
- func (e *TreeEntry) IsExec() bool
- func (e *TreeEntry) IsSymlink() bool
- func (e *TreeEntry) IsTree() bool
- func (e *TreeEntry) Mode() EntryMode
- func (e *TreeEntry) Name() string
- func (e *TreeEntry) Size(ctx context.Context) int64
- func (e *TreeEntry) Type() ObjectType
- type UpdateServerInfoOptions
- type UploadPackOptions
- type WorktreeAddOptions
- type WorktreeRemoveOptions
Constants ¶
const ( RefsHeads = "refs/heads/" RefsTags = "refs/tags/" )
const DefaultHooksDir = "hooks"
DefaultHooksDir is the default directory for Git hooks.
const DefaultTimeout = time.Minute
DefaultTimeout is the default timeout duration for all commands. It is applied when the context does not already have a deadline.
const EmptyID = "0000000000000000000000000000000000000000"
EmptyID is an ID with empty SHA-1 hash.
const LogFormatHashOnly = `format:%H`
Variables ¶
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") )
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`, } )
var ErrReferenceNotExist = errors.New("reference does not exist")
Functions ¶
func BinVersion ¶
BinVersion returns current Git binary version that is used by this module. Successful results are cached; failed attempts are not cached, allowing retries with a fresh context.
func Clone ¶
func Clone(ctx context.Context, url, dst string, opts ...CloneOptions) error
Clone clones the repository from remote URL to the destination.
func Init ¶
func Init(ctx context.Context, path string, opts ...InitOptions) error
Init initializes a new Git repository.
func IsURLAccessible ¶
IsURLAccessible returns true if given remote URL is accessible via Git. The caller should use context.WithTimeout to control the timeout.
func ReceivePack ¶
ReceivePack receives what is pushed into the repository in given path.
func RefShortName ¶
RefShortName returns short name of heads or tags. Other references will return original string.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the prefix to be prepended to each log entry.
func StreamParseDiff ¶
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 UnescapeChars ¶
UnescapeChars reverses escaped characters in quoted output from Git.
func UpdateServerInfo ¶
func UpdateServerInfo(ctx context.Context, path string, opts ...UpdateServerInfoOptions) error
UpdateServerInfo updates the auxiliary info file on the server side for the repository in given path.
func UploadPack ¶
UploadPack sends the packfile to the client for the repository in given path.
Types ¶
type AddOptions ¶
type AddOptions struct {
// Indicates whether to add all changes to index.
All bool
// The specific pathspecs to be added to index.
Pathspecs []string
CommandOptions
}
AddOptions contains optional arguments for adding local changes.
type ArchiveFormat ¶
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 ¶
type Blame struct {
// contains filtered or unexported fields
}
Blame contains information of a Git file blame.
type BlameOptions ¶
type BlameOptions struct {
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.
type CatFileBlobOptions ¶
type CatFileBlobOptions struct {
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 ¶
type CatFileCommitOptions struct {
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 ¶
type CatFileTypeOptions struct {
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
CommandOptions
}
CheckoutOptions contains optional arguments for checking out to a branch.
type CloneOptions ¶
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
CommandOptions
}
CloneOptions contains optional arguments for cloning a repository.
type CommandOptions ¶
type CommandOptions struct {
Envs []string
}
CommandOptions contains additional options for running a Git command.
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 (*Commit) Ancestors ¶
Ancestors returns a list of ancestors of this commit in reverse chronological order.
func (*Commit) CommitByPath ¶
func (c *Commit) CommitByPath(ctx context.Context, opts ...CommitByRevisionOptions) (*Commit, error)
CommitByPath returns the commit of the path in the state of this commit.
func (*Commit) CommitsAfter ¶
func (c *Commit) CommitsAfter(ctx context.Context, 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 ¶
func (c *Commit) CommitsByPage(ctx context.Context, 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 ¶
CommitsCount returns number of total commits up to this commit.
func (*Commit) FilesChangedAfter ¶
func (c *Commit) FilesChangedAfter(ctx context.Context, after string, opts ...DiffNameOnlyOptions) ([]string, error)
FilesChangedAfter returns a list of files changed after given commit ID.
func (*Commit) IsImageFile ¶
IsImageFile returns true if the blob of the commit is an image by subpath.
func (*Commit) IsImageFileByIndex ¶
IsImageFileByIndex returns true if the blob of the commit is an image by index.
func (*Commit) Parent ¶
Parent returns the n-th parent commit (0-based) of this commit. It returns ErrRevisionNotExist if no such parent exists.
func (*Commit) ParentID ¶
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 ¶
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(ctx context.Context, pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)
SearchCommits searches commit message with given pattern. The returned list is in reverse chronological order.
func (*Commit) ShowNameStatus ¶
func (c *Commit) ShowNameStatus(ctx context.Context, opts ...ShowNameStatusOptions) (*NameStatus, error)
ShowNameStatus returns name status of the commit.
func (*Commit) Submodule ¶
Submodule returns submodule by given name. It returns an ErrSubmoduleNotExist if the path does not exist as a submodule.
func (*Commit) Submodules ¶
func (c *Commit) Submodules(ctx context.Context) (Submodules, error)
Submodules returns submodules found in this commit. Successful results are cached; failed attempts are not cached, allowing retries with a fresh context.
type CommitByRevisionOptions ¶
type CommitByRevisionOptions struct {
// The relative path of the repository.
Path string
CommandOptions
}
CommitByRevisionOptions contains optional arguments for getting a commit.
type CommitOptions ¶
type CommitOptions struct {
// Author is the author of the changes if that's not the same as committer.
Author *Signature
CommandOptions
}
CommitOptions contains optional arguments to commit changes.
type CommitsByPageOptions ¶
type CommitsByPageOptions struct {
// The relative path of the repository.
Path string
CommandOptions
}
CommitsByPageOptions contains optional arguments for getting paginated commits.
type CommitsInfoOptions ¶
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
}
CommitsInfoOptions contains optional arguments for getting commits information.
type CommitsSinceOptions ¶
type CommitsSinceOptions struct {
// The relative path of the repository.
Path string
CommandOptions
}
CommitsSinceOptions contains optional arguments for listing commits since a time.
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.
type CountObjectsOptions ¶
type CountObjectsOptions struct {
CommandOptions
}
CountObjectsOptions contains optional arguments for counting objects.
type CreateTagOptions ¶
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
CommandOptions
}
CreateTagOptions contains optional arguments for creating a tag.
type DeleteBranchOptions ¶
type DeleteBranchOptions struct {
// Indicates whether to force delete the branch.
Force bool
CommandOptions
}
DeleteBranchOptions contains optional arguments for deleting a branch.
type DeleteTagOptions ¶
type DeleteTagOptions struct {
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 ¶
IsIncomplete returns true if the file is incomplete to the entire diff.
func (*Diff) TotalAdditions ¶
TotalAdditions returns the total additions in the diff.
func (*Diff) TotalDeletions ¶
TotalDeletions returns the total deletions in the diff.
type DiffBinaryOptions ¶
type DiffBinaryOptions struct {
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) IsIncomplete ¶
IsIncomplete returns true if the file is incomplete to the file diff.
func (*DiffFile) IsSubmodule ¶
IsSubmodule returns true if the file contains information of a submodule.
func (*DiffFile) NumAdditions ¶
NumAdditions returns the number of additions in the file.
func (*DiffFile) NumDeletions ¶
NumDeletions returns the number of deletions in the file.
func (*DiffFile) NumSections ¶
NumSections returns the number of sections in the file.
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 ¶
type DiffNameOnlyOptions struct {
// Indicates whether two commits should have a merge base.
NeedsMergeBase bool
// The relative path of the repository.
Path string
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 ¶
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
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 ¶
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 ¶
func (es Entries) CommitsInfo(ctx context.Context, 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.
type EntryCommitInfo ¶
EntryCommitInfo contains a tree entry with its commit information.
type FetchOptions ¶
type FetchOptions struct {
// Indicates whether to prune during fetching.
Prune bool
CommandOptions
}
FetchOptions contains optional arguments for fetching repository updates.
type FsckOptions ¶
type FsckOptions struct {
CommandOptions
}
FsckOptions contains optional arguments for verifying the objects.
type GrepOptions ¶
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
CommandOptions
}
GrepOptions contains optional arguments for grep search over repository files.
type GrepResult ¶
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.
type InitOptions ¶
type InitOptions struct {
// Indicates whether the repository should be initialized in bare format.
Bare bool
CommandOptions
}
InitOptions contains optional arguments for initializing a repository.
type LatestCommitTimeOptions ¶
type LatestCommitTimeOptions struct {
// To get the latest commit time of the branch. When not set, it checks all branches.
Branch string
CommandOptions
}
LatestCommitTimeOptions contains optional arguments for getting the latest commit time.
type LogOptions ¶
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
CommandOptions
}
LogOptions contains optional arguments for listing commits.
type LsRemoteOptions ¶
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
CommandOptions
}
LsRemoteOptions contains arguments for listing references in a remote repository.
type LsTreeOptions ¶
type LsTreeOptions struct {
// Verbatim outputs filenames unquoted using the -z flag. This avoids issues
// with special characters in filenames that would otherwise be quoted by Git.
Verbatim bool
CommandOptions
}
LsTreeOptions contains optional arguments for listing trees.
type MergeBaseOptions ¶
type MergeBaseOptions struct {
CommandOptions
}
MergeBaseOptions contains optional arguments for getting merge base.
type MoveOptions ¶
type MoveOptions struct {
CommandOptions
}
MoveOptions contains optional arguments for moving a file, a directory, or a symlink.
type NameStatus ¶
NameStatus contains name status of a commit.
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 ¶
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
CommandOptions
}
PullOptions contains optional arguments for pulling repository updates.
type PushOptions ¶
type PushOptions struct {
// Indicates whether to set upstream tracking for the branch.
SetUpstream bool
CommandOptions
}
PushOptions contains optional arguments for pushing repository changes.
type RawDiffFormat ¶
type RawDiffFormat string
RawDiffFormat is the format of a raw diff.
const ( RawDiffNormal RawDiffFormat = "diff" RawDiffPatch RawDiffFormat = "patch" )
type RawDiffOptions ¶
type RawDiffOptions struct {
CommandOptions
}
RawDiffOptions contains optional arguments for dumping a raw diff.
type ReceivePackOptions ¶
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
CommandOptions
}
ReceivePackOptions contains optional arguments for receiving the info pushed to the repository.
type RemoteAddOptions ¶
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
CommandOptions
}
RemoteAddOptions contains options to add a remote address.
Docs: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
type RemoteGetURLOptions ¶
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
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 ¶
type RemoteRemoveOptions struct {
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 ¶
type RemoteSetURLAddOptions struct {
// Indicates whether to get push URLs instead of fetch URLs.
Push bool
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 ¶
type RemoteSetURLDeleteOptions struct {
// Indicates whether to get push URLs instead of fetch URLs.
Push bool
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 ¶
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
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 ¶
type RemotesOptions struct {
CommandOptions
}
RemotesOptions contains arguments for listing remotes of the repository. / Docs: https://git-scm.com/docs/git-remote#_commands
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository contains information of a Git repository.
func Open ¶
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 ¶
func (r *Repository) Add(ctx context.Context, opts ...AddOptions) error
Add adds local changes to index for the repository.
func (*Repository) Blame ¶
func (r *Repository) Blame(ctx context.Context, rev, file string, opts ...BlameOptions) (*Blame, error)
Blame returns blame results of the file with the given revision of the repository.
func (*Repository) BranchCommit ¶
func (r *Repository) BranchCommit(ctx context.Context, 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 ¶
func (r *Repository) BranchCommitID(ctx context.Context, 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 ¶
func (r *Repository) Branches(ctx context.Context) ([]string, error)
Branches returns a list of all branches in the repository.
func (*Repository) CatFileBlob ¶
func (r *Repository) CatFileBlob(ctx context.Context, rev string, opts ...CatFileBlobOptions) (*Blob, error)
CatFileBlob returns the blob corresponding to the given revision of the repository.
func (*Repository) CatFileCommit ¶
func (r *Repository) CatFileCommit(ctx context.Context, 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 ¶
func (r *Repository) CatFileType(ctx context.Context, rev string, opts ...CatFileTypeOptions) (ObjectType, error)
CatFileType returns the object type of given revision of the repository.
func (*Repository) Checkout ¶
func (r *Repository) Checkout(ctx context.Context, branch string, opts ...CheckoutOptions) error
Checkout checks out to given branch for the repository.
func (*Repository) Commit ¶
func (r *Repository) Commit(ctx context.Context, committer *Signature, message string, opts ...CommitOptions) error
Commit commits local changes with given author, committer and message for the repository.
func (*Repository) CommitByRevision ¶
func (r *Repository) CommitByRevision(ctx context.Context, rev string, opts ...CommitByRevisionOptions) (*Commit, error)
CommitByRevision returns a commit by given revision.
func (*Repository) CommitsByPage ¶
func (r *Repository) CommitsByPage(ctx context.Context, 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 ¶
func (r *Repository) CommitsSince(ctx context.Context, 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 ¶
func (r *Repository) CountObjects(ctx context.Context, opts ...CountObjectsOptions) (*CountObject, error)
CountObjects returns disk usage report of the repository.
func (*Repository) CreateTag ¶
func (r *Repository) CreateTag(ctx context.Context, name, rev string, opts ...CreateTagOptions) error
CreateTag creates a new tag on given revision.
func (*Repository) DeleteBranch ¶
func (r *Repository) DeleteBranch(ctx context.Context, name string, opts ...DeleteBranchOptions) error
DeleteBranch deletes the branch from the repository.
func (*Repository) DeleteTag ¶
func (r *Repository) DeleteTag(ctx context.Context, name string, opts ...DeleteTagOptions) error
DeleteTag deletes a tag from the repository.
func (*Repository) Diff ¶
func (r *Repository) Diff(ctx context.Context, 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 ¶
func (r *Repository) DiffBinary(ctx context.Context, 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 ¶
func (r *Repository) DiffNameOnly(ctx context.Context, 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 ¶
func (r *Repository) Fetch(ctx context.Context, opts ...FetchOptions) error
Fetch fetches updates for the repository.
func (*Repository) Fsck ¶
func (r *Repository) Fsck(ctx context.Context, opts ...FsckOptions) error
Fsck verifies the connectivity and validity of the objects in the database for the repository.
func (*Repository) Grep ¶
func (r *Repository) Grep(ctx context.Context, pattern string, opts ...GrepOptions) []*GrepResult
Grep returns the results of a grep search in the repository.
func (*Repository) HasBranch ¶
func (r *Repository) HasBranch(ctx context.Context, 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 ¶
func (r *Repository) HasReference(ctx context.Context, 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 ¶
func (r *Repository) HasTag(ctx context.Context, 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 ¶
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 ¶
func (r *Repository) LatestCommitTime(ctx context.Context, opts ...LatestCommitTimeOptions) (time.Time, error)
LatestCommitTime returns the time of latest commit of the repository.
func (*Repository) Log ¶
func (r *Repository) Log(ctx context.Context, 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 ¶
func (r *Repository) LsTree(ctx context.Context, treeID string, opts ...LsTreeOptions) (*Tree, error)
LsTree returns the tree object in the repository by given tree ID.
func (*Repository) MergeBase ¶
func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...MergeBaseOptions) (string, error)
MergeBase returns merge base between base and head revisions of the repository.
func (*Repository) Move ¶
func (r *Repository) Move(ctx context.Context, 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 ¶
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 ¶
func (r *Repository) Pull(ctx context.Context, opts ...PullOptions) error
Pull pulls updates for the repository.
func (*Repository) Push ¶
func (r *Repository) Push(ctx context.Context, remote, branch string, opts ...PushOptions) error
Push pushes local changes to given remote and branch for the repository.
func (*Repository) RawDiff ¶
func (r *Repository) RawDiff(ctx context.Context, 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 ¶
func (r *Repository) RemoteAdd(ctx context.Context, name, url string, opts ...RemoteAddOptions) error
RemoteAdd adds a new remote to the repository.
func (*Repository) RemoteGetURL ¶
func (r *Repository) RemoteGetURL(ctx context.Context, name string, opts ...RemoteGetURLOptions) ([]string, error)
RemoteGetURL retrieves URL(s) of a remote of the repository.
func (*Repository) RemoteRemove ¶
func (r *Repository) RemoteRemove(ctx context.Context, name string, opts ...RemoteRemoveOptions) error
RemoteRemove removes a remote from the repository.
func (*Repository) RemoteSetURL ¶
func (r *Repository) RemoteSetURL(ctx context.Context, name, newurl string, opts ...RemoteSetURLOptions) error
RemoteSetURL sets the first URL of the remote with given name of the repository.
func (*Repository) RemoteSetURLAdd ¶
func (r *Repository) RemoteSetURLAdd(ctx context.Context, 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 ¶
func (r *Repository) RemoteSetURLDelete(ctx context.Context, name, regex string, opts ...RemoteSetURLDeleteOptions) error
RemoteSetURLDelete deletes all URLs matching regex of the remote with given name of the repository.
func (*Repository) Remotes ¶
func (r *Repository) Remotes(ctx context.Context, opts ...RemotesOptions) ([]string, error)
Remotes lists remotes of the repository.
func (*Repository) Reset ¶
func (r *Repository) Reset(ctx context.Context, rev string, opts ...ResetOptions) error
Reset resets working tree to given revision for the repository.
func (*Repository) RevList ¶
func (r *Repository) RevList(ctx context.Context, refspecs []string, opts ...RevListOptions) ([]*Commit, error)
RevList returns a list of commits based on given refspecs in reverse chronological order.
func (*Repository) RevListCount ¶
func (r *Repository) RevListCount(ctx context.Context, refspecs []string, opts ...RevListCountOptions) (int64, error)
RevListCount returns number of total commits up to given refspec of the repository.
func (*Repository) RevParse ¶
func (r *Repository) RevParse(ctx context.Context, rev string, opts ...RevParseOptions) (string, error)
RevParse returns full length (40) commit ID by given revision in the repository.
func (*Repository) SearchCommits ¶
func (r *Repository) SearchCommits(ctx context.Context, 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 ¶
func (r *Repository) ShowNameStatus(ctx context.Context, rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)
ShowNameStatus returns name status of given revision of the repository.
func (*Repository) ShowRef ¶
func (r *Repository) ShowRef(ctx context.Context, opts ...ShowRefOptions) ([]*Reference, error)
ShowRef returns a list of references in the repository.
func (*Repository) ShowRefVerify ¶
func (r *Repository) ShowRefVerify(ctx context.Context, 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 ¶
func (r *Repository) SymbolicRef(ctx context.Context, 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 ¶
func (r *Repository) Tag(ctx context.Context, name string, opts ...TagOptions) (*Tag, error)
Tag returns a Git tag by given name, e.g. "v1.0.0".
func (*Repository) TagCommit ¶
func (r *Repository) TagCommit(ctx context.Context, 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 ¶
func (r *Repository) TagCommitID(ctx context.Context, 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 ¶
func (r *Repository) Tags(ctx context.Context, opts ...TagsOptions) ([]string, error)
Tags returns a list of tags of the repository.
func (*Repository) WorktreeAdd ¶
func (r *Repository) WorktreeAdd(ctx context.Context, path, commitIsh string, opts ...WorktreeAddOptions) error
WorktreeAdd creates a new worktree at the given path linked to this repository. The commitIsh determines the HEAD of the new worktree.
func (*Repository) WorktreeRemove ¶
func (r *Repository) WorktreeRemove(ctx context.Context, path string, opts ...WorktreeRemoveOptions) error
WorktreeRemove removes a worktree at the given path.
type ResetOptions ¶
type ResetOptions struct {
// Indicates whether to perform a hard reset.
Hard bool
CommandOptions
}
ResetOptions contains optional arguments for resetting a branch.
type RevListCountOptions ¶
type RevListCountOptions struct {
// The relative path of the repository.
Path string
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 ¶
type RevListOptions struct {
// The relative path of the repository.
Path string
CommandOptions
}
RevListOptions contains optional arguments for listing commits.
type RevParseOptions ¶
type RevParseOptions struct {
CommandOptions
}
RevParseOptions contains optional arguments for parsing revision.
type SHA1 ¶
type SHA1 struct {
// contains filtered or unexported fields
}
SHA1 is the SHA-1 hash of a Git object.
func MustIDFromString ¶
MustIDFromString always returns a new sha from a ID with no validation of input.
func NewIDFromString ¶
NewIDFromString returns a new SHA1 from a ID string of length 40.
type SearchCommitsOptions ¶
type SearchCommitsOptions struct {
// The maximum number of commits to output.
MaxCount int
// The relative path of the repository.
Path string
CommandOptions
}
SearchCommitsOptions contains optional arguments for searching commits.
type ShowNameStatusOptions ¶
type ShowNameStatusOptions struct {
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 ¶
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
CommandOptions
}
ShowRefOptions contains optional arguments for listing references.
type ShowRefVerifyOptions ¶
type ShowRefVerifyOptions struct {
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 ¶
SteamParseDiffResult contains results of streaming parsing a diff.
type Submodule ¶
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 SymbolicRefOptions ¶
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
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.
type TagOptions ¶
type TagOptions struct {
CommandOptions
}
TagOptions contains optional arguments for getting a tag.
type TagsOptions ¶
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
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) BlobByIndex ¶
BlobByIndex returns blob object by given index.
func (*Tree) Entries ¶
Entries returns all entries of the tree. Successful results are cached; failed attempts are not cached, allowing retries with a fresh context.
type TreeEntry ¶
type TreeEntry struct {
// contains filtered or unexported fields
}
func (*TreeEntry) IsTree ¶
IsTree returns tree if the entry itself is another tree (i.e. a directory).
func (*TreeEntry) Size ¶
Size returns the size of the entry. It runs a git command to determine the size on first call. Successful results are cached; failed attempts are not cached, allowing retries with a fresh context.
func (*TreeEntry) Type ¶
func (e *TreeEntry) Type() ObjectType
Type returns the object type of the entry.
type UpdateServerInfoOptions ¶
type UpdateServerInfoOptions struct {
// Indicates whether to overwrite the existing server info.
Force bool
CommandOptions
}
UpdateServerInfoOptions contains optional arguments for updating auxiliary info file on the server side.
type UploadPackOptions ¶
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 git-level inactivity timeout passed to git-upload-pack's --timeout flag.
// This is separate from the command execution timeout which is controlled via
// context.Context.
InactivityTimeout time.Duration
CommandOptions
}
UploadPackOptions contains optional arguments for sending the packfile to the client.
type WorktreeAddOptions ¶
type WorktreeAddOptions struct {
// The new branch name to create and checkout in the worktree.
Branch string
CommandOptions
}
WorktreeAddOptions contains optional arguments for adding a worktree.
Docs: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-add
type WorktreeRemoveOptions ¶
type WorktreeRemoveOptions struct {
// Indicates whether to force removal even if the worktree is dirty.
Force bool
CommandOptions
}
WorktreeRemoveOptions contains optional arguments for removing a worktree.
Docs: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-remove
Source Files
¶
- blame.go
- blob.go
- command.go
- commit.go
- commit_archive.go
- commit_submodule.go
- diff.go
- error.go
- git.go
- hook.go
- object.go
- repo.go
- repo_blame.go
- repo_blob.go
- repo_commit.go
- repo_diff.go
- repo_grep.go
- repo_hook.go
- repo_pull.go
- repo_reference.go
- repo_remote.go
- repo_tag.go
- repo_tree.go
- repo_worktree.go
- server.go
- sha1.go
- signature.go
- tag.go
- tree.go
- tree_blob.go
- tree_entry.go
- utils.go