Documentation
¶
Overview ¶
Package validation provides reusable precondition validators for actions.
Validators can be composed into chains for consistent validation:
err := validation.Chain{
validation.MustBeOnBranch(eng),
validation.MustNotHaveRebaseInProgress(git, ctx),
validation.MustNotHaveUncommittedChanges(git, ctx),
}.Validate()
Index ¶
- func ValidateSourceBranch(eng BranchValidationEngine, branchName, operation string) error
- func ValidateTargetBranch(eng BranchValidationEngine, sourceName, targetName, operation string) error
- type BranchValidationEngine
- type Chain
- type GitOperationEngine
- type GitStateReader
- type Validator
- func BranchMustBeModifiable(eng BranchValidationEngine, branchName string) Validator
- func BranchMustBeTracked(eng BranchValidationEngine, branchName string) Validator
- func BranchMustNotBeTrunk(eng BranchValidationEngine, branchName string) Validator
- func CurrentBranchMustBeModifiable(ctx context.Context, eng BranchValidationEngine) Validator
- func CurrentBranchMustBeTracked(ctx context.Context, eng BranchValidationEngine) Validator
- func CurrentBranchMustNotBeTrunk(ctx context.Context, eng BranchValidationEngine, operation string) Validator
- func MustBeOnBranch(ctx context.Context, eng BranchValidationEngine) Validator
- func MustNotHaveRebaseInProgress(ctx context.Context, g GitStateReader) Validator
- func MustNotHaveUncommittedChanges(ctx context.Context, g GitStateReader) Validator
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateSourceBranch ¶
func ValidateSourceBranch(eng BranchValidationEngine, branchName, operation string) error
ValidateSourceBranch validates that a source branch can be used for operations like move, pluck, or delete. Returns nil if valid, error otherwise.
Checks performed:
- Branch is not trunk
- Branch is tracked by stackit
- Branch is not a worktree anchor
The operation parameter is used in error messages (e.g., "move", "pluck", "delete").
func ValidateTargetBranch ¶
func ValidateTargetBranch(eng BranchValidationEngine, sourceName, targetName, operation string) error
ValidateTargetBranch validates that a target branch can be used for reparenting operations like move or pluck. Returns nil if valid, error otherwise.
Checks performed:
- Target is provided (not empty)
- Target exists (as trunk, tracked, or untracked git branch)
- Target is not a worktree anchor
- Target is not the same as source
The operation parameter is used in error messages (e.g., "move", "pluck").
Types ¶
type BranchValidationEngine ¶
type BranchValidationEngine interface {
ValidateOnBranch(ctx context.Context) (string, error)
GetBranch(branchName string) engine.Branch
CurrentBranch(ctx context.Context) *engine.Branch
BranchNames() *engine.BranchSet
}
BranchValidationEngine is the minimal engine contract needed by validators. Keeping this narrow avoids coupling callers to the full engine.Engine surface.
type Chain ¶
type Chain []Validator
Chain is a sequence of validators that are checked in order. Validation stops at the first error.
func AbsorbChain ¶
func AbsorbChain(ctx context.Context, eng GitOperationEngine, operation string) Chain
AbsorbChain validates for absorb operations (works with staged changes). Checks: on branch, not trunk, modifiable, no rebase in progress.
func GitOperationChain ¶
func GitOperationChain(ctx context.Context, eng GitOperationEngine, operation string) Chain
GitOperationChain validates for git history modifications (fold, pop, reorder). Checks: on branch, not trunk, tracked, no rebase in progress, no uncommitted changes, modifiable.
func ModifyBranchChain ¶
func ModifyBranchChain(ctx context.Context, eng BranchValidationEngine, operation string) Chain
ModifyBranchChain validates for simple branch modifications (rename, scope). Checks: on branch, not trunk, modifiable.
type GitOperationEngine ¶ added in v0.19.1
type GitOperationEngine interface {
BranchValidationEngine
GitStateReader
}
GitOperationEngine is the engine contract needed by the git-state chains: branch validation plus git-state reads. engine.Engine satisfies it, so callers pass the engine rather than the raw git runner.
type GitStateReader ¶ added in v0.19.1
type GitStateReader interface {
IsRebaseInProgress(ctx context.Context) bool
HasUncommittedChanges(ctx context.Context) bool
HasStagedChanges(ctx context.Context) (bool, error)
}
GitStateReader is the minimal git-state contract the git-aware validators need. engine.Engine satisfies it, so callers pass the engine instead of the raw git runner — keeping validation in the domain layer.
type Validator ¶
type Validator interface {
// Validate checks the precondition and returns an error if it fails.
Validate() error
}
Validator validates a single precondition.
func BranchMustBeModifiable ¶
func BranchMustBeModifiable(eng BranchValidationEngine, branchName string) Validator
BranchMustBeModifiable validates that a branch can be modified (not locked, frozen, or worktree anchor).
func BranchMustBeTracked ¶
func BranchMustBeTracked(eng BranchValidationEngine, branchName string) Validator
BranchMustBeTracked validates that a branch is tracked by stackit.
func BranchMustNotBeTrunk ¶
func BranchMustNotBeTrunk(eng BranchValidationEngine, branchName string) Validator
BranchMustNotBeTrunk validates that a branch is not the trunk branch.
func CurrentBranchMustBeModifiable ¶
func CurrentBranchMustBeModifiable(ctx context.Context, eng BranchValidationEngine) Validator
CurrentBranchMustBeModifiable validates that the current branch can be modified.
func CurrentBranchMustBeTracked ¶
func CurrentBranchMustBeTracked(ctx context.Context, eng BranchValidationEngine) Validator
CurrentBranchMustBeTracked validates that the current branch is tracked by stackit.
func CurrentBranchMustNotBeTrunk ¶
func CurrentBranchMustNotBeTrunk(ctx context.Context, eng BranchValidationEngine, operation string) Validator
CurrentBranchMustNotBeTrunk validates that the current branch is not trunk. The operation parameter is used in the error message (e.g., "reorder", "fold").
func MustBeOnBranch ¶
func MustBeOnBranch(ctx context.Context, eng BranchValidationEngine) Validator
MustBeOnBranch validates that HEAD is on a branch (not detached). Returns a Validator that checks the engine's current branch state.
func MustNotHaveRebaseInProgress ¶
func MustNotHaveRebaseInProgress(ctx context.Context, g GitStateReader) Validator
MustNotHaveRebaseInProgress validates that no rebase operation is in progress.
func MustNotHaveUncommittedChanges ¶
func MustNotHaveUncommittedChanges(ctx context.Context, g GitStateReader) Validator
MustNotHaveUncommittedChanges validates that there are no uncommitted changes.
type ValidatorFunc ¶
type ValidatorFunc func() error
ValidatorFunc allows using a function as a Validator.
func (ValidatorFunc) Validate ¶
func (f ValidatorFunc) Validate() error
Validate implements Validator.