gitrepo

package
v3.1.32 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllCommitsCount

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

AllCommitsCount returns count of all commits in repository

func CalcRepositorySize

func CalcRepositorySize(repo Repository) (int64, error)

CalcRepositorySize returns the disk consumption for a given path

func CheckDelegateHooks

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

CheckDelegateHooks checks the hooks scripts for the repo

func Clone

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

func CloneExternalRepo

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

CloneExternalRepo clones an external repository to the managed repository.

func CloneRepoToLocal

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

CloneRepoToLocal clones a managed repository to a local path.

func CommitsCount

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

CommitsCount returns number of total commits of until given revision.

func CommitsCountBetween

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

CommitsCountBetween return numbers of commits between two commits

func CommitsCountOfCommit

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

CommitsCountOfCommit returns number of total commits of until current revision.

func CreateArchive

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

CreateArchive create archive content to the target path

func CreateBranch

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

CreateBranch create a new branch

func CreateBundle

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

CreateBundle create bundle content to the target path

func CreateDelegateHooks

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

CreateDelegateHooks creates all the hooks scripts for the repo

func CreateRepoFile

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

func DeleteBranch

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

DeleteBranch delete a branch by name on repository.

func DeleteRepository

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 FileCommitsCount

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

FileCommitsCount return the number of files at a revision

func Fsck

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 GetDefaultBranch

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

GetDefaultBranch gets default branch of repository.

func GetDiffShortStatByCmdArgs

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

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

func GetLatestCommitTime

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

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

func GetRepoFS

func GetRepoFS(repo Repository) fs.FS

func GetReverseRawDiff

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

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

func GitConfigAdd

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

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

func GitConfigSet

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

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

func GitRemoteGetURL

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

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

func GitRemotePrune

func GitRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error

GitRemotePrune prunes the remote branches that no longer exist in the remote repository.

func GitRemoteRemove

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

func GitRemoteUpdatePrune

func GitRemoteUpdatePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error

GitRemoteUpdatePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.

func InitRepository

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

func IsBranchExist

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

IsBranchExist returns true if given branch exists in the repository.

func IsReferenceExist

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

IsReferenceExist returns true if given reference exists in the repository.

func IsRepoDirExist

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

func IsRepoFileExist

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

func IsRepositoryExist

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

IsRepositoryExist returns true if the repository directory exists in the disk

func IsTagExist

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

IsTagExist returns true if given tag exists in the repository.

func LineBlame

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

func NewBatch

func NewBatch(ctx context.Context, repo Repository) (catfile.Batch, 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

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

Push pushes from one managed repository to another managed repository.

func PushFromLocal

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

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

PushToExternal pushes a managed repository to an external remote.

func RemoveRef

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

func RemoveRepoFileOrDir

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

func RenameBranch

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

RenameBranch rename a branch

func RenameRepository

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

RenameRepository renames a repository's name on disk

func RepoGitURL

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

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

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

func RunCmdBytes

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

func RunCmdString

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

func SetDefaultBranch

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

SetDefaultBranch sets default branch of repository.

func UpdateRef

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

func UpdateServerInfo

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

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

Types

type BlamePart

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

BlamePart represents block of blame - continuous lines with one sha

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 git.ObjectFormat, repo Repository, commit *git.Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, err 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 CommitFileStatus

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

CommitFileStatus represents status of files in a commit.

func GetCommitFileStatus

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

GetCommitFileStatus returns file status of commit in given repository.

func NewCommitFileStatus

func NewCommitFileStatus() *CommitFileStatus

NewCommitFileStatus creates a CommitFileStatus

type CommitsCountOptions

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

CommitsCountOptions the options when counting commits

type DivergeObject

type DivergeObject struct {
	Ahead  int
	Behind int
}

DivergeObject represents commit count diverging commits

func GetDivergingCommits

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

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

Source Files

  • archive.go
  • blame.go
  • branch.go
  • cat_file.go
  • clone.go
  • command.go
  • commit.go
  • commit_file.go
  • commitgraph.go
  • compare.go
  • config.go
  • diff.go
  • fsck.go
  • gitrepo.go
  • hooks.go
  • push.go
  • ref.go
  • remote.go
  • signing.go
  • size.go
  • tag.go
  • url.go
  • walk_nogogit.go

Jump to

Keyboard shortcuts

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