Documentation
¶
Overview ¶
Package hook runs lifecycle hooks defined in .treepad.toml.
Index ¶
Constants ¶
This section is empty.
Variables ¶
CutEvents are the events a worktree cut fires, in the order it fires them. PreSync and PostSync are on the list because config sync happens inside the cut, so a caller that only knew about pre_new and post_new would miss half of what a cut can run. Declared beside the constants so a new event is named and listed in the same file.
var TeardownEvents = []Event{PreRemove, PostRemove}
Functions ¶
Types ¶
type CommandRunner ¶
type Config ¶
type Config struct {
PreNew []HookEntry `toml:"pre_new,omitempty"`
PostNew []HookEntry `toml:"post_new,omitempty"`
PreRemove []HookEntry `toml:"pre_remove,omitempty"`
PostRemove []HookEntry `toml:"post_remove,omitempty"`
PreSync []HookEntry `toml:"pre_sync,omitempty"`
PostSync []HookEntry `toml:"post_sync,omitempty"`
PostConfigInit []HookEntry `toml:"post_config_init,omitempty"`
}
Config holds the hook entries for each event.
type Data ¶
type Data struct {
Branch string // raw branch name
WorktreePath string // absolute path of the worktree on disk
Slug string // repo slug
HookType string // event being fired, e.g. "post_new"
OutputDir string // artifact output directory
}
Data is the context available when rendering hook command templates.
type ExecRunner ¶
type ExecRunner struct {
Runner CommandRunner
TTY TTYRunner
}
ExecRunner renders each hook command as a text/template and executes it via sh -c.
type HookEntry ¶
type HookEntry struct {
Command string `toml:"command"`
Only []string `toml:"only"`
Except []string `toml:"except"`
Interactive bool `toml:"interactive,omitempty"`
}
HookEntry is a single hook command with optional branch filters. Only and Except use glob patterns (** crosses path separators). If Only is non-empty the branch must match at least one pattern. If Except is non-empty the branch must not match any pattern. Both conditions apply when both are set.
Interactive gives the command the caller's terminal so it can prompt. Without it the command runs with no TTY and its output is discarded, which makes pickers and confirmation prompts silently fall back to non-interactive mode.
type PostErr ¶
PostErr holds a post-hook failure. The caller should log it as a warning — post failures are non-blocking; the main operation is already complete.
func RunSandwich ¶
func RunSandwich( ctx context.Context, p profile.Profiler, r Runner, cfg Config, pre, post Event, data Data, do func() error, ) (*PostErr, error)
RunSandwich runs pre → do → post. Pre failure aborts and returns an error. Post failure returns a non-nil *PostErr with a nil main error — the caller should log it as a warning. p times the pre and post hook phases as "<event>_hooks" stages.
type TTYRunner ¶
type TTYRunner interface {
Run(ctx context.Context, dir, name string, args ...string) (int, error)
}
TTYRunner executes a command with the caller's terminal inherited, returning the child's exit code. A non-zero exit is reported through the code, not the error. Satisfied by passthrough.Runner.