Documentation
¶
Index ¶
- func ConfigDir() (string, error)
- func GenerateStackHash(name string) string
- func PRNumberFromURL(url string) int
- 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) GetSyncStrategy(repoPath string) string
- func (c *Config) GetUseWorktrees(repoPath string) bool
- 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) bool
- func (s *Stack) DisplayName() 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) IsFullyMerged(cache *CacheConfig) bool
- func (s *Stack) PopulateBranches()
- func (s *Stack) PopulateBranchesWithCache(cache *CacheConfig)
- func (s *Stack) RemoveBranch(branchName string)
- func (s *Stack) RenameBranchInTree(oldName, newName string) bool
- 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 ¶
func ConfigDir ¶
ConfigDir returns the path to the ezstack config directory. Checks EZSTACK_HOME first, then defaults to $HOME/.ezstack.
func GenerateStackHash ¶ added in v0.1.2
GenerateStackHash generates a 7-char hex hash from a stack name using FNV-32a
func PRNumberFromURL ¶ added in v1.3.0
PRNumberFromURL extracts the PR number from a GitHub PR URL. e.g. "https://github.com/owner/repo/pull/123" → 123 Returns 0 if the URL is empty or unparseable.
Types ¶
type Branch ¶
type Branch struct {
Name string `json:"name"`
Parent string `json:"parent"`
WorktreePath string `json:"worktree_path"`
PRNumber int `json:"-"` // Runtime-only: derived from PRUrl via PRNumberFromURL
PRUrl string `json:"pr_url,omitempty"`
PRState string `json:"pr_state,omitempty"` // Cached: "OPEN", "DRAFT", "MERGED", "CLOSED"
BaseBranch string `json:"base_branch"` // original tree parent, used for display ordering
IsRemote bool `json:"is_remote,omitempty"` // branch belongs to another contributor
IsMerged bool `json:"is_merged,omitempty"`
}
Branch represents a single branch in a stack, constructed from the tree 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:"-"` // Runtime-only: derived from PRUrl via PRNumberFromURL
PRUrl string `json:"pr_url,omitempty"`
PRState string `json:"pr_state,omitempty"` // Cached: "OPEN", "DRAFT", "MERGED", "CLOSED"
IsMerged bool `json:"is_merged,omitempty"`
IsRemote bool `json:"is_remote,omitempty"`
}
BranchCache holds cached metadata for a branch
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. This now delegates to the combined stacks file. Kept for backward compatibility with callers that load cache separately.
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 writes the cache data back to the combined stacks.json file. This loads the current stacks.json, updates the branches for this repo, and writes it back atomically.
func (*CacheConfig) SetBranchCache ¶
func (cc *CacheConfig) SetBranchCache(branchName string, cache *BranchCache)
SetBranchCache sets cached metadata for a branch
type Config ¶
type Config struct {
DefaultBaseBranch string `json:"default_base_branch"`
GitHubToken string `json:"github_token,omitempty"`
Repos map[string]*RepoConfig `json:"repos"`
}
Config holds the global configuration for ezstack
func Load ¶
Load loads the configuration from ~/.ezstack/config.json. Top-level scalar values are resolved through Viper so that EZSTACK_-prefixed environment variables (e.g. EZSTACK_GITHUB_TOKEN) take precedence over the file. The repos map is read directly from JSON because Viper lowercases all keys, which would corrupt filesystem-path map keys like /Users/….
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: true)
func (*Config) GetRepoConfig ¶
func (c *Config) GetRepoConfig(repoPath string) *RepoConfig
GetRepoConfig returns the configuration for a specific repo path
func (*Config) GetSyncStrategy ¶ added in v1.8.0
GetSyncStrategy returns the sync strategy for a repo ("rebase" or "merge", default "rebase")
func (*Config) GetUseWorktrees ¶ added in v1.1.1
GetUseWorktrees returns whether to use worktrees for new branches (default: true)
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 string `json:"repo_path"`
WorktreeBaseDir string `json:"worktree_base_dir"`
DefaultBaseBranch string `json:"default_base_branch,omitempty"`
CdAfterNew *bool `json:"cd_after_new,omitempty"`
UseWorktrees *bool `json:"use_worktrees,omitempty"`
AutoDraftWipCommits *bool `json:"auto_draft_wip_commits,omitempty"`
SyncStrategy string `json:"sync_strategy,omitempty"` // "rebase" (default) or "merge"
}
RepoConfig holds configuration for a specific repository
type Stack ¶
type Stack struct {
Hash string `json:"-"` // Populated from map key at load time
Name string `json:"name,omitempty"` // Optional user-given name for the stack
Root string `json:"root"` // The base branch (e.g. "main", or a remote branch name)
RootPRNumber int `json:"-"` // Runtime-only: derived from RootPRUrl
RootPRUrl string `json:"root_pr_url,omitempty"` // PR URL of the root branch (for remote base branches)
DeleteDeclined bool `json:"delete_declined,omitempty"` // User declined cleanup prompt; don't re-ask
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 Hash is the map key in StackConfig.Stacks and is populated at load time.
func (*Stack) AddSubtree ¶
func (s *Stack) AddSubtree(branchName string, subtree BranchTree, parentName string) bool
AddSubtree adds a branch with its subtree under a parent. Returns false if parentName was not found in the tree (non-root case).
func (*Stack) DisplayName ¶ added in v1.1.0
DisplayName returns the display string for a stack: "name hash" or just hash
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) IsFullyMerged ¶ added in v0.1.2
func (s *Stack) IsFullyMerged(cache *CacheConfig) bool
IsFullyMerged returns true if every branch in the stack is marked as merged
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) RenameBranchInTree ¶ added in v0.1.2
RenameBranchInTree renames a branch in the tree, preserving its children and position
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"`
Cache *CacheConfig `json:"-"` // loaded alongside stacks, not serialized separately
// 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 and branch cache for a specific repo from $HOME/.ezstack/stacks.json It handles migration from older formats using a versioned migration chain.
func (*StackConfig) Save ¶
func (sc *StackConfig) Save(repoDir string) error
Save saves the stack config and cache for this repo to $HOME/.ezstack/stacks.json