Documentation ¶
Index ¶
- Constants
- Variables
- func AddChanges(repoPath string, all bool, files ...string) error
- func AddChangesWithArgs(repoPath string, globalArgs TrustedCmdArgs, all bool, files ...string) error
- func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, files ...string) (int64, error)
- func AttributeToBool(attr map[string]string, name string) optional.Option[bool]
- func AttributeToString(attr map[string]string, name string) optional.Option[string]
- func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte
- func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error
- func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, ...) (err error)
- func CommitChanges(repoPath string, opts CommitChangesOptions) error
- func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChangesOptions) error
- func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
- func CommonCmdServEnvs() []string
- func CommonGitCmdEnvs() []string
- func ConcatenateError(err error, stderr string) error
- func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLine int) (string, error)
- func DiscardFull(rd *bufio.Reader, discard int64) error
- func Fsck(ctx context.Context, repoPath string, timeout time.Duration, ...) error
- func GetAffectedFiles(repo *Repository, branchName, oldCommitID, newCommitID string, env []string) ([]string, error)
- func GetDefaultBranch(ctx context.Context, repoPath string) (string, error)
- func GetDiffShortStat(ctx context.Context, repoPath string, trustedArgs TrustedCmdArgs, ...) (numFiles, totalAdditions, totalDeletions int, err 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 GetLatestCommitTime(ctx context.Context, repoPath string) (time.Time, error)
- func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) error
- func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) error
- func GetRemoteAddress(ctx context.Context, repoPath, remoteName string) (string, error)
- func GetRemoteURL(ctx context.Context, repoPath, remoteName string) (*giturl.GitURL, error)
- func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, ...) error
- func GetReverseRawDiff(ctx context.Context, repoPath, commitID string, writer io.Writer) error
- func HashFilePathForWebUI(s string) string
- func HomeDir() string
- func InitFull(ctx context.Context) (err error)
- func InitRepository(ctx context.Context, repoPath string, bare bool, objectFormatName string) error
- func InitSimple(ctx context.Context) error
- func IsBranchExist(ctx context.Context, repoPath, name string) bool
- func IsEmptyCommitID(commitID string) bool
- func IsErrBadLink(err error) bool
- func IsErrBranchNotExist(err error) bool
- func IsErrCanceledOrKilled(err error) bool
- func IsErrMoreThanOne(err error) bool
- func IsErrNotExist(err error) bool
- func IsErrPushOutOfDate(err error) bool
- func IsErrPushRejected(err error) bool
- func IsErrorExitCode(err error, code int) bool
- func IsReferenceExist(ctx context.Context, repoPath, name string) bool
- func IsRepoURLAccessible(ctx context.Context, url string) bool
- func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool
- func IsTagExist(ctx context.Context, repoPath, name string) 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 ParseDiffHunkString(diffhunk string) (leftLine, leftHunk, rightLine, righHunk int)
- func ParseTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error)
- func Push(ctx context.Context, repoPath string, opts PushOptions) error
- func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error)
- func ReadTagObjectID(rd *bufio.Reader, size int64) (string, error)
- func ReadTreeID(rd *bufio.Reader, size int64) (string, error)
- func RefURL(repoURL, ref string) string
- func SanitizeRefPattern(name string) string
- func SetExecutablePath(path string) error
- func SetUpdateHook(repoPath, content string) (err error)
- func TryReadLanguageAttribute(attrs map[string]string) optional.Option[string]
- func WalkGitLog(ctx context.Context, repo *Repository, head *Commit, treepath string, ...) (map[string]string, error)
- func WalkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, ...) (countAll int, err error)
- func WriteCommitGraph(ctx context.Context, repoPath string) error
- type ArchiveType
- type Batch
- type BlamePart
- type BlameReader
- type Blob
- func (b *Blob) DataAsync() (io.ReadCloser, error)
- func (b *Blob) GetBlobContent(limit int64) (string, error)
- func (b *Blob) GetBlobContentBase64() (string, error)
- func (b *Blob) GetBlobLineCount() (int, error)
- func (b *Blob) GuessContentType() (typesniffer.SniffedType, error)
- func (b *Blob) Name() string
- func (b *Blob) Size() int64
- type Branch
- type CheckAttributeOpts
- type CheckAttributeReader
- type CloneRepoOptions
- type CodeActivityAuthor
- type CodeActivityStats
- type Command
- func (c *Command) AddArguments(args ...internal.CmdArg) *Command
- func (c *Command) AddDashesAndList(list ...string) *Command
- func (c *Command) AddDynamicArguments(args ...string) *Command
- func (c *Command) AddOptionFormat(opt string, args ...any) *Command
- func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command
- func (c *Command) Run(opts *RunOpts) error
- func (c *Command) RunStdBytes(opts *RunOpts) (stdout, stderr []byte, runErr RunStdError)
- func (c *Command) RunStdString(opts *RunOpts) (stdout, stderr string, runErr RunStdError)
- func (c *Command) SetDescription(desc string) *Command
- func (c *Command) SetParentContext(ctx context.Context) *Command
- func (c *Command) String() string
- 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 string) ([]*Commit, error)
- func (c *Commit) CommitsCount() (int64, error)
- func (c *Commit) FileChangedSinceCommit(filename, pastCommit string) (bool, error)
- func (c *Commit) GetBranchName() (string, 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) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, 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 CommitChangesOptions
- type CommitFileStatus
- type CommitInfo
- type CommitSignature
- type CommitSubModuleFile
- type CommitTreeOpts
- type CommitsByFileAndRangeOptions
- type CommitsCountOptions
- type CompareInfo
- type DeleteBranchOptions
- type DivergeObject
- type EmptyReader
- type Entries
- type EntryMode
- type ErrBadLink
- type ErrBranchNotExist
- type ErrInvalidSHA
- type ErrMoreThanOne
- type ErrNotExist
- type ErrPushOutOfDate
- type ErrPushRejected
- type Features
- type GPGSettings
- type GrepOptions
- type GrepResult
- type Hook
- type IndexObjectInfo
- type LastCommitCache
- type LimitedReaderCloser
- type LogNameStatusCommitData
- type LogNameStatusRepoParser
- 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() string
- func (ref RefName) RemoteName() string
- func (ref RefName) ShortName() string
- func (ref RefName) String() string
- func (ref RefName) TagName() string
- type Reference
- type Repository
- func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error
- 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) (WriteCloserError, *bufio.Reader, func(), error)
- func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error)
- func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[string]string, error)
- func (repo *Repository) CheckAttributeReader(commitID string) (*CheckAttributeReader, context.CancelFunc)
- 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) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error)
- func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error)
- func (repo *Repository) CommitsCountBetween(start, end string) (int64, error)
- func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error)
- func (repo *Repository) CreateAnnotatedTag(name, message, revision string) error
- func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, target io.Writer, usePrefix bool, ...) error
- func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error
- func (repo *Repository) CreateBundle(ctx context.Context, commit string, out io.Writer) error
- func (repo *Repository) CreateTag(name, revision string) error
- func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error
- func (repo *Repository) EmptyIndex() error
- func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bool, error)
- func (repo *Repository) FileCommitsCount(revision, file string) (int64, error)
- func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
- func (repo *Repository) GetAllCommitsCount() (int64, error)
- func (repo *Repository) GetAnnotatedTag(sha string) (*Tag, error)
- func (repo *Repository) GetBlob(idStr string) (*Blob, error)
- func (repo *Repository) GetBranch(branch string) (*Branch, 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) GetBranches(skip, limit int) ([]*Branch, 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) GetCompareInfo(basePath, baseBranch, headBranch string, directComparison, fileOnly bool) (_ *CompareInfo, err error)
- func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error)
- func (repo *Repository) GetDiff(base, head string, w io.Writer) error
- func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error
- func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error
- func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparison bool) (int, error)
- func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, binary bool) error
- func (repo *Repository) GetDiffShortStat(base, head string) (numFiles, totalAdditions, totalDeletions int, err error)
- func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error)
- func (repo *Repository) GetHEADBranch() (*Branch, error)
- func (repo *Repository) GetHook(name string) (*Hook, error)
- func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error)
- func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, string, error)
- func (repo *Repository) GetObjectFormat() (ObjectFormat, error)
- func (repo *Repository) GetPatch(base, head string, w io.Writer) error
- func (repo *Repository) GetRefCommitID(name string) (string, error)
- func (repo *Repository) GetRefType(ref string) ObjectType
- 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) GetTags(skip, limit int) (tags []string, err error)
- func (repo *Repository) GetTree(idStr string) (*Tree, error)
- func (repo *Repository) HashObject(reader io.Reader) (ObjectID, error)
- func (repo *Repository) Hooks() ([]*Hook, error)
- func (repo *Repository) IsBranchExist(name string) bool
- func (repo *Repository) IsCommitExist(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) LineBlame(revision, path, file string, line uint) (*Commit, error)
- 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) NewBatch(ctx context.Context) (*Batch, error)
- func (repo *Repository) NewBatchCheck(ctx context.Context) (*Batch, 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) RemoveReference(name string) error
- func (repo *Repository) RemoveRemote(name string) error
- func (repo *Repository) RenameBranch(from, to string) error
- func (repo *Repository) ResolveReference(name string) (string, error)
- func (repo *Repository) SetReference(name, commitID string) 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 RunOpts
- type RunStdError
- 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 SubModule
- type Tag
- type Tree
- func (t *Tree) GetBlobByPath(relpath string) (*Blob, error)
- func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, 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 TreeEntry
- func (te *TreeEntry) Blob() *Blob
- func (te *TreeEntry) FollowLink() (*TreeEntry, error)
- func (te *TreeEntry) FollowLinks() (*TreeEntry, error)
- 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
- type TrustedCmdArgs
- type WriteCloserError
Examples ¶
Constants ¶
const ( AttributeLinguistVendored = "linguist-vendored" AttributeLinguistGenerated = "linguist-generated" AttributeLinguistDocumentation = "linguist-documentation" AttributeLinguistDetectable = "linguist-detectable" AttributeLinguistLanguage = "linguist-language" AttributeGitlabLanguage = "gitlab-language" )
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 DefaultLocale = "C"
DefaultLocale is the default LC_ALL to run git commands in.
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 (
// HookPathUpdate hook update path
HookPathUpdate = "hooks/update"
)
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.0.0" // the minimum Git version required
const TagPrefix = "refs/tags/"
TagPrefix tags prefix path on the repository
Variables ¶
var ( GitExecutable = "git" // the command name of git, will be updated to an absolute path during initialization DefaultContext context.Context // the default context to run git commands in, must be initialized by git.InitXxx )
var ErrBrokenCommand = errors.New("git command is broken")
var ErrNotValidHook = errors.New("not a valid Git hook")
ErrNotValidHook error when a git hook is not valid
Functions ¶
func AddChanges ¶
AddChanges marks local changes to be ready for commit.
func AddChangesWithArgs ¶
func AddChangesWithArgs(repoPath string, globalArgs TrustedCmdArgs, all bool, files ...string) error
AddChangesWithArgs marks local changes to be ready for commit.
func AllCommitsCount ¶
func AllCommitsCount(ctx context.Context, repoPath string, hidePRRefs bool, files ...string) (int64, error)
AllCommitsCount returns count of all commits in repository
func AttributeToBool ¶
true if "set"/"true", false if "unset"/"false", none otherwise
func AttributeToString ¶
func BinToHex ¶
func BinToHex(objectFormat ObjectFormat, sha, out []byte) []byte
BinToHexHeash converts a binary Hash into a hex encoded one. Input and output can be the same byte slice to support in place conversion without allocations. This is at least 100x quicker that hex.EncodeToString
func Clone ¶
func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error
Clone clones original repository to target path.
func CloneWithArgs ¶
func CloneWithArgs(ctx context.Context, args TrustedCmdArgs, from, to string, opts CloneRepoOptions) (err error)
CloneWithArgs 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 CommitChangesWithArgs ¶
func CommitChangesWithArgs(repoPath string, args TrustedCmdArgs, opts CommitChangesOptions) error
CommitChangesWithArgs commits local changes with given committer, author and message. If author is nil, it will be the same as committer.
func CommitsCount ¶
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error)
CommitsCount returns number of total commits of until given revision.
func CommonCmdServEnvs ¶
func CommonCmdServEnvs() []string
CommonCmdServEnvs is like CommonGitCmdEnvs, but it only returns minimal required environment variables for the "gitea serv" command
func CommonGitCmdEnvs ¶
func CommonGitCmdEnvs() []string
CommonGitCmdEnvs returns the common environment variables for a "git" command.
func ConcatenateError ¶
ConcatenateError concatenats an error with stderr string
func CutDiffAroundLine ¶
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)
Output:
func GetAffectedFiles ¶
func GetAffectedFiles(repo *Repository, branchName, oldCommitID, newCommitID string, env []string) ([]string, error)
GetAffectedFiles returns the affected files between two commits
func GetDiffShortStat ¶
func GetDiffShortStat(ctx context.Context, repoPath string, trustedArgs TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error)
GetDiffShortStat counts number of changed files, number of additions and deletions
func GetFullCommitID ¶
GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
func GetLastCommitForPaths ¶
func GetLastCommitForPaths(ctx context.Context, commit *Commit, treePath string, paths []string) (map[string]*Commit, error)
GetLastCommitForPaths returns last commit information
func GetLatestCommitTime ¶
GetLatestCommitTime returns time for latest commit in repository (across all branches)
func GetNote ¶
GetNote retrieves the git-notes data for a given commit. FIXME: Add LastCommitCache support
func GetRawDiff ¶
func GetRawDiff(repo *Repository, commitID string, diffType RawDiffType, writer io.Writer) error
GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
func GetRemoteAddress ¶
GetRemoteAddress returns remote url of git repository in the repoPath with special remote name
func GetRemoteURL ¶
GetRemoteURL returns the url of a specific remote of the repository.
func GetRepoRawDiffForFile ¶
func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diffType RawDiffType, file string, writer io.Writer) error
GetRepoRawDiffForFile dumps diff results of file in given commit ID to io.Writer according given repository
func GetReverseRawDiff ¶
GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.
func HashFilePathForWebUI ¶
func HomeDir ¶
func HomeDir() string
HomeDir is the home dir for git to store the global config file used by Gitea internally
func InitFull ¶
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 ¶
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 IsBranchExist ¶
IsBranchExist returns true if given branch exists in the repository.
func IsEmptyCommitID ¶
func IsErrBranchNotExist ¶
IsErrBranchNotExist checks if an error is a ErrBranchNotExist.
func IsErrCanceledOrKilled ¶
func IsErrMoreThanOne ¶
IsErrMoreThanOne checks if an error is a ErrMoreThanOne
func IsErrPushOutOfDate ¶
IsErrPushOutOfDate checks if an error is a ErrPushOutOfDate.
func IsErrPushRejected ¶
IsErrPushRejected checks if an error is a ErrPushRejected.
func IsErrorExitCode ¶
func IsReferenceExist ¶
IsReferenceExist returns true if given reference exists in the repository.
func IsRepoURLAccessible ¶
IsRepoURLAccessible checks if given repository URL is accessible.
func IsStringLikelyCommitID ¶
func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool
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 IsValidObjectFormat ¶
func IsValidRefPattern ¶
IsValidRefPattern ensures that the provided string could be a valid reference
func LogNameStatusRepo ¶
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 ¶
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 ParseDiffHunkString ¶
ParseDiffHunkString parse the diffhunk content and return
func ParseTreeLine ¶
func ParseTreeLine(objectFormat ObjectFormat, rd *bufio.Reader, modeBuf, fnameBuf, shaBuf []byte) (mode, fname, sha []byte, n int, err error)
ParseTreeLine 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 Push ¶
func Push(ctx context.Context, repoPath string, opts PushOptions) error
Push pushs local commits to given remote branch.
func ReadBatchLine ¶
ReadBatchLine reads the header line from cat-file --batch We expect: <oid> SP <type> SP <size> LF then leaving the rest of the stream "<contents> LF" to be read
func ReadTagObjectID ¶
ReadTagObjectID reads a tag object ID hash from a cat-file --batch stream, throwing away the rest of the stream.
func ReadTreeID ¶
ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
func SanitizeRefPattern ¶
func SetExecutablePath ¶
SetExecutablePath changes the path of git executable and checks the file permission and version.
func SetUpdateHook ¶
SetUpdateHook writes given content to update hook of the repository.
func WalkGitLog ¶
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 ¶
Types ¶
type ArchiveType ¶
type ArchiveType int
ArchiveType archive types
const ( // ZIP zip archive type ZIP ArchiveType = iota + 1 // TARGZ tar gz archive type TARGZ // BUNDLE bundle archive type BUNDLE )
func ToArchiveType ¶
func ToArchiveType(s string) ArchiveType
func (ArchiveType) String ¶
func (a ArchiveType) String() string
String converts an ArchiveType to string
type Batch ¶
type Batch struct { Reader *bufio.Reader Writer WriteCloserError // contains filtered or unexported fields }
type BlameReader ¶
type BlameReader struct {
// contains filtered or unexported fields
}
BlameReader returns part of file blame one by one
func CreateBlameReader ¶
func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error)
CreateBlameReader creates reader for given repository, commit and file
func (*BlameReader) Close ¶
func (r *BlameReader) Close() error
Close BlameReader - don't run NextPart after invoking that
func (*BlameReader) NextPart ¶
func (r *BlameReader) NextPart() (*BlamePart, error)
NextPart returns next part of blame (sequential code lines with the same commit)
func (*BlameReader) UsesIgnoreRevs ¶
func (r *BlameReader) UsesIgnoreRevs() bool
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, 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) 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 encode and returns the encoded string
func (*Blob) GetBlobLineCount ¶
GetBlobLineCount gets line count of the blob
func (*Blob) GuessContentType ¶
func (b *Blob) GuessContentType() (typesniffer.SniffedType, error)
GuessContentType guesses the content type of the blob.
type CheckAttributeOpts ¶
type CheckAttributeOpts struct { CachedOnly bool AllAttributes bool Attributes []string Filenames []string IndexFile string WorkTree string }
CheckAttributeOpts represents the possible options to CheckAttribute
type CheckAttributeReader ¶
type CheckAttributeReader struct { // params Attributes []string Repo *Repository IndexFile string WorkTree string // contains filtered or unexported fields }
CheckAttributeReader provides a reader for check-attribute content that can be long running
func (*CheckAttributeReader) CheckPath ¶
func (c *CheckAttributeReader) CheckPath(path string) (rs map[string]string, err error)
CheckPath check attr for given path
func (*CheckAttributeReader) Close ¶
func (c *CheckAttributeReader) Close() error
Close close pip after use
type CloneRepoOptions ¶
type CloneRepoOptions struct { Timeout time.Duration Mirror bool Bare bool Quiet bool Branch string NoCheckout bool Depth int Filter string SkipTLSVerify bool }
CloneRepoOptions options when clone a repository
type CodeActivityAuthor ¶
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 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. Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
func NewCommandContextNoGlobals ¶
NewCommandContextNoGlobals creates and returns a new Git Command based on given command and arguments only with the specify args and don't care global command args Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
func (*Command) AddArguments ¶
AddArguments adds new git arguments (option/value) to the command. It only accepts string literals, or trusted CmdArg. Type CmdArg is in the internal package, so it can not be used outside of this package directly, it makes sure that user-provided arguments won't cause RCE risks. User-provided arguments should be passed by other AddXxx functions
func (*Command) AddDashesAndList ¶
AddDashesAndList adds the "--" and then add the list as arguments, it's usually for adding file list At the moment, this function can be only called once, maybe in future it can be refactored to support multiple calls (if necessary)
func (*Command) AddDynamicArguments ¶
AddDynamicArguments adds new dynamic argument values to the command. The arguments may come from user input and can not be trusted, so no leading '-' is allowed to avoid passing options. TODO: in the future, this function can be renamed to AddArgumentValues
func (*Command) AddOptionFormat ¶
AddOptionFormat adds a new option with a format string and arguments For example: AddOptionFormat("--opt=%s %s", val1, val2) means 1 argument: {"--opt=val1 val2"}.
func (*Command) AddOptionValues ¶
AddOptionValues adds a new option with a list of non-option values For example: AddOptionValues("--opt", val) means 2 arguments: {"--opt", val}. The values are treated as dynamic argument values. It equals to: AddArguments("--opt") then AddDynamicArguments(val).
func (*Command) RunStdBytes ¶
func (c *Command) RunStdBytes(opts *RunOpts) (stdout, stderr []byte, runErr RunStdError)
RunStdBytes runs the command with options and returns stdout/stderr as bytes. and store stderr to returned error (err combined with stderr).
func (*Command) RunStdString ¶
func (c *Command) RunStdString(opts *RunOpts) (stdout, stderr string, runErr RunStdError)
RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
func (*Command) SetDescription ¶
SetDescription sets the description for this command which be returned on c.String()
func (*Command) SetParentContext ¶
SetParentContext sets the parent context for this command
type Commit ¶
type Commit struct { Tree ID ObjectID // The ID of this commit object Author *Signature Committer *Signature CommitMessage string Signature *CommitSignature Parents []ObjectID // ID strings // contains filtered or unexported fields }
Commit represents a git commit.
func CommitFromReader ¶
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 ¶
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) CommitsCount ¶
CommitsCount returns number of total commits of until current revision.
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) GetBranchName ¶
GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
func (*Commit) GetCommitByPath ¶
GetCommitByPath return the commit of relative path object.
func (*Commit) GetFileContent ¶
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) GetRepositoryDefaultPublicGPGKey ¶
func (c *Commit) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error)
GetRepositoryDefaultPublicGPGKey returns the default public key for this commit
func (*Commit) GetSubModule ¶
GetSubModule get the submodule according entry name
func (*Commit) GetSubModules ¶
func (c *Commit) GetSubModules() (*ObjectCache[*SubModule], error)
GetSubModules get all the submodules of current revision git tree
func (*Commit) HasFile ¶
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 ¶
HasPreviousCommit returns true if a given commitHash is contained in commit's parents
func (*Commit) IsForcePush ¶
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 CommitChangesOptions ¶
CommitChangesOptions the options when a commit created
type CommitFileStatus ¶
CommitFileStatus represents status of files in a commit.
func GetCommitFileStatus ¶
func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*CommitFileStatus, error)
GetCommitFileStatus returns file status of commit in given repository.
func NewCommitFileStatus ¶
func NewCommitFileStatus() *CommitFileStatus
NewCommitFileStatus creates a CommitFileStatus
type CommitInfo ¶
type CommitInfo struct { Entry *TreeEntry Commit *Commit SubModuleFile *CommitSubModuleFile }
CommitInfo describes the first commit with the provided entry
type CommitSignature ¶
type CommitSignature struct { Signature string Payload string // TODO check if can be reconstruct from the rest of commit information to not have duplicate data }
CommitSignature represents a git commit signature part.
type CommitSubModuleFile ¶
type CommitSubModuleFile struct {
// contains filtered or unexported fields
}
CommitSubModuleFile represents a file with submodule type.
func NewCommitSubModuleFile ¶
func NewCommitSubModuleFile(refURL, refID string) *CommitSubModuleFile
NewCommitSubModuleFile create a new submodule file
func (*CommitSubModuleFile) RefID ¶
func (sf *CommitSubModuleFile) RefID() string
RefID returns reference ID.
func (*CommitSubModuleFile) RefURL ¶
func (sf *CommitSubModuleFile) RefURL(urlPrefix, repoFullName, sshDomain string) string
RefURL guesses and returns reference URL. FIXME: template passes AppURL as urlPrefix, it needs to figure out the correct approach (no hard-coded AppURL anymore)
type CommitTreeOpts ¶
type CommitTreeOpts struct { Parents []string Message string KeyID string NoGPGSign bool AlwaysSign bool }
CommitTreeOpts represents the possible options to CommitTree
type CommitsCountOptions ¶
CommitsCountOptions the options when counting commits
type CompareInfo ¶
type CompareInfo struct { MergeBase string BaseCommitID string HeadCommitID string Commits []*Commit NumFiles int }
CompareInfo represents needed information for comparing references.
type DeleteBranchOptions ¶
type DeleteBranchOptions struct {
Force bool
}
DeleteBranchOptions Option(s) for delete branch
type DivergeObject ¶
DivergeObject represents commit count diverging commits
func GetDivergingCommits ¶
func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch string) (do DivergeObject, err error)
GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch
type EmptyReader ¶
type EmptyReader struct{}
type Entries ¶
type Entries []*TreeEntry
Entries a list of entry
func (Entries) CustomSort ¶
CustomSort customizable string comparing sort entry list
func (Entries) GetCommitsInfo ¶
func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath string) ([]CommitInfo, *Commit, error)
GetCommitsInfo gets information of all commits that are corresponding to these entries
type EntryMode ¶
type EntryMode int
EntryMode the type of the object in the git tree
const ( // EntryModeBlob EntryModeBlob EntryMode = 0o100644 // EntryModeExec EntryModeExec EntryMode = 0o100755 // EntryModeSymlink EntryModeSymlink EntryMode = 0o120000 // EntryModeCommit EntryModeCommit EntryMode = 0o160000 // EntryModeTree 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 ToEntryMode ¶
ToEntryMode converts a string to an EntryMode
type ErrBadLink ¶
ErrBadLink entry.FollowLink error
func (ErrBadLink) Error ¶
func (err ErrBadLink) Error() string
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 ¶
func (err ErrBranchNotExist) Unwrap() error
type ErrInvalidSHA ¶
type ErrInvalidSHA struct {
SHA string
}
func (ErrInvalidSHA) Error ¶
func (err ErrInvalidSHA) Error() string
type ErrMoreThanOne ¶
ErrMoreThanOne represents an error if pull request fails when there are more than one sources (branch, tag) with the same name
func (*ErrMoreThanOne) Error ¶
func (err *ErrMoreThanOne) Error() string
type ErrNotExist ¶
ErrNotExist commit not exist error
func (ErrNotExist) Error ¶
func (err ErrNotExist) Error() string
func (ErrNotExist) Unwrap ¶
func (err ErrNotExist) Unwrap() error
type ErrPushOutOfDate ¶
ErrPushOutOfDate represents an error if merging fails due to the base branch being updated
func (*ErrPushOutOfDate) Error ¶
func (err *ErrPushOutOfDate) Error() string
func (*ErrPushOutOfDate) Unwrap ¶
func (err *ErrPushOutOfDate) Unwrap() error
Unwrap unwraps the underlying error
type ErrPushRejected ¶
ErrPushRejected represents an error if merging fails due to rejection from a hook
func (*ErrPushRejected) Error ¶
func (err *ErrPushRejected) Error() string
func (*ErrPushRejected) GenerateMessage ¶
func (err *ErrPushRejected) GenerateMessage()
GenerateMessage generates the remote message from the stderr
func (*ErrPushRejected) Unwrap ¶
func (err *ErrPushRejected) Unwrap() error
Unwrap unwraps the underlying error
type Features ¶
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 // contains filtered or unexported fields }
func DefaultFeatures ¶
func DefaultFeatures() *Features
func (*Features) CheckVersionAtLeast ¶
func (*Features) VersionInfo ¶
VersionInfo returns git version information
type GPGSettings ¶
GPGSettings represents the default GPG settings for this repository
func (*GPGSettings) LoadPublicKeyContent ¶
func (gpgSettings *GPGSettings) LoadPublicKeyContent() error
LoadPublicKeyContent will load the key from gpg
type GrepOptions ¶
type GrepResult ¶
func GrepSearch ¶
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 ¶
type LastCommitCache ¶
type LastCommitCache struct {
// contains filtered or unexported fields
}
LastCommitCache represents a cache to store last commit
func NewLastCommitCache ¶
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 ¶
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 LimitedReaderCloser ¶
LimitedReaderCloser is a limited reader closer
func (*LimitedReaderCloser) Close ¶
func (l *LimitedReaderCloser) Close() error
Close implements io.Closer
type LogNameStatusCommitData ¶
LogNameStatusCommitData represents a commit artefact from git log raw
type LogNameStatusRepoParser ¶
type LogNameStatusRepoParser struct {
// contains filtered or unexported fields
}
LogNameStatusRepoParser parses a git log raw output from LogRawRepo
func NewLogNameStatusRepoParser ¶
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 ¶
func (g *LogNameStatusRepoParser) Close()
Close closes the parser
func (*LogNameStatusRepoParser) Next ¶
func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int, changed []bool, maxpathlen int) (*LogNameStatusCommitData, error)
Next returns the next LogStatusCommitData
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 ¶
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 ¶
func ObjectFormatFromName(name string) ObjectFormat
type ObjectID ¶
type ObjectID interface { String() string IsZero() bool RawValue() []byte Type() ObjectFormat }
func ComputeBlobHash ¶
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 ¶
func (o ObjectType) Bytes() []byte
Bytes returns the byte array for the Object Type
type PushOptions ¶
type PushOptions struct { Remote string Branch string Force bool Mirror bool Env []string Timeout time.Duration }
PushOptions options when push to remote
type RawDiffType ¶
type RawDiffType string
RawDiffType type of a raw diff.
const ( RawDiffNormal RawDiffType = "diff" RawDiffPatch RawDiffType = "patch" )
RawDiffType possible values.
type RefName ¶
type RefName string
RefName represents a full git reference name
func RefNameFromBranch ¶
func RefNameFromTag ¶
func (RefName) BranchName ¶
BranchName returns simple branch name if it's an operation to branch
func (RefName) ForBranchName ¶
ForBranchName returns the branch name part of refs like refs/for/<branch_name>
func (RefName) PullName ¶
PullName returns the pull request name part of refs like refs/pull/<pull_name>/head
func (RefName) RefGroup ¶
RefGroup returns the group type of the reference Using the name of the directory under .git/refs
func (RefName) RefType ¶
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 Here we using branch but not heads, using tag but not tags
func (RefName) RemoteName ¶
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) AddLastCommitCache ¶
func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error
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 ¶
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 ¶
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error)
CatFileBatch obtains a CatFileBatch for this repository
func (*Repository) CatFileBatchCheck ¶
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error)
CatFileBatchCheck obtains a CatFileBatchCheck for this repository
func (*Repository) CheckAttribute ¶
func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[string]string, error)
CheckAttribute return the Blame object of file
func (*Repository) CheckAttributeReader ¶
func (repo *Repository) CheckAttributeReader(commitID string) (*CheckAttributeReader, context.CancelFunc)
Create a check attribute reader for the current repository and provided commit ID
func (*Repository) Close ¶
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 ¶
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) CommitsBetweenNotBase ¶
func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error)
CommitsBetweenNotBase returns a list that contains commits between [before, last), excluding commits in baseBranch. If before is detached (removed by reset + push) it is not included.
func (*Repository) CommitsByFileAndRange ¶
func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) ([]*Commit, error)
CommitsByFileAndRange return the commits according revision file and the page
func (*Repository) CommitsCountBetween ¶
func (repo *Repository) CommitsCountBetween(start, end string) (int64, error)
CommitsCountBetween return numbers of commits between two commits
func (*Repository) ConvertToGitID ¶
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) CreateArchive ¶
func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, target io.Writer, usePrefix bool, commitID string) error
CreateArchive create archive content to the target path
func (*Repository) CreateBranch ¶
func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error
CreateBranch create a new branch
func (*Repository) CreateBundle ¶
CreateBundle create bundle content to the target path
func (*Repository) CreateTag ¶
func (repo *Repository) CreateTag(name, revision string) error
CreateTag create one tag in the repository
func (*Repository) DeleteBranch ¶
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error
DeleteBranch delete a branch by name on 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) FileCommitsCount ¶
func (repo *Repository) FileCommitsCount(revision, file string) (int64, error)
FileCommitsCount return the number of files at a revision
func (*Repository) FilesCountBetween ¶
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error)
FilesCountBetween return the number of files changed between two commits
func (*Repository) GetAllCommitsCount ¶
func (repo *Repository) GetAllCommitsCount() (int64, error)
GetAllCommitsCount returns count of all commits in repository
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) GetBranch ¶
func (repo *Repository) GetBranch(branch string) (*Branch, error)
GetBranch returns a branch by it's name
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 ¶
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) GetBranches ¶
func (repo *Repository) GetBranches(skip, limit int) ([]*Branch, int, error)
GetBranches returns a slice of *git.Branch
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 ¶
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error)
func (*Repository) GetCommitByPath ¶
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error)
GetCommitByPath returns the last commit of relative path.
func (*Repository) GetCommitsFromIDs ¶
func (repo *Repository) GetCommitsFromIDs(commitIDs []string) []*Commit
GetCommitsFromIDs get commits from commit IDs
func (*Repository) GetCompareInfo ¶
func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string, directComparison, fileOnly bool) (_ *CompareInfo, err error)
GetCompareInfo generates and returns compare information between base and head branches of repositories.
func (*Repository) GetDefaultPublicGPGKey ¶
func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error)
GetDefaultPublicGPGKey will return and cache the default public GPG settings for this repository
func (*Repository) GetDiff ¶
func (repo *Repository) GetDiff(base, head string, w io.Writer) error
GetDiff generates and returns patch data between given revisions, optimized for human readability
func (*Repository) GetDiffBinary ¶
func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error
GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
func (*Repository) GetDiffFromMergeBase ¶
func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error
GetDiffFromMergeBase generates and return patch data from merge base to head
func (*Repository) GetDiffNumChangedFiles ¶
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) GetDiffOrPatch ¶
GetDiffOrPatch generates either diff or formatted patch data between given revisions
func (*Repository) GetDiffShortStat ¶
func (repo *Repository) GetDiffShortStat(base, head string) (numFiles, totalAdditions, totalDeletions int, err error)
GetDiffShortStat counts number of changed files, number of additions and deletions
func (*Repository) GetFilesChangedBetween ¶
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) GetHEADBranch ¶
func (repo *Repository) GetHEADBranch() (*Branch, error)
GetHEADBranch returns corresponding branch of HEAD.
func (*Repository) GetHook ¶
func (repo *Repository) GetHook(name string) (*Hook, error)
GetHook get one hook according the name on a repository
func (*Repository) GetLanguageStats ¶
func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error)
GetLanguageStats calculates language stats for git repository at specified commit
func (*Repository) GetMergeBase ¶
func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, string, error)
GetMergeBase checks and returns merge base of two branches and the reference used as base.
func (*Repository) GetObjectFormat ¶
func (repo *Repository) GetObjectFormat() (ObjectFormat, error)
func (*Repository) GetPatch ¶
func (repo *Repository) GetPatch(base, head 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) GetRefType ¶
func (repo *Repository) GetRefType(ref string) ObjectType
GetRefType gets the type of the ref based on the string
func (*Repository) GetRefs ¶
func (repo *Repository) GetRefs() ([]*Reference, error)
GetRefs returns all references of the repository.
func (*Repository) GetRefsBySha ¶
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 ¶
func (repo *Repository) GetTagWithID(idStr, name string) (*Tag, error)
GetTagWithID returns a Git tag by given name and ID
func (*Repository) GetTags ¶
func (repo *Repository) GetTags(skip, limit int) (tags []string, err error)
GetTags returns all tags of the repository. returning at most limit tags, or all if limit is 0.
func (*Repository) GetTree ¶
func (repo *Repository) GetTree(idStr string) (*Tree, error)
GetTree find the tree object in the repository.
func (*Repository) HashObject ¶
func (repo *Repository) HashObject(reader io.Reader) (ObjectID, error)
HashObject takes a reader and returns hash for that reader
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) IsCommitExist ¶
func (repo *Repository) IsCommitExist(name string) bool
IsCommitExist returns true if given commit exists in current repository.
func (*Repository) IsCommitInBranch ¶
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 ¶
func (repo *Repository) IsObjectExist(name string) bool
IsObjectExist returns true if the given object exists in the repository.
func (*Repository) IsReferenceExist ¶
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) LineBlame ¶
func (repo *Repository) LineBlame(revision, path, file string, line uint) (*Commit, error)
LineBlame returns the latest commit at the given line
func (*Repository) ListOccurrences ¶
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 ¶
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error)
LsTree checks if the given filenames are in the tree
func (*Repository) NewBatchCheck ¶
func (repo *Repository) NewBatchCheck(ctx context.Context) (*Batch, error)
func (*Repository) ReadPatchCommit ¶
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 ¶
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) RemoveReference ¶
func (repo *Repository) RemoveReference(name string) error
RemoveReference removes the given reference (e.g. branch or tag).
func (*Repository) RemoveRemote ¶
func (repo *Repository) RemoveRemote(name string) error
RemoveRemote removes a remote from repository.
func (*Repository) RenameBranch ¶
func (repo *Repository) RenameBranch(from, to string) error
RenameBranch rename a branch
func (*Repository) ResolveReference ¶
func (repo *Repository) ResolveReference(name string) (string, error)
ResolveReference resolves a name to a reference
func (*Repository) SetReference ¶
func (repo *Repository) SetReference(name, commitID string) error
SetReference sets the commit ID string of given reference (e.g. branch or tag).
func (*Repository) UnstableGuessRefByShortName ¶
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 ¶
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 RunOpts ¶
type RunOpts struct { Env []string Timeout time.Duration UseContextTimeout bool // Dir is the working dir for the git command, however: // FIXME: this could be incorrect in many cases, for example: // * /some/path/.git // * /some/path/.git/gitea-data/data/repositories/user/repo.git // If "user/repo.git" is invalid/broken, then running git command in it will use "/some/path/.git", and produce unexpected results // The correct approach is to use `--git-dir" global argument Dir string Stdout, Stderr io.Writer // Stdin is used for passing input to the command // The caller must make sure the Stdin writer is closed properly to finish the Run function. // Otherwise, the Run function may hang for long time or forever, especially when the Git's context deadline is not the same as the caller's. // Some common mistakes: // * `defer stdinWriter.Close()` then call `cmd.Run()`: the Run() would never return if the command is killed by timeout // * `go { case <- parentContext.Done(): stdinWriter.Close() }` with `cmd.Run(DefaultTimeout)`: the command would have been killed by timeout but the Run doesn't return until stdinWriter.Close() // * `go { if stdoutReader.Read() err != nil: stdinWriter.Close() }` with `cmd.Run()`: the stdoutReader may never return error if the command is killed by timeout // In the future, ideally the git module itself should have full control of the stdin, to avoid such problems and make it easier to refactor to a better architecture. Stdin io.Reader PipelineFunc func(context.Context, context.CancelFunc) error }
RunOpts represents parameters to run the command. If UseContextTimeout is specified, then Timeout is ignored.
type RunStdError ¶
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 Sha1ObjectFormatImpl ¶
type Sha1ObjectFormatImpl struct{}
func (Sha1ObjectFormatImpl) ComputeHash ¶
func (h Sha1ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
ComputeHash compute the hash for a given ObjectType and content
func (Sha1ObjectFormatImpl) EmptyObjectID ¶
func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID
func (Sha1ObjectFormatImpl) EmptyTree ¶
func (Sha1ObjectFormatImpl) EmptyTree() ObjectID
func (Sha1ObjectFormatImpl) FullLength ¶
func (Sha1ObjectFormatImpl) FullLength() int
func (Sha1ObjectFormatImpl) IsValid ¶
func (Sha1ObjectFormatImpl) IsValid(input string) bool
func (Sha1ObjectFormatImpl) MustID ¶
func (Sha1ObjectFormatImpl) MustID(b []byte) ObjectID
func (Sha1ObjectFormatImpl) Name ¶
func (Sha1ObjectFormatImpl) Name() string
type Sha256Hash ¶
type Sha256Hash [32]byte
func (*Sha256Hash) IsZero ¶
func (h *Sha256Hash) IsZero() bool
func (*Sha256Hash) RawValue ¶
func (h *Sha256Hash) RawValue() []byte
func (*Sha256Hash) String ¶
func (h *Sha256Hash) String() string
func (*Sha256Hash) Type ¶
func (*Sha256Hash) Type() ObjectFormat
type Sha256ObjectFormatImpl ¶
type Sha256ObjectFormatImpl struct{}
func (Sha256ObjectFormatImpl) ComputeHash ¶
func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
ComputeHash compute the hash for a given ObjectType and content
func (Sha256ObjectFormatImpl) EmptyObjectID ¶
func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID
func (Sha256ObjectFormatImpl) EmptyTree ¶
func (Sha256ObjectFormatImpl) EmptyTree() ObjectID
func (Sha256ObjectFormatImpl) FullLength ¶
func (Sha256ObjectFormatImpl) FullLength() int
func (Sha256ObjectFormatImpl) IsValid ¶
func (Sha256ObjectFormatImpl) IsValid(input string) bool
func (Sha256ObjectFormatImpl) MustID ¶
func (Sha256ObjectFormatImpl) MustID(b []byte) ObjectID
func (Sha256ObjectFormatImpl) Name ¶
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 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 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 Tree ¶
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 ¶
ListEntriesRecursiveFast returns all entries of current tree recursively including all subtrees, no size
func (*Tree) ListEntriesRecursiveWithSize ¶
ListEntriesRecursiveWithSize returns all entries of current tree recursively including all subtrees, with size
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) FollowLink ¶
FollowLink returns the entry pointed to by a symlink
func (*TreeEntry) FollowLinks ¶
FollowLinks returns the entry ultimately pointed to by a symlink
func (*TreeEntry) GetSubJumpablePathName ¶
GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
func (*TreeEntry) IsExecutable ¶
IsExecutable if the entry is an executable file (not necessarily binary)
func (*TreeEntry) IsSubModule ¶
IsSubModule if the entry is a sub module
type TrustedCmdArgs ¶
TrustedCmdArgs returns the trusted arguments for git command. It's mainly for passing user-provided and trusted arguments to git command In most cases, it shouldn't be used. Use AddXxx function instead
func AllowLFSFiltersArgs ¶
func AllowLFSFiltersArgs() TrustedCmdArgs
AllowLFSFiltersArgs return globalCommandArgs with lfs filter, it should only be used for tests
func ToTrustedCmdArgs ¶
func ToTrustedCmdArgs(args []string) TrustedCmdArgs
ToTrustedCmdArgs converts a list of strings (trusted as argument) to TrustedCmdArgs In most cases, it shouldn't be used. Use NewCommand().AddXxx() function instead
type WriteCloserError ¶
type WriteCloserError interface { io.WriteCloser CloseWithError(err error) error }
WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function
Source Files ¶
- attribute.go
- batch.go
- batch_reader.go
- blame.go
- blob.go
- blob_nogogit.go
- command.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
- fsck.go
- git.go
- grep.go
- hook.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_nogogit.go
- ref.go
- remote.go
- repo.go
- repo_archive.go
- repo_attribute.go
- repo_base_nogogit.go
- repo_blame.go
- repo_blob.go
- repo_blob_nogogit.go
- repo_branch.go
- repo_branch_nogogit.go
- repo_commit.go
- repo_commit_nogogit.go
- repo_commitgraph.go
- repo_compare.go
- repo_gpg.go
- repo_hook.go
- repo_index.go
- repo_language_stats.go
- repo_language_stats_nogogit.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
- 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