hooks

package
v1.233.0-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

View Source
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"
)
View Source
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

func Install(ctx context.Context, cfg *schema.GitConfig, names []string, force bool) error

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

func IsKnownGitHookName(name string) bool

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

func Run(cfg *schema.GitConfig, hookName string, hookArgs []string, opts ...RunOption) error

Run executes the configured command for the named hook, forwarding the hook arguments and stdin.

func ShimContent

func ShimContent(hookName string) string

ShimContent returns the generated shim content for a given hook name. The shim finds atmos on PATH.

func ShimContentFor

func ShimContentFor(hookName, atmosPath string) string

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

func Uninstall(ctx context.Context, cfg *schema.GitConfig, names []string) error

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

func ValidateShimName(hookName string) error

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

func WithContext(ctx context.Context) RunOption

WithContext supplies cancellation and deadlines for step execution.

func WithOutputWriters

func WithOutputWriters(stdout, stderr io.Writer) RunOption

WithOutputWriters routes step output to the host streams.

func WithStdin

func WithStdin(stdin io.Reader) RunOption

WithStdin supplies the data Git pipes to the hook, instead of reading the process's standard input. It applies to the hooks Git writes data to: pre-push, pre-receive, post-receive, post-rewrite, reference-transaction, and proc-receive.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL