Documentation
¶
Overview ¶
Package config handles loading and validation of wt configuration.
Configuration is read from ~/.config/wt/config.toml with environment variable overrides for directory settings.
Configuration Sources (highest priority first) ¶
- WT_WORKTREE_DIR env var: Target directory for worktrees
- WT_REPO_DIR env var: Directory to scan for repositories
- Config file settings
- Default values
Key Settings ¶
- worktree_dir: Base directory for new worktrees (must be absolute or ~/...)
- repo_dir: Optional separate directory for repo scanning
- worktree_format: Template for worktree folder names (default: "{repo}-{branch}")
- base_ref: "local" or "remote" for new branch base (default: "remote")
- default_sort: Default sort order for "wt list"
Hooks Configuration ¶
Hooks are defined in [hooks.NAME] sections:
[hooks.vscode]
command = "code {path}"
description = "Open VS Code"
on = ["add"] # auto-run for add command
Hooks with "on" run automatically for matching commands (add, pr, prune, merge). Hooks without "on" only run via explicit --hook=name flag.
Forge Configuration ¶
The [clone] section configures default forge and pattern-based rules:
[clone] forge = "github" [[clone.rules]] pattern = "company/*" forge = "gitlab"
The [hosts] section maps custom domains to forge types for self-hosted instances.
Path Validation ¶
Directory paths must be absolute or start with ~ (no relative paths like "." or "..") to avoid confusion about the working directory.
Index ¶
Constants ¶
const DefaultWorktreeFormat = "{repo}-{branch}"
DefaultWorktreeFormat is the default format for worktree folder names
Variables ¶
This section is empty.
Functions ¶
func DefaultConfig ¶ added in v0.4.0
func DefaultConfig() string
DefaultConfig returns the default configuration content.
func Init ¶
Init creates a default config file at ~/.config/wt/config.toml If force is true, overwrites existing file Returns the path to the created file
func ValidatePath ¶
ValidatePath checks that the path is absolute or starts with ~ Returns error if path is relative (like "." or "..")
Types ¶
type CloneConfig ¶
type CloneConfig struct {
Forge string `toml:"forge"` // default forge: "github" or "gitlab"
Org string `toml:"org"` // default organization when not specified
Rules []CloneRule `toml:"rules"` // pattern-based rules
}
CloneConfig holds clone-related configuration
func (*CloneConfig) GetForgeForRepo ¶
func (c *CloneConfig) GetForgeForRepo(repoSpec string) string
GetForgeForRepo returns the forge name for a given repo spec (e.g., "org/repo") Matches against clone rules in order, returns default if no match
type CloneRule ¶
type CloneRule struct {
Pattern string `toml:"pattern"` // glob pattern like "n26/*" or "company/*"
Forge string `toml:"forge"` // "github" or "gitlab"
}
CloneRule maps a pattern to a forge
type Config ¶
type Config struct {
WorktreeDir string `toml:"worktree_dir"`
RepoDir string `toml:"repo_dir"` // optional: where to find repos for -r/-l
WorktreeFormat string `toml:"worktree_format"`
BaseRef string `toml:"base_ref"` // "local" or "remote" (default: "remote")
DefaultSort string `toml:"default_sort"` // "id", "repo", "branch", "commit" (default: "id")
Hooks HooksConfig `toml:"-"` // custom parsing needed
Clone CloneConfig `toml:"clone"`
Merge MergeConfig `toml:"merge"`
Hosts map[string]string `toml:"hosts"` // domain -> forge type mapping
}
Config holds the wt configuration
func Load ¶
Load reads config from ~/.config/wt/config.toml Returns Default() if file doesn't exist (no error) Returns error only if file exists but is invalid Environment variables override config file values: - WT_WORKTREE_DIR overrides worktree_dir - WT_REPO_DIR overrides repo_dir
func (*Config) GetAbsWorktreeDir ¶ added in v0.4.0
GetAbsWorktreeDir returns the absolute worktree directory, defaulting to cwd.
func (*Config) RepoScanDir ¶
RepoScanDir returns the directory to scan for repositories. Returns RepoDir if set, otherwise falls back to WorktreeDir.
type Hook ¶
type Hook struct {
Command string `toml:"command"`
Description string `toml:"description"`
On []string `toml:"on"` // commands this hook runs on (empty = only via --hook)
}
Hook defines a post-create hook
type HooksConfig ¶
HooksConfig holds hook-related configuration
type MergeConfig ¶
type MergeConfig struct {
Strategy string `toml:"strategy"` // "squash", "rebase", or "merge"
}
MergeConfig holds merge-related configuration