Documentation
¶
Index ¶
- Constants
- Variables
- func BinVersion() (string, error)
- func Debug(a ...interface{})
- func Debugf(f string, a ...interface{})
- func RefShortName(ref string) string
- func RepoCheckout(repoPath, branch string, opts ...CheckoutOptions) error
- func RepoCommit(repoPath string, committer *Signature, message string, opts ...CommitOptions) error
- func RepoHasBranch(repoPath, branch string, opts ...ShowRefVerifyOptions) bool
- func RepoHasReference(repoPath, ref string, opts ...ShowRefVerifyOptions) bool
- func RepoHasTag(repoPath, tag string, opts ...ShowRefVerifyOptions) bool
- func RepoShowRefVerify(repoPath, ref string, opts ...ShowRefVerifyOptions) (string, error)
- type AuthorLinesCounter
- type BranchCommit
- type CatFileCommitOptions
- type CatFileTypeOptions
- type CheckoutOptions
- type Command
- func (c *Command) AddArgs(args ...string) *Command
- func (c *Command) AddEnvs(envs ...string) *Command
- func (c *Command) Run() ([]byte, error)
- func (c *Command) RunInDir(dir string) ([]byte, error)
- func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error
- func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error)
- func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error)
- func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error)
- func (c *Command) String() string
- type Commit
- type CommitByRevisionOptions
- type CommitChan
- type CommitOptions
- type CommitsByPageOptions
- type CommitsSinceOptions
- type Git
- type LogOptions
- type Reference
- type Repository
- func (r *Repository) BranchCommit(branch string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) BranchCommitID(branch string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) Branches() ([]string, error)
- func (r *Repository) CatFileCommit(rev string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) CatFileType(rev string, opts ...CatFileTypeOptions) (string, error)
- func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error
- func (r *Repository) Commit(committer *Signature, message string, opts ...CommitOptions) error
- func (r *Repository) CommitByRevision(rev string, opts ...CommitByRevisionOptions) (*Commit, error)
- func (r *Repository) CommitsByPage(rev string, page, size int, opts ...CommitsByPageOptions) ([]*Commit, error)
- func (r *Repository) CommitsSince(rev string, since time.Time, opts ...CommitsSinceOptions) ([]*Commit, error)
- func (r *Repository) HasBranch(branch string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) HasReference(ref string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) HasTag(tag string, opts ...ShowRefVerifyOptions) bool
- func (r *Repository) Log(rev string, opts ...LogOptions) ([]*Commit, error)
- func (r *Repository) LogGo(rev string, opts ...LogOptions) (count int, err error)
- func (r *Repository) Path() string
- func (r *Repository) RevParse(rev string, opts ...RevParseOptions) (string, error)
- func (r *Repository) SearchCommits(rev, pattern string, opts ...SearchCommitsOptions) ([]*Commit, error)
- func (r *Repository) ShowRef(opts ...ShowRefOptions) ([]*Reference, error)
- func (r *Repository) ShowRefVerify(ref string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) SumAuthor(author *Signature) *AuthorLinesCounter
- func (r *Repository) SymbolicRef(opts ...SymbolicRefOptions) (string, error)
- func (r *Repository) TagCommit(tag string, opts ...CatFileCommitOptions) (*Commit, error)
- func (r *Repository) TagCommitID(tag string, opts ...ShowRefVerifyOptions) (string, error)
- func (r *Repository) Tags() ([]string, error)
- type RevParseOptions
- type SearchCommitsOptions
- type ShowRefOptions
- type ShowRefVerifyOptions
- type Signature
- type Summary
- type SymbolicRefOptions
Constants ¶
const ( RefsHeads = "refs/heads/" RefsTags = "refs/tags/" )
const DefaultTimeout = time.Minute
DefaultTimeout is the default timeout duration for all commands.
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") ErrExecTimeout = errors.New("execution was timed out") ErrNoMergeBase = errors.New("no merge based was found") ErrNotBlob = errors.New("the entry is not a blob") ErrReferenceNotExist = errors.New("reference does not exist") )
Functions ¶
func BinVersion ¶
BinVersion returns current Git binary version that is used by this module.
func RefShortName ¶
RefShortName returns short name of heads or tags. Other references will retrun original string.
func RepoCheckout ¶
func RepoCheckout(repoPath, branch string, opts ...CheckoutOptions) error
Checkout checks out to given branch for the repository in given path.
func RepoCommit ¶
func RepoCommit(repoPath string, committer *Signature, message string, opts ...CommitOptions) error
RepoCommit commits local changes with given author, committer and message for the repository in given path.
func RepoHasBranch ¶
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 ¶
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 ¶
func RepoHasTag(repoPath, tag string, opts ...ShowRefVerifyOptions) bool
RepoHasTag 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 RepoShowRefVerify ¶
func RepoShowRefVerify(repoPath, ref string, opts ...ShowRefVerifyOptions) (string, error)
ShowRefVerify returns the commit ID of given reference if it exists in the repository in given path.
Types ¶
type AuthorLinesCounter ¶
type AuthorLinesCounter struct { Email string // 作者邮箱 Name string // 作者名称 CommitCount int // 提交次数 Addition int // 增加 Deletion int // 删除 }
func (*AuthorLinesCounter) String ¶
func (a *AuthorLinesCounter) String() string
type BranchCommit ¶ added in v0.0.7
type CatFileCommitOptions ¶
type CatFileCommitOptions 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 }
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 { // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
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. Timeout time.Duration }
CheckoutOptions contains optional arguments for checking out to a branch. Docs: https://git-scm.com/docs/git-checkout
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command contains the name, arguments and environment variables of a command.
func NewCommand ¶
NewCommand creates and returns a new Command with given arguments for "git".
func (*Command) Run ¶
Run executes the command in working directory and default timeout duration. It returns stdout in string and error (combined with stderr).
func (*Command) RunInDir ¶
RunInDir executes the command in given directory and default timeout duration. It returns stdout and error (combined with stderr).
func (*Command) RunInDirPipeline ¶
RunInDirPipeline executes the command in given directory and default timeout duration. It pipes stdout and stderr to supplied io.Writer.
func (*Command) RunInDirPipelineWithTimeout ¶
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.
func (*Command) RunInDirWithTimeout ¶
RunInDirWithTimeout executes the command in given directory and timeout duration. It returns stdout in []byte and error (combined with stderr).
func (*Command) RunWithTimeout ¶
RunWithTimeout executes the command in working directory and given timeout duration. It returns stdout in string and error (combined with stderr).
type Commit ¶
type Commit struct { // The author of the commit. Author *Signature // The committer of the commit. Committer *Signature // The full commit message. Message string }
Commit contains information of a Git commit.
type CommitByRevisionOptions ¶
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 }
CommitByRevisionOptions contains optional arguments for getting a commit. Docs: https://git-scm.com/docs/git-log
type CommitChan ¶ added in v0.0.5
type CommitChan struct { AuthorEmail chan *Commit // contains filtered or unexported fields }
func GetChanInstance ¶ added in v0.0.5
func GetChanInstance() *CommitChan
func (*CommitChan) Complete ¶ added in v0.0.5
func (ch *CommitChan) Complete()
func (*CommitChan) IsDone ¶ added in v0.0.5
func (ch *CommitChan) IsDone() bool
IsDone returns true only if process>0 and process==receive
func (*CommitChan) Process ¶ added in v0.0.5
func (ch *CommitChan) Process(c *Commit)
Process set processCount.Inc()
type CommitOptions ¶
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. Timeout time.Duration }
CommitOptions contains optional arguments to commit changes. Docs: https://git-scm.com/docs/git-commit
type CommitsByPageOptions ¶
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 }
CommitsByPageOptions contains optional arguments for getting paginated commits. Docs: https://git-scm.com/docs/git-log
type CommitsSinceOptions ¶
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 }
CommitsSinceOptions contains optional arguments for listing commits since a time. Docs: https://git-scm.com/docs/git-log
type Git ¶
type Git struct { Summary *Summary // contains filtered or unexported fields }
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 // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
LogOptions contains optional arguments for listing commits. Docs: https://git-scm.com/docs/git-log
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) BranchCommit ¶
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 ¶
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 ¶
func (r *Repository) Branches() ([]string, error)
Branches returns a list of all branches in the repository.
func (*Repository) CatFileCommit ¶
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 ¶
func (r *Repository) CatFileType(rev string, opts ...CatFileTypeOptions) (string, error)
CatFileType returns the object type of given revision of the repository.
func (*Repository) Checkout ¶
func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error
Checkout checks out to given branch for the repository.
func (*Repository) Commit ¶
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 ¶
func (r *Repository) CommitByRevision(rev string, opts ...CommitByRevisionOptions) (*Commit, error)
CommitByRevisionOptions returns a commit by given revision.
func (*Repository) CommitsByPage ¶
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 ¶
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) HasBranch ¶
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 ¶
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 ¶
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) Log ¶
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) LogGo ¶ added in v0.0.5
func (r *Repository) LogGo(rev string, opts ...LogOptions) (count int, err error)
func (*Repository) Path ¶
func (r *Repository) Path() string
Path returns the path of the repository.
func (*Repository) RevParse ¶
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 ¶
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) ShowRef ¶
func (r *Repository) ShowRef(opts ...ShowRefOptions) ([]*Reference, error)
ShowRef returns a list of references in the repository.
func (*Repository) ShowRefVerify ¶
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) SumAuthor ¶
func (r *Repository) SumAuthor(author *Signature) *AuthorLinesCounter
func (*Repository) SymbolicRef ¶
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) TagCommit ¶
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 ¶
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 v0.0.5
func (r *Repository) Tags() ([]string, error)
type RevParseOptions ¶
type RevParseOptions 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 }
RevParseOptions contains optional arguments for parsing revision. Docs: https://git-scm.com/docs/git-rev-parse
type SearchCommitsOptions ¶
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 }
SearchCommitsOptions contains optional arguments for searching commits. Docs: https://git-scm.com/docs/git-log
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 // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
ShowRefOptions contains optional arguments for listing references. Docs: https://git-scm.com/docs/git-show-ref
type ShowRefVerifyOptions ¶
type ShowRefVerifyOptions 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 }
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 Summary ¶
type Summary struct { Branch int Tags int BranchCommits []*BranchCommit AuthorCountList []*AuthorLinesCounter // 用户列表 CurrentBranch string // 当前分支 // contains filtered or unexported fields }
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 // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
SymbolicRefOptions contains optional arguments for get and set symbolic ref.