Documentation
¶
Overview ¶
Package engine implements the core scan/update/push workflows for SSU.
The engine orchestrates git operations through the GitService interface, providing parallel execution with bounded concurrency, progress reporting, and compound status detection for submodules.
Index ¶
- type CheckoutAction
- type CheckoutOpts
- type CheckoutResult
- type Engine
- func (e *Engine) Checkout(ctx context.Context, targets []*SubmoduleInfo, opts CheckoutOpts) (*CheckoutResult, error)
- func (e *Engine) Push(ctx context.Context, targets []*SubmoduleInfo, opts PushOpts) (*PushResult, error)
- func (e *Engine) Scan(ctx context.Context, opts ScanOpts) (*ScanResult, error)
- func (e *Engine) Update(ctx context.Context, targets []*SubmoduleInfo, opts UpdateOpts) (*UpdateResult, error)
- type ProgressEvent
- type ProgressEventType
- type ProgressFunc
- type PushAction
- type PushOpts
- type PushResult
- type ScanOpts
- type ScanResult
- type SubmoduleInfo
- type UpdateAction
- type UpdateOpts
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckoutAction ¶ added in v1.1.3
type CheckoutAction struct {
Path string
Branch string // Branch checked out (or empty if skipped)
Action string // e.g. "checked out develop", "skipped (not detached)", "skipped (no matching branch)"
Error error
}
CheckoutAction records what happened to a single submodule during checkout.
type CheckoutOpts ¶ added in v1.1.3
type CheckoutOpts struct {
RootDir string
Concurrency int
BranchOpts git.BranchCheckoutOpts
OnProgress ProgressFunc
}
CheckoutOpts configures a Checkout operation.
type CheckoutResult ¶ added in v1.1.3
type CheckoutResult struct {
Actions []CheckoutAction
}
CheckoutResult holds the aggregate outcome of checking out submodules.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates scan, update, and push workflows. It operates on git repositories through the GitService interface, enabling full testability with MockGitService.
func New ¶
func New(svc git.GitService) *Engine
New creates an Engine backed by the given GitService.
func (*Engine) Checkout ¶ added in v1.1.3
func (e *Engine) Checkout(ctx context.Context, targets []*SubmoduleInfo, opts CheckoutOpts) (*CheckoutResult, error)
Checkout re-attaches HEAD to the correct branch for selected submodules. Only submodules in detached HEAD state are processed. It finds which branch tips match HEAD and checks out the best match. This is completely safe: only branches whose tip equals HEAD are considered, so no commits are gained or lost.
func (*Engine) Push ¶
func (e *Engine) Push(ctx context.Context, targets []*SubmoduleInfo, opts PushOpts) (*PushResult, error)
Push pushes selected submodules in parallel with bounded concurrency. It skips root and detached-HEAD submodules, auto-sets up tracking branches when missing, and continues on error (one failure does not abort others).
func (*Engine) Scan ¶
Scan enumerates submodules, fetches in parallel with bounded concurrency, detects per-submodule status (including compound statuses), and includes root repository as display-only.
Individual fetch or status-detection failures do not abort the scan; they are recorded as StatusError on the affected submodule.
func (*Engine) Update ¶
func (e *Engine) Update(ctx context.Context, targets []*SubmoduleInfo, opts UpdateOpts) (*UpdateResult, error)
Update processes selected submodules by merging their target branch. It handles dirty submodules with a 3-step stash+merge+stash-pop strategy, and provides actionable ConflictHint commands on failure.
The targets parameter is the subset of scan.Submodules the caller selected for update -- the engine does NOT decide what to update.
Individual update failures do not abort other updates (continue-on-error).
type ProgressEvent ¶
type ProgressEvent struct {
Type ProgressEventType // Started, Completed, or Failed
Path string // Submodule path (or "." for root)
Phase string // "fetch", "status", "update", "push"
Error error // Non-nil for EventFailed
Total int // Total number of items being processed
Done int // Number of items completed so far
Action string // Human-readable result (e.g. "pushed", "merged 3 commits")
}
ProgressEvent carries information about scan/update/push progress.
type ProgressEventType ¶
type ProgressEventType int
ProgressEventType identifies the kind of progress event.
const ( // EventStarted fires when processing begins for a submodule. EventStarted ProgressEventType = iota // EventCompleted fires when processing finishes successfully for a submodule. EventCompleted // EventFailed fires when processing fails for a submodule. EventFailed )
type ProgressFunc ¶
type ProgressFunc func(ProgressEvent)
ProgressFunc is a callback that receives progress events during operations. Implementations must be safe for concurrent calls from multiple goroutines.
type PushAction ¶
type PushAction struct {
Path string
Branch string
Action string // e.g. "pushed", "set-upstream", "skipped", "error"
Error error
}
PushAction records what happened to a single submodule during push.
type PushOpts ¶
type PushOpts struct {
RootDir string
Concurrency int
OnProgress ProgressFunc
}
PushOpts configures a Push operation.
type PushResult ¶
type PushResult struct {
Actions []PushAction
}
PushResult holds the aggregate outcome of pushing submodules.
type ScanOpts ¶
type ScanOpts struct {
RootDir string // Absolute path to the project root
SkipList []string // Submodule paths to exclude
Concurrency int // Max parallel goroutines (0 = runtime.NumCPU())
BranchOpts git.BranchDetectOpts // Passed to DetectBestBranch per submodule
OnProgress ProgressFunc // Optional callback for progress events
}
ScanOpts configures a Scan operation.
type ScanResult ¶
type ScanResult struct {
Root *SubmoduleInfo // Root repository info (display-only, nil if scan failed)
Submodules []*SubmoduleInfo // Per-submodule scan results, sorted by path
}
ScanResult holds the aggregate outcome of scanning all submodules.
type SubmoduleInfo ¶
type SubmoduleInfo struct {
Path string // Relative path from root (e.g. "plugins/auth"), or "." for root
IsRoot bool // True for root repository
Statuses []git.SubmoduleStatus // Compound status set (can have multiple)
CurrentBranch string // Branch name, or empty if detached
TargetBranch string // Branch detected by DetectBestBranch
DetachedHead bool // True if HEAD is detached
CommitsBehind int // Number of commits behind remote
CommitsAhead int // Number of unpushed commits
HasChanges bool // Uncommitted local changes exist
Changelog []string // Incoming commit summaries (oneline format)
Error error // Non-nil if scan failed for this submodule
}
SubmoduleInfo holds scan results for a single submodule (or root).
func (*SubmoduleInfo) HasStatus ¶
func (info *SubmoduleInfo) HasStatus(s git.SubmoduleStatus) bool
HasStatus reports whether info has the given status in its compound set.
func (*SubmoduleInfo) PrimaryStatus ¶
func (info *SubmoduleInfo) PrimaryStatus() git.SubmoduleStatus
PrimaryStatus returns the highest-priority status for display. Priority order: error > conflict > modified > ahead > pending > missing > skipped > current.
type UpdateAction ¶
type UpdateAction struct {
Path string
BeforeStatus []git.SubmoduleStatus
AfterStatus []git.SubmoduleStatus
Action string // e.g. "merged", "conflict-resolved", "skipped", "error"
Error error
ConflictHint string // Human-readable hint if conflict occurred
}
UpdateAction records what happened to a single submodule during update.
type UpdateOpts ¶
type UpdateOpts struct {
RootDir string
Concurrency int
OnProgress ProgressFunc
}
UpdateOpts configures an Update operation.
type UpdateResult ¶
type UpdateResult struct {
Actions []UpdateAction
}
UpdateResult holds the aggregate outcome of updating submodules.