gitrepo

package
v1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const MaxConflictedDetectFiles = 10

Variables

This section is empty.

Functions

func AllCommitsCount added in v1.26.0

func AllCommitsCount(ctx context.Context, repo Repository, hidePRRefs bool, files ...string) (int64, error)

AllCommitsCount returns count of all commits in repository

func CalcRepositorySize added in v1.26.0

func CalcRepositorySize(repo Repository) (int64, error)

CalcRepositorySize returns the disk consumption for a given path

func CheckDelegateHooks added in v1.24.0

func CheckDelegateHooks(_ context.Context, repo Repository) ([]string, error)

CheckDelegateHooks checks the hooks scripts for the repo

func Clone added in v1.26.0

func Clone(ctx context.Context, fromRepo, toRepo Repository, opts git.CloneRepoOptions) error

func CloneExternalRepo added in v1.26.0

func CloneExternalRepo(ctx context.Context, fromRemoteURL string, toRepo Repository, opts git.CloneRepoOptions) error

CloneExternalRepo clones an external repository to the managed repository.

func CloneRepoToLocal added in v1.26.0

func CloneRepoToLocal(ctx context.Context, fromRepo Repository, toLocalPath string, opts git.CloneRepoOptions) error

CloneRepoToLocal clones a managed repository to a local path.

func CommitsCount added in v1.26.0

func CommitsCount(ctx context.Context, repo Repository, opts CommitsCountOptions) (int64, error)

CommitsCount returns number of total commits of until given revision.

func CommitsCountBetween added in v1.26.0

func CommitsCountBetween(ctx context.Context, repo Repository, start, end string) (int64, error)

CommitsCountBetween return numbers of commits between two commits

func CommitsCountOfCommit added in v1.26.0

func CommitsCountOfCommit(ctx context.Context, repo Repository, commitID string) (int64, error)

CommitsCountOfCommit returns number of total commits of until current revision.

func CreateArchive added in v1.26.0

func CreateArchive(ctx context.Context, repo Repository, format string, target io.Writer, usePrefix bool, commitID string, paths []string) error

CreateArchive create archive content to the target path

func CreateBranch added in v1.26.0

func CreateBranch(ctx context.Context, repo Repository, branch, oldbranchOrCommit string) error

CreateBranch create a new branch

func CreateBundle added in v1.26.0

func CreateBundle(ctx context.Context, repo Repository, commit string, out io.Writer) error

CreateBundle create bundle content to the target path

func CreateDelegateHooks added in v1.24.0

func CreateDelegateHooks(_ context.Context, repo Repository) (err error)

CreateDelegateHooks creates all the hooks scripts for the repo

func CreateRepoFile added in v1.26.0

func CreateRepoFile(ctx context.Context, repo Repository, relativeFilePath string) (io.WriteCloser, error)

func DeleteBranch added in v1.26.0

func DeleteBranch(ctx context.Context, repo Repository, name string, force bool) error

DeleteBranch delete a branch by name on repository.

func DeleteRepository added in v1.24.0

func DeleteRepository(ctx context.Context, repo Repository) error

DeleteRepository deletes the repository directory from the disk, it will return nil if the repository does not exist.

func FetchRemoteCommit added in v1.26.0

func FetchRemoteCommit(ctx context.Context, repo, remoteRepo Repository, commitID string) error

FetchRemoteCommit fetches a specific commit and its related objects from a remote repository into the managed repository.

If no reference (branch, tag, or other ref) points to the fetched commit, it will be treated as unreachable and cleaned up by `git gc` after the default prune expiration period (2 weeks). Ref: https://www.kernel.org/pub/software/scm/git/docs/git-gc.html

This behavior is sufficient for temporary operations, such as determining the merge base between commits.

func FileCommitsCount added in v1.26.0

func FileCommitsCount(ctx context.Context, repo Repository, revision, file string) (int64, error)

FileCommitsCount return the number of files at a revision

func Fsck added in v1.25.0

func Fsck(ctx context.Context, repo Repository, timeout time.Duration, args gitcmd.TrustedCmdArgs) error

Fsck verifies the connectivity and validity of the objects in the database

func GetBranchCommitID

func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (string, error)

func GetBranchesByPath

func GetBranchesByPath(ctx context.Context, repo Repository, skip, limit int) ([]string, int, error)

GetBranchesByPath returns a branch by its path if limit = 0 it will not limit

func GetCommitIDsBetweenReverse added in v1.26.0

func GetCommitIDsBetweenReverse(ctx context.Context, repo Repository, startRef, endRef, notRef string, limit int) ([]string, error)

GetCommitIDsBetweenReverse returns the last commit IDs between two commits in reverse order (from old to new) with limit. If the result exceeds the limit, the old commits IDs will be ignored

func GetDefaultBranch

func GetDefaultBranch(ctx context.Context, repo Repository) (string, error)

GetDefaultBranch gets default branch of repository.

func GetDiffShortStatByCmdArgs added in v1.26.0

func GetDiffShortStatByCmdArgs(ctx context.Context, repo Repository, trustedArgs gitcmd.TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error)

GetDiffShortStatByCmdArgs counts number of changed files, number of additions and deletions TODO: it can be merged with another "GetDiffShortStat" in the future

func GetFullCommitID added in v1.26.0

func GetFullCommitID(ctx context.Context, repo Repository, shortID string) (string, error)

func GetLatestCommitTime added in v1.26.0

func GetLatestCommitTime(ctx context.Context, repo Repository) (time.Time, error)

GetLatestCommitTime returns time for latest commit in repository (across all branches)

func GetRepoFS added in v1.26.0

func GetRepoFS(repo Repository) fs.FS

func GetReverseRawDiff added in v1.26.0

func GetReverseRawDiff(ctx context.Context, repo Repository, commitID string, writer io.Writer) error

GetReverseRawDiff dumps the reverse diff results of repository in given commit ID to io.Writer.

func GetSigningKey added in v1.26.0

func GetSigningKey(ctx context.Context) (*git.SigningKey, *git.Signature)

func GitConfigAdd added in v1.25.0

func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error

GitConfigAdd add a git configuration key to a specific value for the given repository.

func GitConfigGet added in v1.25.0

func GitConfigGet(ctx context.Context, repo Repository, key string) (string, error)

func GitConfigSet added in v1.25.0

func GitConfigSet(ctx context.Context, repo Repository, key, value string) error

GitConfigSet updates a git configuration key to a specific value for the given repository. If the key does not exist, it will be created. If the key exists, it will be updated to the new value.

func GitRemoteAdd added in v1.25.0

func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...RemoteOption) error

func GitRemoteGetURL added in v1.25.0

func GitRemoteGetURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error)

GitRemoteGetURL returns the url of a specific remote of the repository.

func GitRemoteRemove added in v1.25.0

func GitRemoteRemove(ctx context.Context, repo Repository, remoteName string) error

func InitRepository added in v1.25.0

func InitRepository(ctx context.Context, repo Repository, objectFormatName string) error

func IsBranchExist added in v1.24.0

func IsBranchExist(ctx context.Context, repo Repository, name string) bool

IsBranchExist returns true if given branch exists in the repository.

func IsReferenceExist added in v1.24.0

func IsReferenceExist(ctx context.Context, repo Repository, name string) bool

IsReferenceExist returns true if given reference exists in the repository.

func IsRepoDirExist added in v1.26.0

func IsRepoDirExist(ctx context.Context, repo Repository, relativeDirPath string) (bool, error)

func IsRepoFileExist added in v1.26.0

func IsRepoFileExist(ctx context.Context, repo Repository, relativeFilePath string) (bool, error)

func IsRepositoryExist added in v1.24.0

func IsRepositoryExist(ctx context.Context, repo Repository) (bool, error)

IsRepositoryExist returns true if the repository directory exists in the disk

func IsTagExist added in v1.24.0

func IsTagExist(ctx context.Context, repo Repository, name string) bool

IsTagExist returns true if given tag exists in the repository.

func LineBlame added in v1.26.0

func LineBlame(ctx context.Context, repo Repository, revision, file string, line uint) (string, error)

func MergeBase added in v1.26.0

func MergeBase(ctx context.Context, repo Repository, baseCommitID, headCommitID string) (string, error)

MergeBase checks and returns merge base of two commits.

func MergeTree added in v1.26.0

func MergeTree(ctx context.Context, repo Repository, baseRef, headRef, mergeBase string) (treeID string, isErrHasConflicts bool, conflictFiles []string, _ error)

MergeTree performs a merge between two commits (baseRef and headRef) with an optional merge base. It returns the resulting tree hash, a list of conflicted files (if any), and an error if the operation fails. If there are no conflicts, the list of conflicted files will be nil.

func NewBatch added in v1.26.0

func NewBatch(ctx context.Context, repo Repository) (git.CatFileBatchCloser, error)

func OpenRepository

func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error)

OpenRepository opens the repository at the given relative path with the provided context.

func Push added in v1.26.0

func Push(ctx context.Context, fromRepo, toRepo Repository, opts git.PushOptions) error

Push pushes from one managed repository to another managed repository.

func PushFromLocal added in v1.26.0

func PushFromLocal(ctx context.Context, fromLocalPath string, toRepo Repository, opts git.PushOptions) error

PushFromLocal pushes from a local path to a managed repository.

func PushToExternal added in v1.26.0

func PushToExternal(ctx context.Context, repo Repository, opts git.PushOptions) error

PushToExternal pushes a managed repository to an external remote.

func RemoveRef added in v1.25.0

func RemoveRef(ctx context.Context, repo Repository, refName string) error

func RemoveRepoFileOrDir added in v1.26.0

func RemoveRepoFileOrDir(ctx context.Context, repo Repository, relativeFileOrDirPath string) error

func RenameBranch added in v1.26.0

func RenameBranch(ctx context.Context, repo Repository, from, to string) error

RenameBranch rename a branch

func RenameRepository added in v1.24.0

func RenameRepository(ctx context.Context, repo, newRepo Repository) error

RenameRepository renames a repository's name on disk

func RepoGitURL added in v1.23.0

func RepoGitURL(repo Repository) string

func RepositoryFromContextOrOpen

func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Repository, io.Closer, error)

RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it The caller must call "defer gitRepo.Close()"

func RepositoryFromRequestContextOrOpen added in v1.24.0

func RepositoryFromRequestContextOrOpen(ctx reqctx.RequestContext, repo Repository) (*git.Repository, error)

RepositoryFromRequestContextOrOpen opens the repository at the given relative path in the provided request context. Caller shouldn't close the git repo manually, the git repo will be automatically closed when the request context is done.

func RunCmd added in v1.26.0

func RunCmd(ctx context.Context, repo Repository, cmd *gitcmd.Command) error

func RunCmdBytes added in v1.26.0

func RunCmdBytes(ctx context.Context, repo Repository, cmd *gitcmd.Command) ([]byte, []byte, gitcmd.RunStdError)

func RunCmdString added in v1.26.0

func RunCmdString(ctx context.Context, repo Repository, cmd *gitcmd.Command) (string, string, gitcmd.RunStdError)

func RunCmdWithStderr added in v1.26.0

func RunCmdWithStderr(ctx context.Context, repo Repository, cmd *gitcmd.Command) gitcmd.RunStdError

func SetDefaultBranch

func SetDefaultBranch(ctx context.Context, repo Repository, name string) error

SetDefaultBranch sets default branch of repository.

func UpdateRef added in v1.25.0

func UpdateRef(ctx context.Context, repo Repository, refName, newCommitID string) error

func UpdateServerInfo added in v1.26.0

func UpdateServerInfo(ctx context.Context, repo Repository) error

func WalkReferences

func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error)

WalkReferences walks all the references from the repository

func WriteCommitGraph added in v1.26.0

func WriteCommitGraph(ctx context.Context, repo Repository) error

Types

type BlamePart added in v1.26.0

type BlamePart struct {
	Sha          string
	Lines        []string
	PreviousSha  string
	PreviousPath string
}

BlamePart represents block of blame - continuous lines with one sha

type BlameReader added in v1.26.0

type BlameReader struct {
	// contains filtered or unexported fields
}

BlameReader returns part of file blame one by one

func CreateBlameReader added in v1.26.0

func CreateBlameReader(ctx context.Context, objectFormat git.ObjectFormat, repo Repository, commit *git.Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, retErr error)

CreateBlameReader creates reader for given repository, commit and file

func (*BlameReader) Close added in v1.26.0

func (r *BlameReader) Close() error

Close BlameReader - don't run NextPart after invoking that

func (*BlameReader) NextPart added in v1.26.0

func (r *BlameReader) NextPart() (*BlamePart, error)

NextPart returns next part of blame (sequential code lines with the same commit)

func (*BlameReader) UsesIgnoreRevs added in v1.26.0

func (r *BlameReader) UsesIgnoreRevs() bool

type CommitFileStatus added in v1.26.0

type CommitFileStatus struct {
	Added    []string
	Removed  []string
	Modified []string
}

CommitFileStatus represents status of files in a commit.

func GetCommitFileStatus added in v1.26.0

func GetCommitFileStatus(ctx context.Context, repo Repository, commitID string) (*CommitFileStatus, error)

GetCommitFileStatus returns file status of commit in given repository.

func NewCommitFileStatus added in v1.26.0

func NewCommitFileStatus() *CommitFileStatus

NewCommitFileStatus creates a CommitFileStatus

type CommitsCountOptions added in v1.26.0

type CommitsCountOptions struct {
	Not      string
	Revision []string
	RelPath  []string
	Since    string
	Until    string
}

CommitsCountOptions the options when counting commits

type DivergeObject added in v1.26.0

type DivergeObject struct {
	Ahead  int
	Behind int
}

DivergeObject represents commit count diverging commits

func GetDivergingCommits added in v1.26.0

func GetDivergingCommits(ctx context.Context, repo Repository, baseBranch, targetBranch string) (*DivergeObject, error)

GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch

type RemoteOption added in v1.25.0

type RemoteOption string
const (
	RemoteOptionMirrorPush  RemoteOption = "--mirror=push"
	RemoteOptionMirrorFetch RemoteOption = "--mirror=fetch"
)

type Repository

type Repository interface {
	RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
}

Repository represents a git repository which stored in a disk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL