Documentation
¶
Index ¶
- func ParseEnv(envSlice []string) (map[string]string, error)
- func ParseEnvWithStdin(envSlice []string) (map[string]string, error)
- func RunAll(matches []HookMatch, ctx Context) error
- func RunAllNonFatal(matches []HookMatch, ctx Context, workDir string)
- func RunForEach(matches []HookMatch, ctx Context, workDir string)
- func RunSingle(name string, hook *config.Hook, ctx Context) error
- func SubstitutePlaceholders(command string, ctx Context) string
- type CommandType
- type Context
- type HookMatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseEnv ¶
ParseEnv parses a slice of "key=value" strings into a map. Returns an error if any entry doesn't contain "=".
func ParseEnvWithStdin ¶
ParseEnvWithStdin parses a slice of "key=value" strings into a map. If any value is "-", reads stdin content and assigns it to all such keys. Returns an error if stdin is requested but not piped or empty.
func RunAll ¶
RunAll runs all matched hooks with the given context. Prints "No hooks matched" if matches is empty, otherwise runs each hook. Returns on first error.
func RunAllNonFatal ¶
RunAllNonFatal runs all matched hooks, logging failures as warnings instead of returning errors. Prints "No hooks matched" if matches is empty.
func RunForEach ¶
RunForEach runs all matched hooks for a single item (e.g., one worktree in a batch). Logs failures as warnings with branch context. Does NOT print "no hooks matched".
func RunSingle ¶
RunSingle runs a single hook by name with the given context. Used by `wt hook` to execute a specific hook manually.
func SubstitutePlaceholders ¶
SubstitutePlaceholders replaces {placeholder} with values from Context.
Static placeholders: {path}, {branch}, {repo}, {folder}, {main-repo}, {trigger} Env placeholders (from Context.Env via --arg key=value):
- {key} - value from --arg key=value
- {key:-default} - value with default if key not set
Types ¶
type CommandType ¶
type CommandType string
CommandType identifies which command is triggering the hook
const ( CommandAdd CommandType = "add" CommandPR CommandType = "pr" CommandPrune CommandType = "prune" CommandMerge CommandType = "merge" CommandCd CommandType = "cd" )
type Context ¶
type Context struct {
Path string // absolute worktree path
Branch string // branch name
Repo string // repo name from git origin
Folder string // main repo folder name
MainRepo string // main repo path
Trigger string // command that triggered the hook (add, pr, prune, merge)
Env map[string]string // custom variables from -e key=value flags
DryRun bool // if true, print command instead of executing
}
Context holds the values for placeholder substitution
type HookMatch ¶
HookMatch represents a hook that matched the current command
func SelectHooks ¶
func SelectHooks(cfg config.HooksConfig, hookName string, noHook bool, cmdType CommandType) ([]HookMatch, error)
SelectHooks determines which hooks to run based on config and CLI flags. Returns all matching hooks. If hookName is specified, only that hook runs. Otherwise, all hooks with matching "on" conditions run. Returns nil slice if no hooks should run, error if specified hook doesn't exist.