core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package core implements the business logic for git-vendor including configuration, syncing, and Git operations.

Index

Constants

View Source
const (
	VendorDir  = "vendor"
	ConfigName = "vendor.yml"
	LockName   = "vendor.lock"
	LicenseDir = "licenses"
)

Constants for the new "Clean Root" structure

View Source
const (
	ErrStaleCommitMsg    = "" /* 252-byte string literal not displayed */
	ErrCheckoutFailed    = "checkout locked hash %s failed: %w"
	ErrRefCheckoutFailed = "checkout ref %s failed: %w"
	ErrPathNotFound      = "path '%s' not found"
	ErrInvalidURL        = "invalid url"
	ErrVendorNotFound    = "vendor '%s' not found"
	ErrComplianceFailed  = "compliance check failed"
)

Error messages

View Source
const ErrNotInitialized = "vendor directory not found. Run 'git-vendor init' first"

ErrNotInitialized is returned when vendor directory doesn't exist

Variables

View Source
var AllowedLicenses = []string{
	"MIT",
	"Apache-2.0",
	"BSD-3-Clause",
	"BSD-2-Clause",
	"ISC",
	"Unlicense",
	"CC0-1.0",
}

AllowedLicenses defines the list of open-source licenses permitted by default.

View Source
var LicenseFileNames = []string{"LICENSE", "LICENSE.txt", "COPYING"}

LicenseFileNames lists standard filenames checked when searching for repository licenses.

View Source
var Verbose = false

Verbose controls whether git commands are logged

Functions

func ComputeAutoPath

func ComputeAutoPath(sourcePath, defaultTarget, fallbackName string) string

ComputeAutoPath generates automatic path name with consistent logic. This consolidates 4 duplicate instances of auto-naming logic in vendor_syncer.go.

Parameters:

  • sourcePath: The source path from the remote repository
  • defaultTarget: Optional default target directory from spec.DefaultTarget
  • fallbackName: Fallback name to use if path cannot be derived (typically vendor name)

Returns: The computed destination path

func FindVendor

func FindVendor(vendors []types.VendorSpec, name string) *types.VendorSpec

FindVendor returns the vendor with matching name, or nil if not found. This consolidates 4 duplicate instances of vendor lookup across vendor_syncer.go

func FindVendorIndex

func FindVendorIndex(vendors []types.VendorSpec, name string) int

FindVendorIndex returns the index of vendor with matching name, or -1 if not found. Useful for update and delete operations that need the index.

func ForEachMapping

func ForEachMapping(vendor *types.VendorSpec, fn func(spec types.BranchSpec, mapping types.PathMapping) error) error

ForEachMapping iterates over all path mappings in a vendor. This replaces duplicate triple-nested loops (2 instances in vendor_syncer.go).

func ForEachVendor

func ForEachVendor(config types.VendorConfig, fn func(types.VendorSpec) error) error

ForEachVendor applies function to each vendor in config. Returns early if function returns an error.

func FormatDiffOutput

func FormatDiffOutput(diff *types.VendorDiff) string

FormatDiffOutput formats a VendorDiff for display

func IsGitInstalled

func IsGitInstalled() bool

IsGitInstalled checks if git is available on the system

func IsVendorInitialized

func IsVendorInitialized() bool

IsVendorInitialized checks if the vendor directory structure exists

func ParseSmartURL

func ParseSmartURL(rawURL string) (baseURL, ref, path string)

ParseSmartURL extracts repository, ref, and path from GitHub URLs

func Pluralize

func Pluralize(count int, singular, plural string) string

Pluralize returns the singular or plural form based on count. Examples:

Pluralize(1, "vendor", "vendors") => "1 vendor"
Pluralize(2, "vendor", "vendors") => "2 vendors"
Pluralize(0, "vendor", "vendors") => "0 vendors"

func ValidateDestPath

func ValidateDestPath(destPath string) error

ValidateDestPath ensures destination path is safe and doesn't allow path traversal

Types

type CacheStore

type CacheStore interface {
	Load(vendorName, ref string) (types.IncrementalSyncCache, error)
	Save(cache *types.IncrementalSyncCache) error
	Delete(vendorName, ref string) error
	ComputeFileChecksum(path string) (string, error)
	BuildCache(vendorName, ref, commitHash string, files []string) (types.IncrementalSyncCache, error)
}

CacheStore handles incremental sync cache I/O operations

type ConfigStore

type ConfigStore interface {
	Load() (types.VendorConfig, error)
	Save(config types.VendorConfig) error
	Path() string
}

ConfigStore handles vendor.yml I/O operations

type CopyStats

type CopyStats struct {
	FileCount int
	ByteCount int64
}

CopyStats tracks file copy statistics

func (*CopyStats) Add

func (s *CopyStats) Add(other CopyStats)

Add adds another CopyStats to this one

type FallbackLicenseChecker

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

FallbackLicenseChecker implements license detection by reading LICENSE files This is used when no API is available (Bitbucket, generic git, or API failures)

func NewFallbackLicenseChecker

func NewFallbackLicenseChecker(fs FileSystem, gitClient GitClient) *FallbackLicenseChecker

NewFallbackLicenseChecker creates a new fallback license checker

func (*FallbackLicenseChecker) CheckLicense

func (c *FallbackLicenseChecker) CheckLicense(repoURL string) (string, error)

CheckLicense reads LICENSE file from repository and attempts to detect license

type FileCacheStore

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

FileCacheStore implements CacheStore using JSON files in vendor/.cache/

func NewFileCacheStore

func NewFileCacheStore(fs FileSystem, rootDir string) *FileCacheStore

NewFileCacheStore creates a new FileCacheStore

func (*FileCacheStore) BuildCache

func (s *FileCacheStore) BuildCache(vendorName, ref, commitHash string, files []string) (types.IncrementalSyncCache, error)

BuildCache creates a cache entry by computing checksums for all files

func (*FileCacheStore) ComputeFileChecksum

func (s *FileCacheStore) ComputeFileChecksum(path string) (string, error)

ComputeFileChecksum computes SHA-256 hash of a file

func (*FileCacheStore) Delete

func (s *FileCacheStore) Delete(vendorName, ref string) error

Delete removes the cache file for a vendor@ref

func (*FileCacheStore) Load

func (s *FileCacheStore) Load(vendorName, ref string) (types.IncrementalSyncCache, error)

Load reads the cache file for a vendor@ref

func (*FileCacheStore) Save

Save writes the cache file for a vendor@ref

type FileConfigStore

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

FileConfigStore implements ConfigStore using YAMLStore

func NewFileConfigStore

func NewFileConfigStore(rootDir string) *FileConfigStore

NewFileConfigStore creates a new FileConfigStore

func (*FileConfigStore) Load

func (s *FileConfigStore) Load() (types.VendorConfig, error)

Load reads and parses vendor.yml

func (*FileConfigStore) Path

func (s *FileConfigStore) Path() string

Path returns the config file path

func (*FileConfigStore) Save

func (s *FileConfigStore) Save(cfg types.VendorConfig) error

Save writes vendor.yml

type FileCopyService

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

FileCopyService handles copying files according to path mappings

func NewFileCopyService

func NewFileCopyService(fs FileSystem) *FileCopyService

NewFileCopyService creates a new FileCopyService

func (*FileCopyService) CopyMappings

func (s *FileCopyService) CopyMappings(tempDir string, vendor *types.VendorSpec, spec types.BranchSpec) (CopyStats, error)

CopyMappings copies all files according to path mappings for a vendor spec

type FileLockStore

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

FileLockStore implements LockStore using YAMLStore

func NewFileLockStore

func NewFileLockStore(rootDir string) *FileLockStore

NewFileLockStore creates a new FileLockStore

func (*FileLockStore) GetHash

func (s *FileLockStore) GetHash(vendorName, ref string) string

GetHash retrieves the locked commit hash for a vendor@ref

func (*FileLockStore) Load

func (s *FileLockStore) Load() (types.VendorLock, error)

Load reads and parses vendor.lock

func (*FileLockStore) Path

func (s *FileLockStore) Path() string

Path returns the lock file path

func (*FileLockStore) Save

func (s *FileLockStore) Save(lock types.VendorLock) error

Save writes vendor.lock

type FileSystem

type FileSystem interface {
	CopyFile(src, dst string) (CopyStats, error)
	CopyDir(src, dst string) (CopyStats, error)
	MkdirAll(path string, perm os.FileMode) error
	ReadDir(path string) ([]string, error)
	Stat(path string) (os.FileInfo, error)
	Remove(path string) error
	CreateTemp(dir, pattern string) (string, error)
	RemoveAll(path string) error
}

FileSystem abstracts file system operations for testing

type GitClient

type GitClient interface {
	Init(dir string) error
	AddRemote(dir, name, url string) error
	Fetch(dir string, depth int, ref string) error
	FetchAll(dir string) error
	Checkout(dir, ref string) error
	GetHeadHash(dir string) (string, error)
	Clone(dir, url string, opts *types.CloneOptions) error
	ListTree(dir, ref, subdir string) ([]string, error)
	GetCommitLog(dir, oldHash, newHash string, maxCount int) ([]types.CommitInfo, error)
}

GitClient handles git command operations

type GitHubLicenseChecker

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

GitHubLicenseChecker implements LicenseChecker for GitHub

func NewGitHubLicenseChecker

func NewGitHubLicenseChecker(httpClient *http.Client, allowedLicenses []string) *GitHubLicenseChecker

NewGitHubLicenseChecker creates a new GitHubLicenseChecker

func (*GitHubLicenseChecker) CheckLicense

func (c *GitHubLicenseChecker) CheckLicense(rawURL string) (string, error)

CheckLicense queries GitHub API for repository license

func (*GitHubLicenseChecker) IsAllowed

func (c *GitHubLicenseChecker) IsAllowed(license string) bool

IsAllowed checks if a license is in the allowed list

type GitLabAPIChecker

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

GitLabAPIChecker implements license detection via GitLab API

func NewGitLabAPIChecker

func NewGitLabAPIChecker() *GitLabAPIChecker

NewGitLabAPIChecker creates a new GitLab API license checker

func (*GitLabAPIChecker) CheckLicense

func (c *GitLabAPIChecker) CheckLicense(repoURL string) (string, error)

CheckLicense queries the GitLab API for license information

GitLab API endpoint: GET /api/v4/projects/:id Documentation: https://docs.gitlab.com/ee/api/projects.html#get-single-project

Supports both gitlab.com and self-hosted instances

type HookExecutor

type HookExecutor interface {
	// ExecutePreSync runs pre-sync hook if configured
	ExecutePreSync(vendor *types.VendorSpec, ctx *types.HookContext) error

	// ExecutePostSync runs post-sync hook if configured
	ExecutePostSync(vendor *types.VendorSpec, ctx *types.HookContext) error
}

HookExecutor handles pre/post sync hook execution

func NewHookService

func NewHookService(ui UICallback) HookExecutor

NewHookService creates a new hook executor

type JSONError

type JSONError struct {
	Title   string `json:"title"`   // Error title
	Message string `json:"message"` // Error message
}

JSONError represents error information in JSON output

type JSONOutput

type JSONOutput struct {
	Status  string                 `json:"status"`            // "success", "error", "warning"
	Message string                 `json:"message,omitempty"` // Optional message
	Data    map[string]interface{} `json:"data,omitempty"`    // Command-specific data
	Error   *JSONError             `json:"error,omitempty"`   // Error details
}

JSONOutput represents structured output

type LicenseChecker

type LicenseChecker interface {
	CheckLicense(url string) (string, error)
	IsAllowed(license string) bool
}

LicenseChecker checks repository licenses

type LicenseService

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

LicenseService handles license checking and file management

func NewLicenseService

func NewLicenseService(licenseChecker LicenseChecker, fs FileSystem, rootDir string, ui UICallback) *LicenseService

NewLicenseService creates a new LicenseService

func (*LicenseService) CheckCompliance

func (s *LicenseService) CheckCompliance(url string) (string, error)

CheckCompliance checks license compliance for a URL Returns the detected license or error

func (*LicenseService) CheckLicense

func (s *LicenseService) CheckLicense(url string) (string, error)

CheckLicense checks the license for a URL (delegates to checker)

func (*LicenseService) CopyLicense

func (s *LicenseService) CopyLicense(tempDir, vendorName string) error

CopyLicense copies license file from temp repo to vendor/licenses

func (*LicenseService) GetLicensePath

func (s *LicenseService) GetLicensePath(vendorName string) string

GetLicensePath returns the path to a vendor's license file

type LockStore

type LockStore interface {
	Load() (types.VendorLock, error)
	Save(lock types.VendorLock) error
	Path() string
	GetHash(vendorName, ref string) string
}

LockStore handles vendor.lock I/O operations

type Manager

type Manager struct {
	RootDir string
	// contains filtered or unexported fields
}

Manager provides the main API for git-vendor operations It delegates to VendorSyncer for all business logic

func NewManager

func NewManager() *Manager

NewManager creates a new Manager with default dependencies

func NewManagerWithSyncer

func NewManagerWithSyncer(syncer *VendorSyncer) *Manager

NewManagerWithSyncer creates a Manager with a custom VendorSyncer (useful for testing)

func (*Manager) AddVendor

func (m *Manager) AddVendor(spec *types.VendorSpec) error

AddVendor adds a new vendor with license compliance check

func (*Manager) Audit

func (m *Manager) Audit()

Audit checks lockfile status

func (*Manager) CheckGitHubLicense

func (m *Manager) CheckGitHubLicense(rawURL string) (string, error)

CheckGitHubLicense checks a repository's license via GitHub API

func (*Manager) CheckSyncStatus

func (m *Manager) CheckSyncStatus() (types.SyncStatus, error)

CheckSyncStatus checks if local files are in sync with the lockfile

func (*Manager) CheckUpdates

func (m *Manager) CheckUpdates() ([]types.UpdateCheckResult, error)

CheckUpdates checks for available updates for all vendors

func (*Manager) ConfigPath

func (m *Manager) ConfigPath() string

ConfigPath returns the path to vendor.yml

func (*Manager) DetectConflicts

func (m *Manager) DetectConflicts() ([]types.PathConflict, error)

DetectConflicts checks for path conflicts between vendors

func (*Manager) DiffVendor

func (m *Manager) DiffVendor(vendorName string) ([]types.VendorDiff, error)

DiffVendor shows commit differences between locked and latest versions

func (*Manager) FetchRepoDir

func (m *Manager) FetchRepoDir(url, ref, subdir string) ([]string, error)

FetchRepoDir fetches directory listing from a remote repository

func (*Manager) GetConfig

func (m *Manager) GetConfig() (types.VendorConfig, error)

GetConfig returns the vendor configuration

func (*Manager) GetLockHash

func (m *Manager) GetLockHash(vendorName, ref string) string

GetLockHash retrieves the locked commit hash for a vendor@ref

func (*Manager) Init

func (m *Manager) Init() error

Init initializes the vendor directory structure

func (*Manager) LicensePath

func (m *Manager) LicensePath(name string) string

LicensePath returns the path for a vendor's license file

func (*Manager) ListLocalDir

func (m *Manager) ListLocalDir(path string) ([]string, error)

ListLocalDir lists contents of a local directory

func (*Manager) LockPath

func (m *Manager) LockPath() string

LockPath returns the path to vendor.lock

func (*Manager) ParseSmartURL

func (m *Manager) ParseSmartURL(rawURL string) (string, string, string)

ParseSmartURL extracts repository, ref, and path from URLs

func (*Manager) RemoveVendor

func (m *Manager) RemoveVendor(name string) error

RemoveVendor removes a vendor by name

func (*Manager) SaveVendor

func (m *Manager) SaveVendor(spec *types.VendorSpec) error

SaveVendor saves or updates a vendor spec

func (*Manager) SetUICallback

func (m *Manager) SetUICallback(ui UICallback)

SetUICallback sets the UI callback for user interactions

func (*Manager) Sync

func (m *Manager) Sync() error

Sync performs locked synchronization

func (*Manager) SyncDryRun

func (m *Manager) SyncDryRun() error

SyncDryRun performs a dry-run sync

func (*Manager) SyncWithGroup

func (m *Manager) SyncWithGroup(groupName string, force, noCache bool) error

SyncWithGroup performs sync for all vendors in a group

func (*Manager) SyncWithOptions

func (m *Manager) SyncWithOptions(vendorName string, force, noCache bool) error

SyncWithOptions performs sync with vendor filter, force, and cache options

func (*Manager) SyncWithParallel

func (m *Manager) SyncWithParallel(vendorName string, force, noCache bool, parallelOpts types.ParallelOptions) error

SyncWithParallel performs sync with parallel processing

func (*Manager) UpdateAll

func (m *Manager) UpdateAll() error

UpdateAll updates all vendors and regenerates lockfile

func (*Manager) UpdateAllWithParallel

func (m *Manager) UpdateAllWithParallel(parallelOpts types.ParallelOptions) error

UpdateAllWithParallel updates all vendors with parallel processing

func (*Manager) UpdateVerboseMode

func (m *Manager) UpdateVerboseMode(verbose bool)

UpdateVerboseMode updates the verbose flag for git operations

func (*Manager) ValidateConfig

func (m *Manager) ValidateConfig() error

ValidateConfig performs comprehensive config validation

func (*Manager) WatchConfig

func (m *Manager) WatchConfig(callback func() error) error

WatchConfig watches for changes to vendor.yml and triggers a callback

type MultiPlatformLicenseChecker

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

MultiPlatformLicenseChecker implements LicenseChecker interface with support for multiple git hosting platforms

func NewMultiPlatformLicenseChecker

func NewMultiPlatformLicenseChecker(
	registry *providers.ProviderRegistry,
	fs FileSystem,
	gitClient GitClient,
	allowedLicenses []string,
) *MultiPlatformLicenseChecker

NewMultiPlatformLicenseChecker creates a new multi-platform license checker

func (*MultiPlatformLicenseChecker) CheckLicense

func (c *MultiPlatformLicenseChecker) CheckLicense(url string) (string, error)

CheckLicense detects license using platform-specific API or fallback

Strategy:

  1. Detect provider from URL (GitHub, GitLab, Bitbucket, or generic)
  2. Try platform-specific API if available (GitHub, GitLab)
  3. If API fails or unavailable, fall back to reading LICENSE file
  4. Return normalized SPDX license identifier

func (*MultiPlatformLicenseChecker) GetProviderName

func (c *MultiPlatformLicenseChecker) GetProviderName(url string) string

GetProviderName returns the detected provider name for debugging

func (*MultiPlatformLicenseChecker) IsAllowed

func (c *MultiPlatformLicenseChecker) IsAllowed(license string) bool

IsAllowed checks if the given license is in the allowed list

type NoOpProgressTracker

type NoOpProgressTracker struct{}

NoOpProgressTracker is a no-op implementation for testing

func (*NoOpProgressTracker) Complete

func (t *NoOpProgressTracker) Complete()

Complete does nothing (no-op implementation).

func (*NoOpProgressTracker) Fail

func (t *NoOpProgressTracker) Fail(_ error)

Fail does nothing (no-op implementation).

func (*NoOpProgressTracker) Increment

func (t *NoOpProgressTracker) Increment(_ string)

Increment does nothing (no-op implementation).

func (*NoOpProgressTracker) SetTotal

func (t *NoOpProgressTracker) SetTotal(_ int)

SetTotal does nothing (no-op implementation).

type NonInteractiveFlags

type NonInteractiveFlags struct {
	Yes  bool       // Auto-approve prompts
	Mode OutputMode // Output formatting mode
}

NonInteractiveFlags groups all non-interactive options

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem implements FileSystem using standard os package

func NewOSFileSystem

func NewOSFileSystem() *OSFileSystem

NewOSFileSystem creates a new OSFileSystem

func (*OSFileSystem) CopyDir

func (fs *OSFileSystem) CopyDir(src, dst string) (CopyStats, error)

CopyDir recursively copies a directory from src to dst

func (*OSFileSystem) CopyFile

func (fs *OSFileSystem) CopyFile(src, dst string) (CopyStats, error)

CopyFile copies a single file from src to dst

func (*OSFileSystem) CreateTemp

func (fs *OSFileSystem) CreateTemp(dir, pattern string) (string, error)

CreateTemp creates a temporary directory

func (*OSFileSystem) MkdirAll

func (fs *OSFileSystem) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory path

func (*OSFileSystem) ReadDir

func (fs *OSFileSystem) ReadDir(path string) ([]string, error)

ReadDir lists directory contents

func (*OSFileSystem) Remove

func (fs *OSFileSystem) Remove(path string) error

Remove removes a file

func (*OSFileSystem) RemoveAll

func (fs *OSFileSystem) RemoveAll(path string) error

RemoveAll removes a directory tree

func (*OSFileSystem) Stat

func (fs *OSFileSystem) Stat(path string) (os.FileInfo, error)

Stat returns file info

type OutputMode

type OutputMode int

OutputMode controls how output is displayed

const (
	OutputNormal OutputMode = iota // Default: styled output
	OutputQuiet                    // Minimal output
	OutputJSON                     // Structured JSON
)

OutputMode constants define available output formatting modes.

type ParallelExecutor

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

ParallelExecutor handles concurrent processing of multiple vendors

func NewParallelExecutor

func NewParallelExecutor(opts types.ParallelOptions, ui UICallback) *ParallelExecutor

NewParallelExecutor creates a new parallel executor

func (*ParallelExecutor) ExecuteParallelSync

func (p *ParallelExecutor) ExecuteParallelSync(
	vendors []types.VendorSpec,
	lockMap map[string]map[string]string,
	opts SyncOptions,
	syncFunc SyncVendorFunc,
) ([]VendorResult, error)

ExecuteParallelSync processes vendors in parallel using a worker pool

func (*ParallelExecutor) ExecuteParallelUpdate

func (p *ParallelExecutor) ExecuteParallelUpdate(
	vendors []types.VendorSpec,
	updateFunc UpdateVendorFunc,
) ([]VendorResult, error)

ExecuteParallelUpdate processes vendor updates in parallel

type PathOwner

type PathOwner struct {
	VendorName string
	Mapping    types.PathMapping
	Ref        string
}

PathOwner tracks which vendor owns a path

type RemoteExplorer

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

RemoteExplorer handles remote repository browsing and URL parsing

func NewRemoteExplorer

func NewRemoteExplorer(gitClient GitClient, fs FileSystem) *RemoteExplorer

NewRemoteExplorer creates a new RemoteExplorer

func (*RemoteExplorer) FetchRepoDir

func (e *RemoteExplorer) FetchRepoDir(url, ref, subdir string) ([]string, error)

FetchRepoDir fetches directory listing from remote repository

func (*RemoteExplorer) GetProviderName

func (e *RemoteExplorer) GetProviderName(url string) string

GetProviderName returns the detected provider name for a URL Useful for debugging and logging

func (*RemoteExplorer) ListLocalDir

func (e *RemoteExplorer) ListLocalDir(path string) ([]string, error)

ListLocalDir lists local directory contents

func (*RemoteExplorer) ParseSmartURL

func (e *RemoteExplorer) ParseSmartURL(rawURL string) (string, string, string)

ParseSmartURL parses URLs from any supported git hosting platform Supports GitHub, GitLab, Bitbucket, and generic git URLs

type SilentUICallback

type SilentUICallback struct{}

SilentUICallback is a no-op implementation (for testing/CI)

func (*SilentUICallback) AskConfirmation

func (s *SilentUICallback) AskConfirmation(_, _ string) bool

AskConfirmation implements UICallback for silent operation (always returns false).

func (*SilentUICallback) FormatJSON

func (s *SilentUICallback) FormatJSON(_ JSONOutput) error

FormatJSON implements UICallback for silent operation (does nothing).

func (*SilentUICallback) GetOutputMode

func (s *SilentUICallback) GetOutputMode() OutputMode

GetOutputMode implements UICallback for silent operation (returns OutputNormal).

func (*SilentUICallback) IsAutoApprove

func (s *SilentUICallback) IsAutoApprove() bool

IsAutoApprove implements UICallback for silent operation (returns false).

func (*SilentUICallback) ShowError

func (s *SilentUICallback) ShowError(_, _ string)

ShowError implements UICallback for silent operation (no output).

func (*SilentUICallback) ShowLicenseCompliance

func (s *SilentUICallback) ShowLicenseCompliance(_ string)

ShowLicenseCompliance implements UICallback for silent operation (no output).

func (*SilentUICallback) ShowSuccess

func (s *SilentUICallback) ShowSuccess(_ string)

ShowSuccess implements UICallback for silent operation (no output).

func (*SilentUICallback) ShowWarning

func (s *SilentUICallback) ShowWarning(_, _ string)

ShowWarning implements UICallback for silent operation (no output).

func (*SilentUICallback) StartProgress

func (s *SilentUICallback) StartProgress(_ int, _ string) types.ProgressTracker

StartProgress implements UICallback for silent operation (no-op).

func (*SilentUICallback) StyleTitle

func (s *SilentUICallback) StyleTitle(title string) string

StyleTitle implements UICallback for silent operation (returns plain text).

type SyncOptions

type SyncOptions struct {
	DryRun     bool
	VendorName string // Empty = all vendors
	GroupName  string // Empty = all groups, filters vendors by group
	Force      bool
	NoCache    bool                  // Disable incremental sync cache
	Parallel   types.ParallelOptions // Parallel processing options
}

SyncOptions configures sync operation behavior

type SyncService

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

SyncService handles vendor synchronization operations

func NewSyncService

func NewSyncService(
	configStore ConfigStore,
	lockStore LockStore,
	gitClient GitClient,
	fs FileSystem,
	fileCopy *FileCopyService,
	license *LicenseService,
	cache CacheStore,
	hooks HookExecutor,
	ui UICallback,
	rootDir string,
) *SyncService

NewSyncService creates a new SyncService

func (*SyncService) Sync

func (s *SyncService) Sync(opts SyncOptions) error

Sync performs synchronization based on the provided options Note: Caller should check for lockfile existence before calling this

type SyncVendorFunc

type SyncVendorFunc func(v types.VendorSpec, lockedRefs map[string]string, opts SyncOptions) (map[string]string, CopyStats, error)

SyncVendorFunc is a function type that syncs a single vendor

type SystemGitClient

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

SystemGitClient implements GitClient using system git commands

func NewSystemGitClient

func NewSystemGitClient(verbose bool) *SystemGitClient

NewSystemGitClient creates a new SystemGitClient

func (*SystemGitClient) AddRemote

func (g *SystemGitClient) AddRemote(dir, name, url string) error

AddRemote adds a git remote

func (*SystemGitClient) Checkout

func (g *SystemGitClient) Checkout(dir, ref string) error

Checkout checks out a git ref

func (*SystemGitClient) Clone

func (g *SystemGitClient) Clone(dir, url string, opts *types.CloneOptions) error

Clone clones a repository with options

func (*SystemGitClient) Fetch

func (g *SystemGitClient) Fetch(dir string, depth int, ref string) error

Fetch fetches from remote with optional depth

func (*SystemGitClient) FetchAll

func (g *SystemGitClient) FetchAll(dir string) error

FetchAll fetches all refs from origin

func (*SystemGitClient) GetCommitLog

func (g *SystemGitClient) GetCommitLog(dir, oldHash, newHash string, maxCount int) ([]types.CommitInfo, error)

GetCommitLog retrieves commit history between two commits

func (*SystemGitClient) GetHeadHash

func (g *SystemGitClient) GetHeadHash(dir string) (string, error)

GetHeadHash returns the current HEAD commit hash

func (*SystemGitClient) Init

func (g *SystemGitClient) Init(dir string) error

Init initializes a git repository

func (*SystemGitClient) ListTree

func (g *SystemGitClient) ListTree(dir, ref, subdir string) ([]string, error)

ListTree lists files/directories at a given ref and subdir

type UICallback

type UICallback interface {
	ShowError(title, message string)
	ShowSuccess(message string)
	ShowWarning(title, message string)
	AskConfirmation(title, message string) bool
	ShowLicenseCompliance(license string)
	StyleTitle(title string) string

	// New methods for non-interactive mode
	GetOutputMode() OutputMode
	IsAutoApprove() bool
	FormatJSON(output JSONOutput) error

	// Progress tracking
	StartProgress(total int, label string) types.ProgressTracker
}

UICallback handles user interaction during vendor operations

type UpdateChecker

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

UpdateChecker handles checking for vendor updates

func NewUpdateChecker

func NewUpdateChecker(
	configStore ConfigStore,
	lockStore LockStore,
	gitClient GitClient,
	fs FileSystem,
	ui UICallback,
) *UpdateChecker

NewUpdateChecker creates a new UpdateChecker

func (*UpdateChecker) CheckUpdates

func (c *UpdateChecker) CheckUpdates() ([]types.UpdateCheckResult, error)

CheckUpdates compares lockfile commit hashes with latest available commits

type UpdateService

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

UpdateService handles update operations and lockfile regeneration

func NewUpdateService

func NewUpdateService(
	configStore ConfigStore,
	lockStore LockStore,
	syncService *SyncService,
	ui UICallback,
	rootDir string,
) *UpdateService

NewUpdateService creates a new UpdateService

func (*UpdateService) UpdateAll

func (s *UpdateService) UpdateAll() error

UpdateAll updates all vendors and regenerates the lockfile

func (*UpdateService) UpdateAllWithOptions

func (s *UpdateService) UpdateAllWithOptions(parallelOpts types.ParallelOptions) error

UpdateAllWithOptions updates all vendors with optional parallel processing

type UpdateVendorFunc

type UpdateVendorFunc func(v types.VendorSpec, opts SyncOptions) (map[string]string, error)

UpdateVendorFunc is a function type that updates a single vendor

type ValidationService

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

ValidationService handles config validation and conflict detection

func NewValidationService

func NewValidationService(configStore ConfigStore) *ValidationService

NewValidationService creates a new ValidationService

func (*ValidationService) DetectConflicts

func (s *ValidationService) DetectConflicts() ([]types.PathConflict, error)

DetectConflicts checks for path conflicts between vendors

func (*ValidationService) ValidateConfig

func (s *ValidationService) ValidateConfig() error

ValidateConfig performs comprehensive configuration validation

type VendorRepository

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

VendorRepository handles vendor CRUD operations

func NewVendorRepository

func NewVendorRepository(configStore ConfigStore) *VendorRepository

NewVendorRepository creates a new VendorRepository

func (*VendorRepository) Delete

func (r *VendorRepository) Delete(name string) error

Delete removes a vendor by name

func (*VendorRepository) Exists

func (r *VendorRepository) Exists(name string) (bool, error)

Exists checks if a vendor with the given name exists

func (*VendorRepository) Find

func (r *VendorRepository) Find(name string) (*types.VendorSpec, error)

Find returns the vendor with the given name, or nil if not found

func (*VendorRepository) FindAll

func (r *VendorRepository) FindAll() ([]types.VendorSpec, error)

FindAll returns all vendors

func (*VendorRepository) GetConfig

func (r *VendorRepository) GetConfig() (types.VendorConfig, error)

GetConfig returns the vendor configuration

func (*VendorRepository) Save

func (r *VendorRepository) Save(vendor *types.VendorSpec) error

Save adds or updates a vendor

type VendorResult

type VendorResult struct {
	Vendor      types.VendorSpec
	UpdatedRefs map[string]string // ref -> commit hash
	Stats       CopyStats
	Error       error
}

VendorResult represents the result of processing a single vendor

type VendorSyncer

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

VendorSyncer orchestrates vendor operations using domain services

func NewVendorSyncer

func NewVendorSyncer(
	configStore ConfigStore,
	lockStore LockStore,
	gitClient GitClient,
	fs FileSystem,
	licenseChecker LicenseChecker,
	rootDir string,
	ui UICallback,
) *VendorSyncer

NewVendorSyncer creates a new VendorSyncer with injected dependencies

func (*VendorSyncer) AddVendor

func (s *VendorSyncer) AddVendor(spec *types.VendorSpec) error

AddVendor adds a new vendor with license compliance check

func (*VendorSyncer) Audit

func (s *VendorSyncer) Audit()

Audit checks lockfile status

func (*VendorSyncer) CheckGitHubLicense

func (s *VendorSyncer) CheckGitHubLicense(url string) (string, error)

CheckGitHubLicense delegates to the license service

func (*VendorSyncer) CheckSyncStatus

func (s *VendorSyncer) CheckSyncStatus() (types.SyncStatus, error)

CheckSyncStatus checks if local files are in sync with the lockfile

func (*VendorSyncer) CheckUpdates

func (s *VendorSyncer) CheckUpdates() ([]types.UpdateCheckResult, error)

CheckUpdates checks for available updates for all vendors

func (*VendorSyncer) DetectConflicts

func (s *VendorSyncer) DetectConflicts() ([]types.PathConflict, error)

DetectConflicts checks for path conflicts between vendors

func (*VendorSyncer) DiffVendor

func (s *VendorSyncer) DiffVendor(vendorName string) ([]types.VendorDiff, error)

DiffVendor compares the locked version with the latest available version

func (*VendorSyncer) FetchRepoDir

func (s *VendorSyncer) FetchRepoDir(url, ref, subdir string) ([]string, error)

FetchRepoDir fetches directory listing from remote repository

func (*VendorSyncer) GetConfig

func (s *VendorSyncer) GetConfig() (types.VendorConfig, error)

GetConfig returns the vendor configuration

func (*VendorSyncer) GetLockHash

func (s *VendorSyncer) GetLockHash(vendorName, ref string) string

GetLockHash retrieves the locked commit hash for a vendor@ref

func (*VendorSyncer) Init

func (s *VendorSyncer) Init() error

Init initializes vendor directory structure

func (*VendorSyncer) ListLocalDir

func (s *VendorSyncer) ListLocalDir(path string) ([]string, error)

ListLocalDir lists local directory contents

func (*VendorSyncer) ParseSmartURL

func (s *VendorSyncer) ParseSmartURL(rawURL string) (string, string, string)

ParseSmartURL delegates to the remote explorer

func (*VendorSyncer) RemoveVendor

func (s *VendorSyncer) RemoveVendor(name string) error

RemoveVendor removes a vendor by name

func (*VendorSyncer) SaveVendor

func (s *VendorSyncer) SaveVendor(spec *types.VendorSpec) error

SaveVendor saves or updates a vendor spec

func (*VendorSyncer) Sync

func (s *VendorSyncer) Sync() error

Sync performs locked synchronization

func (*VendorSyncer) SyncDryRun

func (s *VendorSyncer) SyncDryRun() error

SyncDryRun performs a dry-run sync

func (*VendorSyncer) SyncWithGroup

func (s *VendorSyncer) SyncWithGroup(groupName string, force, noCache bool) error

SyncWithGroup performs sync for all vendors in a group

func (*VendorSyncer) SyncWithOptions

func (s *VendorSyncer) SyncWithOptions(vendorName string, force, noCache bool) error

SyncWithOptions performs sync with vendor filter, force, and cache options

func (*VendorSyncer) SyncWithParallel

func (s *VendorSyncer) SyncWithParallel(vendorName string, force, noCache bool, parallelOpts types.ParallelOptions) error

SyncWithParallel performs sync with parallel processing

func (*VendorSyncer) UpdateAll

func (s *VendorSyncer) UpdateAll() error

UpdateAll updates all vendors and regenerates lockfile

func (*VendorSyncer) UpdateAllWithParallel

func (s *VendorSyncer) UpdateAllWithParallel(parallelOpts types.ParallelOptions) error

UpdateAllWithParallel updates all vendors with parallel processing

func (*VendorSyncer) ValidateConfig

func (s *VendorSyncer) ValidateConfig() error

ValidateConfig performs comprehensive config validation

func (*VendorSyncer) WatchConfig

func (s *VendorSyncer) WatchConfig(callback func() error) error

WatchConfig watches for changes to vendor.yml and triggers sync

type YAMLStore

type YAMLStore[T any] struct {
	// contains filtered or unexported fields
}

YAMLStore provides generic YAML file I/O operations. This consolidates duplicate code between ConfigStore and LockStore. It's a perfect use case for Go 1.18+ generics.

func NewYAMLStore

func NewYAMLStore[T any](rootDir, filename string, allowMissing bool) *YAMLStore[T]

NewYAMLStore creates a new YAML store for type T.

Parameters:

  • rootDir: Directory containing the YAML file
  • filename: Name of the YAML file (e.g., "vendor.yml", "vendor.lock")
  • allowMissing: If true, Load() returns zero value for missing files instead of error

func (*YAMLStore[T]) Load

func (s *YAMLStore[T]) Load() (T, error)

Load reads and unmarshals the YAML file into type T

func (*YAMLStore[T]) Path

func (s *YAMLStore[T]) Path() string

Path returns the full file path

func (*YAMLStore[T]) Save

func (s *YAMLStore[T]) Save(data T) error

Save marshals and writes type T to the YAML file

Directories

Path Synopsis
Package providers implements git platform-specific URL parsing and operations.
Package providers implements git platform-specific URL parsing and operations.

Jump to

Keyboard shortcuts

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