stack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterRebaseCallback

type AfterRebaseCallback func(result RebaseResult, g *git.Git) bool

AfterRebaseCallback is called after each successful rebase It receives the result and the git instance for the worktree Returns true if sync should continue, false to stop

type BeforeRebaseCallback

type BeforeRebaseCallback func(info SyncInfo) bool

BeforeRebaseCallback is called before each rebase to ask for confirmation It receives the sync info for the branch about to be synced Returns true to proceed with rebase, false to skip this branch

type CleanupResult

type CleanupResult struct {
	Branch             string
	Success            bool
	Error              string
	WorktreeWasDeleted bool // True if worktree was already deleted before cleanup
}

CleanupResult contains information about a branch cleanup operation

type Manager

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

Manager handles stack operations

func NewManager

func NewManager(repoDir string) (*Manager, error)

NewManager creates a new stack manager

func (*Manager) AddBranchToStack

func (m *Manager) AddBranchToStack(name, parentBranch, worktreeDir string) (*config.Branch, error)

AddBranchToStack adds an existing branch to a stack (worktree should already exist) This is used when the worktree was created externally (e.g., from a remote branch)

func (*Manager) AddWorktreeToStack

func (m *Manager) AddWorktreeToStack(branchName, worktreePath, parentName string) (*config.Branch, error)

AddWorktreeToStack adds an unregistered worktree to a stack with the specified parent

func (*Manager) CleanupMergedBranches

func (m *Manager) CleanupMergedBranches(branches []MergedBranchInfo, currentDir string) []CleanupResult

CleanupMergedBranches marks branches as merged - deletes worktrees and git branches but keeps metadata in config This allows merged PRs to still show up in ezs ls/status with strikethrough styling Returns detailed results for each branch cleanup operation

func (*Manager) CreateBranch

func (m *Manager) CreateBranch(name, parentBranch, worktreeDir string) (*config.Branch, error)

CreateBranch creates a new branch in the stack

func (*Manager) CreateWorktreeOnly

func (m *Manager) CreateWorktreeOnly(name, parentBranch, worktreeDir string) error

CreateWorktreeOnly creates a worktree without adding it to a stack This is used when the user wants to create a standalone worktree from main/master

func (*Manager) DeleteBranch

func (m *Manager) DeleteBranch(branchName string, force bool) error

DeleteBranch removes a branch from the stack and deletes its worktree Returns an error if the branch has child branches

func (*Manager) DetectMergedBranches

func (m *Manager) DetectMergedBranches(gh *github.Client) ([]MergedBranchInfo, error)

DetectMergedBranches finds branches in the CURRENT stack whose PRs have been merged to main These are candidates for cleanup (deleting local branch and worktree)

func (*Manager) DetectMergedBranchesAllStacks

func (m *Manager) DetectMergedBranchesAllStacks(gh *github.Client) ([]MergedBranchInfo, error)

DetectMergedBranchesAllStacks finds branches across ALL stacks whose PRs have been merged to main

func (*Manager) DetectMissingWorktrees

func (m *Manager) DetectMissingWorktrees() []MissingWorktreeInfo

DetectMissingWorktrees finds branches whose worktree directories no longer exist on disk This can happen when a user manually removes a worktree with `rm -rf`

func (*Manager) DetectOrphanedBranches

func (m *Manager) DetectOrphanedBranches() []string

DetectOrphanedBranches finds branches in config that no longer exist in git

func (*Manager) DetectSyncNeeded

func (m *Manager) DetectSyncNeeded(gh *github.Client) ([]SyncInfo, error)

DetectSyncNeeded checks for branches that need syncing in the CURRENT stack only: - Branches whose parents have been merged to main - Branches whose parent is main but are behind origin/main

func (*Manager) DetectSyncNeededAllStacks

func (m *Manager) DetectSyncNeededAllStacks(gh *github.Client) ([]SyncInfo, error)

DetectSyncNeededAllStacks checks for branches that need syncing across ALL stacks: - Branches whose parents have been merged to main - Branches whose parent is main but are behind origin/main

func (*Manager) DetectSyncNeededForBranch

func (m *Manager) DetectSyncNeededForBranch(branchName string, gh *github.Client) *SyncInfo

DetectSyncNeededForBranch checks if a specific branch needs syncing Returns SyncInfo if the branch needs syncing, nil otherwise

func (*Manager) GetAllBranchesInAllStacks

func (m *Manager) GetAllBranchesInAllStacks() []*config.Branch

GetAllBranchesInAllStacks returns all branches across all stacks

func (*Manager) GetBranch

func (m *Manager) GetBranch(name string) *config.Branch

GetBranch returns a branch by name

func (*Manager) GetChildren

func (m *Manager) GetChildren(branchName string) []*config.Branch

GetChildren returns all child branches of a given branch

func (*Manager) GetCurrentStack

func (m *Manager) GetCurrentStack() (*config.Stack, *config.Branch, error)

GetCurrentStack returns the stack for the current branch

func (*Manager) GetRepoDir

func (m *Manager) GetRepoDir() string

GetRepoDir returns the main repository directory

func (*Manager) GetUnregisteredWorktrees

func (m *Manager) GetUnregisteredWorktrees() ([]git.Worktree, error)

GetUnregisteredWorktrees returns worktrees that exist but are not registered in any stack

func (*Manager) HandleMissingWorktrees

func (m *Manager) HandleMissingWorktrees(branches []MissingWorktreeInfo) error

HandleMissingWorktrees cleans up branches whose worktrees were manually removed It removes the branches from the stack config (git worktree prune should be called first)

func (*Manager) IsMainBranch

func (m *Manager) IsMainBranch(name string) bool

IsMainBranch checks if a branch is the main/master branch

func (*Manager) ListStacks

func (m *Manager) ListStacks() []*config.Stack

ListStacks returns all stacks

func (*Manager) MarkBranchMerged

func (m *Manager) MarkBranchMerged(branchName string) error

MarkBranchMerged marks a branch as merged - deletes worktree and git branch but keeps metadata in config This allows merged branches to still show up in ezs ls/status with strikethrough The tree structure is NOT modified - children stay under the merged parent for display order. The effective git parent for children is computed at runtime by skipping merged ancestors.

func (*Manager) RebaseChildren

func (m *Manager) RebaseChildren() ([]RebaseResult, error)

RebaseChildren rebases all child branches after updating the current branch Returns results for each child branch processed

func (*Manager) RebaseOnParent

func (m *Manager) RebaseOnParent() error

RebaseOnParent rebases the current branch onto its updated parent

func (*Manager) RegisterExistingBranch

func (m *Manager) RegisterExistingBranch(branchName, worktreePath, baseBranch string) (*config.Branch, error)

RegisterExistingBranch registers an existing branch/worktree as the root of a new stack

func (*Manager) RegisterRemoteBranch

func (m *Manager) RegisterRemoteBranch(branchName, baseBranch string, prNumber int, prURL string) (*config.Branch, error)

RegisterRemoteBranch registers a remote branch (someone else's PR) as the root of a new stack Remote branches don't have local worktrees - only their child branches do

func (*Manager) RemoveOrphanedBranches

func (m *Manager) RemoveOrphanedBranches(branchNames []string) error

RemoveOrphanedBranches removes branches from config that no longer exist in git

func (*Manager) ReparentBranch

func (m *Manager) ReparentBranch(branchName, newParentName string, doRebase bool) (*config.Branch, error)

ReparentBranch changes the parent of a branch to a new parent This handles several cases: 1. Branch is already in a stack - just update parent pointer 2. Branch is standalone (not in any stack) - add it to the new parent's stack 3. New parent is in a different stack - merge stacks or move branch If doRebase is true, performs git rebase --onto to move commits Returns the updated branch and any error

func (*Manager) SyncBranch

func (m *Manager) SyncBranch(branchName string, gh *github.Client) (*RebaseResult, error)

SyncBranch syncs a specific branch, handling all cases: - Branch is behind origin/main (parent is main) - Parent branch was merged (rebase --onto main) - Branch is behind its parent (rebase onto parent)

func (*Manager) SyncStack

func (m *Manager) SyncStack(gh *github.Client, callbacks *SyncCallbacks) ([]RebaseResult, error)

SyncStack syncs branches in the CURRENT stack only that need syncing This handles three cases: - Branches whose parent is main but are behind origin/main (simple rebase) - Branches whose parent was merged (rebase onto main using --onto) - Branches whose parent is not merged but has new commits (rebase onto parent) Callbacks can be used to ask for confirmation before each rebase and push after

func (*Manager) SyncStackAll

func (m *Manager) SyncStackAll(gh *github.Client, callbacks *SyncCallbacks) ([]RebaseResult, error)

SyncStackAll syncs branches in ALL stacks that need syncing

func (*Manager) UntrackBranch

func (m *Manager) UntrackBranch(branchName string) error

UntrackBranch removes a branch from ezstack tracking without deleting the git branch or worktree Children of the untracked branch are reparented to the untracked branch's parent

type MergedBranchInfo

type MergedBranchInfo struct {
	Branch       string
	PRNumber     int
	WorktreePath string
	StackName    string
}

MergedBranchInfo contains information about a branch whose PR has been merged

type MissingWorktreeInfo

type MissingWorktreeInfo struct {
	BranchName   string
	WorktreePath string
}

MissingWorktreeInfo contains info about a branch whose worktree was removed

type RebaseResult

type RebaseResult struct {
	Branch       string
	Success      bool
	HasConflict  bool
	Error        error
	SyncedParent string // If non-empty, parent was merged and we synced to this new parent
	WorktreePath string // Path to the worktree (useful for conflict resolution)
	BehindBy     int    // Number of commits behind (for branches that need sync with origin/main)
}

RebaseResult represents the result of a rebase operation

type ReparentInfo

type ReparentInfo struct {
	BranchName string
	OldParent  string
	NewParent  string
}

ReparentInfo contains info about a branch that was reparented

type SyncCallbacks

type SyncCallbacks struct {
	BeforeRebase BeforeRebaseCallback
	AfterRebase  AfterRebaseCallback
}

SyncCallbacks contains optional callbacks for sync operations

type SyncInfo

type SyncInfo struct {
	Branch       string
	MergedParent string // Non-empty if parent was merged
	BehindBy     int    // Number of commits behind target
	BehindParent string // Non-empty if behind a non-main parent
	NeedsSync    bool   // True if branch needs to be synced
}

SyncInfo contains information about a branch that needs syncing

type UpdateResult

type UpdateResult struct {
	// Branches that were removed from config because they no longer exist in git
	RemovedBranches []string
	// Worktrees that were discovered and added to stacks
	AddedBranches []*config.Branch
	// Branches whose parent was updated based on merge-base analysis
	ReparentedBranches []ReparentInfo
}

UpdateResult contains the results of an update operation

Jump to

Keyboard shortcuts

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