git

package
v0.0.0-...-b94671b Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveCacheDir

func ResolveCacheDir(cacheDir string) string

ResolveCacheDir determines the cache directory to use based on: 1. Explicit cacheDir parameter (highest priority) 2. PROMPT_SYNC_CACHE_DIR environment variable 3. Default: $HOME/.prompt-sync/repos

Types

type Backend

type Backend string

Backend represents the type of Git implementation to use.

const (
	// BackendGoGit uses the pure-Go go-git library.
	BackendGoGit Backend = "go-git"
	// BackendExec uses the system git binary.
	BackendExec Backend = "exec"
	// BackendAuto automatically selects the best backend.
	BackendAuto Backend = "auto"
)

type Fetcher

type Fetcher interface {
	// Clone fetches a repository at the given ref and returns the local path.
	// If already cached, it may return the existing path.
	Clone(repoURL, ref string) (string, error)

	// Update pulls the latest changes for a repository at the given ref.
	// Returns error if the repo is not already cloned.
	Update(repoURL, ref string) error

	// CachedPath returns the local path for a cached repository, if it exists.
	// The bool indicates whether the repo is cached.
	CachedPath(repoURL, ref string) (string, bool)

	// CloneOrUpdate fetches a repository at the given ref and returns the local path and commit hash.
	// If already cached, it updates and returns the existing path.
	CloneOrUpdate(repoURL, ref string) (path string, commit string, err error)
}

Fetcher defines the interface for Git repository operations. Implementations may use go-git, exec git, or other backends.

func NewExecFetcher

func NewExecFetcher(options ...Option) Fetcher

NewExecFetcher creates a GitFetcher that shells out to system git.

func NewFetcher

func NewFetcher(options ...Option) Fetcher

NewFetcher creates a new GitFetcher with the given options.

func NewFetcherWithBackend

func NewFetcherWithBackend(backend Backend, options ...Option) Fetcher

NewFetcherWithBackend creates a GitFetcher with the specified backend.

type Option

type Option func(*Options)

Option is a function that configures a Fetcher

func WithCacheDir

func WithCacheDir(dir string) Option

WithCacheDir sets a custom cache directory

func WithOfflineMode

func WithOfflineMode() Option

WithOfflineMode enables offline mode

type Options

type Options struct {
	CacheDir string // Base directory for git cache (default: $HOME/.prompt-sync/repos)
	Offline  bool   // If true, only use cached repos (no network access)
}

Options configures a GitFetcher instance.

Jump to

Keyboard shortcuts

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