Documentation
¶
Overview ¶
Package sync provides functionality for synchronizing stacked branches with remote repositories.
Index ¶
- Constants
- func Action(ctx *app.Context, opts Options, handler Handler) error
- func FormatSummaryParts(summary Summary) []string
- func FormatSummaryString(summary Summary) string
- type DryRunResult
- type Event
- type EventType
- type GitHubSyncResult
- type Handler
- type NullHandler
- func (h *NullHandler) Complete(Summary)
- func (h *NullHandler) EmitEvent(Event)
- func (h *NullHandler) OnRestackBranch(string, RestackResult, string, *int, engine.LockReason, bool, bool, string, ...)
- func (h *NullHandler) OnRestackComplete(int, int, []string)
- func (h *NullHandler) OnRestackStart(int)
- func (h *NullHandler) PromptBranchDeletions(branches map[string]string, unpushedBranches map[string]bool) (map[string]bool, error)
- func (h *NullHandler) PromptMetadataConflict(_ *engine.MetadataDiff) (bool, error)
- func (h *NullHandler) PromptOrphanedMetadata(_ engine.OrphanedMetadataInfo) (bool, error)
- func (h *NullHandler) PromptResolveConflicts(_ []string) (bool, error)
- func (h *NullHandler) Start(int)
- type Options
- type ParentsToGitHubResult
- type Phase
- type RestackHandler
- type RestackResult
- type StackMetadataGCResult
- type Summary
- type WorktreeCleanupResult
Constants ¶
const ( RestackDone = handlers.RestackDone RestackUnneeded = handlers.RestackUnneeded RestackConflict = handlers.RestackConflict )
Re-export RestackResult constants from handlers package for convenience
Variables ¶
This section is empty.
Functions ¶
func FormatSummaryParts ¶
FormatSummaryParts returns the summary parts as a slice of strings This is shared between SimpleSyncHandler and InteractiveSyncHandler
func FormatSummaryString ¶
FormatSummaryString returns the full summary as a string
Types ¶
type DryRunResult ¶
type DryRunResult struct {
WouldPull string `json:"would_pull,omitempty"` // Trunk branch that would be pulled
WouldClean []string `json:"would_clean,omitempty"` // Branches that would be deleted
WouldRestack []string `json:"would_restack,omitempty"` // Branches that would be restacked
WouldRestackStacks []string `json:"would_restack_stacks,omitempty"` // Deduped independent stack roots covering the current dry-run's would_restack set; recompute after sync before passing to `restack --stacks <roots>` because cleanup/reparenting can change roots
SkippedStacks []string `json:"skipped_stacks,omitempty"` // Stacks skipped due to dirty worktrees
}
DryRunResult represents the JSON output for sync --dry-run
type Event ¶
type Event struct {
Phase Phase // Current phase
Type EventType // Event type
Branch string // Branch name (if applicable)
PRNumber *int // PR number (if applicable)
Message string // Human-readable description
OldRevision string // For position changes
NewRevision string // For position changes
Conflict bool // Is this a conflict?
LockReason engine.LockReason // Why the branch is locked (empty if not locked)
Frozen bool // Is the branch frozen?
IsCurrent bool // Is this the current branch?
Parent string // Parent branch name (if applicable)
RerereResolvedCount int // Number of rebase continuations handled by git rerere
Error error // If non-nil, this step had an error
}
Event represents a progress update during sync
type GitHubSyncResult ¶
type GitHubSyncResult struct {
BranchNames []string
RepoOwner string
RepoName string
PRInfos map[string]*github.PullRequestInfo
// contains filtered or unexported fields
}
GitHubSyncResult holds the results from GitHub PR info sync (network operation)
type Handler ¶
type Handler interface {
// Start is called at the beginning of sync with the total operation count
Start(totalOps int)
// EmitEvent is called for each progress update
EmitEvent(event Event)
// Complete is called when sync finishes with the summary
Complete(summary Summary)
// Cleanup ensures terminal is restored on error (may be no-op for non-TTY handlers)
Cleanup()
// IsInteractive returns true if this handler supports interactive prompts.
// Non-interactive handlers return false and their prompt methods return defaults.
IsInteractive() bool
// PromptMetadataConflict displays a metadata conflict and asks user to accept remote.
// Returns true to accept remote metadata, false to keep local.
// In non-interactive mode, returns (false, nil) to preserve local changes.
PromptMetadataConflict(diff *engine.MetadataDiff) (acceptRemote bool, err error)
// PromptOrphanedMetadata asks what to do when remote metadata was deleted but local has changes.
// Returns true to push local metadata to remote, false to accept deletion.
// In non-interactive mode, returns (false, nil) to accept the remote deletion.
PromptOrphanedMetadata(info engine.OrphanedMetadataInfo) (pushLocal bool, err error)
// PromptBranchDeletions displays planned branch deletions and asks user to confirm each one.
// unpushedBranches identifies branches with local commits not yet pushed to remote.
// Returns a map of branch names that the user confirmed for deletion.
// In non-interactive mode, returns all branches except unpushed ones (which are skipped by default).
PromptBranchDeletions(branches map[string]string, unpushedBranches map[string]bool) (confirmed map[string]bool, err error)
// PromptResolveConflicts asks user if they want to resolve restack conflicts now or skip them.
// Returns true to start conflict resolution workflow, false to skip and continue.
// In non-interactive mode, returns (false, nil) to skip conflicts.
PromptResolveConflicts(conflictBranches []string) (resolve bool, err error)
// RestackHandler methods are available for restack-specific output
// This allows the same handler to be used for standalone restack operations
RestackHandler
}
Handler abstracts TTY vs non-TTY output for sync operations It embeds RestackHandler to provide a unified interface for operations that include restacking
type NullHandler ¶
NullHandler is a no-op handler for testing or when output is not needed NullHandler is a no-op handler for when nil is passed. It embeds handler.NullBase for Cleanup() and IsInteractive().
func (*NullHandler) EmitEvent ¶
func (h *NullHandler) EmitEvent(Event)
EmitEvent implements Handler.
func (*NullHandler) OnRestackBranch ¶
func (h *NullHandler) OnRestackBranch(string, RestackResult, string, *int, engine.LockReason, bool, bool, string, bool, string, string, int)
OnRestackBranch implements RestackHandler.
func (*NullHandler) OnRestackComplete ¶
func (h *NullHandler) OnRestackComplete(int, int, []string)
OnRestackComplete implements RestackHandler.
func (*NullHandler) OnRestackStart ¶
func (h *NullHandler) OnRestackStart(int)
OnRestackStart implements RestackHandler.
func (*NullHandler) PromptBranchDeletions ¶
func (h *NullHandler) PromptBranchDeletions(branches map[string]string, unpushedBranches map[string]bool) (map[string]bool, error)
PromptBranchDeletions implements Handler. Skips unpushed branches, auto-confirms the rest.
func (*NullHandler) PromptMetadataConflict ¶
func (h *NullHandler) PromptMetadataConflict(_ *engine.MetadataDiff) (bool, error)
PromptMetadataConflict implements Handler. Returns false (keep local) in non-interactive mode.
func (*NullHandler) PromptOrphanedMetadata ¶
func (h *NullHandler) PromptOrphanedMetadata(_ engine.OrphanedMetadataInfo) (bool, error)
PromptOrphanedMetadata implements Handler. Returns false (accept deletion) in non-interactive mode.
func (*NullHandler) PromptResolveConflicts ¶
func (h *NullHandler) PromptResolveConflicts(_ []string) (bool, error)
PromptResolveConflicts implements Handler. Returns false (skip) in non-interactive mode.
type Options ¶
type Options struct {
All bool
Force bool
Restack bool // Explicitly restack the full current stack (opt-in)
NoRestack bool // Skip all restacking entirely
DryRun bool
RestackScope []string // When non-nil, only restack these branches (skip current-branch expansion)
}
Options contains options for the sync command
type ParentsToGitHubResult ¶
type ParentsToGitHubResult struct {
BranchesUpdated []string // Branches whose PR base was updated on GitHub
}
ParentsToGitHubResult contains the result of pushing local parents to GitHub
func PushParentsToGitHub ¶
func PushParentsToGitHub(ctx *app.Context, result *GitHubSyncResult, dirtyAnchors map[string]bool) (*ParentsToGitHubResult, error)
PushParentsToGitHub pushes local parent relationships to GitHub PR bases. Local metadata is authoritative - if local parent differs from GitHub PR base, update GitHub.
type RestackHandler ¶
type RestackHandler = handlers.RestackHandler
RestackHandler is an alias for handlers.RestackHandler
type RestackResult ¶
type RestackResult = handlers.RestackResult
RestackResult is an alias for handlers.RestackResult
type StackMetadataGCResult ¶
type StackMetadataGCResult struct {
DeletedStackIDs []string // Stack IDs whose refs were deleted
Errors []string // Any errors encountered (non-fatal)
}
StackMetadataGCResult contains the results of stack metadata garbage collection.
type Summary ¶
type Summary struct {
TrunkUpdated bool // Was trunk updated?
TrunkRevision string // New trunk revision (short hash)
BranchesSynced int // Number of branches synced from remote
BranchesRestacked int // Number of branches restacked
BranchesDeleted int // Number of branches deleted
BranchesSkipped int // Number of branches skipped (due to conflicts)
ConflictBranches []string // Names of branches that conflicted
UpToDate bool // Everything was already current
WorktreesCleaned int // Number of orphaned worktrees cleaned up
SkippedStacks []string // Stacks skipped due to dirty worktrees
}
Summary holds aggregate results from a sync operation
func (*Summary) HasChanges ¶
HasChanges returns true if any operations were performed
type WorktreeCleanupResult ¶
type WorktreeCleanupResult struct {
RemovedWorktrees []string // Stack roots whose worktrees were removed
Errors []string // Any errors encountered (non-fatal)
}
WorktreeCleanupResult contains the results of worktree cleanup