Documentation ¶
Index ¶
- Constants
- Variables
- func AddChanges(repoPath string, all bool, files ...string) error
- func BinVersion() (string, error)
- func Checkout(repoPath string, opts CheckoutOptions) error
- func Clone(from, to string, opts CloneRepoOptions) (err error)
- func CommitChanges(repoPath string, opts CommitChangesOptions) error
- func CommitsCount(repoPath, revision string) (int64, error)
- func DetectEncoding(content []byte) (string, error)
- func Fetch(repoPath string, opts FetchRemoteOptions) error
- func Fsck(repoPath string, timeout time.Duration, args ...string) error
- func InitRepository(repoPath string, bare bool) error
- func IsBranchExist(repoPath, name string) bool
- func IsErrExecTimeout(err error) bool
- func IsErrNotExist(err error) bool
- func IsErrUnsupportedVersion(err error) bool
- func IsReferenceExist(repoPath, name string) bool
- func IsRepoURLAccessible(opts NetworkOptions) bool
- func IsTagExist(repoPath, name string) bool
- func IsValidHookName(name string) bool
- func MoveFile(repoPath, oldTreeName, newTreeName string) error
- func MustID(b []byte) sha1
- func MustIDFromString(s string) sha1
- func NewID(b []byte) (sha1, error)
- func NewIDFromString(s string) (sha1, error)
- func Pull(repoPath string, opts PullRemoteOptions) error
- func Push(repoPath, remote, branch string) error
- func RefEndName(refStr string) string
- func ResetHEAD(repoPath string, hard bool, revision string) error
- func UnescapeChars(in []byte) []byte
- func Version() string
- type ArchiveType
- type Blob
- type Branch
- type CheckoutOptions
- type CloneRepoOptions
- type Command
- func (c *Command) AddArguments(args ...string) *Command
- func (c *Command) AddEnvs(envs ...string) *Command
- func (c *Command) Run() (string, error)
- func (c *Command) RunInDir(dir string) (string, error)
- func (c *Command) RunInDirBytes(dir string) ([]byte, error)
- func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error
- func (c *Command) RunInDirTimeout(timeout time.Duration, dir string) ([]byte, error)
- func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error
- func (c *Command) RunTimeout(timeout time.Duration) (string, error)
- func (c *Command) String() string
- type Commit
- func (c *Commit) CommitsBefore() (*list.List, error)
- func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error)
- func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error)
- func (c *Commit) CommitsByRange(page int) (*list.List, error)
- func (c *Commit) CommitsByRangeSize(page, size int) (*list.List, error)
- func (c *Commit) CommitsCount() (int64, error)
- func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error
- func (c *Commit) FileStatus() (*CommitFileStatus, error)
- func (c *Commit) GetCommitByPath(relpath string) (*Commit, error)
- func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error)
- func (c *Commit) GetSubModule(entryname string) (*SubModule, error)
- func (c *Commit) GetSubModules() (*objectCache, error)
- func (c *Commit) IsImageFile(name string) bool
- func (c *Commit) Message() string
- func (c *Commit) Parent(n int) (*Commit, error)
- func (c *Commit) ParentCount() int
- func (c *Commit) ParentID(n int) (sha1, error)
- func (c *Commit) SearchCommits(keyword string) (*list.List, error)
- func (c *Commit) Summary() string
- type CommitChangesOptions
- type CommitFileStatus
- type CountObject
- type DeleteBranchOptions
- type Diff
- type DiffFile
- type DiffFileType
- type DiffLine
- type DiffLineType
- type DiffSection
- type Entries
- func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error)
- func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath string, maxConcurrency int) ([][]interface{}, error)
- func (tes Entries) Len() int
- func (tes Entries) Less(i, j int) bool
- func (tes Entries) Sort()
- func (tes Entries) Swap(i, j int)
- type EntryMode
- type ErrExecTimeout
- type ErrNotExist
- type ErrUnsupportedVersion
- type FetchRemoteOptions
- type Hook
- type NetworkOptions
- type ObjectType
- type PullRemoteOptions
- type PullRequestInfo
- type RawDiffType
- type Repository
- func (repo *Repository) AddRemote(name, url string, fetch bool) error
- func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error)
- func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error)
- func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error)
- func (repo *Repository) CommitsByFileAndRangeSize(revision, file string, page, size int) (*list.List, error)
- func (repo *Repository) CommitsByRange(revision string, page int) (*list.List, error)
- func (repo *Repository) CommitsByRangeSize(revision string, page, size int) (*list.List, error)
- func (repo *Repository) CommitsCountBetween(start, end string) (int64, error)
- func (repo *Repository) CreateTag(name, revision string) error
- func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error
- func (repo *Repository) DeleteTag(name string) error
- func (repo *Repository) FileCommitsCount(revision, file string) (int64, error)
- func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
- func (repo *Repository) GetBranchCommit(name string) (*Commit, error)
- func (repo *Repository) GetBranchCommitID(name string) (string, error)
- func (repo *Repository) GetBranches() ([]string, error)
- func (repo *Repository) GetCommit(commitID string) (*Commit, error)
- func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)
- func (repo *Repository) GetDiffCommit(commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error)
- func (repo *Repository) GetDiffRange(beforeCommitID, afterCommitID string, ...) (*Diff, error)
- func (repo *Repository) GetHEADBranch() (*Branch, error)
- func (repo *Repository) GetHook(name string) (*Hook, error)
- func (repo *Repository) GetMergeBase(base, head string) (string, error)
- func (repo *Repository) GetPatch(base, head string) ([]byte, error)
- func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error)
- func (repo *Repository) GetRawDiff(commitID string, diffType RawDiffType, writer io.Writer) error
- func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error)
- func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error)
- func (repo *Repository) GetTag(name string) (*Tag, error)
- func (repo *Repository) GetTagCommit(name string) (*Commit, error)
- func (repo *Repository) GetTagCommitID(name string) (string, error)
- func (repo *Repository) GetTags() ([]string, error)
- func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error)
- func (repo *Repository) GetTree(idStr string) (*Tree, error)
- func (repo *Repository) Hooks() ([]*Hook, error)
- func (repo *Repository) IsBranchExist(name string) bool
- func (repo *Repository) IsTagExist(name string) bool
- func (repo *Repository) RemoveRemote(name string) error
- func (repo *Repository) SetDefaultBranch(name string) error
- type Signature
- type SubModule
- type SubModuleFile
- type Tag
- type TagsResult
- type Tree
- type TreeEntry
Constants ¶
const AnsiCharset = "ascii"
const BRANCH_PREFIX = "refs/heads/"
const DEFAULT_TIMEOUT = 60 * time.Second
const DIFF_HEAD = "diff --git "
const EMPTY_SHA = "0000000000000000000000000000000000000000"
const REMOTE_PREFIX = "refs/remotes/"
const TAG_PREFIX = "refs/tags/"
Variables ¶
var ( // Debug enables verbose logging on everything. // This should be false in case Gogs starts in SSH mode. Debug = false Prefix = "[git-module] " )
var ( // Direcotry of hook and sample files. Can be changed to "custom_hooks" for very purpose. HookDir = "hooks" HookSampleDir = HookDir // HookNames is a list of Git server hooks' name that are supported. HookNames = []string{ "pre-receive", "update", "post-receive", } )
var DefaultCommitsPageSize = 30
var (
ErrNotValidHook = errors.New("not a valid Git hook")
)
Functions ¶
func AddChanges ¶
AddAllChanges marks local changes to be ready for commit.
func Checkout ¶
func Checkout(repoPath string, opts CheckoutOptions) error
Checkout checkouts a branch
func Clone ¶
func Clone(from, to string, opts CloneRepoOptions) (err error)
Clone clones original repository to target path.
func CommitChanges ¶
func CommitChanges(repoPath string, opts CommitChangesOptions) error
CommitChanges commits local changes with given committer, author and message. If author is nil, it will be the same as committer.
func CommitsCount ¶
CommitsCount returns number of total commits of until given revision.
func DetectEncoding ¶
func Fetch ¶
func Fetch(repoPath string, opts FetchRemoteOptions) error
Fetch fetches changes from remotes without merging.
func InitRepository ¶
InitRepository initializes a new Git repository.
func IsBranchExist ¶
IsBranchExist returns true if given branch exists in the repository.
func IsErrExecTimeout ¶
func IsErrNotExist ¶
func IsErrUnsupportedVersion ¶
func IsReferenceExist ¶
IsReferenceExist returns true if given reference exists in the repository.
func IsRepoURLAccessible ¶
func IsRepoURLAccessible(opts NetworkOptions) bool
IsRepoURLAccessible checks if given repository URL is accessible.
func IsTagExist ¶
IsTagExist returns true if given tag exists in the repository.
func IsValidHookName ¶
IsValidHookName returns true if given name is a valid Git hook.
func MustID ¶
func MustID(b []byte) sha1
MustID always creates a new sha1 from a [20]byte array with no validation of input.
func MustIDFromString ¶
func MustIDFromString(s string) sha1
MustIDFromString always creates a new sha from a ID with no validation of input.
func NewIDFromString ¶
NewIDFromString creates a new sha1 from a ID string of length 40.
func Pull ¶
func Pull(repoPath string, opts PullRemoteOptions) error
Pull pulls changes from remotes.
func RefEndName ¶
func UnescapeChars ¶
UnescapeChars reverses escaped characters.
Types ¶
type Blob ¶
type Blob struct { *TreeEntry // contains filtered or unexported fields }
Blob represents a Git object.
type CheckoutOptions ¶
type CloneRepoOptions ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a command with its subcommands or arguments.
func NewCommand ¶
NewCommand creates and returns a new Git Command based on given command and arguments.
func (*Command) AddArguments ¶
AddArguments adds new argument(s) to the command.
func (*Command) Run ¶
Run executes the command in defualt working directory and returns stdout in string and error (combined with stderr).
func (*Command) RunInDir ¶
RunInDir executes the command in given directory and returns stdout in string and error (combined with stderr).
func (*Command) RunInDirBytes ¶
RunInDir executes the command in given directory and returns stdout in []byte and error (combined with stderr).
func (*Command) RunInDirPipeline ¶
RunInDirPipeline executes the command in given directory, it pipes stdout and stderr to given io.Writer.
func (*Command) RunInDirTimeout ¶
RunInDirTimeout executes the command in given directory with given timeout, and returns stdout in []byte and error (combined with stderr).
func (*Command) RunInDirTimeoutPipeline ¶
func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error
RunInDirTimeoutPipeline executes the command in given directory with given timeout, it pipes stdout and stderr to given io.Writer.
func (*Command) RunTimeout ¶
RunTimeout executes the command in defualt working directory with given timeout, and returns stdout in string and error (combined with stderr).
type Commit ¶
type Commit struct { Tree ID sha1 // The ID of this commit object Author *Signature Committer *Signature CommitMessage string // contains filtered or unexported fields }
Commit represents a git commit.
func (*Commit) CommitsBeforeLimit ¶
func (*Commit) CommitsBeforeUntil ¶
func (*Commit) CommitsByRangeSize ¶
func (*Commit) CommitsCount ¶
func (*Commit) CreateArchive ¶
func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error
func (*Commit) FileStatus ¶
func (c *Commit) FileStatus() (*CommitFileStatus, error)
FileStatus returns file status of commit.
func (*Commit) GetCommitByPath ¶
GetCommitByPath return the commit of relative path object.
func (*Commit) GetFilesChangedSinceCommit ¶
func (*Commit) GetSubModules ¶
func (*Commit) IsImageFile ¶
func (*Commit) Message ¶
Message returns the commit message. Same as retrieving CommitMessage directly.
func (*Commit) ParentCount ¶
ParentCount returns number of parents of the commit. 0 if this is the root commit, otherwise 1,2, etc.
type CommitChangesOptions ¶
type CommitFileStatus ¶
CommitFileStatus represents status of files in a commit.
func GetCommitFileStatus ¶
func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error)
GetCommitFileStatus returns file status of commit in given repository.
func NewCommitFileStatus ¶
func NewCommitFileStatus() *CommitFileStatus
type CountObject ¶
type CountObject struct { Count int64 Size int64 InPack int64 Packs int64 SizePack int64 PrunePackable int64 Garbage int64 SizeGarbage int64 }
CountObject represents disk usage report of Git repository.
func GetRepoSize ¶
func GetRepoSize(repoPath string) (*CountObject, error)
GetRepoSize returns disk usage report of repository in given path.
type DeleteBranchOptions ¶
type DeleteBranchOptions struct {
Force bool
}
Option(s) for delete branch
type Diff ¶
func ParsePatch ¶
type DiffFile ¶
type DiffFileType ¶
type DiffFileType uint8
const ( DIFF_FILE_ADD DiffFileType = iota + 1 DIFF_FILE_CHANGE DIFF_FILE_DEL DIFF_FILE_RENAME )
type DiffLineType ¶
type DiffLineType uint8
const ( DIFF_LINE_PLAIN DiffLineType = iota + 1 DIFF_LINE_ADD DIFF_LINE_DEL DIFF_LINE_SECTION )
type DiffSection ¶
type Entries ¶
type Entries []*TreeEntry
func (Entries) GetCommitsInfo ¶
GetCommitsInfo takes advantages of concurrency to speed up getting information of all commits that are corresponding to these entries. This method will automatically choose the right number of goroutine (concurrency) to use related of the host CPU.
func (Entries) GetCommitsInfoWithCustomConcurrency ¶
func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath string, maxConcurrency int) ([][]interface{}, error)
GetCommitsInfoWithCustomConcurrency takes advantages of concurrency to speed up getting information of all commits that are corresponding to these entries. If the given maxConcurrency is negative or equal to zero: the right number of goroutine (concurrency) to use will be choosen related of the host CPU.
type EntryMode ¶
type EntryMode int
const ( ENTRY_MODE_BLOB EntryMode = 0100644 ENTRY_MODE_EXEC EntryMode = 0100755 ENTRY_MODE_SYMLINK EntryMode = 0120000 ENTRY_MODE_COMMIT EntryMode = 0160000 ENTRY_MODE_TREE EntryMode = 0040000 )
There are only a few file modes in Git. They look like unix file modes, but they can only be one of these.
type ErrExecTimeout ¶
func (ErrExecTimeout) Error ¶
func (err ErrExecTimeout) Error() string
type ErrNotExist ¶
func (ErrNotExist) Error ¶
func (err ErrNotExist) Error() string
type ErrUnsupportedVersion ¶
type ErrUnsupportedVersion struct {
Required string
}
func (ErrUnsupportedVersion) Error ¶
func (err ErrUnsupportedVersion) Error() string
type FetchRemoteOptions ¶
type Hook ¶
type Hook struct { IsActive bool // Indicates whether repository has this hook. Content string // Content of hook if it's active. Sample string // Sample content from Git. // contains filtered or unexported fields }
Hook represents a Git hook.
type NetworkOptions ¶
type ObjectType ¶
type ObjectType string
const ( OBJECT_COMMIT ObjectType = "commit" OBJECT_TREE ObjectType = "tree" OBJECT_BLOB ObjectType = "blob" OBJECT_TAG ObjectType = "tag" )
type PullRemoteOptions ¶
type PullRequestInfo ¶
PullRequestInfo represents needed information for a pull request.
type RawDiffType ¶
type RawDiffType string
const ( RAW_DIFF_NORMAL RawDiffType = "diff" RAW_DIFF_PATCH RawDiffType = "patch" )
type Repository ¶
type Repository struct { Path string // contains filtered or unexported fields }
Repository represents a Git repository.
func OpenRepository ¶
func OpenRepository(repoPath string) (*Repository, error)
OpenRepository opens the repository at the given path.
func (*Repository) AddRemote ¶
func (repo *Repository) AddRemote(name, url string, fetch bool) error
AddRemote adds a new remote to repository.
func (*Repository) CommitsBetween ¶
CommitsBetween returns a list that contains commits between [last, before).
func (*Repository) CommitsBetweenIDs ¶
func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error)
func (*Repository) CommitsByFileAndRange ¶
func (*Repository) CommitsByFileAndRangeSize ¶
func (*Repository) CommitsByRange ¶
func (*Repository) CommitsByRangeSize ¶
func (*Repository) CommitsCountBetween ¶
func (repo *Repository) CommitsCountBetween(start, end string) (int64, error)
func (*Repository) CreateTag ¶
func (repo *Repository) CreateTag(name, revision string) error
func (*Repository) DeleteBranch ¶
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error
DeleteBranch delete a branch by name on repository.
func (*Repository) DeleteTag ¶
func (repo *Repository) DeleteTag(name string) error
DeleteTag deletes a tag from the repository
func (*Repository) FileCommitsCount ¶
func (repo *Repository) FileCommitsCount(revision, file string) (int64, error)
func (*Repository) FilesCountBetween ¶
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
func (*Repository) GetBranchCommit ¶
func (repo *Repository) GetBranchCommit(name string) (*Commit, error)
GetBranchCommit returns the last commit of given branch.
func (*Repository) GetBranchCommitID ¶
func (repo *Repository) GetBranchCommitID(name string) (string, error)
GetBranchCommitID returns last commit ID string of given branch.
func (*Repository) GetBranches ¶
func (repo *Repository) GetBranches() ([]string, error)
GetBranches returns all branches of the repository.
func (*Repository) GetCommit ¶
func (repo *Repository) GetCommit(commitID string) (*Commit, error)
GetCommit returns commit object of by ID string.
func (*Repository) GetCommitByPath ¶
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)
GetCommitByPath returns the last commit of relative path.
func (*Repository) GetDiffCommit ¶
func (repo *Repository) GetDiffCommit(commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error)
func (*Repository) GetDiffRange ¶
func (repo *Repository) GetDiffRange(beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error)
func (*Repository) GetHEADBranch ¶
func (repo *Repository) GetHEADBranch() (*Branch, error)
GetHEADBranch returns corresponding branch of HEAD.
func (*Repository) GetMergeBase ¶
func (repo *Repository) GetMergeBase(base, head string) (string, error)
GetMergeBase checks and returns merge base of two branches.
func (*Repository) GetPatch ¶
func (repo *Repository) GetPatch(base, head string) ([]byte, error)
GetPatch generates and returns patch data between given revisions.
func (*Repository) GetPullRequestInfo ¶
func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error)
GetPullRequestInfo generates and returns pull request information between base and head branches of repositories.
func (*Repository) GetRawDiff ¶
func (repo *Repository) GetRawDiff(commitID string, diffType RawDiffType, writer io.Writer) error
GetRawDiff dumps diff results of repository in given commit ID to io.Writer. TODO: move this function to gogits/git-module
func (*Repository) GetRemoteBranchCommit ¶
func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error)
GetRemoteBranchCommit returns the last commit of given remote branch.
func (*Repository) GetRemoteBranchCommitID ¶
func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error)
GetRemoteBranchCommitID returns last commit ID string of given remote branch.
func (*Repository) GetTag ¶
func (repo *Repository) GetTag(name string) (*Tag, error)
GetTag returns a Git tag by given name.
func (*Repository) GetTagCommit ¶
func (repo *Repository) GetTagCommit(name string) (*Commit, error)
GetTagCommit returns the commit of given tag.
func (*Repository) GetTagCommitID ¶
func (repo *Repository) GetTagCommitID(name string) (string, error)
GetTagCommitID returns last commit ID string of given tag.
func (*Repository) GetTags ¶
func (repo *Repository) GetTags() ([]string, error)
GetTags returns all tags of the repository.
func (*Repository) GetTagsAfter ¶
func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error)
GetTagsAfter returns list of tags 'after' (exlusive) given tag.
func (*Repository) GetTree ¶
func (repo *Repository) GetTree(idStr string) (*Tree, error)
Find the tree object in the repository.
func (*Repository) Hooks ¶
func (repo *Repository) Hooks() ([]*Hook, error)
func (*Repository) IsBranchExist ¶
func (repo *Repository) IsBranchExist(name string) bool
func (*Repository) IsTagExist ¶
func (repo *Repository) IsTagExist(name string) bool
func (*Repository) RemoveRemote ¶
func (repo *Repository) RemoveRemote(name string) error
RemoveRemote removes a remote from repository.
func (*Repository) SetDefaultBranch ¶
func (repo *Repository) SetDefaultBranch(name string) error
SetDefaultBranch sets default branch of repository.
type SubModuleFile ¶
type SubModuleFile struct { *Commit // contains filtered or unexported fields }
SubModuleFile represents a file with submodule type.
func NewSubModuleFile ¶
func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile
type Tag ¶
type Tag struct { Name string ID sha1 Object sha1 // The id of this commit object Type string Tagger *Signature Message string // contains filtered or unexported fields }
Tag represents a Git tag.
type TagsResult ¶
type Tree ¶
type Tree struct { ID sha1 // contains filtered or unexported fields }
Tree represents a flat directory listing.
func NewTree ¶
func NewTree(repo *Repository, id sha1) *Tree
func (*Tree) GetTreeEntryByPath ¶
func (*Tree) ListEntries ¶
ListEntries returns all entries of current tree.
type TreeEntry ¶
type TreeEntry struct { ID sha1 Type ObjectType // contains filtered or unexported fields }