Documentation
¶
Index ¶
- func ConfigDir() (string, error)
- type Branch
- type BranchCache
- type BranchTree
- type CacheConfig
- type Config
- func (c *Config) GetBaseBranch(repoPath string) string
- func (c *Config) GetCdAfterNew(repoPath string) bool
- func (c *Config) GetRepoConfig(repoPath string) *RepoConfig
- func (c *Config) GetWorktreeBaseDir(repoPath string) string
- func (c *Config) Save() error
- func (c *Config) SetRepoConfig(repoPath string, repoCfg *RepoConfig)
- type RepoConfig
- type Stack
- func (s *Stack) AddBranch(branchName, parentName string)
- func (s *Stack) AddSubtree(branchName string, subtree BranchTree, parentName string)
- func (s *Stack) ExtractSubtree(branchName string) BranchTree
- func (s *Stack) FindBranch(branchName string) (parent string, found bool)
- func (s *Stack) GetBranches(cache *CacheConfig) []*Branch
- func (s *Stack) GetChildren(branchName string) []string
- func (s *Stack) HasBranch(branchName string) bool
- func (s *Stack) PopulateBranches()
- func (s *Stack) PopulateBranchesWithCache(cache *CacheConfig)
- func (s *Stack) RemoveBranch(branchName string)
- func (s *Stack) ReparentBranch(branchName, newParent string)
- func (s *Stack) SetCache(cache *CacheConfig)
- type StackConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Branch ¶
type Branch struct {
Name string `json:"name"`
Parent string `json:"parent"` // Parent branch name
WorktreePath string `json:"worktree_path"` // Path to the worktree
PRNumber int `json:"pr_number,omitempty"`
PRUrl string `json:"pr_url,omitempty"`
BaseBranch string `json:"base_branch"` // The branch this PR targets (same as Parent for display)
IsRemote bool `json:"is_remote,omitempty"` // True if this is someone else's branch
IsMerged bool `json:"is_merged,omitempty"` // True if this branch's PR has been merged
}
Branch represents a single branch in a stack (used internally for compatibility) This is constructed from the tree structure and cache at runtime
func SortBranchesTopologically ¶
SortBranchesTopologically sorts branches so parents come before children This ensures the display shows the correct parent -> child order IMPORTANT: When a parent branch is merged and its children are reparented to main, the merged branch should still appear in its original position (before its former children). We use BaseBranch to detect the original parent-child relationships.
type BranchCache ¶
type BranchCache struct {
WorktreePath string `json:"worktree_path,omitempty"`
PRNumber int `json:"pr_number,omitempty"`
PRUrl string `json:"pr_url,omitempty"`
IsMerged bool `json:"is_merged,omitempty"`
IsRemote bool `json:"is_remote,omitempty"`
}
BranchCache holds cached metadata for a branch (stored in cache.json)
type BranchTree ¶
type BranchTree map[string]BranchTree
BranchTree is a recursive map representing the stack hierarchy Each key is a branch name, and its value is another BranchTree of its children
type CacheConfig ¶
type CacheConfig struct {
Branches map[string]*BranchCache `json:"branches"`
// contains filtered or unexported fields
}
CacheConfig holds cached branch metadata for a repo
func LoadCacheConfig ¶
func LoadCacheConfig(repoDir string) (*CacheConfig, error)
LoadCacheConfig loads cached branch metadata from $HOME/.ezstack/cache.json
func (*CacheConfig) GetBranchCache ¶
func (cc *CacheConfig) GetBranchCache(branchName string) *BranchCache
GetBranchCache returns cached metadata for a branch
func (*CacheConfig) Save ¶
func (cc *CacheConfig) Save(repoDir string) error
Save saves the cache config for this repo to $HOME/.ezstack/cache.json
func (*CacheConfig) SetBranchCache ¶
func (cc *CacheConfig) SetBranchCache(branchName string, cache *BranchCache)
SetBranchCache sets cached metadata for a branch
type Config ¶
type Config struct {
// DefaultBaseBranch is the default base branch (usually "main" or "master")
DefaultBaseBranch string `json:"default_base_branch"`
// GitHubToken for API access (optional, can use gh cli)
GitHubToken string `json:"github_token,omitempty"`
// Repos holds per-repository configuration, keyed by repo path
Repos map[string]*RepoConfig `json:"repos"`
}
Config holds the global configuration for ezstack
func (*Config) GetBaseBranch ¶
GetBaseBranch returns the base branch for a repo (repo-specific or global default)
func (*Config) GetCdAfterNew ¶
GetCdAfterNew returns whether to cd after creating a new worktree (default: false)
func (*Config) GetRepoConfig ¶
func (c *Config) GetRepoConfig(repoPath string) *RepoConfig
GetRepoConfig returns the configuration for a specific repo path
func (*Config) GetWorktreeBaseDir ¶
GetWorktreeBaseDir returns the worktree base dir for a repo, or empty if not configured
func (*Config) SetRepoConfig ¶
func (c *Config) SetRepoConfig(repoPath string, repoCfg *RepoConfig)
SetRepoConfig sets the configuration for a specific repo
type RepoConfig ¶
type RepoConfig struct {
// RepoPath is the absolute path to the main repository
RepoPath string `json:"repo_path"`
// WorktreeBaseDir is where worktrees are created for this repo
WorktreeBaseDir string `json:"worktree_base_dir"`
// DefaultBaseBranch overrides the global default for this repo
DefaultBaseBranch string `json:"default_base_branch,omitempty"`
// CdAfterNew if true, outputs cd command after creating new worktree
CdAfterNew *bool `json:"cd_after_new,omitempty"`
// AutoDraftWipCommits if true, auto-creates draft PRs when commit starts with "wip"
AutoDraftWipCommits *bool `json:"auto_draft_wip_commits,omitempty"`
}
RepoConfig holds configuration for a specific repository
type Stack ¶
type Stack struct {
Name string `json:"name"`
Root string `json:"root"` // The base branch (usually "main")
Tree BranchTree `json:"tree"` // The tree of branches
Branches []*Branch `json:"-"` // Runtime-only: populated from Tree for backward compatibility
// contains filtered or unexported fields
}
Stack represents a chain of stacked branches as a tree
func (*Stack) AddSubtree ¶
func (s *Stack) AddSubtree(branchName string, subtree BranchTree, parentName string)
AddSubtree adds a branch with its subtree under a parent
func (*Stack) ExtractSubtree ¶
func (s *Stack) ExtractSubtree(branchName string) BranchTree
ExtractSubtree removes a branch and its entire subtree from the stack and returns the subtree
func (*Stack) FindBranch ¶
FindBranch finds a branch in the tree and returns its parent name
func (*Stack) GetBranches ¶
func (s *Stack) GetBranches(cache *CacheConfig) []*Branch
GetBranches returns a flat list of branches from the tree structure Branches are returned in depth-first order with siblings sorted alphabetically The cache is used to populate metadata fields
func (*Stack) GetChildren ¶
GetChildren returns the immediate children of a branch
func (*Stack) PopulateBranches ¶
func (s *Stack) PopulateBranches()
PopulateBranches rebuilds the Branches slice from the Tree structure This should be called after loading or after modifying the Tree
func (*Stack) PopulateBranchesWithCache ¶
func (s *Stack) PopulateBranchesWithCache(cache *CacheConfig)
PopulateBranchesWithCache rebuilds the Branches slice using the provided cache
func (*Stack) RemoveBranch ¶
RemoveBranch removes a branch from the stack tree If the branch has children, they are moved up to the branch's parent
func (*Stack) ReparentBranch ¶
ReparentBranch moves a branch to be under a new parent If newParent is empty or matches the root, the branch becomes a root-level branch
func (*Stack) SetCache ¶
func (s *Stack) SetCache(cache *CacheConfig)
SetCache sets the cache for this stack, allowing branch metadata to be loaded
type StackConfig ¶
type StackConfig struct {
Stacks map[string]*Stack `json:"stacks"`
// contains filtered or unexported fields
}
StackConfig holds metadata about stacks for a single repo
func LoadStackConfig ¶
func LoadStackConfig(repoDir string) (*StackConfig, error)
LoadStackConfig loads stack metadata for a specific repo from $HOME/.ezstack/stacks.json It handles migration from the legacy flat array format to the new tree format
func (*StackConfig) Save ¶
func (sc *StackConfig) Save(repoDir string) error
Save saves the stack config for this repo to $HOME/.ezstack/stacks.json