Documentation
¶
Index ¶
- Constants
- Variables
- func AddTemplateSubmoduleIndexes(ctx context.Context, repoPath string, submodules []TemplateSubmoduleCommit) error
- func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error
- func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLine int) (string, error)
- func DiscardFull(rd BufferedReader, discard int64) error
- func GetAffectedFiles(repo *Repository, branchName, oldCommitID, newCommitID string, env []string) ([]string, error)
- func GetFileDiffCutAroundLine(repo *Repository, startCommit, endCommit, treePath string, line int64, ...) (ret string, retErr error)
- func GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, error)
- func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string, paths []string) (map[string]*Commit, error)
- func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) error
- func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) (retErr error)
- func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string, error)
- func GetSigningKey(ctx context.Context) (*SigningKey, *Signature)
- func HashFilePathForWebUI(s string) string
- func InitFull() (err error)
- func InitRepository(ctx context.Context, repoPath string, bare bool, objectFormatName string) error
- func InitSimple() error
- func IsAllowedVerbForServe(verb string) bool
- func IsAllowedVerbForServeLfs(verb string) bool
- func IsEmptyCommitID(commitID string) bool
- func IsErrBranchNotExist(err error) bool
- func IsErrInvalidCloneAddr(err error) bool
- func IsErrMoreThanOne(err error) bool
- func IsErrNotExist(err error) bool
- func IsErrPushOutOfDate(err error) bool
- func IsErrPushRejected(err error) bool
- func IsRemoteNotExistError(err error) bool
- func IsRepoURLAccessible(ctx context.Context, url string) bool
- func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool
- func IsValidHookName(name string) bool
- func IsValidObjectFormat(name string) bool
- func IsValidRefPattern(name string) bool
- func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, paths ...string) (*bufio.Reader, func())
- func ParseBool(value string) (result, valid bool)
- func ParseCatFileTreeLine(objectFormat ObjectFormat, rd BufferedReader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error)
- func ParseDiffHunkString(diffHunk string) (leftLine, leftHunk, rightLine, rightHunk int)
- func ParseRefSuffix(ref string) (string, string)
- func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error)
- func Push(ctx context.Context, repoPath string, opts PushOptions) error
- func ReadTagObjectID(rd BufferedReader, size int64) (string, error)
- func ReadTreeID(rd BufferedReader, size int64) (string, error)
- func RunGitTests(m interface{ ... })
- func SanitizeRefPattern(name string) string
- func SplitCommitTitleBody(commitMessage string, titleRuneLimit int) (title, body string)
- func WalkGitLog(ctx context.Context, repo *Repository, head *Commit, treepath string, ...) (map[string]string, error)
- func WalkShowRef(ctx context.Context, repoPath string, extraArgs gitcmd.TrustedCmdArgs, ...) (countAll int, err error)
- func WriteCommitGraph(ctx context.Context, repoPath string) error
- type Blob
- func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error)
- func (b *Blob) GetBlobBytes(limit int64) ([]byte, error)
- func (b *Blob) GetBlobContent(limit int64) (string, error)
- func (b *Blob) GetBlobContentBase64(originContent *strings.Builder) (string, error)
- func (b *Blob) GetBlobLineCount(w io.Writer) (int, error)
- func (b *Blob) GuessContentType() (typesniffer.SniffedType, error)
- func (b *Blob) Name() string
- func (b *Blob) Size() int64
- type BufferedReader
- type CatFileBatch
- type CatFileBatchCloser
- type CatFileObject
- type CloneRepoOptions
- type CodeActivityAuthor
- type CodeActivityStats
- type Commit
- func (c *Commit) CacheCommit(ctx context.Context) error
- func (c *Commit) CommitsBefore() ([]*Commit, error)
- func (c *Commit) CommitsBeforeLimit(num int) ([]*Commit, error)
- func (c *Commit) CommitsBeforeUntil(commitID string) ([]*Commit, error)
- func (c *Commit) CommitsByRange(page, pageSize int, not, since, until string) ([]*Commit, error)
- func (c *Commit) FileChangedSinceCommit(filename, pastCommit string) (bool, error)
- func (c *Commit) GetCommitByPath(relpath string) (*Commit, error)
- func (c *Commit) GetFileContent(filename string, limit int) (string, error)
- func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error)
- func (c *Commit) GetSubModule(entryName string) (*SubModule, error)
- func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error)
- func (c *Commit) HasFile(filename string) (bool, error)
- func (c *Commit) HasPreviousCommit(objectID ObjectID) (bool, error)
- func (c *Commit) IsForcePush(oldCommitID string) (bool, error)
- func (c *Commit) Message() string
- func (c *Commit) Parent(n int) (*Commit, error)
- func (c *Commit) ParentCount() int
- func (c *Commit) ParentID(n int) (ObjectID, error)
- func (c *Commit) SearchCommits(opts SearchCommitsOptions) ([]*Commit, error)
- func (c *Commit) Summary() string
- type CommitInfo
- type CommitSignature
- type CommitSubmoduleFile
- type CommitTreeOpts
- type CommitsByFileAndRangeOptions
- type Entries
- type EntryFollowResult
- type EntryMode
- type ErrBranchNotExist
- type ErrInvalidCloneAddr
- type ErrInvalidSHA
- type ErrMoreThanOne
- type ErrNotExist
- type ErrPushOutOfDate
- type ErrPushRejected
- type Features
- type GPGSettings
- type GrepModeType
- type GrepOptions
- type GrepResult
- type Hook
- type IndexObjectInfo
- type LastCommitCache
- type LogNameStatusCommitData
- type LogNameStatusRepoParser
- type LsTreeEntry
- type Note
- type ObjectCache
- type ObjectFormat
- type ObjectID
- type ObjectType
- type PushOptions
- type RawDiffType
- type RefName
- func (ref RefName) BranchName() string
- func (ref RefName) ForBranchName() string
- func (ref RefName) IsBranch() bool
- func (ref RefName) IsFor() bool
- func (ref RefName) IsPull() bool
- func (ref RefName) IsRemote() bool
- func (ref RefName) IsTag() bool
- func (ref RefName) PullName() string
- func (ref RefName) RefGroup() string
- func (ref RefName) RefType() RefType
- func (ref RefName) RefWebLinkPath() string
- func (ref RefName) RemoteName() string
- func (ref RefName) ShortName() string
- func (ref RefName) String() string
- func (ref RefName) TagName() string
- type RefType
- type Reference
- type Repository
- func (repo *Repository) AddObjectToIndex(mode string, object ObjectID, filename string) error
- func (repo *Repository) AddObjectsToIndex(objects ...IndexObjectInfo) error
- func (repo *Repository) AddRemote(name, url string, fetch bool) error
- func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, closeFunc func(), err error)
- func (repo *Repository) Close() error
- func (repo *Repository) CommitTree(author, committer *Signature, tree *Tree, opts CommitTreeOpts) (ObjectID, error)
- func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error)
- func (repo *Repository) CommitsBetweenIDs(last, before string) ([]*Commit, error)
- func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip int) ([]*Commit, error)
- func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error)
- func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error)
- func (repo *Repository) CreateAnnotatedTag(name, message, revision string) error
- func (repo *Repository) CreateTag(name, revision string) error
- func (repo *Repository) EmptyIndex() error
- func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bool, error)
- func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
- func (repo *Repository) GetAnnotatedTag(sha string) (*Tag, error)
- func (repo *Repository) GetBlob(idStr string) (*Blob, error)
- func (repo *Repository) GetBranchCommit(name string) (*Commit, error)
- func (repo *Repository) GetBranchCommitID(name string) (string, error)
- func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error)
- func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) (*CodeActivityStats, error)
- func (repo *Repository) GetCommit(commitID string) (*Commit, error)
- func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error)
- func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)
- func (repo *Repository) GetCommitsFromIDs(commitIDs []string) []*Commit
- func (repo *Repository) GetDiff(compareArg string, w io.Writer) error
- func (repo *Repository) GetDiffBinary(compareArg string, w io.Writer) error
- func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparison bool) (int, error)
- func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error)
- func (repo *Repository) GetHook(name string) (*Hook, error)
- func (repo *Repository) GetObjectFormat() (ObjectFormat, error)
- func (repo *Repository) GetPatch(compareArg string, w io.Writer) error
- func (repo *Repository) GetRefCommitID(name string) (string, error)
- func (repo *Repository) GetRefs() ([]*Reference, error)
- func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error)
- func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, 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) GetTagID(name string) (string, error)
- func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error)
- func (repo *Repository) GetTagNameBySHA(sha string) (string, error)
- func (repo *Repository) GetTagType(id ObjectID) (string, error)
- func (repo *Repository) GetTagWithID(idStr, name string) (*Tag, error)
- func (repo *Repository) GetTree(idStr string) (*Tree, error)
- func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Commit, error)
- func (repo *Repository) HashObjectBytes(buf []byte) (ObjectID, error)
- func (repo *Repository) Hooks() ([]*Hook, error)
- func (repo *Repository) IsBranchExist(name string) bool
- func (repo *Repository) IsCommitInBranch(commitID, branch string) (r bool, err error)
- func (repo *Repository) IsEmpty() (bool, error)
- func (repo *Repository) IsObjectExist(name string) bool
- func (repo *Repository) IsReferenceExist(name string) bool
- func (repo *Repository) IsTagExist(name string) bool
- func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error)
- func (repo *Repository) LsFiles(filenames ...string) ([]string, error)
- func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error)
- func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error)
- func (repo *Repository) ReadTreeToIndex(treeish string, indexFilename ...string) error
- func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (tmpIndexFilename, tmpDir string, cancel context.CancelFunc, err error)
- func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error
- func (repo *Repository) ResolveReference(name string) (string, error)
- func (repo *Repository) ShowPrettyFormatLogToList(ctx context.Context, revisionRange string) ([]*Commit, error)
- func (repo *Repository) UnstableGuessRefByShortName(shortName string) RefName
- func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error)
- func (repo *Repository) WriteTree() (*Tree, error)
- type SearchCommitsOptions
- type Sha1Hash
- type Sha1ObjectFormatImpl
- func (h Sha1ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
- func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID
- func (Sha1ObjectFormatImpl) EmptyTree() ObjectID
- func (Sha1ObjectFormatImpl) FullLength() int
- func (Sha1ObjectFormatImpl) IsValid(input string) bool
- func (Sha1ObjectFormatImpl) MustID(b []byte) ObjectID
- func (Sha1ObjectFormatImpl) Name() string
- type Sha256Hash
- type Sha256ObjectFormatImpl
- func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
- func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID
- func (Sha256ObjectFormatImpl) EmptyTree() ObjectID
- func (Sha256ObjectFormatImpl) FullLength() int
- func (Sha256ObjectFormatImpl) IsValid(input string) bool
- func (Sha256ObjectFormatImpl) MustID(b []byte) ObjectID
- func (Sha256ObjectFormatImpl) Name() string
- type Signature
- type SigningKey
- type SubModule
- type SubmoduleWebLink
- type Tag
- type TemplateSubmoduleCommit
- type Tree
- func (t *Tree) GetBlobByPath(relpath string) (*Blob, error)
- func (t *Tree) GetTreeEntryByPath(relpath string) (_ *TreeEntry, err error)
- func (t *Tree) ListEntries() (Entries, error)
- func (t *Tree) ListEntriesRecursiveFast() (Entries, error)
- func (t *Tree) ListEntriesRecursiveWithSize() (Entries, error)
- func (t *Tree) SubTree(rpath string) (*Tree, error)
- type TreeCommon
- type TreeEntry
- func (te *TreeEntry) Blob() *Blob
- func (te *TreeEntry) GetSubJumpablePathName() string
- func (te *TreeEntry) IsDir() bool
- func (te *TreeEntry) IsExecutable() bool
- func (te *TreeEntry) IsLink() bool
- func (te *TreeEntry) IsRegular() bool
- func (te *TreeEntry) IsSubModule() bool
- func (te *TreeEntry) Mode() EntryMode
- func (te *TreeEntry) Name() string
- func (te *TreeEntry) Size() int64
- func (te *TreeEntry) Tree() *Tree
- func (te *TreeEntry) Type() string
Examples ¶
Constants ¶
const ( CmdVerbUploadPack = "git-upload-pack" CmdVerbUploadArchive = "git-upload-archive" CmdVerbReceivePack = "git-receive-pack" CmdVerbLfsAuthenticate = "git-lfs-authenticate" CmdVerbLfsTransfer = "git-lfs-transfer" CmdSubVerbLfsUpload = "upload" CmdSubVerbLfsDownload = "download" )
const ( SigningKeyFormatOpenPGP = "openpgp" // for GPG keys, the expected default of git cli SigningKeyFormatSSH = "ssh" )
Based on https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
const ( // RemotePrefix is the base directory of the remotes information of git. RemotePrefix = "refs/remotes/" // PullPrefix is the base directory of the pull information of git. PullPrefix = "refs/pull/" )
const BranchPrefix = "refs/heads/"
BranchPrefix base dir of the branch information file store on git
const ForPrefix = "refs/for/"
ForPrefix special ref to create a pull request: refs/for/<target-branch>/<topic-branch> or refs/for/<targe-branch> -o topic='<topic-branch>'
const NotesRef = "refs/notes/commits"
NotesRef is the git ref where Gitea will look for git-notes data. The value ("refs/notes/commits") is the default ref used by git-notes.
const RequiredVersion = "2.6.0" // the minimum Git version required
const TagPrefix = "refs/tags/"
TagPrefix tags prefix path on the repository
Variables ¶
var ErrNotValidHook = errors.New("not a valid Git hook")
ErrNotValidHook error when a git hook is not valid
Functions ¶
func AddTemplateSubmoduleIndexes ¶ added in v1.23.0
func AddTemplateSubmoduleIndexes(ctx context.Context, repoPath string, submodules []TemplateSubmoduleCommit) error
AddTemplateSubmoduleIndexes Adds the given submodules to the git index. It is only for generating new repos based on existing template, requires the .gitmodules file to be already present in the work dir.
func Clone ¶
func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error
Clone clones original repository to target path.
func CutDiffAroundLine ¶ added in v1.12.0
func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLine int) (string, error)
CutDiffAroundLine cuts a diff of a file in way that only the given line + numberOfLine above it will be shown it also recalculates hunks and adds the appropriate headers to the new diff. Warning: Only one-file diffs are allowed.
Example ¶
const diff = `diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # gitea-github-migrator + + Build Status - Latest Release Docker Pulls + cut off + cut off` result, _ := CutDiffAroundLine(strings.NewReader(diff), 4, false, 3) println(result)
func DiscardFull ¶ added in v1.21.6
func DiscardFull(rd BufferedReader, discard int64) error
func GetAffectedFiles ¶ added in v1.16.0
func GetAffectedFiles(repo *Repository, branchName, oldCommitID, newCommitID string, env []string) ([]string, error)
GetAffectedFiles returns the affected files between two commits
func GetFileDiffCutAroundLine ¶ added in v1.26.0
func GetFileDiffCutAroundLine( repo *Repository, startCommit, endCommit, treePath string, line int64, old bool, numbersOfLine int, ) (ret string, retErr error)
GetFileDiffCutAroundLine cuts the old or new part of the diff of a file around a specific line number
func GetFullCommitID ¶
GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
func GetLastCommitForPaths ¶ added in v1.13.0
func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string, paths []string) (map[string]*Commit, error)
GetLastCommitForPaths returns last commit information
func GetNote ¶
GetNote retrieves the git-notes data for a given commit. FIXME: Add LastCommitCache support
func GetRawDiff ¶ added in v1.12.0
func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) (retErr error)
GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
func GetRemoteAddress ¶ added in v1.15.0
GetRemoteAddress returns remote url of git repository in the repoPath with special remote name
func GetSigningKey ¶ added in v1.26.0
func GetSigningKey(ctx context.Context) (*SigningKey, *Signature)
GetSigningKey returns the KeyID and git Signature for the repo
func HashFilePathForWebUI ¶ added in v1.22.0
func InitFull ¶ added in v1.17.4
func InitFull() (err error)
InitFull initializes git module with version check and change global variables, sync gitconfig. It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables.
func InitRepository ¶
InitRepository initializes a new Git repository.
func InitSimple ¶ added in v1.17.0
func InitSimple() error
InitSimple initializes git module with a very simple step, no config changes, no global command arguments. This method doesn't change anything to filesystem. At the moment, it is only used by some Gitea sub-commands.
func IsAllowedVerbForServe ¶ added in v1.24.0
func IsAllowedVerbForServeLfs ¶ added in v1.24.0
func IsEmptyCommitID ¶ added in v1.22.0
func IsErrBranchNotExist ¶
IsErrBranchNotExist checks if an error is a ErrBranchNotExist.
func IsErrInvalidCloneAddr ¶ added in v1.24.0
IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
func IsErrMoreThanOne ¶ added in v1.15.0
IsErrMoreThanOne checks if an error is a ErrMoreThanOne
func IsErrPushOutOfDate ¶ added in v1.12.0
IsErrPushOutOfDate checks if an error is a ErrPushOutOfDate.
func IsErrPushRejected ¶ added in v1.12.0
IsErrPushRejected checks if an error is a ErrPushRejected.
func IsRemoteNotExistError ¶ added in v1.23.0
IsRemoteNotExistError checks the prefix of the error message to see whether a remote does not exist.
func IsRepoURLAccessible ¶
IsRepoURLAccessible checks if given repository URL is accessible.
func IsStringLikelyCommitID ¶ added in v1.23.0
func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool
func IsValidHookName ¶
IsValidHookName returns true if given name is a valid Git hook.
func IsValidObjectFormat ¶ added in v1.22.0
func IsValidRefPattern ¶ added in v1.17.2
IsValidRefPattern ensures that the provided string could be a valid reference
func LogNameStatusRepo ¶ added in v1.15.0
func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, paths ...string) (*bufio.Reader, func())
LogNameStatusRepo opens git log --raw in the provided repo and returns a stdin pipe, a stdout reader and cancel function
func ParseBool ¶ added in v1.11.0
ParseBool returns the boolean value represented by the string as per git's git_config_bool true will be returned for the result if the string is empty, but valid will be false. "true", "yes", "on" are all true, true "false", "no", "off" are all false, true 0 is false, true Any other integer is true, true Anything else will return false, false
func ParseCatFileTreeLine ¶ added in v1.23.0
func ParseCatFileTreeLine(objectFormat ObjectFormat, rd BufferedReader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error)
ParseCatFileTreeLine reads an entry from a tree in a cat-file --batch stream This carefully avoids allocations - except where fnameBuf is too small. It is recommended therefore to pass in an fnameBuf large enough to avoid almost all allocations
Each line is composed of: <mode-in-ascii-dropping-initial-zeros> SP <fname> NUL <binary HASH>
We don't attempt to convert the raw HASH to save a lot of time
func ParseDiffHunkString ¶ added in v1.12.0
ParseDiffHunkString parse the diff hunk content and return
func ParseRefSuffix ¶ added in v1.26.0
func ParseRemoteAddr ¶ added in v1.24.0
ParseRemoteAddr checks if given remote address is valid, and returns composed URL with needed username and password.
func Push ¶
func Push(ctx context.Context, repoPath string, opts PushOptions) error
Push pushs local commits to given remote branch.
func ReadTagObjectID ¶ added in v1.14.0
func ReadTagObjectID(rd BufferedReader, size int64) (string, error)
ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream.
func ReadTreeID ¶ added in v1.14.0
func ReadTreeID(rd BufferedReader, size int64) (string, error)
ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
func RunGitTests ¶ added in v1.26.0
func RunGitTests(m interface{ Run() int })
RunGitTests helps to init the git module and run tests. FIXME: GIT-PACKAGE-DEPENDENCY: the dependency is not right, setting.Git.HomePath is initialized in this package but used in gitcmd package
func SanitizeRefPattern ¶ added in v1.17.2
func SplitCommitTitleBody ¶ added in v1.24.4
func WalkGitLog ¶ added in v1.15.0
func WalkGitLog(ctx context.Context, repo *Repository, head *Commit, treepath string, paths ...string) (map[string]string, error)
WalkGitLog walks the git log --name-status for the head commit in the provided treepath and files
func WalkShowRef ¶ added in v1.22.0
Types ¶
type Blob ¶
type Blob struct {
ID ObjectID
// contains filtered or unexported fields
}
Blob represents a Git object.
func (*Blob) DataAsync ¶
func (b *Blob) DataAsync() (_ io.ReadCloser, retErr error)
DataAsync gets a ReadCloser for the contents of a blob without reading it all. Calling the Close function on the result will discard all unread output.
func (*Blob) GetBlobBytes ¶ added in v1.25.0
GetBlobBytes Gets the limited content of the blob
func (*Blob) GetBlobContent ¶
GetBlobContent Gets the limited content of the blob as raw text
func (*Blob) GetBlobContentBase64 ¶
GetBlobContentBase64 Reads the content of the blob with a base64 encoding and returns the encoded string
func (*Blob) GetBlobLineCount ¶ added in v1.11.0
GetBlobLineCount gets line count of the blob. It will also try to write the content to w if it's not nil, then we could pre-fetch the content without reading it again.
func (*Blob) GuessContentType ¶ added in v1.15.0
func (b *Blob) GuessContentType() (typesniffer.SniffedType, error)
GuessContentType guesses the content type of the blob.
type BufferedReader ¶ added in v1.26.0
type CatFileBatch ¶ added in v1.14.0
type CatFileBatch interface {
// QueryInfo queries the object info from the git repository by its object name using "git cat-file --batch" family commands.
// "git cat-file" accepts "<rev>" for the object name, it can be a ref name, object id, etc. https://git-scm.com/docs/gitrevisions
// In Gitea, we only use the simple ref name or object id, no other complex rev syntax like "suffix" or "git describe" although they are supported by git.
QueryInfo(obj string) (*CatFileObject, error)
// QueryContent is similar to QueryInfo, it queries the object info and additionally returns a reader for its content.
// FIXME: this design still follows the old pattern: the returned BufferedReader is very fragile,
// callers should carefully maintain its lifecycle and discard all unread data.
// TODO: It needs to be refactored to a fully managed Reader stream in the future, don't let callers manually Close or Discard
QueryContent(obj string) (*CatFileObject, BufferedReader, error)
}
type CatFileBatchCloser ¶ added in v1.26.0
type CatFileBatchCloser interface {
CatFileBatch
Close()
}
func NewBatch ¶ added in v1.24.0
func NewBatch(ctx context.Context, repoPath string) (CatFileBatchCloser, error)
NewBatch creates a "batch object provider (CatFileBatch)" for the given repository path to retrieve object info and content efficiently. The CatFileBatch and the readers create by it should only be used in the same goroutine.
type CatFileObject ¶ added in v1.26.0
type CloneRepoOptions ¶
type CloneRepoOptions struct {
Timeout time.Duration
Mirror bool
Bare bool
Quiet bool
Branch string
NoCheckout bool
Depth int
Filter string
SkipTLSVerify bool
SingleBranch bool
Env []string
}
CloneRepoOptions options when clone a repository
type CodeActivityAuthor ¶ added in v1.12.0
CodeActivityAuthor represents git statistics data for commit authors
type CodeActivityStats ¶
type CodeActivityStats struct {
AuthorCount int64
CommitCount int64
ChangedFiles int64
Additions int64
Deletions int64
CommitCountInAllBranches int64
Authors []*CodeActivityAuthor
}
CodeActivityStats represents git statistics data
type Commit ¶
type Commit struct {
Tree // FIXME: bad design, this field can be nil if the commit is from "last commit cache"
ID ObjectID
Author *Signature // never nil
Committer *Signature // never nil
CommitMessage string
Signature *CommitSignature
Parents []ObjectID // ID strings
// contains filtered or unexported fields
}
Commit represents a git commit.
func CommitFromReader ¶ added in v1.12.0
CommitFromReader will generate a Commit from a provided reader We need this to interpret commits from cat-file or cat-file --batch
If used as part of a cat-file --batch stream you need to limit the reader to the correct size
func (*Commit) CacheCommit ¶ added in v1.17.4
CacheCommit will cache the commit from the gitRepository
func (*Commit) CommitsBefore ¶
CommitsBefore returns all the commits before current revision
func (*Commit) CommitsBeforeLimit ¶
CommitsBeforeLimit returns num commits before current revision
func (*Commit) CommitsBeforeUntil ¶
CommitsBeforeUntil returns the commits between commitID to current revision
func (*Commit) CommitsByRange ¶
CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
func (*Commit) FileChangedSinceCommit ¶
FileChangedSinceCommit Returns true if the file given has changed since the past commit YOU MUST ENSURE THAT pastCommit is a valid commit ID.
func (*Commit) GetCommitByPath ¶
GetCommitByPath return the commit of relative path object.
func (*Commit) GetFileContent ¶ added in v1.17.0
GetFileContent reads a file content as a string or returns false if this was not possible
func (*Commit) GetFilesChangedSinceCommit ¶
GetFilesChangedSinceCommit get all changed file names between pastCommit to current revision
func (*Commit) GetSubModule ¶
GetSubModule gets the submodule by the entry name. It returns "nil, nil" if the submodule does not exist, caller should always remember to check the "nil"
func (*Commit) GetSubModules ¶
func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error)
GetSubModules get all the submodules of current revision git tree
func (*Commit) HasFile ¶ added in v1.10.0
HasFile returns true if the file given exists on this commit This does only mean it's there - it does not mean the file was changed during the commit.
func (*Commit) HasPreviousCommit ¶ added in v1.11.0
HasPreviousCommit returns true if a given commitHash is contained in commit's parents
func (*Commit) IsForcePush ¶ added in v1.20.0
IsForcePush returns true if a push from oldCommitHash to this is a force push
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.
func (*Commit) ParentID ¶
ParentID returns oid of n-th parent (0-based index). It returns nil if no such parent exists.
func (*Commit) SearchCommits ¶
func (c *Commit) SearchCommits(opts SearchCommitsOptions) ([]*Commit, error)
SearchCommits returns the commits match the keyword before current revision
type CommitInfo ¶ added in v1.14.0
type CommitInfo struct {
Entry *TreeEntry
Commit *Commit
SubmoduleFile *CommitSubmoduleFile
}
CommitInfo describes the first commit with the provided entry
type CommitSignature ¶ added in v1.22.0
CommitSignature represents a git commit signature part.
type CommitSubmoduleFile ¶ added in v1.24.0
type CommitSubmoduleFile struct {
// contains filtered or unexported fields
}
CommitSubmoduleFile represents a file with submodule type.
func GetCommitInfoSubmoduleFile ¶ added in v1.24.4
func GetCommitInfoSubmoduleFile(repoLink, fullPath string, commit *Commit, refCommitID ObjectID) (*CommitSubmoduleFile, error)
func NewCommitSubmoduleFile ¶ added in v1.24.0
func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSubmoduleFile
NewCommitSubmoduleFile create a new submodule file
func (*CommitSubmoduleFile) RefID ¶ added in v1.24.0
func (sf *CommitSubmoduleFile) RefID() string
RefID returns the commit ID of the submodule, it returns empty string for nil receiver
func (*CommitSubmoduleFile) SubmoduleWebLinkCompare ¶ added in v1.24.3
func (sf *CommitSubmoduleFile) SubmoduleWebLinkCompare(ctx context.Context, commitID1, commitID2 string) *SubmoduleWebLink
SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver It returns nil if the submodule does not have a valid URL or is nil
func (*CommitSubmoduleFile) SubmoduleWebLinkTree ¶ added in v1.24.3
func (sf *CommitSubmoduleFile) SubmoduleWebLinkTree(ctx context.Context, optCommitID ...string) *SubmoduleWebLink
SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver It returns nil if the submodule does not have a valid URL or is nil
type CommitTreeOpts ¶
type CommitTreeOpts struct {
Parents []string
Message string
Key *SigningKey
NoGPGSign bool
AlwaysSign bool
}
CommitTreeOpts represents the possible options to CommitTree
type CommitsByFileAndRangeOptions ¶ added in v1.20.0
type Entries ¶
type Entries []*TreeEntry
Entries a list of entry
func (Entries) CustomSort ¶
CustomSort customizable string comparing sort entry list
type EntryFollowResult ¶ added in v1.25.0
type EntryFollowResult struct {
SymlinkContent string
TargetFullPath string
TargetEntry *TreeEntry
}
func EntryFollowLink ¶ added in v1.25.0
func EntryFollowLink(commit *Commit, fullPath string, te *TreeEntry) (*EntryFollowResult, error)
func EntryFollowLinks ¶ added in v1.25.0
type EntryMode ¶
type EntryMode int
EntryMode the type of the object in the git tree
const ( // EntryModeNoEntry is possible if the file was added or removed in a commit. In the case of // when adding the base commit doesn't have the file in its tree, a mode of 0o000000 is used. EntryModeNoEntry EntryMode = 0o000000 EntryModeBlob EntryMode = 0o100644 EntryModeExec EntryMode = 0o100755 EntryModeSymlink EntryMode = 0o120000 EntryModeCommit EntryMode = 0o160000 EntryModeTree EntryMode = 0o040000 )
There are only a few file modes in Git. They look like unix file modes, but they can only be one of these.
func ParseEntryMode ¶ added in v1.24.0
func (EntryMode) IsExecutable ¶ added in v1.24.3
IsExecutable if the entry is an executable file (not necessarily binary)
func (EntryMode) IsSubModule ¶ added in v1.24.3
IsSubModule if the entry is a submodule
type ErrBranchNotExist ¶
type ErrBranchNotExist struct {
Name string
}
ErrBranchNotExist represents a "BranchNotExist" kind of error.
func (ErrBranchNotExist) Error ¶
func (err ErrBranchNotExist) Error() string
func (ErrBranchNotExist) Unwrap ¶ added in v1.17.4
func (err ErrBranchNotExist) Unwrap() error
type ErrInvalidCloneAddr ¶ added in v1.24.0
type ErrInvalidCloneAddr struct {
Host string
IsURLError bool
IsInvalidPath bool
IsProtocolInvalid bool
IsPermissionDenied bool
LocalPath bool
}
ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
func (*ErrInvalidCloneAddr) Error ¶ added in v1.24.0
func (err *ErrInvalidCloneAddr) Error() string
func (*ErrInvalidCloneAddr) Unwrap ¶ added in v1.24.0
func (err *ErrInvalidCloneAddr) Unwrap() error
type ErrInvalidSHA ¶ added in v1.20.0
type ErrInvalidSHA struct {
SHA string
}
func (ErrInvalidSHA) Error ¶ added in v1.20.0
func (err ErrInvalidSHA) Error() string
type ErrMoreThanOne ¶ added in v1.15.0
ErrMoreThanOne represents an error if pull request fails when there are more than one sources (branch, tag) with the same name
func (*ErrMoreThanOne) Error ¶ added in v1.15.0
func (err *ErrMoreThanOne) Error() string
type ErrNotExist ¶
ErrNotExist commit not exist error
func (ErrNotExist) Error ¶
func (err ErrNotExist) Error() string
func (ErrNotExist) Unwrap ¶ added in v1.17.4
func (err ErrNotExist) Unwrap() error
type ErrPushOutOfDate ¶ added in v1.12.0
ErrPushOutOfDate represents an error if merging fails due to the base branch being updated
func (*ErrPushOutOfDate) Error ¶ added in v1.12.0
func (err *ErrPushOutOfDate) Error() string
func (*ErrPushOutOfDate) Unwrap ¶ added in v1.12.0
func (err *ErrPushOutOfDate) Unwrap() error
Unwrap unwraps the underlying error
type ErrPushRejected ¶ added in v1.12.0
ErrPushRejected represents an error if merging fails due to rejection from a hook
func (*ErrPushRejected) Error ¶ added in v1.12.0
func (err *ErrPushRejected) Error() string
func (*ErrPushRejected) GenerateMessage ¶ added in v1.12.0
func (err *ErrPushRejected) GenerateMessage()
GenerateMessage generates the remote message from the stderr
func (*ErrPushRejected) Unwrap ¶ added in v1.12.0
func (err *ErrPushRejected) Unwrap() error
Unwrap unwraps the underlying error
type Features ¶ added in v1.22.0
type Features struct {
UsingGogit bool
SupportProcReceive bool // >= 2.29
SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’
SupportedObjectFormats []ObjectFormat // sha1, sha256
SupportCheckAttrOnBare bool // >= 2.40
SupportCatFileBatchCommand bool // >= 2.36, support `git cat-file --batch-command`
SupportGitMergeTree bool // >= 2.40 // we also need "--merge-base"
// contains filtered or unexported fields
}
func DefaultFeatures ¶ added in v1.22.0
func DefaultFeatures() *Features
func (*Features) CheckVersionAtLeast ¶ added in v1.22.0
func (*Features) VersionInfo ¶ added in v1.22.0
VersionInfo returns git version information
type GPGSettings ¶ added in v1.11.0
type GPGSettings struct {
Sign bool
KeyID string
Email string
Name string
PublicKeyContent string
Format string
}
GPGSettings represents the default GPG settings for this repository
func GetDefaultPublicGPGKey ¶ added in v1.26.0
func GetDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error)
GetDefaultPublicGPGKey will return and cache the default public GPG settings
func (*GPGSettings) LoadPublicKeyContent ¶ added in v1.11.0
func (gpgSettings *GPGSettings) LoadPublicKeyContent() error
LoadPublicKeyContent will load the key from gpg
type GrepModeType ¶ added in v1.24.0
type GrepModeType string
const ( GrepModeExact GrepModeType = "exact" GrepModeWords GrepModeType = "words" GrepModeRegexp GrepModeType = "regexp" )
type GrepOptions ¶ added in v1.22.0
type GrepResult ¶ added in v1.22.0
func GrepSearch ¶ added in v1.22.0
func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepOptions) ([]*GrepResult, error)
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 IndexObjectInfo ¶ added in v1.22.2
type LastCommitCache ¶
type LastCommitCache struct {
// contains filtered or unexported fields
}
LastCommitCache represents a cache to store last commit
func NewLastCommitCache ¶ added in v1.14.0
func NewLastCommitCache(count int64, repoPath string, gitRepo *Repository, cache cache.StringCache) *LastCommitCache
NewLastCommitCache creates a new last commit cache for repo
func (*LastCommitCache) Get ¶
func (c *LastCommitCache) Get(ref, entryPath string) (*Commit, error)
Get gets the last commit information by commit id and entry path
func (*LastCommitCache) GetCommitByPath ¶ added in v1.17.4
func (c *LastCommitCache) GetCommitByPath(commitID, entryPath string) (*Commit, error)
GetCommitByPath gets the last commit for the entry in the provided commit
func (*LastCommitCache) Put ¶
func (c *LastCommitCache) Put(ref, entryPath, commitID string) error
Put put the last commit id with commit and entry path
type LogNameStatusCommitData ¶ added in v1.15.0
LogNameStatusCommitData represents a commit artefact from git log raw
type LogNameStatusRepoParser ¶ added in v1.15.0
type LogNameStatusRepoParser struct {
// contains filtered or unexported fields
}
LogNameStatusRepoParser parses a git log raw output from LogRawRepo
func NewLogNameStatusRepoParser ¶ added in v1.15.0
func NewLogNameStatusRepoParser(ctx context.Context, repository, head, treepath string, paths ...string) *LogNameStatusRepoParser
NewLogNameStatusRepoParser returns a new parser for a git log raw output
func (*LogNameStatusRepoParser) Close ¶ added in v1.15.0
func (g *LogNameStatusRepoParser) Close()
Close closes the parser
func (*LogNameStatusRepoParser) Next ¶ added in v1.15.0
func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int, changed []bool, maxpathlen int) (*LogNameStatusCommitData, error)
Next returns the next LogStatusCommitData
type LsTreeEntry ¶ added in v1.23.0
type ObjectCache ¶
type ObjectCache[T any] struct { // contains filtered or unexported fields }
ObjectCache provides thread-safe cache operations.
func (*ObjectCache[T]) Get ¶
func (oc *ObjectCache[T]) Get(id string) (T, bool)
Get gets cached obj by id
type ObjectFormat ¶ added in v1.22.0
type ObjectFormat interface {
// Name returns the name of the object format
Name() string
// EmptyObjectID creates a new empty ObjectID from an object format hash name
EmptyObjectID() ObjectID
// EmptyTree is the hash of an empty tree
EmptyTree() ObjectID
// FullLength is the length of the hash's hex string
FullLength() int
// IsValid returns true if the input is a valid hash
IsValid(input string) bool
// MustID creates a new ObjectID from a byte slice
MustID(b []byte) ObjectID
// ComputeHash compute the hash for a given ObjectType and content
ComputeHash(t ObjectType, content []byte) ObjectID
}
var ( Sha1ObjectFormat ObjectFormat = Sha1ObjectFormatImpl{} Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{} )
func ObjectFormatFromName ¶ added in v1.22.0
func ObjectFormatFromName(name string) ObjectFormat
type ObjectID ¶ added in v1.22.0
type ObjectID interface {
String() string
IsZero() bool
RawValue() []byte
Type() ObjectFormat
}
func ComputeBlobHash ¶ added in v1.14.0
func ComputeBlobHash(hashType ObjectFormat, content []byte) ObjectID
ComputeBlobHash compute the hash for a given blob content
func MustIDFromString ¶
func NewIDFromString ¶
type ObjectType ¶
type ObjectType string
ObjectType git object type
const ( // ObjectCommit commit object type ObjectCommit ObjectType = "commit" // ObjectTree tree object type ObjectTree ObjectType = "tree" // ObjectBlob blob object type ObjectBlob ObjectType = "blob" // ObjectTag tag object type ObjectTag ObjectType = "tag" // ObjectBranch branch object type ObjectBranch ObjectType = "branch" )
func (ObjectType) Bytes ¶ added in v1.14.0
func (o ObjectType) Bytes() []byte
Bytes returns the byte array for the Object Type
type PushOptions ¶
type PushOptions struct {
Remote string
LocalRefName string
Branch string
Force bool
ForceWithLease string
Mirror bool
Env []string
Timeout time.Duration
}
PushOptions options when push to remote
type RawDiffType ¶ added in v1.12.0
type RawDiffType string
RawDiffType output format: diff or patch
const ( RawDiffNormal RawDiffType = "diff" RawDiffPatch RawDiffType = "patch" )
type RefName ¶ added in v1.17.4
type RefName string
RefName represents a full git reference name
func RefNameFromBranch ¶ added in v1.20.0
func RefNameFromCommit ¶ added in v1.24.0
func RefNameFromTag ¶ added in v1.20.0
func (RefName) BranchName ¶ added in v1.20.0
BranchName returns simple branch name if it's an operation to branch
func (RefName) ForBranchName ¶ added in v1.20.0
ForBranchName returns the branch name part of refs like refs/for/<branch_name>
func (RefName) PullName ¶ added in v1.20.0
PullName returns the pull request name part of refs like refs/pull/<pull_name>/head
func (RefName) RefGroup ¶ added in v1.17.4
RefGroup returns the group type of the reference Using the name of the directory under .git/refs
func (RefName) RefType ¶ added in v1.20.0
RefType returns the simple ref type of the reference, e.g. branch, tag It's different from RefGroup, which is using the name of the directory under .git/refs
func (RefName) RefWebLinkPath ¶ added in v1.24.0
RefWebLinkPath returns a path for the reference that can be used in a web link: * "branch/<branch_name>" * "tag/<tag_name>" * "commit/<commit_id>" It returns an empty string if the reference is not a branch, tag or commit.
func (RefName) RemoteName ¶ added in v1.20.0
type RefType ¶ added in v1.24.0
type RefType string
RefType is a simple ref type of the reference, it is used for UI and webhooks
type Reference ¶
type Reference struct {
Name string
Object ObjectID // The id of this commit object
Type string
// contains filtered or unexported fields
}
Reference represents a Git ref.
type Repository ¶
type Repository struct {
Path string
Ctx context.Context
LastCommitCache *LastCommitCache
// contains filtered or unexported fields
}
Repository represents a Git repository.
func OpenRepository ¶
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error)
OpenRepository opens the repository at the given path with the provided context.
func (*Repository) AddObjectToIndex ¶
func (repo *Repository) AddObjectToIndex(mode string, object ObjectID, filename string) error
AddObjectToIndex adds the provided object hash to the index at the provided filename
func (*Repository) AddObjectsToIndex ¶ added in v1.22.2
func (repo *Repository) AddObjectsToIndex(objects ...IndexObjectInfo) error
AddObjectsToIndex adds the provided object hashes to the index at the provided filenames
func (*Repository) AddRemote ¶
func (repo *Repository) AddRemote(name, url string, fetch bool) error
AddRemote adds a new remote to repository.
func (*Repository) CatFileBatch ¶ added in v1.15.0
func (repo *Repository) CatFileBatch(ctx context.Context) (_ CatFileBatch, closeFunc func(), err error)
CatFileBatch obtains a "batch object provider" for this repository. It reuses an existing one if available, otherwise creates a new one.
func (*Repository) Close ¶ added in v1.9.6
func (repo *Repository) Close() error
func (*Repository) CommitTree ¶
func (repo *Repository) CommitTree(author, committer *Signature, tree *Tree, opts CommitTreeOpts) (ObjectID, error)
CommitTree creates a commit from a given tree id for the user with provided message
func (*Repository) CommitsBetween ¶
func (repo *Repository) CommitsBetween(last, before *Commit) ([]*Commit, error)
CommitsBetween returns a list that contains commits between [before, last). If before is detached (removed by reset + push) it is not included.
func (*Repository) CommitsBetweenIDs ¶
func (repo *Repository) CommitsBetweenIDs(last, before string) ([]*Commit, error)
CommitsBetweenIDs return commits between twoe commits
func (*Repository) CommitsBetweenLimit ¶ added in v1.11.0
func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip int) ([]*Commit, error)
CommitsBetweenLimit returns a list that contains at most limit commits skipping the first skip commits between [before, last)
func (*Repository) CommitsByFileAndRange ¶
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error)
CommitsByFileAndRange return the commits according revision file and the page
func (*Repository) ConvertToGitID ¶ added in v1.22.0
func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error)
ConvertToGitID returns a GitHash object from a potential ID string
func (*Repository) CreateAnnotatedTag ¶
func (repo *Repository) CreateAnnotatedTag(name, message, revision string) error
CreateAnnotatedTag create one annotated tag in the repository
func (*Repository) CreateTag ¶
func (repo *Repository) CreateTag(name, revision string) error
CreateTag create one tag in the repository
func (*Repository) EmptyIndex ¶
func (repo *Repository) EmptyIndex() error
EmptyIndex empties the index
func (*Repository) FileChangedBetweenCommits ¶
func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bool, error)
FileChangedBetweenCommits Returns true if the file changed between commit IDs id1 and id2 You must ensure that id1 and id2 are valid commit ids.
func (*Repository) FilesCountBetween ¶
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
FilesCountBetween return the number of files changed between two commits
func (*Repository) GetAnnotatedTag ¶
func (repo *Repository) GetAnnotatedTag(sha string) (*Tag, error)
GetAnnotatedTag returns a Git tag by its SHA, must be an annotated tag
func (*Repository) GetBlob ¶
func (repo *Repository) GetBlob(idStr string) (*Blob, error)
GetBlob finds the blob object in the repository.
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) GetBranchNames ¶ added in v1.16.0
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error)
GetBranchNames returns branches from the repository, skipping "skip" initial branches and returning at most "limit" branches, or all branches if "limit" is 0.
func (*Repository) GetCodeActivityStats ¶
func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) (*CodeActivityStats, error)
GetCodeActivityStats returns code statistics for activity page
func (*Repository) GetCommit ¶
func (repo *Repository) GetCommit(commitID string) (*Commit, error)
GetCommit returns commit object of by ID string.
func (*Repository) GetCommitBranchStart ¶ added in v1.22.2
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error)
GetCommitBranchStart returns the commit where the branch diverged
func (*Repository) GetCommitByPath ¶
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)
GetCommitByPath returns the last commit of relative path.
func (*Repository) GetCommitsFromIDs ¶ added in v1.13.0
func (repo *Repository) GetCommitsFromIDs(commitIDs []string) []*Commit
GetCommitsFromIDs get commits from commit IDs
func (*Repository) GetDiff ¶ added in v1.11.0
func (repo *Repository) GetDiff(compareArg string, w io.Writer) error
GetDiff generates and returns patch data between given revisions, optimized for human readability
func (*Repository) GetDiffBinary ¶ added in v1.16.0
func (repo *Repository) GetDiffBinary(compareArg string, w io.Writer) error
GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
func (*Repository) GetDiffNumChangedFiles ¶ added in v1.13.0
func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparison bool) (int, error)
GetDiffNumChangedFiles counts the number of changed files This is substantially quicker than shortstat but...
func (*Repository) GetFilesChangedBetween ¶ added in v1.17.0
func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error)
GetFilesChangedBetween returns a list of all files that have been changed between the given commits If base is undefined empty SHA (zeros), it only returns the files changed in the head commit If base is the SHA of an empty tree (EmptyTreeSHA), it returns the files changes from the initial commit to the head commit
func (*Repository) GetHook ¶
func (repo *Repository) GetHook(name string) (*Hook, error)
GetHook get one hook according the name on a repository
func (*Repository) GetObjectFormat ¶ added in v1.22.0
func (repo *Repository) GetObjectFormat() (ObjectFormat, error)
func (*Repository) GetPatch ¶
func (repo *Repository) GetPatch(compareArg string, w io.Writer) error
GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
func (*Repository) GetRefCommitID ¶
func (repo *Repository) GetRefCommitID(name string) (string, error)
GetRefCommitID returns the last commit ID string of given reference (branch or tag).
func (*Repository) GetRefs ¶
func (repo *Repository) GetRefs() ([]*Reference, error)
GetRefs returns all references of the repository.
func (*Repository) GetRefsBySha ¶ added in v1.17.0
func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error)
GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash
func (*Repository) GetRefsFiltered ¶
func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error)
GetRefsFiltered returns all references of the repository that matches patterm exactly or starting with.
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 get the commit of the specific tag via name
func (*Repository) GetTagCommitID ¶
func (repo *Repository) GetTagCommitID(name string) (string, error)
GetTagCommitID returns last commit ID string of given tag.
func (*Repository) GetTagID ¶
func (repo *Repository) GetTagID(name string) (string, error)
GetTagID returns the object ID for a tag (annotated tags have both an object SHA AND a commit SHA)
func (*Repository) GetTagInfos ¶
func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, int, error)
GetTagInfos returns all tag infos of the repository.
func (*Repository) GetTagNameBySHA ¶
func (repo *Repository) GetTagNameBySHA(sha string) (string, error)
GetTagNameBySHA returns the name of a tag from its tag object SHA or commit SHA
func (*Repository) GetTagType ¶
func (repo *Repository) GetTagType(id ObjectID) (string, error)
GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
func (*Repository) GetTagWithID ¶ added in v1.16.6
func (repo *Repository) GetTagWithID(idStr, name string) (*Tag, error)
GetTagWithID returns a Git tag by given name and ID
func (*Repository) GetTree ¶
func (repo *Repository) GetTree(idStr string) (*Tree, error)
GetTree find the tree object in the repository.
func (*Repository) GetTreePathLatestCommit ¶ added in v1.23.0
func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Commit, error)
GetTreePathLatestCommit returns the latest commit of a tree path
func (*Repository) HashObjectBytes ¶ added in v1.26.0
func (repo *Repository) HashObjectBytes(buf []byte) (ObjectID, error)
HashObjectBytes returns hash for the content
func (*Repository) Hooks ¶
func (repo *Repository) Hooks() ([]*Hook, error)
Hooks get all the hooks on the repository
func (*Repository) IsBranchExist ¶
func (repo *Repository) IsBranchExist(name string) bool
IsBranchExist returns true if given branch exists in current repository.
func (*Repository) IsCommitInBranch ¶ added in v1.14.0
func (repo *Repository) IsCommitInBranch(commitID, branch string) (r bool, err error)
IsCommitInBranch check if the commit is on the branch
func (*Repository) IsEmpty ¶
func (repo *Repository) IsEmpty() (bool, error)
IsEmpty Check if repository is empty.
func (*Repository) IsObjectExist ¶ added in v1.15.0
func (repo *Repository) IsObjectExist(name string) bool
IsObjectExist returns true if the given object exists in the repository. FIXME: this function doesn't seem right, it is only used by GarbageCollectLFSMetaObjectsForRepo
func (*Repository) IsReferenceExist ¶ added in v1.15.0
func (repo *Repository) IsReferenceExist(name string) bool
IsReferenceExist returns true if given reference exists in the repository.
func (*Repository) IsTagExist ¶
func (repo *Repository) IsTagExist(name string) bool
IsTagExist returns true if given tag exists in the repository.
func (*Repository) ListOccurrences ¶ added in v1.21.0
func (repo *Repository) ListOccurrences(ctx context.Context, refType, commitSHA string) ([]string, error)
ListOccurrences lists all refs of the given refType the given commit appears in sorted by creation date DESC refType should only be a literal "branch" or "tag" and nothing else
func (*Repository) LsFiles ¶
func (repo *Repository) LsFiles(filenames ...string) ([]string, error)
LsFiles checks if the given filenames are in the index
func (*Repository) LsTree ¶ added in v1.15.0
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error)
LsTree checks if the given filenames are in the tree
func (*Repository) ReadPatchCommit ¶ added in v1.16.0
func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error)
ReadPatchCommit will check if a diff patch exists and return stats
func (*Repository) ReadTreeToIndex ¶
func (repo *Repository) ReadTreeToIndex(treeish string, indexFilename ...string) error
ReadTreeToIndex reads a treeish to the index
func (*Repository) ReadTreeToTemporaryIndex ¶ added in v1.16.0
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (tmpIndexFilename, tmpDir string, cancel context.CancelFunc, err error)
ReadTreeToTemporaryIndex reads a treeish to a temporary index file
func (*Repository) RemoveFilesFromIndex ¶
func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error
RemoveFilesFromIndex removes given filenames from the index - it does not check whether they are present.
func (*Repository) ResolveReference ¶ added in v1.14.0
func (repo *Repository) ResolveReference(name string) (string, error)
ResolveReference resolves a name to a reference
func (*Repository) ShowPrettyFormatLogToList ¶ added in v1.25.0
func (*Repository) UnstableGuessRefByShortName ¶ added in v1.23.0
func (repo *Repository) UnstableGuessRefByShortName(shortName string) RefName
UnstableGuessRefByShortName does the best guess to see whether a "short name" provided by user is a branch, tag or commit. It could guess wrongly if the input is already ambiguous. For example: * "refs/heads/the-name" vs "refs/heads/refs/heads/the-name" * "refs/tags/1234567890" vs commit "1234567890" In most cases, it SHOULD AVOID using this function, unless there is an irresistible reason (eg: make API friendly to end users) If the function is used, the caller SHOULD CHECK the ref type carefully.
func (*Repository) WalkReferences ¶ added in v1.16.6
func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error)
WalkReferences walks all the references from the repository refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty.
func (*Repository) WriteTree ¶
func (repo *Repository) WriteTree() (*Tree, error)
WriteTree writes the current index as a tree to the object db and returns its hash
type SearchCommitsOptions ¶
type SearchCommitsOptions struct {
Keywords []string
Authors, Committers []string
After, Before string
All bool
}
SearchCommitsOptions specify the parameters for SearchCommits
func NewSearchCommitsOptions ¶
func NewSearchCommitsOptions(searchString string, forAllRefs bool) SearchCommitsOptions
NewSearchCommitsOptions construct a SearchCommitsOption from a space-delimited search string
type Sha1Hash ¶ added in v1.22.0
type Sha1Hash [20]byte
func (*Sha1Hash) Type ¶ added in v1.22.0
func (*Sha1Hash) Type() ObjectFormat
type Sha1ObjectFormatImpl ¶ added in v1.22.0
type Sha1ObjectFormatImpl struct{}
func (Sha1ObjectFormatImpl) ComputeHash ¶ added in v1.22.0
func (h Sha1ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
ComputeHash compute the hash for a given ObjectType and content
func (Sha1ObjectFormatImpl) EmptyObjectID ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID
func (Sha1ObjectFormatImpl) EmptyTree ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) EmptyTree() ObjectID
func (Sha1ObjectFormatImpl) FullLength ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) FullLength() int
func (Sha1ObjectFormatImpl) IsValid ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) IsValid(input string) bool
func (Sha1ObjectFormatImpl) MustID ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) MustID(b []byte) ObjectID
func (Sha1ObjectFormatImpl) Name ¶ added in v1.22.0
func (Sha1ObjectFormatImpl) Name() string
type Sha256Hash ¶ added in v1.22.0
type Sha256Hash [32]byte
func (*Sha256Hash) IsZero ¶ added in v1.22.0
func (h *Sha256Hash) IsZero() bool
func (*Sha256Hash) RawValue ¶ added in v1.22.0
func (h *Sha256Hash) RawValue() []byte
func (*Sha256Hash) String ¶ added in v1.22.0
func (h *Sha256Hash) String() string
func (*Sha256Hash) Type ¶ added in v1.22.0
func (*Sha256Hash) Type() ObjectFormat
type Sha256ObjectFormatImpl ¶ added in v1.22.0
type Sha256ObjectFormatImpl struct{}
func (Sha256ObjectFormatImpl) ComputeHash ¶ added in v1.22.0
func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
ComputeHash compute the hash for a given ObjectType and content
func (Sha256ObjectFormatImpl) EmptyObjectID ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID
func (Sha256ObjectFormatImpl) EmptyTree ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) EmptyTree() ObjectID
func (Sha256ObjectFormatImpl) FullLength ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) FullLength() int
func (Sha256ObjectFormatImpl) IsValid ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) IsValid(input string) bool
func (Sha256ObjectFormatImpl) MustID ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) MustID(b []byte) ObjectID
func (Sha256ObjectFormatImpl) Name ¶ added in v1.22.0
func (Sha256ObjectFormatImpl) Name() string
type Signature ¶
type Signature struct {
Name string // the committer name, it can be anything
Email string // the committer email, it can be anything
When time.Time // the timestamp of the signature
}
Signature represents the Author, Committer or Tagger information.
type SigningKey ¶ added in v1.25.0
SigningKey represents an instance key info which will be used to sign git commits. FIXME: need to refactor it to a new name, this name conflicts with the variable names for "asymkey.GPGKey" in many places.
func (*SigningKey) String ¶ added in v1.25.0
func (s *SigningKey) String() string
type SubModule ¶
type SubModule struct {
Path string
URL string
Branch string // this field is newly added but not really used
}
SubModule is a reference on git repository
type SubmoduleWebLink ¶ added in v1.24.0
type SubmoduleWebLink struct {
RepoWebLink, CommitWebLink string
}
type Tag ¶
type Tag struct {
Name string
ID ObjectID
Object ObjectID // The id of this commit object
Type string
Tagger *Signature
Message string
Signature *CommitSignature
}
Tag represents a Git tag.
type TemplateSubmoduleCommit ¶ added in v1.23.0
func GetTemplateSubmoduleCommits ¶ added in v1.23.0
func GetTemplateSubmoduleCommits(ctx context.Context, repoPath string) (submoduleCommits []TemplateSubmoduleCommit, _ error)
GetTemplateSubmoduleCommits returns a list of submodules paths and their commits from a repository This function is only for generating new repos based on existing template, the template couldn't be too large.
type Tree ¶
type Tree struct {
TreeCommon
// contains filtered or unexported fields
}
Tree represents a flat directory listing.
func NewTree ¶
func NewTree(repo *Repository, id ObjectID) *Tree
NewTree create a new tree according the repository and tree id
func (*Tree) GetBlobByPath ¶
GetBlobByPath get the blob object according the path
func (*Tree) GetTreeEntryByPath ¶
GetTreeEntryByPath get the tree entries according the sub dir
func (*Tree) ListEntries ¶
ListEntries returns all entries of current tree.
func (*Tree) ListEntriesRecursiveFast ¶ added in v1.17.4
ListEntriesRecursiveFast returns all entries of current tree recursively including all subtrees, no size
func (*Tree) ListEntriesRecursiveWithSize ¶ added in v1.17.4
ListEntriesRecursiveWithSize returns all entries of current tree recursively including all subtrees, with size
type TreeCommon ¶ added in v1.26.0
type TreeEntry ¶
type TreeEntry struct {
ID ObjectID
// contains filtered or unexported fields
}
TreeEntry the leaf in the git tree
func ParseTreeEntries ¶
ParseTreeEntries parses the output of a `git ls-tree -l` command.
func (*TreeEntry) GetSubJumpablePathName ¶
GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
func (*TreeEntry) IsExecutable ¶ added in v1.9.1
IsExecutable if the entry is an executable file (not necessarily binary)
func (*TreeEntry) IsSubModule ¶
IsSubModule if the entry is a submodule
Source Files
¶
- blob.go
- blob_nogogit.go
- catfile_batch.go
- catfile_batch_command.go
- catfile_batch_legacy.go
- catfile_batch_reader.go
- cmdverb.go
- commit.go
- commit_info.go
- commit_info_nogogit.go
- commit_reader.go
- commit_submodule.go
- commit_submodule_file.go
- config.go
- config_submodule.go
- diff.go
- error.go
- git.go
- gpg.go
- grep.go
- hook.go
- key.go
- last_commit_cache.go
- last_commit_cache_nogogit.go
- log_name_status.go
- notes.go
- notes_nogogit.go
- object_format.go
- object_id.go
- parse.go
- parse_treeentry.go
- ref.go
- remote.go
- repo.go
- repo_base_nogogit.go
- repo_blob.go
- repo_branch.go
- repo_branch_nogogit.go
- repo_commit.go
- repo_commit_nogogit.go
- repo_commitgraph.go
- repo_compare.go
- repo_hook.go
- repo_index.go
- repo_object.go
- repo_ref.go
- repo_ref_nogogit.go
- repo_stats.go
- repo_tag.go
- repo_tag_nogogit.go
- repo_tree.go
- repo_tree_nogogit.go
- signature.go
- signature_nogogit.go
- submodule.go
- tag.go
- tree.go
- tree_blob.go
- tree_blob_nogogit.go
- tree_entry.go
- tree_entry_mode.go
- tree_entry_nogogit.go
- tree_nogogit.go
- utils.go