repostore

package
v0.0.0-...-5106b98 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileNotFound      = xerror.NotFound(xerror.RepoFile)
	ErrFileExists        = xerror.AlreadyExists(xerror.RepoFile)
	ErrInvalidPath       = xerror.InvalidInput(xerror.RepoFile)
	ErrRepositorySetup   = xerror.Unavailable(xerror.RepoFile)
	ErrRemoteRefNotFound = xerror.New(
		xerror.KindNotFound,
		"REPOSITORY_REMOTE_REF_NOT_FOUND",
		"remote repository ref not found",
	)
)

Functions

func CheckRemote

func CheckRemote(ctx context.Context, repoURL string, env []string) error

CheckRemote verifies a remote repository is reachable.

func HTTPSAuthEnv

func HTTPSAuthEnv(env []string, username, password string) []string

HTTPSAuthEnv configures Git HTTPS credentials without executable temporary files or secrets in repository URLs, Git configuration values, or process arguments.

func NormalizeRemoteURL

func NormalizeRemoteURL(repoURL string) string

NormalizeRemoteURL returns a stable repo identifier for provider-backed remotes when possible. For GitHub/GitLab, it normalizes SSH/HTTPS variants to "<host>/<owner>/<repo>" without the .git suffix. Unknown formats are returned unchanged (trimmed).

func PrepareRemote

func PrepareRemote(
	ctx context.Context,
	repoURL string,
	env []string,
	policy hostguard.DestinationPolicy,
) (string, []string, error)

PrepareRemote resolves a Git remote once and adds native-Git transport settings that force HTTPS or SSH sockets to a vetted IP while preserving the original hostname for TLS and host keys. HTTPS redirects are disabled because native Git cannot expose each redirect target for revalidation.

func PushRemote

func PushRemote(
	ctx context.Context,
	repoDir, repoURL string,
	env []string,
	opts PushOptions,
) error

PushRemote pushes local commits from repoDir to repoURL.

func SanitizeGitErrorDetail

func SanitizeGitErrorDetail(detail string) string

SanitizeGitErrorDetail removes credential-bearing URLs before Git errors reach operator logs.

func SanitizeRemoteURL

func SanitizeRemoteURL(repoURL string) string

SanitizeRemoteURL removes any embedded userinfo from HTTP(S)/SSH URLs before they are logged, persisted, or surfaced in errors. SCP-style SSH remotes do not encode credentials in the URL and are returned unchanged.

func SanitizedGitEnv

func SanitizedGitEnv(base, extra []string) []string

SanitizedGitEnv returns a child-process environment with inherited Git repository context removed and explicit overrides appended.

func WithNativeFileLimits

func WithNativeFileLimits(ctx context.Context, maxBytes int64) (context.Context, error)

WithNativeFileLimits binds Git helpers to an explicit finite transfer allowance.

Types

type FileEntry

type FileEntry struct {
	Path string
	Size int64
}

FileEntry describes a file returned by ListFiles.

type GitMetadata

type GitMetadata struct {
	SourceRef  *string
	LastCommit *string
}

GitMetadata captures source metadata from a checked-out git repository.

func ResolveGitMetadata

func ResolveGitMetadata(ctx context.Context, repoPath string) GitMetadata

ResolveGitMetadata reads best-effort source metadata from repoPath.

type Provider

type Provider string

Provider identifies a git hosting provider inferred from a repository URL.

const (
	ProviderGeneric Provider = "git"
	ProviderGitHub  Provider = "github"
	ProviderGitLab  Provider = "gitlab"
)

func DetectProvider

func DetectProvider(repoURL string) Provider

DetectProvider infers the provider from a repository URL. Unknown/self-hosted remotes are treated as generic git.

type PushOptions

type PushOptions struct {
	Force   bool
	Refspec string
}

PushOptions controls git push behavior for PushRemote.

type RemoteBranch

type RemoteBranch struct {
	Name      string
	IsDefault bool
}

RemoteBranch describes a branch returned by a remote git repository.

func ListRemoteBranches

func ListRemoteBranches(ctx context.Context, repoURL string, env []string) ([]RemoteBranch, error)

ListRemoteBranches returns visible heads from a remote repository.

type RemoteGit

type RemoteGit interface {
	CheckRemote(ctx context.Context, repoURL string, env []string) error
	ListRemoteBranches(ctx context.Context, repoURL string, env []string) ([]RemoteBranch, error)
	CloneRemote(
		ctx context.Context,
		repoURL, branch string,
		env []string,
	) (RepoStore, string, func(), error)
	PushRemote(ctx context.Context, repoDir, repoURL string, env []string, opts PushOptions) error
}

RemoteGit encapsulates remote git operations.

func NewRemoteGit

func NewRemoteGit() RemoteGit

NewRemoteGit returns the default remote git operation client.

type RepoStore

type RepoStore interface {
	// ReadFile returns up to maxBytes of the file at path. A positive maxBytes
	// must be enforced before the implementation materializes file contents.
	// Returns ErrFileNotFound if the file does not exist.
	ReadFile(ctx context.Context, path string, maxBytes int64) ([]byte, error)

	// WriteFile creates or overwrites the file at path with data.
	// message is an opaque commit description used by git-backed implementations.
	WriteFile(ctx context.Context, path string, data []byte, message string) error

	// DeleteFile removes the file at path.
	// Returns ErrFileNotFound if the file does not exist.
	DeleteFile(ctx context.Context, path, message string) error

	// ListFiles returns all files under dir recursively.
	// Pass "" or "." to list files from the repository root.
	ListFiles(ctx context.Context, dir string) ([]FileEntry, error)

	// FileExists reports whether the file at path exists.
	FileExists(ctx context.Context, path string) (bool, error)
}

RepoStore abstracts a content-addressed file store. Implementations must be safe for sequential use but are not required to be safe for concurrent use.

func CloneNativeFileRemote

func CloneNativeFileRemote(ctx context.Context, repoURL, branch, target string, maxBytes int64, env []string) (RepoStore, string, func(), error)

CloneNativeFileRemote materializes only the selected raw blob, checking its size before checkout when maxBytes is positive. A missing target allows creation.

func CloneRemote

func CloneRemote(
	ctx context.Context,
	repoURL, branch string,
	env []string,
) (RepoStore, string, func(), error)

CloneRemote performs a shallow clone of repoURL into targetDir.

type StreamingStore

type StreamingStore interface {
	ReadFileTo(context.Context, string, int64, io.Writer) (*filestream.Metadata, error)
	WriteFileFrom(context.Context, string, io.Reader, filepayload.Reference, bool, string) error
}

StreamingStore extends checkout storage without requiring snapshot stores to materialize large inputs or pretend to support streaming writes.

Jump to

Keyboard shortcuts

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