sync

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package sync provides functionality for synchronizing stacked branches with remote repositories.

Index

Constants

View Source
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 Action

func Action(ctx *app.Context, opts Options, handler Handler) error

Action performs the sync operation

func FormatSummaryParts

func FormatSummaryParts(summary Summary) []string

FormatSummaryParts returns the summary parts as a slice of strings This is shared between SimpleSyncHandler and InteractiveSyncHandler

func FormatSummaryString

func FormatSummaryString(summary Summary) string

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

func (Event) IsLocked

func (e Event) IsLocked() bool

IsLocked returns true if the event associated branch is locked

type EventType

type EventType string

EventType represents the type of sync event

const (
	EventStarted   EventType = "started"
	EventProgress  EventType = "progress"
	EventCompleted EventType = "completed"
	EventSkipped   EventType = "skipped"
)

Event types for sync operations

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

type NullHandler struct {
	handler.NullBase
}

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) Complete

func (h *NullHandler) Complete(Summary)

Complete implements Handler.

func (*NullHandler) EmitEvent

func (h *NullHandler) EmitEvent(Event)

EmitEvent implements Handler.

func (*NullHandler) OnRestackBranch

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.

func (*NullHandler) Start

func (h *NullHandler) Start(int)

Start implements Handler.

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 Phase

type Phase string

Phase represents the current phase of the sync operation

const (
	PhaseTrunk    Phase = "trunk"
	PhaseBranches Phase = "branches"
	PhaseGitHub   Phase = "github"
	PhaseClean    Phase = "clean"
	PhaseRestack  Phase = "restack"
)

Phases of the sync operation

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

func (s *Summary) HasChanges() bool

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

Jump to

Keyboard shortcuts

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