files

package
v3.1.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDiffPatch

ApplyDiffPatch applies a patch to the given repository

func ChangeRepoFiles

func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *ChangeRepoFilesOptions) (_ *structs.FilesResponse, errRet error)

ChangeRepoFiles adds, updates or removes multiple files in the given repository

func CherryPick

func CherryPick(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, revert bool, opts *ApplyDiffPatchOptions) (*structs.FileResponse, error)

CherryPick cherry-picks or reverts a commit to the given repository

func CleanGitTreePath

func CleanGitTreePath(name string) string

CleanGitTreePath cleans a tree path for git, it returns an empty string the path is invalid (e.g.: contains ".git" part)

func GetBlobBySHA

func GetBlobBySHA(repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlobResponse, error)

func GetContentsListFromTreePaths

func GetContentsListFromTreePaths(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, treePaths []string) (files []*api.ContentsResponse)

func GetContentsOrList

func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, opts GetContentsOrListOptions) (ret api.ContentsExtResponse, _ error)

GetContentsOrList gets the metadata of a file's contents (*ContentsResponse) if treePath not a tree directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag

func GetDiffPreview

func GetDiffPreview(ctx context.Context, repo *repo_model.Repository, branch, treePath, content string) (*gitdiff.Diff, error)

GetDiffPreview produces and returns diff result of a file which is not yet committed.

func GetFileCommitResponse

func GetFileCommitResponse(repo *repo_model.Repository, commit *git.Commit) (*api.FileCommitResponse, error)

GetFileCommitResponse Constructs a FileCommitResponse from a Commit object

func GetFileContents

func GetFileContents(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, opts GetContentsOrListOptions) (*api.ContentsResponse, error)

GetFileContents gets the metadata on a file's contents. Ref can be a branch, commit or tag

func GetFileResponseFromFilesResponse

func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index int) *api.FileResponse

constructs a FileResponse with the file at the index from FilesResponse

func GetFilesResponseFromCommit

func GetFilesResponseFromCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, refCommit *utils.RefCommit, treeNames []string) (*api.FilesResponse, error)

func GetPayloadCommitVerification

func GetPayloadCommitVerification(ctx context.Context, commit *git.Commit) *structs.PayloadCommitVerification

GetPayloadCommitVerification returns the verification information of a commit

func GetTreeBySHA

func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error)

GetTreeBySHA get the GitTreeResponse of a repository using a sha hash.

func IsErrCommitIDDoesNotMatch

func IsErrCommitIDDoesNotMatch(err error) bool

IsErrCommitIDDoesNotMatch checks if an error is a ErrCommitIDDoesNotMatch.

func IsErrFilePathInvalid

func IsErrFilePathInvalid(err error) bool

IsErrFilePathInvalid checks if an error is an ErrFilePathInvalid.

func IsErrFilenameInvalid

func IsErrFilenameInvalid(err error) bool

IsErrFilenameInvalid checks if an error is an ErrFilenameInvalid.

func IsErrRepoFileAlreadyExists

func IsErrRepoFileAlreadyExists(err error) bool

IsErrRepoFileAlreadyExists checks if an error is a ErrRepoFileAlreadyExists.

func IsErrSHANotFound

func IsErrSHANotFound(err error) bool

IsErrSHANotFound checks if an error is a ErrSHANotFound.

func IsErrSHAOrCommitIDNotProvided

func IsErrSHAOrCommitIDNotProvided(err error) bool

IsErrSHAOrCommitIDNotProvided checks if an error is a ErrSHAOrCommitIDNotProvided.

func IsErrUserCannotCommit

func IsErrUserCannotCommit(err error) bool

IsErrUserCannotCommit checks if an error is an ErrUserCannotCommit.

func UploadRepoFiles

func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error

UploadRepoFiles uploads files to the given repository

func VerifyBranchProtection

func VerifyBranchProtection(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doer *user_model.User, branchName string, treePaths []string) error

VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch

Types

type ApplyDiffPatchOptions

type ApplyDiffPatchOptions struct {
	LastCommitID string
	OldBranch    string
	NewBranch    string
	Message      string
	Content      string
	Author       *IdentityOptions
	Committer    *IdentityOptions
	Dates        *CommitDateOptions
	Signoff      bool
}

ApplyDiffPatchOptions holds the repository diff patch update options

func (*ApplyDiffPatchOptions) Validate

func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, doer *user_model.User) error

Validate validates the provided options

type ChangeRepoFile

type ChangeRepoFile struct {
	Operation     string
	TreePath      string
	FromTreePath  string
	ContentReader io.ReadSeeker
	SHA           string

	DeleteRecursively bool // when deleting, work as `git rm -r ...`

	Options *RepoFileOptions // FIXME: need to refactor, internal usage only
}

type ChangeRepoFilesOptions

type ChangeRepoFilesOptions struct {
	LastCommitID string
	OldBranch    string
	NewBranch    string
	Message      string
	Files        []*ChangeRepoFile
	Author       *IdentityOptions
	Committer    *IdentityOptions
	Dates        *CommitDateOptions
	Signoff      bool
	ForcePush    bool
}

ChangeRepoFilesOptions holds the repository files update options

type CommitDateOptions

type CommitDateOptions struct {
	Author    time.Time
	Committer time.Time
}

CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE

type CommitTreeUserOptions

type CommitTreeUserOptions struct {
	ParentCommitID string
	TreeHash       string
	CommitMessage  string
	SignOff        bool

	DoerUser *user_model.User

	AuthorIdentity    *IdentityOptions // if nil, use doer
	AuthorTime        *time.Time       // if nil, use now
	CommitterIdentity *IdentityOptions
	CommitterTime     *time.Time
}

type ContentType

type ContentType string

ContentType repo content type

const (
	ContentTypeRegular   ContentType = "file"      // regular content type (file)
	ContentTypeDir       ContentType = "dir"       // dir content type (dir)
	ContentTypeLink      ContentType = "symlink"   // link content type (symlink)
	ContentTypeSubmodule ContentType = "submodule" // submodule content type (submodule)
)

The string representations of different content types

func GetObjectTypeFromTreeEntry

func GetObjectTypeFromTreeEntry(entry *git.TreeEntry) ContentType

GetObjectTypeFromTreeEntry check what content is behind it

func (*ContentType) String

func (ct *ContentType) String() string

String gets the string of ContentType

type ErrCommitIDDoesNotMatch

type ErrCommitIDDoesNotMatch struct {
	GivenCommitID   string
	CurrentCommitID string
}

ErrCommitIDDoesNotMatch represents a "CommitIDDoesNotMatch" kind of error.

func (ErrCommitIDDoesNotMatch) Error

func (err ErrCommitIDDoesNotMatch) Error() string

type ErrFilePathInvalid

type ErrFilePathInvalid struct {
	Message string
	Path    string
	Name    string
	Type    git.EntryMode
}

ErrFilePathInvalid represents a "FilePathInvalid" kind of error.

func (ErrFilePathInvalid) Error

func (err ErrFilePathInvalid) Error() string

func (ErrFilePathInvalid) Unwrap

func (err ErrFilePathInvalid) Unwrap() error

type ErrFilenameInvalid

type ErrFilenameInvalid struct {
	Path string
}

ErrFilenameInvalid represents a "FilenameInvalid" kind of error.

func (ErrFilenameInvalid) Error

func (err ErrFilenameInvalid) Error() string

func (ErrFilenameInvalid) Unwrap

func (err ErrFilenameInvalid) Unwrap() error

type ErrRepoFileAlreadyExists

type ErrRepoFileAlreadyExists struct {
	Path string
}

ErrRepoFileAlreadyExists represents a "RepoFileAlreadyExist" kind of error.

func (ErrRepoFileAlreadyExists) Error

func (err ErrRepoFileAlreadyExists) Error() string

func (ErrRepoFileAlreadyExists) Unwrap

func (err ErrRepoFileAlreadyExists) Unwrap() error

type ErrSHANotFound

type ErrSHANotFound struct {
	SHA string
}

ErrSHANotFound represents a "SHADoesNotMatch" kind of error.

func (ErrSHANotFound) Error

func (err ErrSHANotFound) Error() string

func (ErrSHANotFound) Unwrap

func (err ErrSHANotFound) Unwrap() error

type ErrSHAOrCommitIDNotProvided

type ErrSHAOrCommitIDNotProvided struct{}

ErrSHAOrCommitIDNotProvided represents a "SHAOrCommitIDNotProvided" kind of error.

func (ErrSHAOrCommitIDNotProvided) Error

func (err ErrSHAOrCommitIDNotProvided) Error() string

type ErrUserCannotCommit

type ErrUserCannotCommit struct {
	UserName string
}

ErrUserCannotCommit represents "UserCannotCommit" kind of error.

func (ErrUserCannotCommit) Error

func (err ErrUserCannotCommit) Error() string

func (ErrUserCannotCommit) Unwrap

func (err ErrUserCannotCommit) Unwrap() error

type GetContentsOrListOptions

type GetContentsOrListOptions struct {
	TreePath                 string
	IncludeSingleFileContent bool // include the file's content when the tree path is a file
	IncludeLfsMetadata       bool
	IncludeCommitMetadata    bool
	IncludeCommitMessage     bool
}

type IdentityOptions

type IdentityOptions struct {
	GitUserName  string // to match "git config user.name"
	GitUserEmail string // to match "git config user.email"
}

IdentityOptions for a person's identity like an author or committer

type LazyReadSeeker

type LazyReadSeeker interface {
	io.ReadSeeker
	io.Closer
	OpenLazyReader() error
}

type RepoFileOptions

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

type TemporaryUploadRepository

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

TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone

func NewTemporaryUploadRepository

func NewTemporaryUploadRepository(repo *repo_model.Repository) (*TemporaryUploadRepository, error)

NewTemporaryUploadRepository creates a new temporary upload repository

func (*TemporaryUploadRepository) AddObjectToIndex

func (t *TemporaryUploadRepository) AddObjectToIndex(ctx context.Context, mode, objectHash, objectPath string) error

AddObjectToIndex adds the provided object hash to the index with the provided mode and path

func (*TemporaryUploadRepository) Clone

func (t *TemporaryUploadRepository) Clone(ctx context.Context, branch string, bare bool) error

Clone the base repository to our path and set branch as the HEAD

func (*TemporaryUploadRepository) Close

func (t *TemporaryUploadRepository) Close()

Close the repository cleaning up all files

func (*TemporaryUploadRepository) CommitTree

CommitTree creates a commit from a given tree for the user with provided message

func (*TemporaryUploadRepository) DiffIndex

DiffIndex returns a Diff of the current index to the head

func (*TemporaryUploadRepository) GetBranchCommit

func (t *TemporaryUploadRepository) GetBranchCommit(branch string) (*git.Commit, error)

GetBranchCommit Gets the commit object of the given branch

func (*TemporaryUploadRepository) GetCommit

func (t *TemporaryUploadRepository) GetCommit(commitID string) (*git.Commit, error)

GetCommit Gets the commit object of the given commit ID

func (*TemporaryUploadRepository) GetLastCommit

func (t *TemporaryUploadRepository) GetLastCommit(ctx context.Context) (string, error)

GetLastCommit gets the last commit ID SHA of the repo

func (*TemporaryUploadRepository) GetLastCommitByRef

func (t *TemporaryUploadRepository) GetLastCommitByRef(ctx context.Context, ref string) (string, error)

GetLastCommitByRef gets the last commit ID SHA of the repo by ref

func (*TemporaryUploadRepository) HashObjectAndWrite

func (t *TemporaryUploadRepository) HashObjectAndWrite(ctx context.Context, content io.Reader) (string, error)

HashObjectAndWrite writes the provided content to the object db and returns its hash

func (*TemporaryUploadRepository) Init

func (t *TemporaryUploadRepository) Init(ctx context.Context, objectFormatName string) error

Init the repository

func (*TemporaryUploadRepository) LsFiles

func (t *TemporaryUploadRepository) LsFiles(ctx context.Context, filenames ...string) ([]string, error)

LsFiles checks if the given filename arguments are in the index

func (*TemporaryUploadRepository) Push

func (t *TemporaryUploadRepository) Push(ctx context.Context, doer *user_model.User, commitHash, branch string, force bool) error

Push the provided commitHash to the repository branch by the provided user

func (*TemporaryUploadRepository) RefreshIndex

func (t *TemporaryUploadRepository) RefreshIndex(ctx context.Context) error

RefreshIndex looks at the current index and checks to see if merges or updates are needed by checking stat() information.

func (*TemporaryUploadRepository) RemoveFilesFromIndex

func (t *TemporaryUploadRepository) RemoveFilesFromIndex(ctx context.Context, filenames ...string) error

RemoveFilesFromIndex removes the given files from the index

func (*TemporaryUploadRepository) RemoveRecursivelyFromIndex

func (t *TemporaryUploadRepository) RemoveRecursivelyFromIndex(ctx context.Context, path string) error

func (*TemporaryUploadRepository) SetDefaultIndex

func (t *TemporaryUploadRepository) SetDefaultIndex(ctx context.Context) error

SetDefaultIndex sets the git index to our HEAD

func (*TemporaryUploadRepository) WriteTree

func (t *TemporaryUploadRepository) WriteTree(ctx context.Context) (string, error)

WriteTree writes the current index as a tree to the object db and returns its hash

type TreeViewNode

type TreeViewNode struct {
	EntryName     string        `json:"entryName"`
	EntryMode     string        `json:"entryMode"`
	EntryIcon     template.HTML `json:"entryIcon"`
	EntryIconOpen template.HTML `json:"entryIconOpen,omitempty"`

	SymLinkedToMode string `json:"symLinkedToMode,omitempty"` // TODO: for the EntryMode="symlink"

	FullPath     string          `json:"fullPath"`
	SubmoduleURL string          `json:"submoduleUrl,omitempty"`
	Children     []*TreeViewNode `json:"children,omitempty"`
}

func GetTreeViewNodes

func GetTreeViewNodes(ctx context.Context, repoLink string, renderedIconPool *fileicon.RenderedIconPool, commit *git.Commit, treePath, subPath string) ([]*TreeViewNode, error)

type UploadRepoFileOptions

type UploadRepoFileOptions struct {
	LastCommitID string
	OldBranch    string
	NewBranch    string
	TreePath     string
	Message      string
	Files        []string // In UUID format.
	Signoff      bool
	Author       *IdentityOptions
	Committer    *IdentityOptions
}

UploadRepoFileOptions contains the uploaded repository file options

Source Files

  • cherry_pick.go
  • commit.go
  • content.go
  • diff.go
  • file.go
  • patch.go
  • temp_repo.go
  • tree.go
  • update.go
  • upload.go

Jump to

Keyboard shortcuts

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