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 shim scripts into .git/hooks for the named hooks (all configured hooks when names is empty). Existing non-Atmos files are only overwritten when force is set.
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 the generated shim content for a given hook name. The shim finds atmos on PATH.
func ShimContentFor ¶
ShimContentFor returns the generated shim content for a hook, pinned to the atmos binary that installed it. The shim runs that absolute path when it is still executable, so a hook keeps working from an IDE, a GUI Git client, or a cron job whose PATH does not include atmos, and it falls back to PATH when the binary has moved or been removed. An empty atmosPath yields the PATH-only shim.
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.