git

package
v3.1.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBranchIsProtected = util.ErrorWrap(util.ErrPermissionDenied, "branch is protected")
View Source
var ErrLFSObjectNotExist = db.ErrNotExist{Resource: "LFS Meta object"}

ErrLFSObjectNotExist is returned from lfs models functions in order to differentiate between database and missing object errors.

Functions

func AddBranches

func AddBranches(ctx context.Context, branches []*Branch) error

func AddDeletedBranch

func AddDeletedBranch(ctx context.Context, repoID int64, branchName string, deletedByID int64) error

AddDeletedBranch adds a deleted branch to the database

func BranchesToNamesSet

func BranchesToNamesSet(branches []*Branch) container.Set[string]

func CommitStatusesHideActionsURL

func CommitStatusesHideActionsURL(ctx context.Context, statuses []*CommitStatus)

CommitStatusesHideActionsURL hide Gitea Actions urls

func CopyLFS

func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error

CopyLFS copies LFS data from one repo to another

func CountLFSLockByRepoID

func CountLFSLockByRepoID(ctx context.Context, repoID int64) (int64, error)

CountLFSLockByRepoID returns a count of all LFSLocks associated with a repository.

func CountLFSMetaObjects

func CountLFSMetaObjects(ctx context.Context, repoID int64) (int64, error)

CountLFSMetaObjects returns a count of all LFSMetaObjects associated with a repository

func CountLatestCommitStatus

func CountLatestCommitStatus(ctx context.Context, repoID int64, sha string) (int64, error)

func DeleteBranches

func DeleteBranches(ctx context.Context, repoID, doerID int64, branchIDs []int64) error

func DeleteProtectedBranch

func DeleteProtectedBranch(ctx context.Context, repo *repo_model.Repository, id int64) (err error)

DeleteProtectedBranch removes ProtectedBranch relation between the user and repository.

func DeleteProtectedTag

func DeleteProtectedTag(ctx context.Context, pt *ProtectedTag) error

DeleteProtectedTag deletes a protected tag by ID

func DeleteRepoBranches

func DeleteRepoBranches(ctx context.Context, repoID int64) error

func ExistsLFSObject

func ExistsLFSObject(ctx context.Context, oid string) (bool, error)

ExistsLFSObject checks if a provided Oid exists within the DB

func FindAllMatchedBranches

func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string) ([]string, error)

FindAllMatchedBranches find all matched branches

func FindBranchNames

func FindBranchNames(ctx context.Context, opts FindBranchOptions) ([]string, error)

func FindBranchesByRepoAndBranchName

func FindBranchesByRepoAndBranchName(ctx context.Context, repoBranches map[int64]string) (map[int64]string, error)

func FindRepoRecentCommitStatusContexts

func FindRepoRecentCommitStatusContexts(ctx context.Context, repoID int64, before time.Duration) ([]string, error)

FindRepoRecentCommitStatusContexts returns repository's recent commit status contexts

func GetLatestCommitStatusForPairs

func GetLatestCommitStatusForPairs(ctx context.Context, repoSHAs []RepoSHA) (map[int64][]*CommitStatus, error)

GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs

func GetLatestCommitStatusForRepoCommitIDs

func GetLatestCommitStatusForRepoCommitIDs(ctx context.Context, repoID int64, commitIDs []string) (map[string][]*CommitStatus, error)

GetLatestCommitStatusForRepoCommitIDs returns all statuses with a unique context for a given list of repo-sha pairs

func GetNextCommitStatusIndex

func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (int64, error)

GetNextCommitStatusIndex retried 3 times to generate a resource index

func GetRepoLFSSize

func GetRepoLFSSize(ctx context.Context, repoID int64) (int64, error)

GetRepoLFSSize return a repository's lfs files size

func InsertProtectedTag

func InsertProtectedTag(ctx context.Context, pt *ProtectedTag) error

InsertProtectedTag inserts a protected tag to database

func IsBranchExist

func IsBranchExist(ctx context.Context, repoID int64, branchName string) (bool, error)

IsBranchExist returns true if the branch exists in the repository.

func IsBranchProtected

func IsBranchProtected(ctx context.Context, repoID int64, branchName string) (bool, error)

IsBranchProtected checks if branch is protected

func IsErrBranchAlreadyExists

func IsErrBranchAlreadyExists(err error) bool

IsErrBranchAlreadyExists checks if an error is an ErrBranchAlreadyExists.

func IsErrBranchNameConflict

func IsErrBranchNameConflict(err error) bool

IsErrBranchNameConflict checks if an error is an ErrBranchNameConflict.

func IsErrBranchNotExist

func IsErrBranchNotExist(err error) bool

IsErrBranchNotExist checks if an error is an ErrBranchDoesNotExist.

func IsErrBranchesEqual

func IsErrBranchesEqual(err error) bool

IsErrBranchesEqual checks if an error is an ErrBranchesEqual.

func IsErrLFSLockAlreadyExist

func IsErrLFSLockAlreadyExist(err error) bool

IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.

func IsErrLFSLockNotExist

func IsErrLFSLockNotExist(err error) bool

IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.

func IsRuleNameSpecial

func IsRuleNameSpecial(ruleName string) bool

IsRuleNameSpecial return true if it contains special character

func IsUserAllowedModifyTag

func IsUserAllowedModifyTag(ctx context.Context, pt *ProtectedTag, userID int64) (bool, error)

IsUserAllowedModifyTag returns true if the user is allowed to modify the tag

func IsUserAllowedToControlTag

func IsUserAllowedToControlTag(ctx context.Context, tags []*ProtectedTag, tagName string, userID int64) (bool, error)

IsUserAllowedToControlTag checks if a user can control the specific tag. It returns true if the tag name is not protected or the user is allowed to control it.

func IsUserMergeWhitelisted

func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch, userID int64, permissionInRepo access_model.Permission) bool

IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch

func IsUserOfficialReviewer

func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error)

IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)

func IterateLFSMetaObjectsForRepo

func IterateLFSMetaObjectsForRepo(ctx context.Context, repoID int64, f func(context.Context, *LFSMetaObject, int64) error, opts *IterateLFSMetaObjectsForRepoOptions) error

IterateLFSMetaObjectsForRepo provides a iterator for LFSMetaObjects per Repo

func IterateRepositoryIDsWithLFSMetaObjects

func IterateRepositoryIDsWithLFSMetaObjects(ctx context.Context, f func(ctx context.Context, repoID, count int64) error) error

IterateRepositoryIDsWithLFSMetaObjects iterates across the repositories that have LFSMetaObjects

func LFSAutoAssociate

func LFSAutoAssociate(ctx context.Context, metas []*LFSMetaObject, user *user_model.User, repoID int64) error

LFSAutoAssociate auto associates accessible LFSMetaObjects

func LFSObjectAccessible

func LFSObjectAccessible(ctx context.Context, user *user_model.User, oid string) (bool, error)

LFSObjectAccessible checks if a provided Oid is accessible to the user

func MarkLFSMetaObject

func MarkLFSMetaObject(ctx context.Context, id int64) error

MarkLFSMetaObject updates the updated time for the provided LFSMetaObject

func NewCommitStatus

func NewCommitStatus(ctx context.Context, opts NewCommitStatusOptions) error

NewCommitStatus save commit statuses into database

func RemoveDeletedBranchByID

func RemoveDeletedBranchByID(ctx context.Context, repoID, branchID int64) error

func RemoveLFSMetaObjectByOid

func RemoveLFSMetaObjectByOid(ctx context.Context, repoID int64, oid string) (int64, error)

RemoveLFSMetaObjectByOid removes a LFSMetaObject entry from database by its OID. It may return ErrLFSObjectNotExist or a database error.

func RemoveLFSMetaObjectByOidFn

func RemoveLFSMetaObjectByOidFn(ctx context.Context, repoID int64, oid string, fn func(count int64) error) (int64, error)

RemoveLFSMetaObjectByOidFn removes a LFSMetaObject entry from database by its OID. It may return ErrLFSObjectNotExist or a database error. It will run Fn with the current count within the transaction

func RemoveOldDeletedBranches

func RemoveOldDeletedBranches(ctx context.Context, olderThan time.Duration)

RemoveOldDeletedBranches removes old deleted branches

func RemoveTeamIDFromProtectedBranch

func RemoveTeamIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, teamID int64) error

RemoveTeamIDFromProtectedBranch removes all team ids from protected branch options

func RemoveUserIDFromProtectedBranch

func RemoveUserIDFromProtectedBranch(ctx context.Context, p *ProtectedBranch, userID int64) error

RemoveUserIDFromProtectedBranch removes all user ids from protected branch options

func RenameBranch

func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to string, gitAction func(ctx context.Context, isDefault bool) error) (err error)

RenameBranch rename a branch

func UpdateBranch

func UpdateBranch(ctx context.Context, repoID, pusherID int64, branchName string, commit *git.Commit) (int64, error)

UpdateBranch updates the branch information in the database.

func UpdateCommitStatusSummary

func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) error

func UpdateProtectBranch

func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error)

UpdateProtectBranch saves branch protection options of repository. If ID is 0, it creates a new record. Otherwise, updates existing record. This function also performs check if whitelist user and team's IDs have been changed to avoid unnecessary whitelist delete and regenerate.

func UpdateProtectBranchPriorities

func UpdateProtectBranchPriorities(ctx context.Context, repo *repo_model.Repository, ids []int64) error

func UpdateProtectedTag

func UpdateProtectedTag(ctx context.Context, pt *ProtectedTag) error

UpdateProtectedTag updates the protected tag

Types

type Branch

type Branch struct {
	ID            int64
	RepoID        int64                  `xorm:"UNIQUE(s)"`
	Repo          *repo_model.Repository `xorm:"-"`
	Name          string                 `xorm:"UNIQUE(s) NOT NULL"` // git's ref-name is case-sensitive internally, however, in some databases (mssql, mysql, by default), it's case-insensitive at the moment
	CommitID      string
	CommitMessage string `xorm:"TEXT"` // it only stores the message summary (the first line)
	PusherID      int64
	Pusher        *user_model.User `xorm:"-"`
	IsDeleted     bool             `xorm:"index"`
	DeletedByID   int64
	DeletedBy     *user_model.User   `xorm:"-"`
	DeletedUnix   timeutil.TimeStamp `xorm:"index"`
	CommitTime    timeutil.TimeStamp // The commit
	CreatedUnix   timeutil.TimeStamp `xorm:"created"`
	UpdatedUnix   timeutil.TimeStamp `xorm:"updated"`
}

Branch represents a branch of a repository For those repository who have many branches, stored into database is a good choice for pagination, keyword search and filtering

func GetBranch

func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, error)

func GetBranches

func GetBranches(ctx context.Context, repoID int64, branchNames []string, includeDeleted bool) ([]*Branch, error)

func GetDeletedBranchByID

func GetDeletedBranchByID(ctx context.Context, repoID, branchID int64) (*Branch, error)

func (*Branch) LoadDeletedBy

func (b *Branch) LoadDeletedBy(ctx context.Context) (err error)

func (*Branch) LoadPusher

func (b *Branch) LoadPusher(ctx context.Context) (err error)

func (*Branch) LoadRepo

func (b *Branch) LoadRepo(ctx context.Context) (err error)

type BranchList

type BranchList []*Branch

func (BranchList) LoadDeletedBy

func (branches BranchList) LoadDeletedBy(ctx context.Context) error

func (BranchList) LoadPusher

func (branches BranchList) LoadPusher(ctx context.Context) error

func (BranchList) LoadRepo

func (branches BranchList) LoadRepo(ctx context.Context) error

type CommitStatus

type CommitStatus struct {
	ID     int64                          `xorm:"pk autoincr"`
	Index  int64                          `xorm:"INDEX UNIQUE(repo_sha_index)"`
	RepoID int64                          `xorm:"INDEX UNIQUE(repo_sha_index)"`
	Repo   *repo_model.Repository         `xorm:"-"`
	State  commitstatus.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
	SHA    string                         `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"`

	// TargetURL points to the commit status page reported by a CI system
	// If Gitea Actions is used, it is a relative link like "{RepoLink}/actions/runs/{RunID}/jobs{JobID}"
	TargetURL string `xorm:"TEXT"`

	Description string           `xorm:"TEXT"`
	ContextHash string           `xorm:"VARCHAR(64) index"`
	Context     string           `xorm:"TEXT"`
	Creator     *user_model.User `xorm:"-"`
	CreatorID   int64

	CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
	UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}

CommitStatus holds a single Status of a single Commit

func CalcCommitStatus

func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus

CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc

func GetLatestCommitStatus

func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, error)

GetLatestCommitStatus returns all statuses with a unique context for a given commit.

func GetLatestCommitStatusForRepoAndSHAs

func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA) ([]*CommitStatus, error)

func (*CommitStatus) APIURL

func (status *CommitStatus) APIURL(ctx context.Context) string

APIURL returns the absolute APIURL to this commit-status.

func (*CommitStatus) HideActionsURL

func (status *CommitStatus) HideActionsURL(ctx context.Context)

HideActionsURL set `TargetURL` to an empty string if the status comes from Gitea Actions

func (*CommitStatus) LocaleString

func (status *CommitStatus) LocaleString(lang translation.Locale) string

LocaleString returns the locale string name of the Status

func (*CommitStatus) ParseGiteaActionsTargetURL

func (status *CommitStatus) ParseGiteaActionsTargetURL(ctx context.Context) (runID, jobID int64, ok bool)

ParseGiteaActionsTargetURL parses the commit status target URL as Gitea Actions link

type CommitStatusIndex

type CommitStatusIndex struct {
	ID       int64
	RepoID   int64  `xorm:"unique(repo_sha)"`
	SHA      string `xorm:"unique(repo_sha)"`
	MaxIndex int64  `xorm:"index"`
}

CommitStatusIndex represents a table for commit status index

type CommitStatusOptions

type CommitStatusOptions struct {
	db.ListOptions
	RepoID   int64
	SHA      string
	State    string
	SortType string
}

CommitStatusOptions holds the options for query commit statuses

func (*CommitStatusOptions) ToConds

func (opts *CommitStatusOptions) ToConds() builder.Cond

func (*CommitStatusOptions) ToOrders

func (opts *CommitStatusOptions) ToOrders() string

type CommitStatusSummary

type CommitStatusSummary struct {
	ID        int64                          `xorm:"pk autoincr"`
	RepoID    int64                          `xorm:"INDEX UNIQUE(repo_id_sha)"`
	SHA       string                         `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
	State     commitstatus.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
	TargetURL string                         `xorm:"TEXT"`
}

CommitStatusSummary holds the latest commit Status of a single Commit

type ErrBranchAlreadyExists

type ErrBranchAlreadyExists struct {
	BranchName string
}

ErrBranchAlreadyExists represents an error that branch with such name already exists.

func (ErrBranchAlreadyExists) Error

func (err ErrBranchAlreadyExists) Error() string

func (ErrBranchAlreadyExists) Unwrap

func (err ErrBranchAlreadyExists) Unwrap() error

type ErrBranchNameConflict

type ErrBranchNameConflict struct {
	BranchName string
}

ErrBranchNameConflict represents an error that branch name conflicts with other branch.

func (ErrBranchNameConflict) Error

func (err ErrBranchNameConflict) Error() string

func (ErrBranchNameConflict) Unwrap

func (err ErrBranchNameConflict) Unwrap() error

type ErrBranchNotExist

type ErrBranchNotExist struct {
	RepoID     int64
	BranchName string
}

ErrBranchNotExist represents an error that branch with such name does not exist.

func (ErrBranchNotExist) Error

func (err ErrBranchNotExist) Error() string

func (ErrBranchNotExist) Unwrap

func (err ErrBranchNotExist) Unwrap() error

type ErrBranchesEqual

type ErrBranchesEqual struct {
	BaseBranchName string
	HeadBranchName string
}

ErrBranchesEqual represents an error that base branch is equal to the head branch.

func (ErrBranchesEqual) Error

func (err ErrBranchesEqual) Error() string

func (ErrBranchesEqual) Unwrap

func (err ErrBranchesEqual) Unwrap() error

type ErrLFSFileLocked

type ErrLFSFileLocked struct {
	RepoID   int64
	Path     string
	UserName string
}

ErrLFSFileLocked represents a "LFSFileLocked" kind of error.

func (ErrLFSFileLocked) Error

func (err ErrLFSFileLocked) Error() string

func (ErrLFSFileLocked) Unwrap

func (err ErrLFSFileLocked) Unwrap() error

type ErrLFSLockAlreadyExist

type ErrLFSLockAlreadyExist struct {
	RepoID int64
	Path   string
}

ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.

func (ErrLFSLockAlreadyExist) Error

func (err ErrLFSLockAlreadyExist) Error() string

func (ErrLFSLockAlreadyExist) Unwrap

func (err ErrLFSLockAlreadyExist) Unwrap() error

type ErrLFSLockNotExist

type ErrLFSLockNotExist struct {
	ID     int64
	RepoID int64
	Path   string
}

ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.

func (ErrLFSLockNotExist) Error

func (err ErrLFSLockNotExist) Error() string

func (ErrLFSLockNotExist) Unwrap

func (err ErrLFSLockNotExist) Unwrap() error

type FindBranchOptions

type FindBranchOptions struct {
	db.ListOptions
	RepoID             int64
	ExcludeBranchNames []string
	IsDeletedBranch    optional.Option[bool]
	OrderBy            string
	Keyword            string
}

func (FindBranchOptions) ToConds

func (opts FindBranchOptions) ToConds() builder.Cond

func (FindBranchOptions) ToOrders

func (opts FindBranchOptions) ToOrders() string

type FindRecentlyPushedNewBranchesOptions

type FindRecentlyPushedNewBranchesOptions struct {
	Repo            *repo_model.Repository
	BaseRepo        *repo_model.Repository
	CommitAfterUnix int64
	MaxCount        int
}

type IterateLFSMetaObjectsForRepoOptions

type IterateLFSMetaObjectsForRepoOptions struct {
	OlderThan                 timeutil.TimeStamp
	UpdatedLessRecentlyThan   timeutil.TimeStamp
	OrderByUpdated            bool
	LoopFunctionAlwaysUpdates bool
}

IterateLFSMetaObjectsForRepoOptions provides options for IterateLFSMetaObjectsForRepo

type LFSLock

type LFSLock struct {
	ID      int64            `xorm:"pk autoincr"`
	RepoID  int64            `xorm:"INDEX NOT NULL"`
	OwnerID int64            `xorm:"INDEX NOT NULL"`
	Owner   *user_model.User `xorm:"-"`
	Path    string           `xorm:"TEXT"`
	Created time.Time        `xorm:"created"`
}

LFSLock represents a git lfs lock of repository.

func CreateLFSLock

func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error)

CreateLFSLock creates a new lock.

func DeleteLFSLockByID

func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repository, u *user_model.