parallel

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package parallel provides multi-worktree orchestration for parallel branch execution.

This package extends devflow's git worktree primitives to support fork/join workflows where multiple branches execute in parallel, each in their own isolated worktree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConflictFile

type ConflictFile struct {
	Path          string // File path relative to repo root
	OursContent   string // Content from base branch
	TheirsContent string // Content from feature branch
	Markers       string // Full file content with conflict markers
}

ConflictFile describes a merge conflict.

type Manager

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

Manager orchestrates multiple worktrees for parallel branch execution.

It maintains a mapping from branch IDs (logical identifiers from the workflow) to git worktree paths. Each parallel branch gets its own isolated worktree, allowing concurrent git operations without conflicts.

The Manager uses the "base branch" (whatever branch was checked out at fork time) as the starting point for all branch worktrees. Merges go back to this base branch, NOT to a hardcoded "main" branch.

Thread-safe for concurrent worktree operations.

func NewManager

func NewManager(baseDir, repoPath, baseBranch string) (*Manager, error)

NewManager creates a ParallelWorktreeManager for the given repository.

baseDir is where worktrees will be created (e.g., /tmp/worktrees/run-123) repoPath is the path to the main repository baseBranch is the current branch (working branch) - merges return here

func (*Manager) AbortMerge

func (m *Manager) AbortMerge() error

AbortMerge aborts an in-progress merge.

func (*Manager) BaseBranch

func (m *Manager) BaseBranch() string

BaseBranch returns the base branch name (where merges go).

func (*Manager) BaseDir

func (m *Manager) BaseDir() string

BaseDir returns the directory where worktrees are created.

func (*Manager) BaseRepo

func (m *Manager) BaseRepo() string

BaseRepo returns the path to the base repository.

func (*Manager) BranchCount

func (m *Manager) BranchCount() int

BranchCount returns the number of active branch worktrees.

func (*Manager) CleanupAll

func (m *Manager) CleanupAll() error

CleanupAll removes all branch worktrees.

func (*Manager) CleanupBranch

func (m *Manager) CleanupBranch(branchID string) error

CleanupBranch removes a single branch worktree.

func (*Manager) ContinueMerge

func (m *Manager) ContinueMerge(message string) error

ContinueMerge completes a merge after conflicts have been resolved.

func (*Manager) CreateBranchWorktree

func (m *Manager) CreateBranchWorktree(branchID, gitBranch string) (string, error)

CreateBranchWorktree creates an isolated worktree for a parallel branch.

branchID is the logical identifier from the workflow (e.g., "workerA") gitBranch is the git branch name to create/checkout (if empty, uses branchID)

Returns the path to the worktree directory.

func (*Manager) GetWorktreePath

func (m *Manager) GetWorktreePath(branchID string) string

GetWorktreePath returns the worktree path for a branch ID. Returns empty string if not found.

func (*Manager) GitContextForBranch

func (m *Manager) GitContextForBranch(branchID string) (*git.Context, error)

GitContextForBranch creates a git.Context for a specific branch's worktree. Returns nil if the branch doesn't have a worktree.

func (*Manager) ListBranchWorktrees

func (m *Manager) ListBranchWorktrees() map[string]string

ListBranchWorktrees returns all active branch worktrees.

func (*Manager) MergeBranches

func (m *Manager) MergeBranches(ctx context.Context, cfg MergeConfig) ([]MergeResult, error)

MergeBranches merges all branch worktrees back to the base working branch. Returns results for each branch, including any conflicts.

func (*Manager) MergeSingleBranch

func (m *Manager) MergeSingleBranch(ctx context.Context, branchID string, cfg MergeConfig) *MergeResult

MergeSingleBranch merges one branch worktree back to the base working branch.

func (*Manager) ResolveConflict

func (m *Manager) ResolveConflict(path, resolvedContent string) error

ResolveConflict writes resolved content for a conflicted file.

type MergeConfig

type MergeConfig struct {
	// CommitMessage is the message for the merge commit (if not fast-forward)
	CommitMessage string

	// NoFastForward forces a merge commit even if fast-forward is possible
	NoFastForward bool

	// SquashMerge squashes all branch commits into one
	SquashMerge bool
}

MergeConfig configures how branches are merged back to base.

type MergeResult

type MergeResult struct {
	BranchID  string
	Success   bool
	Conflicts []ConflictFile
	CommitSHA string
	Error     error
}

MergeResult contains the outcome of merging a branch.

Jump to

Keyboard shortcuts

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