Documentation
¶
Overview ¶
Package hooks implements Atmos-managed Git hook shims: writing shim scripts into .git/hooks that delegate to `atmos git hooks run`, removing them, and executing the configured command for a named hook.
Index ¶
- Constants
- func Install(ctx context.Context, cfg *schema.GitConfig, names []string, force bool) error
- func IsKnownGitHookName(name string) bool
- func NotConfiguredError(hookName string, hooks map[string]schema.GitHookEntry) error
- func Run(cfg *schema.GitConfig, hookName string, hookArgs []string, opts ...RunOption) error
- func ShimContent(hookName string) string
- func ShimContentFor(hookName, atmosPath string) string
- func SortedNames(m map[string]schema.GitHookEntry) []string
- func Uninstall(ctx context.Context, cfg *schema.GitConfig, names []string) error
- func ValidateHook(name string, entry schema.GitHookEntry) error
- func ValidateShimName(hookName string) error
- type RunOption
Constants ¶
const ( // ArgsEnvVar holds the arguments Git passed to the hook, joined by single spaces. Shell steps // also receive them as positional parameters ($1, "$@"), which keeps arguments with spaces intact. ArgsEnvVar = "ATMOS_GIT_HOOK_ARGS" // StdinEnvVar holds the path of a file with the data Git piped to the hook on standard input. // It is set only for the hooks Git writes data to, for example the refs a pre-push hook is // about to update. The file is removed when the hook ends. StdinEnvVar = "ATMOS_GIT_HOOK_STDIN" )
const ( // ShimMarker is the unique string embedded in generated shim files. // Its presence identifies a file as Atmos-managed. ShimMarker = "# Generated by Atmos. Do not edit." )
Variables ¶
This section is empty.
Functions ¶
func Install ¶
Install writes configured hook shims, preserving custom hooks unless force is set. Forced replacement backs up recognized pre-commit framework hooks first.
func IsKnownGitHookName ¶
IsKnownGitHookName reports whether Git itself invokes a hook with this name.
func NotConfiguredError ¶
func NotConfiguredError(hookName string, hooks map[string]schema.GitHookEntry) error
NotConfiguredError builds an ErrGitHookNotConfigured error with a hint listing configured hook names.
func Run ¶
Run executes the configured command for the named hook, forwarding the hook arguments and stdin.
func ShimContent ¶
ShimContent returns a shim that prefers the current worktree's build and falls back to PATH.
func ShimContentFor ¶
ShimContentFor returns a shim that resolves the current worktree's build at runtime. Development builds are never pinned into the shared hooks directory. Other installations retain their absolute path as the fallback for GUI clients whose PATH omits atmos.
func SortedNames ¶
func SortedNames(m map[string]schema.GitHookEntry) []string
SortedNames returns the configured hook names in ascending order.
func Uninstall ¶
Uninstall removes Atmos-generated shims from .git/hooks. With names, only those hooks are removed; without names, every Atmos shim in the hooks directory is removed, including orphans whose hook is no longer configured (they would otherwise fail every Git operation with "git hook not configured"). User-authored hooks are never deleted; a warning is emitted instead.
func ValidateHook ¶
func ValidateHook(name string, entry schema.GitHookEntry) error
ValidateHook checks a hook's configuration without running it: the command-vs-steps exclusivity rule and, for step hooks, the same validation RunSteps performs before executing. Every error carries the hook name.
func ValidateShimName ¶
ValidateShimName rejects hook names that could escape .git/hooks.
Types ¶
type RunOption ¶
type RunOption func(*runOptions)
RunOption configures a Git hook invocation.
func WithAtmosConfig ¶
func WithAtmosConfig(config *schema.AtmosConfiguration) RunOption
WithAtmosConfig supplies project configuration to step handlers.
func WithContext ¶
WithContext supplies cancellation and deadlines for step execution.
func WithOutputWriters ¶
WithOutputWriters routes step output to the host streams.