api

package
v1.0.0-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const BranchPrefix = "refs/heads/"

BranchPrefix base dir of the branch information file store on git.

View Source
const (
	// GitTimeLayout is the (default) time layout used by git.
	GitTimeLayout = "Mon Jan _2 15:04:05 2006 -0700"
)
View Source
const (
	// RemotePrefix is the base directory of the remotes information of git.
	RemotePrefix = "refs/remotes/"
)
View Source
const TagPrefix = "refs/tags/"

TagPrefix tags prefix path on the repository.

Variables

View Source
var (
	ErrInvalidPath         = errors.New("path is invalid")
	ErrRepositoryPathEmpty = errors.InvalidArgument("repository path cannot be empty")
	ErrBranchNameEmpty     = errors.InvalidArgument("branch name cannot be empty")
	ErrParseDiffHunkHeader = errors.Internal(nil, "failed to parse diff hunk header")
	ErrNoDefaultBranch     = errors.New("no default branch")
	ErrInvalidSignature    = errors.New("invalid signature")
)

Functions

func CleanUploadFileName

func CleanUploadFileName(name string) string

CleanUploadFileName Trims a filename and returns empty string if it is a .git directory.

func GetReferenceFromBranchName

func GetReferenceFromBranchName(branchName string) string

GetReferenceFromBranchName assumes the provided value is the branch name (not the ref!) and first sanitizes the branch name (remove any spaces or 'refs/heads/' prefix) It then returns the full form of the branch reference.

func GetReferenceFromTagName

func GetReferenceFromTagName(tagName string) string

func GetSubModules

func GetSubModules(rd *BlobReader) (map[string]*Submodule, error)

GetSubModules get all the sub modules of current revision git tree.

func IsErrMoreThanOne

func IsErrMoreThanOne(err error) bool

IsErrMoreThanOne checks if an error is a MoreThanOneError.

func IsErrPushRejected

func IsErrPushRejected(err error) bool

IsErrPushRejected checks if an error is a PushRejectedError.

func IsMergeUnrelatedHistoriesError

func IsMergeUnrelatedHistoriesError(err error) bool

func NewInMemoryLastCommitCache

func NewInMemoryLastCommitCache(
	cacheDuration time.Duration,
) cache.Cache[CommitEntryKey, *Commit]

func NewRedisLastCommitCache

func NewRedisLastCommitCache(
	redisClient redis.UniversalClient,
	cacheDuration time.Duration,
) (cache.Cache[CommitEntryKey, *Commit], error)

func NoLastCommitCache

func NoLastCommitCache() cache.Cache[CommitEntryKey, *Commit]

func ProvideLastCommitCache

func ProvideLastCommitCache(
	config types.Config,
	redisClient redis.UniversalClient,
) (cache.Cache[CommitEntryKey, *Commit], error)

func SanitizeCredentialURLs

func SanitizeCredentialURLs(s string) string

SanitizeCredentialURLs remove all credentials in URLs (starting with "scheme://") for the input string: "https://user:pass@domain.com" => "https://sanitized-credential@domain.com"

Types

type ArchiveAttribute

type ArchiveAttribute string
const (
	ArchiveAttributeExportIgnore ArchiveAttribute = "export-ignore"
	ArchiveAttributeExportSubst  ArchiveAttribute = "export-subst"
)

func (ArchiveAttribute) Validate

func (f ArchiveAttribute) Validate() error

type ArchiveFormat

type ArchiveFormat string
const (
	ArchiveFormatTar   ArchiveFormat = "tar"
	ArchiveFormatZip   ArchiveFormat = "zip"
	ArchiveFormatTarGz ArchiveFormat = "tar.gz"
	ArchiveFormatTgz   ArchiveFormat = "tgz"
)

func ParseArchiveFormat

func ParseArchiveFormat(format string) (ArchiveFormat, error)

func (ArchiveFormat) Validate

func (f ArchiveFormat) Validate() error

type ArchiveParams

type ArchiveParams struct {
	// Format of the resulting archive. Possible values are tar, zip, tar.gz, tgz,
	// and any format defined using the configuration option tar.<format>.command
	// If --format is not given, and the output file is specified, the format is inferred
	// from the filename if possible (e.g. writing to foo.zip makes the output to be in the zip format),
	// Otherwise the output format is tar.
	Format ArchiveFormat

	// Prefix prepend <prefix>/ to paths in the archive. Can be repeated; its rightmost value is used
	// for all tracked files.
	Prefix string

	// Write the archive to <file> instead of stdout.
	File string

	// export-ignore
	// Files and directories with the attribute export-ignore won’t be added to archive files.
	// See gitattributes[5] for details.
	//
	// export-subst
	// If the attribute export-subst is set for a file then Git will expand several placeholders
	// when adding this file to an archive. See gitattributes[5] for details.
	Attributes ArchiveAttribute

	// Set modification time of archive entries. Without this option the committer time is
	// used if <tree-ish> is a commit or tag, and the current time if it is a tree.
	Time *time.Time

	// Compression is level used for tar.gz and zip packers.
	Compression *int

	// The tree or commit to produce an archive for.
	Treeish string

	// Paths is optional parameter, all files and subdirectories of the
	// current working directory are included in the archive, if one or more paths
	// are specified, only these are included.
	Paths []string
}

func (*ArchiveParams) Validate

func (p *ArchiveParams) Validate() error

type BatchHeaderResponse

type BatchHeaderResponse struct {
	SHA  sha.SHA
	Type string
	Size int64
}

func ReadBatchHeaderLine

func ReadBatchHeaderLine(rd *bufio.Reader) (*BatchHeaderResponse, error)

ReadBatchHeaderLine reads the header line from cat-file --batch <sha> SP <type> SP <size> LF sha is a 40byte not 20byte here.

type BlameNextReader

type BlameNextReader interface {
	NextPart() (*BlamePart, error)
}

type BlamePart

type BlamePart struct {
	Commit *Commit  `json:"commit"`
	Lines  []string `json:"lines"`
}

type BlameReader

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

func (*BlameReader) NextPart

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

type BlobReader

type BlobReader struct {
	SHA sha.SHA
	// Size is the actual size of the blob.
	Size int64
	// ContentSize is the total number of bytes returned by the Content Reader.
	ContentSize int64
	// Content contains the (partial) content of the blob.
	Content io.ReadCloser
}

func GetBlob

func GetBlob(
	ctx context.Context,
	repoPath string,
	alternateObjectDirs []string,
	sha sha.SHA,
	sizeLimit int64,
) (*BlobReader, error)

GetBlob returns the blob for the given object sha.

type Branch

type Branch struct {
	Name   string
	SHA    sha.SHA
	Commit *Commit
}

type BranchFilter

type BranchFilter struct {
	Query         string
	Page          int32
	PageSize      int32
	Sort          GitReferenceField
	Order         SortOrder
	IncludeCommit bool
}

type CloneRepoOptions

type CloneRepoOptions struct {
	Timeout       time.Duration
	Mirror        bool
	Bare          bool
	Quiet         bool
	Branch        string
	Shared        bool
	NoCheckout    bool
	Depth         int
	Filter        string
	SkipTLSVerify bool
}

type Commit

type Commit struct {
	SHA        sha.SHA   `json:"sha"`
	Title      string    `json:"title"`
	Message    string    `json:"message,omitempty"`
	Author     Signature `json:"author"`
	Committer  Signature `json:"committer"`
	Signature  *CommitGPGSignature
	ParentSHAs []sha.SHA
	FileStats  []CommitFileStats `json:"file_stats,omitempty"`
}

func CommitFromReader

func CommitFromReader(commitSHA sha.SHA, reader io.Reader) (*Commit, error)

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 GetCommit

func GetCommit(
	ctx context.Context,
	repoPath string,
	rev string,
) (*Commit, error)

GetCommit returns info about a commit. TODO: Move this function outside of the api package.

type CommitChangesOptions

type CommitChangesOptions struct {
	Committer Signature
	Author    Signature
	Message   string
}

type CommitDivergence

type CommitDivergence struct {
	// Ahead is the count of commits the 'From' ref is ahead of the 'To' ref.
	Ahead int32
	// Behind is the count of commits the 'From' ref is behind the 'To' ref.
	Behind int32
}

CommitDivergence contains the information of the count of converging commits between two refs.

type CommitDivergenceRequest

type CommitDivergenceRequest struct {
	// From is the ref from which the counting of the diverging commits starts.
	From string
	// To is the ref at which the counting of the diverging commits ends.
	To string
}

CommitDivergenceRequest contains the refs for which the converging commits should be counted.

type CommitEntryKey

type CommitEntryKey string

func (CommitEntryKey) Split

func (c CommitEntryKey) Split() (
	repoPath string,
	commitSHA string,
	path string,
)

type CommitFileStats

type CommitFileStats struct {
	ChangeType enum.FileDiffStatus
	Path       string
	OldPath    string // populated only in case of renames
	Insertions int64
	Deletions  int64
}

type CommitFilter

type CommitFilter struct {
	Path      string
	AfterRef  string
	Since     int64
	Until     int64
	Committer string
}

type CommitGPGSignature

type CommitGPGSignature struct {
	Signature string
	Payload   string
}

CommitGPGSignature represents a git commit signature part.

type CreateTagOptions

type CreateTagOptions struct {
	// Message is the optional message the tag will be created with - if the message is empty
	// the tag will be lightweight, otherwise it'll be annotated.
	Message string

	// Tagger is the information used in case the tag is annotated (Message is provided).
	Tagger Signature
}

type DiffShortStat

type DiffShortStat struct {
	Files     int
	Additions int
	Deletions int
}

func GetDiffShortStat

func GetDiffShortStat(
	ctx context.Context,
	repoPath string,
	args ...string,
) (DiffShortStat, error)

GetDiffShortStat counts number of changed files, number of additions and deletions.

type FS

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

FS represents a git filesystem. It implements fs.FS interface.

func NewFS

func NewFS(ctx context.Context, rev, dir string) *FS

NewFS creates a new git file system for the provided revision.

func (*FS) Glob

func (f *FS) Glob(pattern string) ([]string, error)

Glob returns all file names that match the pattern. It is part of the fs.GlobFS interface.

func (*FS) Open

func (f *FS) Open(path string) (fs.File, error)

Open opens a file. It is part of the fs.FS interface.

func (*FS) ReadDir

func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir returns all entries for a directory. It is part of the fs.ReadDirFS interface.

func (*FS) ReadFile

func (f *FS) ReadFile(path string) ([]byte, error)

ReadFile reads the whole file. It is part of the fs.ReadFileFS interface.

func (*FS) Stat

func (f *FS) Stat(name string) (fs.FileInfo, error)

Stat returns entry file info for a file path. It is part of the fs.StatFS interface.

type FileContent

type FileContent struct {
	Path    string
	Content []byte
}

type FileDiffRequest

type FileDiffRequest struct {
	Path      string `json:"path"`
	StartLine int    `json:"start_line"`
	EndLine   int    `json:"-"` // warning: changes are possible and this field may not exist in the future
}

type FileDiffRequests

type FileDiffRequests []FileDiffRequest

type Git

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

func New

func New(
	config types.Config,
	lastCommitCache cache.Cache[CommitEntryKey, *Commit],
	githookFactory hook.ClientFactory,
) (*Git, error)

func (*Git) AddFiles

func (g *Git) AddFiles(
	ctx context.Context,
	repoPath string,
	all bool,
	files ...string,
) error

func (*Git) Archive

func (g *Git) Archive(ctx context.Context, repoPath string, params ArchiveParams, w io.Writer) error

func (*Git) Blame

func (g *Git) Blame(
	ctx context.Context,
	repoPath string,
	rev string,
	file string,
	lineFrom int,
	lineTo int,
) BlameNextReader

func (*Git) Clone

func (g *Git) Clone(
	ctx context.Context,
	from string,
	to string,
	opts CloneRepoOptions,
) error

func (*Git) Commit

func (g *Git) Commit(
	ctx context.Context,
	repoPath string,
	opts CommitChangesOptions,
) error

Commit commits the changes of the repository.

func (*Git) CommitDiff

func (g *Git) CommitDiff(
	ctx context.Context,
	repoPath string,
	rev string,
	w io.Writer,
) error

CommitDiff will stream diff for provided ref.

func (*Git) Config

func (g *Git) Config(
	ctx context.Context,
	repoPath string,
	key string,
	value string,
) error

Config set local git key and value configuration.

func (*Git) CountObjects

func (g *Git) CountObjects(ctx context.Context, repoPath string) (ObjectCount, error)

func (*Git) CreateTag

func (g *Git) CreateTag(
	ctx context.Context,
	repoPath string,
	name string,
	targetSHA sha.SHA,
	opts *CreateTagOptions,
) error

CreateTag creates the tag pointing at the provided SHA (could be any type, e.g. commit, tag, blob, ...)

func (*Git) DiffCut

func (g *Git) DiffCut(
	ctx context.Context,
	repoPath string,
	targetRef string,
	sourceRef string,
	path string,
	params parser.DiffCutParams,
) (parser.HunkHeader, parser.Hunk, error)

DiffCut parses full file git diff output and returns lines specified with the parameters. The purpose of this function is to get diff data with which code comments could be generated.

func (*Git) DiffFileName

func (g *Git) DiffFileName(ctx context.Context,
	repoPath string,
	baseRef string,
	headRef string,
	mergeBase bool,
) ([]string, error)

func (*Git) DiffShortStat

func (g *Git) DiffShortStat(
	ctx context.Context,
	repoPath string,
	baseRef string,
	headRef string,
	useMergeBase bool,
) (DiffShortStat, error)

func (*Git) GetAnnotatedTag

func (g *Git) GetAnnotatedTag(
	ctx context.Context,
	repoPath string,
	rev string,
) (*Tag, error)

GetAnnotatedTag returns the tag for a specific tag sha.

func (*Git) GetAnnotatedTags

func (g *Git) GetAnnotatedTags(
	ctx context.Context,
	repoPath string,
	revs []string,
) ([]Tag, error)

GetAnnotatedTags returns the tags for a specific list of tag sha.

func (*Git) GetBranch

func (g *Git) GetBranch(
	ctx context.Context,
	repoPath string,
	branchName string,
) (*Branch, error)

GetBranch gets an existing branch.

func (*Git) GetBranchCount

func (g *Git) GetBranchCount(
	ctx context.Context,
	repoPath string,
) (int, error)

func (*Git) GetCommit

func (g *Git) GetCommit(
	ctx context.Context,
	repoPath string,
	rev string,
) (*Commit, error)

GetCommit returns the (latest) commit for a specific revision.

func (*Git) GetCommitDivergences

func (g *Git) GetCommitDivergences(
	ctx context.Context,
	repoPath string,
	requests []CommitDivergenceRequest,
	max int32,
) ([]CommitDivergence, error)

GetCommitDivergences returns the count of the diverging commits for all branch pairs. IMPORTANT: If a max is provided it limits the overal count of diverging commits (max 10 could lead to (0, 10) while it's actually (2, 12)).

func (*Git) GetCommits

func (g *Git) GetCommits(
	ctx context.Context,
	repoPath string,
	refs []string,
) ([]*Commit, error)

GetCommits returns the (latest) commits for a specific list of refs. Note: ref can be Branch / Tag / CommitSHA.

func (*Git) GetDefaultBranch

func (g *Git) GetDefaultBranch(
	ctx context.Context,
	repoPath string,
) (string, error)

GetDefaultBranch gets the default branch of a repo.

func (*Git) GetDiffHunkHeaders

func (g *Git) GetDiffHunkHeaders(
	ctx context.Context,
	repoPath string,
	targetRef string,
	sourceRef string,
) ([]*parser.DiffFileHunkHeaders, error)

GetDiffHunkHeaders for each file in diff output returns file name (old and new to detect renames), and all hunk headers. The diffs are generated with unified=0 parameter to create minimum sized hunks. Hunks' body is ignored. The purpose of this function is to get data based on which code comments could be repositioned.

func (*Git) GetFullCommitID

func (g *Git) GetFullCommitID(
	ctx context.Context,
	repoPath string,
	shortID string,
) (sha.SHA, error)

func (*Git) GetLatestCommit

func (g *Git) GetLatestCommit(
	ctx context.Context,
	repoPath string,
	rev string,
	treePath string,
) (*Commit, error)

GetLatestCommit gets the latest commit of a path relative from the provided revision.

func (*Git) GetMergeBase

func (g *Git) GetMergeBase(
	ctx context.Context,
	repoPath string,
	remote string,
	base string,
	head string,
) (sha.SHA, string, error)

GetMergeBase checks and returns merge base of two branches and the reference used as base.

func (*Git) GetRef

func (g *Git) GetRef(
	ctx context.Context,
	repoPath string,
	ref string,
) (sha.SHA, error)

GetRef get's the target of a reference IMPORTANT provide full reference name to limit risk of collisions across reference types (e.g `refs/heads/main` instead of `main`).

func (*Git) GetRemoteDefaultBranch

func (g *Git) GetRemoteDefaultBranch(
	ctx context.Context,
	remoteURL string,
) (string, error)

GetRemoteDefaultBranch retrieves the default branch of a remote repository. If the repo doesn't have a default branch, types.ErrNoDefaultBranch is returned.

func (*Git) GetSubmodule

func (g *Git) GetSubmodule(
	ctx context.Context,
	repoPath string,
	ref string,
	treePath string,
) (*Submodule, error)

GetSubmodule returns the submodule at the given path reachable from ref. Note: ref can be Branch / Tag / CommitSHA.

func (*Git) GetTagCount

func (g *Git) GetTagCount(
	ctx context.Context,
	repoPath string,
) (int, error)

func (*Git) GetTreeNode

func (g *Git) GetTreeNode(ctx context.Context, repoPath, rev, treePath string) (*TreeNode, error)

GetTreeNode returns the tree node at the given path as found for the provided reference.

func (*Git) HasBranches

func (g *Git) HasBranches(
	ctx context.Context,
	repoPath string,
) (bool, error)

HasBranches returns true iff there's at least one branch in the repo (any branch) NOTE: This is different from repo.Empty(), as it doesn't care whether the existing branch is the default branch or not.

func (*Git) HashObject

func (g *Git) HashObject(ctx context.Context, repoPath string, reader io.Reader) (sha.SHA, error)

func (*Git) InfoRefs

func (g *Git) InfoRefs(
	ctx context.Context,
	repoPath string,
	service string,
	w io.Writer,
	env ...string,
) error

func (*Git) InitRepository

func (g *Git) InitRepository(
	ctx context.Context,
	repoPath string,
	bare bool,
) error

InitRepository initializes a new Git repository.

func (*Git) IsAncestor

func (g *Git) IsAncestor(
	ctx context.Context,
	repoPath string,
	alternates []string,
	ancestorCommitSHA,
	descendantCommitSHA sha.SHA,
) (bool, error)

IsAncestor returns if the provided commit SHA is ancestor of the other commit SHA.

func (*Git) IsBranchExist

func (g *Git) IsBranchExist(ctx context.Context, repoPath, name string) (bool, error)

func (*Git) ListCommitSHAs

func (g *Git) ListCommitSHAs(
	ctx context.Context,
	repoPath string,
	alternateObjectDirs []string,
	ref string,
	page int,
	limit int,
	filter CommitFilter,
) ([]string, error)

ListCommitSHAs lists the commits reachable from ref. Note: ref & afterRef can be Branch / Tag / CommitSHA. Note: commits returned are [ref->...->afterRef).

func (*Git) ListCommits

func (g *Git) ListCommits(
	ctx context.Context,
	repoPath string,
	ref string,
	page int,
	limit int,
	includeStats bool,
	filter CommitFilter,
) ([]*Commit, []PathRenameDetails, error)

ListCommits lists the commits reachable from ref. Note: ref & afterRef can be Branch / Tag / CommitSHA. Note: commits returned are [ref->...->afterRef).

func (*Git) ListPaths

func (g *Git) ListPaths(
	ctx context.Context,
	repoPath string,
	rev string,
	includeDirs bool,
) (files []string, dirs []string, err error)

ListPaths lists all the paths in a repo recursively (similar-ish to `ls -lR`). Note: Keep method simple for now to avoid unnecessary corner cases by always listing whole repo content (and not relative to any directory).

func (*Git) ListTreeNodes

func (g *Git) ListTreeNodes(ctx context.Context, repoPath, rev, treePath string) ([]TreeNode, error)

ListTreeNodes lists the child nodes of a tree reachable from ref via the specified path.

func (*Git) MatchFiles

func (g *Git) MatchFiles(
	ctx context.Context,
	repoPath string,
	rev string,
	treePath string,
	pattern string,
	maxSize int,
) ([]FileContent, error)

func (*Git) PathsDetails

func (g *Git) PathsDetails(ctx context.Context,
	repoPath string,
	rev string,
	paths []string,
) ([]PathDetails, error)

PathsDetails returns additional details about provided the paths.

func (*Git) Push

func (g *Git) Push(
	ctx context.Context,
	repoPath string,
	opts PushOptions,
) error

Push pushs local commits to given remote branch. TODOD: return our own error types and move to above api.Push method

func (*Git) RawDiff

func (g *Git) RawDiff(
	ctx context.Context,
	w io.Writer,
	repoPath string,
	baseRef string,
	headRef string,
	mergeBase bool,
	alternates []string,
	files ...FileDiffRequest,
) error

func (*Git) ReadTree

func (g *Git) ReadTree(
	ctx context.Context,
	repoPath string,
	ref string,
	w io.Writer,
	args ...string,
) error

func (*Git) ResolveRev

func (g *Git) ResolveRev(ctx context.Context,
	repoPath string,
	rev string,
) (sha.SHA, error)

func (*Git) ServicePack

func (g *Git) ServicePack(
	ctx context.Context,
	repoPath string,
	options ServicePackOptions,
) error

func (*Git) SetDefaultBranch

func (g *Git) SetDefaultBranch(
	ctx context.Context,
	repoPath string,
	defaultBranch string,
	allowEmpty bool,
) error

SetDefaultBranch sets the default branch of a repo.

func (*Git) Sync

func (g *Git) Sync(
	ctx context.Context,
	repoPath string,
	source string,
	refSpecs []string,
) error

Sync synchronizes the repository to match the provided source. NOTE: This is a read operation and doesn't trigger any server side hooks.

func (*Git) WalkReferences

func (g *Git) WalkReferences(
	ctx context.Context,
	repoPath string,
	handler WalkReferencesHandler,
	opts *WalkReferencesOptions,
) error

WalkReferences uses the provided options to filter the available references of the repo, and calls the handle function for every matching node. The instructor & handler are called with a map that contains the matching value for every field provided in fields. TODO: walkReferences related code should be moved to separate file.

type GitObjectType

type GitObjectType string
const (
	GitObjectTypeCommit GitObjectType = "commit"
	GitObjectTypeTree   GitObjectType = "tree"
	GitObjectTypeBlob   GitObjectType = "blob"
	GitObjectTypeTag    GitObjectType = "tag"
)

func ParseGitObjectType

func ParseGitObjectType(t string) (GitObjectType, error)

type GitReferenceField

type GitReferenceField string

GitReferenceField represents the different fields available When listing references. For the full list, see https://git-scm.com/docs/git-for-each-ref#_field_names

const (
	GitReferenceFieldRefName     GitReferenceField = "refname"
	GitReferenceFieldObjectType  GitReferenceField = "objecttype"
	GitReferenceFieldObjectName  GitReferenceField = "objectname"
	GitReferenceFieldCreatorDate GitReferenceField = "creatordate"
)

func ParseGitReferenceField

func ParseGitReferenceField(f string) (GitReferenceField, error)

type Identity

type Identity struct {
	Name  string
	Email string
}

func (Identity) String

func (i Identity) String() string

func (Identity) Validate

func (i Identity) Validate() error

type MergeUnrelatedHistoriesError

type MergeUnrelatedHistoriesError struct {
	Method enum.MergeMethod
	StdOut string
	StdErr string
	Err    error
}

MergeUnrelatedHistoriesError represents an error if merging fails due to unrelated histories.

func (*MergeUnrelatedHistoriesError) Error

func (*MergeUnrelatedHistoriesError) Is

func (e *MergeUnrelatedHistoriesError) Is(target error) bool

func (*MergeUnrelatedHistoriesError) Unwrap

func (e *MergeUnrelatedHistoriesError) Unwrap() error

type MoreThanOneError

type MoreThanOneError struct {
	StdOut string
	StdErr string
	Err    error
}

MoreThanOneError represents an error when there are more than one sources (branch, tag) with the same name.

func (*MoreThanOneError) Error

func (err *MoreThanOneError) Error() string

type ObjectCount

type ObjectCount struct {
	Count         int
	Size          int64
	InPack        int
	Packs         int
	SizePack      int64
	PrunePackable int
	Garbage       int
	SizeGarbage   int64
}

ObjectCount represents the parsed information from the `git count-objects -v` command. For field meanings, see https://git-scm.com/docs/git-count-objects#_options.

type PathDetails

type PathDetails struct {
	Path       string
	LastCommit *Commit
}

type PathRenameDetails

type PathRenameDetails struct {
	OldPath         string
	Path            string
	CommitSHABefore sha.SHA
	CommitSHAAfter  sha.SHA
}

type PushOptions

type PushOptions struct {
	Remote         string
	Branch         string
	Force          bool
	ForceWithLease string
	Env            []string
	Timeout        time.Duration
	Mirror         bool
}

type PushOutOfDateError

type PushOutOfDateError struct {
	StdOut string
	StdErr string
	Err    error
}

PushOutOfDateError represents an error if merging fails due to unrelated histories.

func (*PushOutOfDateError) Error

func (err *PushOutOfDateError) Error() string

func (*PushOutOfDateError) Unwrap

func (err *PushOutOfDateError) Unwrap() error

Unwrap unwraps the underlying error.

type PushRejectedError

type PushRejectedError struct {
	Message string
	StdOut  string
	StdErr  string
	Err     error
}

PushRejectedError represents an error if merging fails due to rejection from a hook.

func (*PushRejectedError) Error

func (err *PushRejectedError) Error() string

func (*PushRejectedError) GenerateMessage

func (err *PushRejectedError) GenerateMessage()

GenerateMessage generates the remote message from the stderr.

func (*PushRejectedError) Unwrap

func (err *PushRejectedError) Unwrap() error

Unwrap unwraps the underlying error.

type ServicePackOptions

type ServicePackOptions struct {
	Service      enum.GitServiceType
	Timeout      int // seconds
	StatelessRPC bool
	Stdout       io.Writer
	Stdin        io.Reader
	Stderr       io.Writer
	Env          []string
	Protocol     string
}

type Signature

type Signature struct {
	Identity Identity
	// When is the timestamp of the Signature.
	When time.Time
}

Signature represents the Author or Committer information.

func DecodeSignature

func DecodeSignature(b []byte) (Signature, error)

DecodeSignature decodes a byte array representing a signature to signature.

func NewSignatureFromCommitLine

func NewSignatureFromCommitLine(line []byte) (Signature, error)

func (Signature) String

func (s Signature) String() string

type SortOrder

type SortOrder int
const (
	SortOrderDefault SortOrder = iota
	SortOrderAsc
	SortOrderDesc
)

type Submodule

type Submodule struct {
	Name string
	URL  string
}

type Tag

type Tag struct {
	Sha        sha.SHA
	Name       string
	TargetSha  sha.SHA
	TargetType GitObjectType
	Title      string
	Message    string
	Tagger     Signature
	Signature  *CommitGPGSignature
}

type TreeNode

type TreeNode struct {
	NodeType TreeNodeType
	Mode     TreeNodeMode
	SHA      sha.SHA
	Name     string
	Path     string
	Size     int64
}

func GetTreeNode

func GetTreeNode(ctx context.Context, repoPath, rev, treePath string, fetchSize bool) (*TreeNode, error)

GetTreeNode returns the tree node at the given path as found for the provided reference.

func ListTreeNodes

func ListTreeNodes(ctx context.Context, repoPath, rev, treePath string, fetchSizes bool) ([]TreeNode, error)

ListTreeNodes lists the child nodes of a tree reachable from ref via the specified path.

func (*TreeNode) IsDir

func (n *TreeNode) IsDir() bool

func (*TreeNode) IsExecutable

func (n *TreeNode) IsExecutable() bool
func (n *TreeNode) IsLink() bool

func (*TreeNode) IsSubmodule

func (n *TreeNode) IsSubmodule() bool

type TreeNodeMode

type TreeNodeMode int

TreeNodeMode specifies the different modes of a node in a git tree. IMPORTANT: has to be consistent with rpc.TreeNodeMode (proto).

const (
	TreeNodeModeFile TreeNodeMode = iota
	TreeNodeModeSymlink
	TreeNodeModeExec
	TreeNodeModeTree
	TreeNodeModeCommit
)

func (TreeNodeMode) String

func (m TreeNodeMode) String() string

type TreeNodeType

type TreeNodeType int

TreeNodeType specifies the different types of nodes in a git tree. IMPORTANT: has to be consistent with rpc.TreeNodeType (proto).

const (
	TreeNodeTypeTree TreeNodeType = iota
	TreeNodeTypeBlob
	TreeNodeTypeCommit
)

type TreeNodeWithCommit

type TreeNodeWithCommit struct {
	TreeNode
	Commit *Commit
}

type WalkInstruction

type WalkInstruction int
const (
	WalkInstructionStop WalkInstruction = iota
	WalkInstructionHandle
	WalkInstructionSkip
)

func DefaultInstructor

func DefaultInstructor(
	_ WalkReferencesEntry,
) (WalkInstruction, error)

type WalkReferencesEntry

type WalkReferencesEntry map[GitReferenceField]string

type WalkReferencesHandler

type WalkReferencesHandler func(WalkReferencesEntry) error

TODO: can be generic (so other walk methods can use the same)

type WalkReferencesInstructor

type WalkReferencesInstructor func(WalkReferencesEntry) (WalkInstruction, error)

TODO: can be generic (so other walk methods can use the same)

type WalkReferencesOptions

type WalkReferencesOptions struct {
	// Patterns are the patterns used to pre-filter the references of the repo.
	// OPTIONAL. By default all references are walked.
	Patterns []string

	// Fields indicates the fields that are passed to the instructor & handler
	// OPTIONAL. Default fields are:
	// - GitReferenceFieldRefName
	// - GitReferenceFieldObjectName
	Fields []GitReferenceField

	// Instructor indicates on how to handle the reference.
	// OPTIONAL. By default all references are handled.
	// NOTE: once walkInstructionStop is returned, the walking stops.
	Instructor WalkReferencesInstructor

	// Sort indicates the field by which the references should be sorted.
	// OPTIONAL. By default GitReferenceFieldRefName is used.
	Sort GitReferenceField

	// Order indicates the Order (asc or desc) of the sorted output
	Order SortOrder

	// MaxWalkDistance is the maximum number of nodes that are iterated over before the walking stops.
	// OPTIONAL. A value of <= 0 will walk all references.
	// WARNING: Skipped elements count towards the walking distance
	MaxWalkDistance int32
}

type WriteCloserError

type WriteCloserError interface {
	io.WriteCloser
	CloseWithError(err error) error
}

WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function.

func CatFileBatch

func CatFileBatch(
	ctx context.Context,
	repoPath string,
	alternateObjectDirs []string,
	flags ...command.CmdOptionFunc,
) (WriteCloserError, *bufio.Reader, func())

CatFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function.

func CatFileBatchCheck

func CatFileBatchCheck(
	ctx context.Context,
	repoPath string,
	alternateObjectDirs []string,
	flags ...command.CmdOptionFunc,
) (WriteCloserError, *bufio.Reader, func())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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