git

package
v3.73.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitRepo sources.SourceUnitKind = "repo"
	UnitDir  sources.SourceUnitKind = "dir"
)

Variables

This section is empty.

Functions

func CleanOnError

func CleanOnError(err *error, path string)

func CloneRepo

func CloneRepo(ctx context.Context, userInfo *url.Userinfo, gitURL string, args ...string) (string, *git.Repository, error)

CloneRepo orchestrates the cloning of a given Git repository, returning its local path and a git.Repository object for further operations. The function sets up error handling infrastructure, ensuring that any encountered errors trigger a cleanup of resources. The core cloning logic is delegated to a nested function, which returns errors to the outer function for centralized error handling and cleanup.

func CloneRepoUsingSSH added in v3.8.0

func CloneRepoUsingSSH(ctx context.Context, gitURL string, args ...string) (string, *git.Repository, error)

CloneRepoUsingSSH clones a repo using SSH.

func CloneRepoUsingToken

func CloneRepoUsingToken(ctx context.Context, token, gitUrl, user string, args ...string) (string, *git.Repository, error)

CloneRepoUsingToken clones a repo using a provided token.

func CloneRepoUsingUnauthenticated

func CloneRepoUsingUnauthenticated(ctx context.Context, url string, args ...string) (string, *git.Repository, error)

CloneRepoUsingUnauthenticated clones a repo with no authentication required.

func CmdCheck added in v3.63.3

func CmdCheck() error

CmdCheck checks if git is installed and meets 2.20.0<=x<3.0.0 version requirements.

func GitURLParse added in v3.44.0

func GitURLParse(gitURL string) (*url.URL, error)

func PingRepoUsingToken added in v3.56.0

func PingRepoUsingToken(ctx context.Context, token, gitUrl, user string) error

PingRepoUsingToken executes git ls-remote on a repo and returns any error that occurs. It can be used to validate that a repo actually exists and is reachable.

Pinging using other authentication methods is only unimplemented because there's been no pressing need for it yet.

func PrepareRepo

func PrepareRepo(ctx context.Context, uriString string) (string, bool, error)

PrepareRepo clones a repo if possible and returns the cloned repo path.

func RepoFromPath

func RepoFromPath(path string, isBare bool) (*git.Repository, error)

func TryAdditionalBaseRefs

func TryAdditionalBaseRefs(repo *git.Repository, base string) (*plumbing.Hash, error)

TryAdditionalBaseRefs looks for additional possible base refs for a repo and returns a hash if found.

func UnmarshalUnit added in v3.41.1

func UnmarshalUnit(data []byte) (sources.SourceUnit, error)

Helper function to unmarshal raw bytes into our SourceUnit struct.

Types

type Config added in v3.66.3

type Config struct {
	Concurrency        int
	SourceMetadataFunc func(file, email, commit, timestamp, repository string, line int64) *source_metadatapb.MetaData

	SourceName   string
	JobID        sources.JobID
	SourceID     sources.SourceID
	SourceType   sourcespb.SourceType
	Verify       bool
	SkipBinaries bool
	SkipArchives bool

	// UseCustomContentWriter indicates whether to use a custom contentWriter.
	// When set to true, the parser will use a custom contentWriter provided through the WithContentWriter option.
	// When false, the parser will use the default buffer (in-memory) contentWriter.
	UseCustomContentWriter bool
}

Config for a Git source.

type Git

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

func NewGit

func NewGit(config *Config) *Git

NewGit creates a new Git instance with the provided configuration. The Git instance is used to interact with Git repositories.

func (*Git) CommitsScanned added in v3.45.1

func (s *Git) CommitsScanned() uint64

func (*Git) ScanCommits

func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string, scanOptions *ScanOptions, reporter sources.ChunkReporter) error

func (*Git) ScanRepo

func (s *Git) ScanRepo(ctx context.Context, repo *git.Repository, repoPath string, scanOptions *ScanOptions, reporter sources.ChunkReporter) error

func (*Git) ScanStaged added in v3.28.5

func (s *Git) ScanStaged(ctx context.Context, repo *git.Repository, path string, scanOptions *ScanOptions, reporter sources.ChunkReporter) error

ScanStaged chunks staged changes.

type ScanOption

type ScanOption func(*ScanOptions)

func ScanOptionBare added in v3.47.0

func ScanOptionBare(bare bool) ScanOption

func ScanOptionBaseHash

func ScanOptionBaseHash(hash string) ScanOption

func ScanOptionExcludeGlobs added in v3.31.0

func ScanOptionExcludeGlobs(globs []string) ScanOption

func ScanOptionFilter

func ScanOptionFilter(filter *common.Filter) ScanOption

func ScanOptionHeadCommit

func ScanOptionHeadCommit(hash string) ScanOption

func ScanOptionLogOptions

func ScanOptionLogOptions(logOptions *git.LogOptions) ScanOption

func ScanOptionMaxDepth

func ScanOptionMaxDepth(maxDepth int64) ScanOption

type ScanOptions

type ScanOptions struct {
	Filter       *common.Filter
	BaseHash     string // When scanning a git.Log, this is the oldest/first commit.
	HeadHash     string
	MaxDepth     int64
	Bare         bool
	ExcludeGlobs []string
	LogOptions   *git.LogOptions
}

func NewScanOptions

func NewScanOptions(options ...ScanOption) *ScanOptions

type Source

type Source struct {
	sources.Progress
	// contains filtered or unexported fields
}

func (*Source) ChunkUnit added in v3.63.0

func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporter sources.ChunkReporter) error

func (*Source) Chunks

func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ ...sources.ChunkingTarget) error

Chunks emits chunks of bytes over a channel.

func (*Source) Enumerate added in v3.63.0

func (s *Source) Enumerate(ctx context.Context, reporter sources.UnitReporter) error

func (*Source) Init

func (s *Source) Init(aCtx context.Context, name string, jobId sources.JobID, sourceId sources.SourceID, verify bool, connection *anypb.Any, concurrency int) error

Init returns an initialized GitHub source.

func (*Source) JobID

func (s *Source) JobID() sources.JobID

func (*Source) SourceID

func (s *Source) SourceID() sources.SourceID

func (*Source) Type

func (s *Source) Type() sourcespb.SourceType

Type returns the type of source. It is used for matching source types in configuration and job input.

func (*Source) UnmarshalSourceUnit added in v3.41.1

func (s *Source) UnmarshalSourceUnit(data []byte) (sources.SourceUnit, error)

func (*Source) WithCustomContentWriter added in v3.66.3

func (s *Source) WithCustomContentWriter()

WithCustomContentWriter sets the useCustomContentWriter flag on the source.

type SourceUnit added in v3.41.1

type SourceUnit struct {
	Kind sources.SourceUnitKind `json:"kind"`
	ID   string                 `json:"id"`
}

A git source unit can be two kinds of units: either a local directory path or a remote repository.

func (SourceUnit) Display added in v3.68.0

func (u SourceUnit) Display() string

Provide a custom Display method.

func (SourceUnit) SourceUnitID added in v3.41.1

func (u SourceUnit) SourceUnitID() (string, sources.SourceUnitKind)

Implement sources.SourceUnit interface.

Jump to

Keyboard shortcuts

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